@zhin.js/cli 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/commands/build.d.ts.map +1 -1
- package/lib/commands/build.js +15 -4
- package/lib/commands/build.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/build.ts +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,YAAY,SA2DrB,CAAC"}
|
package/lib/commands/build.js
CHANGED
|
@@ -7,6 +7,8 @@ export const buildCommand = new Command('build')
|
|
|
7
7
|
.description('构建插件项目')
|
|
8
8
|
.argument('[plugin]', '插件名称(默认构建所有插件)')
|
|
9
9
|
.option('--clean', '清理输出目录', false)
|
|
10
|
+
.option('--production', '生产构建(启用 Tree Shaking)', true)
|
|
11
|
+
.option('--analyze', '分析包体积', false)
|
|
10
12
|
.action(async (pluginName, options) => {
|
|
11
13
|
try {
|
|
12
14
|
const cwd = process.cwd();
|
|
@@ -27,7 +29,7 @@ export const buildCommand = new Command('build')
|
|
|
27
29
|
logger.error(`未找到插件: ${pluginName}`);
|
|
28
30
|
process.exit(1);
|
|
29
31
|
}
|
|
30
|
-
await buildPlugin(pluginPath, pluginName, options
|
|
32
|
+
await buildPlugin(pluginPath, pluginName, options);
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
33
35
|
// 构建所有插件
|
|
@@ -44,7 +46,7 @@ export const buildCommand = new Command('build')
|
|
|
44
46
|
logger.info(`找到 ${validPlugins.length} 个插件,开始构建...`);
|
|
45
47
|
for (const plugin of validPlugins) {
|
|
46
48
|
const pluginPath = path.join(pluginsDir, plugin);
|
|
47
|
-
await buildPlugin(pluginPath, plugin, options
|
|
49
|
+
await buildPlugin(pluginPath, plugin, options);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
}
|
|
@@ -53,11 +55,11 @@ export const buildCommand = new Command('build')
|
|
|
53
55
|
process.exit(1);
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
|
-
async function buildPlugin(pluginPath, pluginName,
|
|
58
|
+
async function buildPlugin(pluginPath, pluginName, options) {
|
|
57
59
|
return new Promise((resolve, reject) => {
|
|
58
60
|
logger.info(`正在构建插件: ${pluginName}...`);
|
|
59
61
|
// 清理输出目录
|
|
60
|
-
if (clean) {
|
|
62
|
+
if (options.clean) {
|
|
61
63
|
const libPath = path.join(pluginPath, 'lib');
|
|
62
64
|
const distPath = path.join(pluginPath, 'dist');
|
|
63
65
|
if (fs.existsSync(libPath)) {
|
|
@@ -69,11 +71,20 @@ async function buildPlugin(pluginPath, pluginName, clean) {
|
|
|
69
71
|
logger.info(`✓ 已清理 ${pluginName}/dist`);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
74
|
+
// 设置环境变量
|
|
75
|
+
const env = {
|
|
76
|
+
...process.env,
|
|
77
|
+
NODE_ENV: options.production ? 'production' : 'development',
|
|
78
|
+
};
|
|
79
|
+
if (options.production) {
|
|
80
|
+
logger.info(`📦 生产构建模式 (启用 Tree Shaking)`);
|
|
81
|
+
}
|
|
72
82
|
// 使用 pnpm build 构建插件
|
|
73
83
|
const child = spawn('pnpm', ['build'], {
|
|
74
84
|
cwd: pluginPath,
|
|
75
85
|
stdio: 'inherit',
|
|
76
86
|
shell: true,
|
|
87
|
+
env,
|
|
77
88
|
});
|
|
78
89
|
child.on('close', (code) => {
|
|
79
90
|
if (code === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,QAAQ,CAAC;KACrB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;KACtC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC;KAClC,MAAM,CAAC,KAAK,EAAE,UAA8B,EAAE,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,QAAQ,CAAC;KACrB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;KACtC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC;KAClC,MAAM,CAAC,cAAc,EAAE,uBAAuB,EAAE,IAAI,CAAC;KACrD,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC;KACnC,MAAM,CAAC,KAAK,EAAE,UAA8B,EAAE,OAAkE,EAAE,EAAE;IACnH,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC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AC;YACvD,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW;IACrC,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAChE,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAEvD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACrD,OAAO,WAAW,CAAC,YAAY,IAAI,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/commands/build.ts
CHANGED
|
@@ -8,7 +8,9 @@ export const buildCommand = new Command('build')
|
|
|
8
8
|
.description('构建插件项目')
|
|
9
9
|
.argument('[plugin]', '插件名称(默认构建所有插件)')
|
|
10
10
|
.option('--clean', '清理输出目录', false)
|
|
11
|
-
.
|
|
11
|
+
.option('--production', '生产构建(启用 Tree Shaking)', true)
|
|
12
|
+
.option('--analyze', '分析包体积', false)
|
|
13
|
+
.action(async (pluginName: string | undefined, options: { clean: boolean; production: boolean; analyze: boolean }) => {
|
|
12
14
|
try {
|
|
13
15
|
const cwd = process.cwd();
|
|
14
16
|
|
|
@@ -34,7 +36,7 @@ export const buildCommand = new Command('build')
|
|
|
34
36
|
process.exit(1);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
await buildPlugin(pluginPath, pluginName, options
|
|
39
|
+
await buildPlugin(pluginPath, pluginName, options);
|
|
38
40
|
} else {
|
|
39
41
|
// 构建所有插件
|
|
40
42
|
const plugins = await fs.readdir(pluginsDir);
|
|
@@ -53,7 +55,7 @@ export const buildCommand = new Command('build')
|
|
|
53
55
|
|
|
54
56
|
for (const plugin of validPlugins) {
|
|
55
57
|
const pluginPath = path.join(pluginsDir, plugin);
|
|
56
|
-
await buildPlugin(pluginPath, plugin, options
|
|
58
|
+
await buildPlugin(pluginPath, plugin, options);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -63,12 +65,12 @@ export const buildCommand = new Command('build')
|
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
async function buildPlugin(pluginPath: string, pluginName: string, clean: boolean): Promise<void> {
|
|
68
|
+
async function buildPlugin(pluginPath: string, pluginName: string, options: { clean: boolean; production: boolean; analyze: boolean }): Promise<void> {
|
|
67
69
|
return new Promise((resolve, reject) => {
|
|
68
70
|
logger.info(`正在构建插件: ${pluginName}...`);
|
|
69
71
|
|
|
70
72
|
// 清理输出目录
|
|
71
|
-
if (clean) {
|
|
73
|
+
if (options.clean) {
|
|
72
74
|
const libPath = path.join(pluginPath, 'lib');
|
|
73
75
|
const distPath = path.join(pluginPath, 'dist');
|
|
74
76
|
|
|
@@ -83,11 +85,22 @@ async function buildPlugin(pluginPath: string, pluginName: string, clean: boolea
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
// 设置环境变量
|
|
89
|
+
const env = {
|
|
90
|
+
...process.env,
|
|
91
|
+
NODE_ENV: options.production ? 'production' : 'development',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (options.production) {
|
|
95
|
+
logger.info(`📦 生产构建模式 (启用 Tree Shaking)`);
|
|
96
|
+
}
|
|
97
|
+
|
|
86
98
|
// 使用 pnpm build 构建插件
|
|
87
99
|
const child = spawn('pnpm', ['build'], {
|
|
88
100
|
cwd: pluginPath,
|
|
89
101
|
stdio: 'inherit',
|
|
90
102
|
shell: true,
|
|
103
|
+
env,
|
|
91
104
|
});
|
|
92
105
|
|
|
93
106
|
child.on('close', (code) => {
|