@eziapp-org/builder 0.0.0-beta.1 → 0.0.0-beta.3

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.
@@ -1,3 +1,8 @@
1
+ type Sizes = {
2
+ name: string;
3
+ size: number;
4
+ color?: string;
5
+ }[];
1
6
  declare class windowsPackager {
2
7
  private packagerBinPath;
3
8
  private eziappBinPath;
@@ -11,5 +16,6 @@ declare class windowsPackager {
11
16
  tempDir: string;
12
17
  });
13
18
  package(): Promise<void>;
19
+ printBuildReport(Sizes: Sizes, outAppPath?: string): void;
14
20
  }
15
21
  export default windowsPackager;
@@ -32,14 +32,18 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  const fs = __importStar(require("fs"));
37
40
  const path = __importStar(require("path"));
38
41
  const child_process_1 = require("child_process");
42
+ const chalk_1 = __importDefault(require("chalk"));
39
43
  class windowsPackager {
40
44
  constructor({ eziConfig, outDir, tempDir }) {
41
- this.packagerBinPath = path.join(__dirname, "../../bin/eziapp-packager-windows.exe");
42
- this.eziappBinPath = path.join(__dirname, "../../bin/eziapp-release.exe");
45
+ this.packagerBinPath = path.join(__dirname, "../../bin/eziapp-packager-winx64.exe");
46
+ this.eziappBinPath = path.join(__dirname, "../../bin/eziapp-npm-release-winx64.exe");
43
47
  this.argv = [];
44
48
  this.eziConfig = eziConfig;
45
49
  this.outDir = outDir;
@@ -82,13 +86,97 @@ class windowsPackager {
82
86
  // 开始打包
83
87
  const packagerCmd = `"${this.packagerBinPath}" --update-version true ${this.argv.join(' ')}`;
84
88
  (0, child_process_1.execSync)(packagerCmd, { stdio: 'inherit' });
85
- console.log("Packaging completed:", outAppPath);
89
+ console.log(chalk_1.default.green("Packaging completed:\n" + outAppPath));
86
90
  }
87
91
  catch (error) {
88
92
  console.error(error);
89
93
  fs.unlinkSync(outAppPath);
90
94
  process.exit(1);
91
95
  }
96
+ // Build Report
97
+ const Sizes = [
98
+ {
99
+ name: 'eziapp-core',
100
+ size: fs.statSync(this.eziappBinPath).size
101
+ },
102
+ {
103
+ name: 'fontend-assets',
104
+ size: fs.statSync(path.join(this.tempDir, 'ezi.assets.binary')).size
105
+ },
106
+ {
107
+ name: 'exe-icon',
108
+ size: fs.existsSync(iconPath) ? fs.statSync(iconPath).size : 0
109
+ },
110
+ {
111
+ name: 'extensions',
112
+ size: 0
113
+ }
114
+ ];
115
+ const appRelativePath = path.relative(process.cwd(), outAppPath);
116
+ this.printBuildReport(Sizes, appRelativePath);
117
+ }
118
+ printBuildReport(Sizes, outAppPath) {
119
+ // 由大到小排序
120
+ Sizes.sort((a, b) => b.size - a.size);
121
+ // 随机设置颜色
122
+ const presetColors = [
123
+ '#e63946',
124
+ '#f1a208',
125
+ '#2a9d8f',
126
+ '#118ab2',
127
+ '#9900a7'
128
+ ];
129
+ function assignColors(Sizes) {
130
+ const shuffled = presetColors
131
+ .map(c => ({ c, r: Math.random() }))
132
+ .sort((a, b) => a.r - b.r)
133
+ .map(x => x.c);
134
+ Sizes.forEach((item, idx) => {
135
+ item.color = shuffled[idx % shuffled.length];
136
+ });
137
+ }
138
+ assignColors(Sizes);
139
+ const totalSize = Sizes.reduce((sum, m) => sum + m.size, 0);
140
+ const puts = (str) => {
141
+ process.stdout.write(str);
142
+ };
143
+ // 打印标题
144
+ puts(chalk_1.default.bold('\n═ Build Report ════════════════════\n\n'));
145
+ puts('Platform: Windows x64\n');
146
+ puts('Build Date: ' + new Date().toLocaleString() + '\n');
147
+ puts('Status: ' + chalk_1.default.green.bold('0 error(s), 0 warning(s)\n'));
148
+ if (outAppPath) {
149
+ puts(`Output: ` + chalk_1.default.bold(outAppPath) + `\n`);
150
+ }
151
+ // 绘制占比进度条
152
+ const barLength = 35;
153
+ puts(chalk_1.default.bold('─'.repeat(barLength)));
154
+ puts('\n');
155
+ Sizes.forEach(m => {
156
+ const percent = m.size / totalSize;
157
+ const blocks = Math.round(percent * barLength);
158
+ puts(chalk_1.default.hex(m.color || '#ffffff').bold('█'.repeat(blocks)));
159
+ });
160
+ puts('\n');
161
+ // 打印模块表格
162
+ const header = '─ Module '.padEnd(19, '─') +
163
+ ' Size '.padEnd(12, '─') +
164
+ ' Pct ';
165
+ puts(chalk_1.default.bold(header) + '\n');
166
+ Sizes.forEach(m => {
167
+ const percent = ((m.size / totalSize) * 100).toFixed(0) + '%';
168
+ const sizeKB = (m.size / 1024).toFixed(0) + 'KB';
169
+ const line = chalk_1.default.hex(m.color || '#ffffff').bold(('■ ' + m.name).padEnd(20)) +
170
+ sizeKB.padEnd(12) +
171
+ percent;
172
+ puts(line + '\n');
173
+ });
174
+ puts(chalk_1.default.bold('─'.repeat(barLength)));
175
+ puts('\n');
176
+ puts((`Total size: `) + chalk_1.default.bold(`${(totalSize / 1024).toFixed(0)}KB\n`));
177
+ puts(`UPX: ` + chalk_1.default.bold('disabled') + ` (↓ 0%)\n`);
178
+ puts(chalk_1.default.bold('─'.repeat(barLength)));
179
+ puts('\n');
92
180
  }
93
181
  }
