-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathbuild.ts
More file actions
37 lines (31 loc) · 1.01 KB
/
build.ts
File metadata and controls
37 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { readFileSync, writeFileSync } from 'fs';
import dts from 'bun-plugin-dts';
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
const VERSION = process.env.VERSION ?? pkg.version;
const OUT = 'dist/mmx.mjs';
const SDK_OUT = 'dist/sdk.mjs';
const DEV_BUILD = process.argv.includes('--dev');
await Bun.build({
entrypoints: ['src/main.ts'],
outdir: 'dist',
naming: 'mmx.mjs',
target: 'node',
minify: !DEV_BUILD,
external: ['undici'],
define: { 'process.env.CLI_VERSION': JSON.stringify(VERSION) },
});
const content = readFileSync(OUT);
writeFileSync(OUT, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), content]));
const size = (content.length / 1024).toFixed(0);
console.log(`dist/mmx.mjs ${size}KB`);
await Bun.build({
entrypoints: ['src/sdk/index.ts'],
outdir: 'dist',
naming: 'sdk.mjs',
target: 'node',
minify: false,
plugins: [dts()],
});
const sdkContent = readFileSync(SDK_OUT);
const sdkSize = (sdkContent.length / 1024).toFixed(0);
console.log(`dist/sdk.mjs ${sdkSize}KB`);