-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
executable file
·99 lines (90 loc) · 2.87 KB
/
Copy pathbuild.ts
File metadata and controls
executable file
·99 lines (90 loc) · 2.87 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env -S bun --bun
import fs from 'node:fs';
import path from 'node:path';
import type { UserConfig as TsDownUserConfig } from 'tsdown';
import * as tsdown from 'tsdown';
import { cli, command, flag } from '@kjanat/dreamcli';
import site from './demo/index.html';
type TsDownLogLevel = NonNullable<TsDownUserConfig['logLevel']>;
const logLevels = ['silent', 'error', 'warn', 'info'] satisfies readonly [
TsDownLogLevel,
...TsDownLogLevel[],
];
const getHerDoneBitch = command('build')
.description('Build the project.')
.flag('watch', flag.boolean().alias('w').env('WATCH'))
.flag('log-level', flag.enum(logLevels).alias('logLevel', { hidden: true }).alias('l').default('info'))
.flag('out-dir', flag.string().alias('outdir', { hidden: true }).alias('o').default('dist').describe(`directory relative to ${import.meta.file}`))
.flag('clean', flag.boolean().alias('c').default(true).describe('clean the output directory before building'))
.derive(async ({ flags }) => {
const outdir = path.join(import.meta.dir, flags['out-dir']);
const browserOutDir = path.join(outdir, 'browser');
const binOutDir = path.join(outdir, 'bin');
const siteOutDir = path.join(outdir, 'site');
if (flags.clean) await Bun.$`rm -rf ${outdir}`.cwd(import.meta.dir);
fs.mkdirSync(outdir, { recursive: true });
const tsdownBuildDefaults = {
clean: false,
dts: true,
exports: false,
format: 'es',
unbundle: false,
minify: true,
outDir: flags['out-dir'],
watch: flags.watch,
logLevel: flags['log-level'],
} satisfies TsDownUserConfig;
return { outdir: flags['out-dir'], browserOutDir, binOutDir, siteOutDir, tsdownBuildDefaults };
})
.derive(({ flags, ctx }) => {
const bunFunction = flags.watch
? Bun.serve({
routes: { '/': site },
development: {
hmr: true,
console: true,
},
})
: Bun.build({
entrypoints: ['demo/index.html'],
outdir: ctx.siteOutDir,
compile: true,
minify: true,
target: 'browser',
});
return { bunFunction };
})
.action(async ({ ctx }) => {
await Promise.all([
tsdown.build({
...ctx.tsdownBuildDefaults,
entry: 'src/index.ts',
dts: { entry: ['src/*.ts', '!src/main.ts', '!src/browser.ts'] },
platform: 'node',
}),
tsdown.build({
...ctx.tsdownBuildDefaults,
entry: { cli: 'src/main.ts' },
dts: false,
// exports: { bin: { 'github-up': './src/main.ts' } },
platform: 'node',
outDir: ctx.binOutDir,
}),
tsdown.build({
...ctx.tsdownBuildDefaults,
entry: { browser: 'src/browser.ts' },
dts: { entry: ['src/browser.ts'] },
// deps: { alwaysBundle: ['statuspage.io'], neverBundle: ['@kjanat/dreamcli'] },
platform: 'browser',
outDir: ctx.browserOutDir,
}),
ctx.bunFunction,
]);
});
void cli('build')
.default(getHerDoneBitch)
.manifest({ from: import.meta.url })
.links()
.run({
help: { width: process.stdout.columns },
});