94
182
  exports.default = windowsPackager;
@@ -38,7 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Builder = void 0;
40
40
  const child_process_1 = require("child_process");
41
- const colorf_1 = require("./colorf");
42
41
  const utils_1 = require("./utils");
43
42
  const fs = __importStar(require("fs"));
44
43
  const path = __importStar(require("path"));
@@ -46,12 +45,14 @@ const vite_1 = require("vite");
46
45
  const zstd_1 = require("@mongodb-js/zstd");
47
46
  const sharp_1 = __importDefault(require("sharp"));
48
47
  const png_to_ico_1 = __importDefault(require("png-to-ico"));
48
+ const chalk_1 = __importDefault(require("chalk"));
49
+ const { red, green, yellow, blue, bold } = chalk_1.default;
49
50
  const packagers = {
50
51
  windows: "../packagers/windows/main"
51
52
  };
52
53
  class Builder {
53
54
  constructor(config) {
54
- this.eziDevExePath = path.join(__dirname, "../bin/eziapp-dev.exe");
55
+ this.eziDevExePath = path.join(__dirname, "../bin/eziapp-npm-dev-winx64.exe");
55
56
  this.mode = config.mode || (0, utils_1.getArg)("--mode") || 'debug';
56
57
  this.platform = config.platform || (0, utils_1.getArg)("--platform") || (0, utils_1.getCurrentPlatformName)();
57
58
  this.viteConfigPath = path.join(process.cwd(), config.viteConfigPath ?? "vite.config.js");
@@ -69,7 +70,7 @@ class Builder {
69
70
  }
70
71
  }
71
72
  catch (e) {
72
- console.log((0, colorf_1.yellow)("! no vite.config.ts found, using default config."));
73
+ console.log(yellow("! no vite.config.js found, using default config."));
73
74
  }
74
75
  this.viteConfig = viteConfig;
75
76
  // ezi config
@@ -81,7 +82,7 @@ class Builder {
81
82
  }
82
83
  }
