-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ts
74 lines (68 loc) · 1.85 KB
/
build.ts
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
import { Command, Flags } from '@oclif/core';
import chalk from 'chalk';
import { Listr } from 'listr2';
import { exec } from '../../shell.js';
import { checkPluginPackageInfo, loadPackageInfo } from '../../package.js';
interface Ctx {
pckg?: unknown;
}
export default class Build extends Command {
static summary = 'Build package';
static description = 'Build package code for distribution using microbundle';
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = {
check: Flags.boolean({
summary: 'Check package info',
description: 'Check for required package.json fields before bundling. Disable using --no-check.',
required: false,
default: true,
allowNo: true
})
};
async run(): Promise<void> {
const { flags } = await this.parse(Build);
const ctx: Ctx = {};
await new Listr(
[
{
title: 'Load package info',
task: async (ctx) => {
ctx.pckg = await loadPackageInfo();
}
},
{
title: 'Check package info',
enabled: () => flags.check,
task: async (ctx) => {
const { errors } = checkPluginPackageInfo(ctx.pckg);
if (errors?.length) {
throw new Error(errors.join('\n'));
}
}
},
{
title: 'Bundle package',
task: async (ctx, task) => {
// @ts-ignore
task.title = chalk`Bundle package {magenta ${ctx.pckg?.name}}`;
return task.newListr(() => [
{
title: 'Create module bundle',
task: async () => {
exec('BROWSERSLIST_ENV=modern npx microbundle -f modern,esm,cjs --css inline');
}
},
{
title: 'Create standalone bundle',
task: async () => {
exec('BROWSERSLIST_ENV=production npx microbundle -f umd --css inline --external none --define process.env.NODE_ENV=production');
}
}
]);
}
}
],
{ ctx }
).run();
}
}