83
84
  catch (e) {
84
- console.log((0, colorf_1.yellow)("! no ezi.config.ts found, using default config."));
85
+ console.log(yellow("! no ezi.config.ts found, using default config."));
85
86
  eziConfig = {
86
87
  application: {
87
88
  name: "EziApplication",
@@ -137,7 +138,7 @@ class Builder {
137
138
  fs.mkdirSync(this.genTempFilePath, { recursive: true });
138
139
  }
139
140
  fs.writeFileSync(path.join(this.genTempFilePath, 'ezi.assets.binary'), Buffer.concat(assetsBinarys));
140
- console.log((0, colorf_1.green)("✓ assets generated."));
141
+ console.log(green("✓ assets generated."));
141
142
  }
142
143
  async genIcon() {
143
144
  const iconPath = "public/" + this.eziConfig.application.icon;
@@ -151,7 +152,7 @@ class Builder {
151
152
  .toBuffer();
152
153
  const icoBuffer = await (0, png_to_ico_1.default)(resizedPngBuffer);
153
154
  fs.writeFileSync(path.join(this.genTempFilePath, 'eziapp.ico'), icoBuffer);
154
- console.log((0, colorf_1.green)("✓ icon generated."));
155
+ console.log(green("✓ icon generated."));
155
156
  }
156
157
  catch (err) {
157
158
  console.error('Error generating icon:', err);
@@ -161,7 +162,7 @@ class Builder {
161
162
  async build() {
162
163
  const packagerPath = packagers[this.platform];
163
164
  if (!packagerPath) {
164
- console.error((0, colorf_1.red)(`✗ Unsupported platform: ${this.platform}`));
165
+ console.error(red(`✗ Unsupported platform: ${this.platform}`));
165
166
  process.exit(1);
166
167
  }
167
168
  if (!this.eziConfig.application.buildEntry) {
@@ -178,7 +179,6 @@ class Builder {
178
179
  tempDir: this.genTempFilePath,
179
180
  });
180
181
  await packager.package();
181
- console.log((0, colorf_1.green)("✓ build completed."));
182
182
  }
183
183
  async dev() {
184
184
  const startTime = Date.now();
@@ -212,15 +212,15 @@ class Builder {
212
212
  windowsHide: false
213
213
  });
214
214
  child.stdout?.on("data", (data) => {
215
- process.stdout.write((0, utils_1.getCurrentTimeString)() + (0, colorf_1.bold)((0, colorf_1.blue)(` [${appName}] `)) + data);
215
+ process.stdout.write((0, utils_1.getCurrentTimeString)() + bold(blue(` [${appName}] `)) + data);
216
216
  });
217
217
  const srcDir = path.join(process.cwd(), this.viteConfig?.root || "");
218
218
  child.stderr?.on("data", (data) => {
219
219
  const errorMsg = data.toString().replace("LOCATION_ORIGIN", srcDir.replaceAll("\\", "/"));
220
- process.stderr.write((0, colorf_1.red)(errorMsg));
220
+ process.stderr.write(red(errorMsg));
221
221
  });
222
222
  child.on("exit", (code) => {
223
- console.log((0, utils_1.getCurrentTimeString)() + (0, colorf_1.bold)((0, colorf_1.blue)(` [${appName}] `)) + (0, colorf_1.yellow)(`process [pid:${child.pid}] exited with code ${code ?? 0}.`));
223
+ console.log((0, utils_1.getCurrentTimeString)() + bold(blue(` [${appName}] `)) + yellow(`process [pid:${child.pid}] exited with code ${code ?? 0}.`));
224
224
  process.exit(0);
225
225
  });
226
226
  function printBoxedMessage(lines) {
@@ -235,12 +235,12 @@ class Builder {
235
235
  }
236
236
  const viteVersion = require("vite/package.json").version;
237
237
  printBoxedMessage([
238
- `${(0, colorf_1.bold)((0, colorf_1.green)('VITE')) + (0, colorf_1.green)(' v' + viteVersion)} ready in ${(0, colorf_1.bold)((Date.now() - startTime).toString())} ms`,
238
+ `${bold(green('VITE')) + green(' v' + viteVersion)} ready in ${bold((Date.now() - startTime).toString())} ms`,
239
239
  ``,
240
- ` ${(0, colorf_1.green)('➜')} ${(0, colorf_1.bold)('devEntry')}: ${(0, colorf_1.blue)((0, colorf_1.bold)(devEziConfig.application.devEntry))}`,
241
- ` ${(0, colorf_1.green)("➜")} ${(0, colorf_1.bold)("EziApp")}: ${(0, colorf_1.bold)((0, colorf_1.blue)(appName))} ${(0, colorf_1.green)("running")} [pid:${(0, colorf_1.bold)("" + child.pid)}]`,
242
- ` ${(0, colorf_1.green)("➜")} ${(0, colorf_1.bold)("Package")}: ${(0, colorf_1.green)(devEziConfig?.application?.package ?? "com.ezi.app")}`,
243
- ` ${(0, colorf_1.green)("➜")} ${(0, colorf_1.bold)("Started")}: ${(0, colorf_1.blue)(new Date().toLocaleString())}`,
240
+ ` ${green('➜')} ${bold('devEntry')}: ${blue(bold(devEziConfig.application.devEntry))}`,
241
+ ` ${green("➜")} ${bold("EziApp")}: ${bold(blue(appName))} ${green("running")} [pid:${bold("" + child.pid)}]`,
242
+ ` ${green("➜")} ${bold("Package")}: ${green(devEziConfig?.application?.package ?? "com.ezi.app")}`,
243
+ ` ${green("➜")} ${bold("Started")}: ${blue(new Date().toLocaleString())}`,
244
244
  ]);
245
245
  const cleanup = () => {
246
246
  if (!child.killed) {
@@ -253,8 +253,8 @@ class Builder {
253
253
  process.on("exit", cleanup);
254
254
  }
255
255
  async main() {
256
- console.log((0, colorf_1.yellow)("! EziApp 正在快速迭代中,当前 API 尚未稳定,请不要用于生产环境。"));
257
- console.log((0, colorf_1.yellow)("! EziApp is rapidly evolving, the API is not yet stable, please do not use it in production."));
256
+ console.log(yellow("! EziApp 正在快速迭代中,当前 API 尚未稳定,请不要用于生产环境。"));
257
+ console.log(yellow("! EziApp is rapidly evolving, the API is not yet stable, please do not use it in production."));
258
258
  await this.LoadConfig();
259
259
  switch (this.mode) {
260
260
  case 'debug':
@@ -264,7 +264,7 @@ class Builder {
264
264
  await this.build();
265
265
  break;
266
266
  default:
267
- console.error((0, colorf_1.red)(`✗ Unsupported build mode: ${this.mode}`));
267
+ console.error(red(`✗ Unsupported build mode: ${this.mode}`));
268
268
  process.exit(1);
269
269
  }
270
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eziapp-org/builder",
3
- "version": "0.0.0-beta.1",
3
+ "version": "0.0.0-beta.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@mongodb-js/zstd": "^7.0.0",
30
+ "chalk": "^5.6.2",
30
31
  "png-to-ico": "^3.0.1",
31
32
  "sharp": "^0.34.5"
32
33
  }
33
- }
34
+ }
Binary file
@@ -1,5 +0,0 @@
1
- export declare function bold(text: string): string;
2
- export declare function blue(text: string): string;
3
- export declare function green(text: string): string;
4
- export declare function red(text: string): string;
5
- export declare function yellow(text: string): string;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bold = bold;
4
- exports.blue = blue;
5
- exports.green = green;
6
- exports.red = red;
7
- exports.yellow = yellow;
8
- function bold(text) {
9
- return `\x1b[1m${text}\x1b[0m`;
10
- }
11
- function blue(text) {
12
- return `\x1b[34m${text}\x1b[0m`;
13
- }
14
- function green(text) {
15
- return `\x1b[32m${text}\x1b[0m`;
16
- }
17
- function red(text) {
18
- return `\x1b[31m${text}\x1b[0m`;
19
- }
20
- function yellow(text) {
21
- return `\x1b[33m${text}\x1b[0m`;
22
- }