@eziapp-org/builder 0.0.0-beta.6 → 0.0.0-beta.7
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/dist/src/builder.d.ts +7 -4
- package/dist/src/builder.js +41 -43
- package/package.json +1 -1
package/dist/src/builder.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
type BuildMode = 'debug' | 'release';
|
|
2
2
|
type Platform = 'windows' | 'linux' | 'macos';
|
|
3
3
|
export declare class Builder {
|
|
4
|
-
private
|
|
4
|
+
private viteTsConfigPath;
|
|
5
|
+
private viteJsConfigPath;
|
|
5
6
|
private eziConfigPath;
|
|
6
7
|
private genTempFilePath;
|
|
7
8
|
private outDir;
|
|
@@ -9,15 +10,17 @@ export declare class Builder {
|
|
|
9
10
|
private eziConfig;
|
|
10
11
|
private mode;
|
|
11
12
|
private platform;
|
|
13
|
+
private defaultEziConfig;
|
|
12
14
|
constructor(config: {
|
|
13
|
-
|
|
15
|
+
viteTsConfigPath?: string;
|
|
16
|
+
viteJsConfigPath?: string;
|
|
14
17
|
eziConfigPath?: string;
|
|
18
|
+
genTempFilePath?: string;
|
|
15
19
|
outDir?: string;
|
|
16
20
|
mode?: BuildMode;
|
|
17
21
|
platform?: Platform;
|
|
18
|
-
genTempFilePath?: string;
|
|
19
22
|
});
|
|
20
|
-
|
|
23
|
+
loadConfig(): Promise<void>;
|
|
21
24
|
genAssets(): Promise<void>;
|
|
22
25
|
genIcon(): Promise<void>;
|
|
23
26
|
build(): Promise<void>;
|
package/dist/src/builder.js
CHANGED
|
@@ -55,47 +55,50 @@ const eziDevExePaths = {
|
|
|
55
55
|
};
|
|
56
56
|
class Builder {
|
|
57
57
|
constructor(config) {
|
|
58
|
+
this.defaultEziConfig = {
|
|
59
|
+
application: {
|
|
60
|
+
name: "EziApplication",
|
|
61
|
+
package: "com.ezi.app",
|
|
62
|
+
},
|
|
63
|
+
window: {
|
|
64
|
+
title: "Ezi Application"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
58
67
|
this.mode = config.mode || (0, utils_1.getArg)("--mode") || 'debug';
|
|
59
68
|
this.platform = config.platform || (0, utils_1.getArg)("--platform") || (0, utils_1.getCurrentPlatformName)();
|
|
60
|
-
this.
|
|
69
|
+
this.viteTsConfigPath = path.join(process.cwd(), config.viteTsConfigPath ?? "vite.config.ts");
|
|
70
|
+
this.viteJsConfigPath = path.join(process.cwd(), config.viteJsConfigPath ?? "vite.config.js");
|
|
61
71
|
this.eziConfigPath = path.join(process.cwd(), config.eziConfigPath ?? "ezi.config.ts");
|
|
62
72
|
this.outDir = path.join(process.cwd(), config.outDir ?? "build");
|
|
63
|
-
this.genTempFilePath = path.join(process.cwd(), config.genTempFilePath ?? "
|
|
73
|
+
this.genTempFilePath = path.join(process.cwd(), config.genTempFilePath ?? "node_modules/.eziapp");
|
|
74
|
+
// 确保生成临时文件的目录存在
|
|
75
|
+
// 用于生成打包资源文件和调试时的配置文件
|
|
76
|
+
if (!fs.existsSync(this.genTempFilePath)) {
|
|
77
|
+
fs.mkdirSync(this.genTempFilePath, { recursive: true });
|
|
78
|
+
}
|
|
64
79
|
}
|
|
65
|
-
async
|
|
80
|
+
async loadConfig() {
|
|
66
81
|
// vite config
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
viteConfig =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
82
|
+
if (fs.existsSync(this.viteTsConfigPath)) {
|
|
83
|
+
const mod = await Promise.resolve(`${this.viteTsConfigPath}`).then(s => __importStar(require(s)));
|
|
84
|
+
this.viteConfig = mod.default || mod;
|
|
85
|
+
}
|
|
86
|
+
else if (fs.existsSync(this.viteJsConfigPath)) {
|
|
87
|
+
const mod = await Promise.resolve(`${this.viteJsConfigPath}`).then(s => __importStar(require(s)));
|
|
88
|
+
this.viteConfig = mod.default || mod;
|
|
73
89
|
}
|
|
74
|
-
|
|
75
|
-
console.log(yellow(
|
|
90
|
+
else {
|
|
91
|
+
console.log(yellow(`! no ${path.basename(this.viteTsConfigPath)} found, using default config.`));
|
|
76
92
|
}
|
|
77
|
-
this.viteConfig = viteConfig;
|
|
78
93
|
// ezi config
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
eziConfig =
|
|
82
|
-
if (eziConfig.default) {
|
|
83
|
-
eziConfig = eziConfig.default;
|
|
84
|
-
}
|
|
94
|
+
if (fs.existsSync(this.eziConfigPath)) {
|
|
95
|
+
const mod = await Promise.resolve(`${this.eziConfigPath}`).then(s => __importStar(require(s)));
|
|
96
|
+
this.eziConfig = mod.default || mod;
|
|
85
97
|
}
|
|
86
|
-
|
|
87
|
-
console.log(yellow(
|
|
88
|
-
eziConfig =
|
|
89
|
-
application: {
|
|
90
|
-
name: "EziApplication",
|
|
91
|
-
package: "com.ezi.app",
|
|
92
|
-
},
|
|
93
|
-
window: {
|
|
94
|
-
title: "Ezi Application"
|
|
95
|
-
}
|
|
96
|
-
};
|
|
98
|
+
else {
|
|
99
|
+
console.log(yellow(`! no ${path.basename(this.eziConfigPath)} found, using default config.`));
|
|
100
|
+
this.eziConfig = this.defaultEziConfig;
|
|
97
101
|
}
|
|
98
|
-
this.eziConfig = eziConfig;
|
|
99
102
|
}
|
|
100
103
|
async genAssets() {
|
|
101
104
|
const assetsMatas = {};
|
|
@@ -115,7 +118,7 @@ class Builder {
|
|
|
115
118
|
const filePath = path.join(assetsDir, file);
|
|
116
119
|
const stat = fs.statSync(filePath);
|
|
117
120
|
if (stat.isFile()) {
|
|
118
|
-
const packageName = this.eziConfig?.application?.package ||
|
|
121
|
+
const packageName = this.eziConfig?.application?.package || this.defaultEziConfig.application.package;
|
|
119
122
|
const fileBuffer = await (0, zstd_1.compress)(fs.readFileSync(filePath));
|
|
120
123
|
const assetsId = `https://${packageName}/${file.split(path.sep).join("/")}`;
|
|
121
124
|
const size = fileBuffer.length;
|
|
@@ -136,9 +139,6 @@ class Builder {
|
|
|
136
139
|
const headerBuffer = Buffer.alloc(manifestSizeFlag);
|
|
137
140
|
headerBuffer.writeUInt32LE(manifestSize, 0);
|
|
138
141
|
assetsBinarys.push(headerBuffer);
|
|
139
|
-
if (!fs.existsSync(this.genTempFilePath)) {
|
|
140
|
-
fs.mkdirSync(this.genTempFilePath, { recursive: true });
|
|
141
|
-
}
|
|
142
142
|
fs.writeFileSync(path.join(this.genTempFilePath, 'ezi.assets.binary'), Buffer.concat(assetsBinarys));
|
|
143
143
|
console.log(green("✓ assets generated."));
|
|
144
144
|
}
|
|
@@ -167,14 +167,15 @@ class Builder {
|
|
|
167
167
|
console.error(red(`✗ Unsupported platform: ${this.platform}`));
|
|
168
168
|
process.exit(1);
|
|
169
169
|
}
|
|
170
|
+
// 获取输出目录
|
|
170
171
|
if (!this.eziConfig.application.buildEntry) {
|
|
171
172
|
this.eziConfig.application.buildEntry = this.viteConfig?.build?.outDir || "dist";
|
|
172
173
|
}
|
|
173
|
-
await (0, vite_1.build)(
|
|
174
|
+
await (0, vite_1.build)();
|
|
174
175
|
await this.genAssets();
|
|
175
176
|
await this.genIcon();
|
|
176
177
|
const packagerModule = await Promise.resolve(`${path.join(__dirname, packagerPath)}`).then(s => __importStar(require(s)));
|
|
177
|
-
const PackagerClass = packagerModule.default;
|
|
178
|
+
const PackagerClass = packagerModule.default || packagerModule;
|
|
178
179
|
const packager = new PackagerClass({
|
|
179
180
|
eziConfig: this.eziConfig,
|
|
180
181
|
outDir: this.outDir,
|
|
@@ -204,11 +205,8 @@ class Builder {
|
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
const eziConfigJsonPath = path.join(this.genTempFilePath, "ezi.config.json");
|
|
207
|
-
if (!fs.existsSync(this.genTempFilePath)) {
|
|
208
|
-
fs.mkdirSync(this.genTempFilePath, { recursive: true });
|
|
209
|
-
}
|
|
210
208
|
fs.writeFileSync(eziConfigJsonPath, JSON.stringify(devEziConfig, null, 4), { encoding: "utf-8" });
|
|
211
|
-
const appName = devEziConfig?.application?.name ||
|
|
209
|
+
const appName = devEziConfig?.application?.name || this.defaultEziConfig.application.name;
|
|
212
210
|
const child = (0, child_process_1.spawn)(devExePath, [
|
|
213
211
|
'--configpath',
|
|
214
212
|
eziConfigJsonPath,
|
|
@@ -221,9 +219,9 @@ class Builder {
|
|
|
221
219
|
child.stdout?.on("data", (data) => {
|
|
222
220
|
process.stdout.write((0, utils_1.getCurrentTimeString)() + bold(blue(` [${appName}] `)) + data);
|
|
223
221
|
});
|
|
224
|
-
const srcDir = path.join(process.cwd(), this.viteConfig?.root || "");
|
|
222
|
+
const srcDir = path.join(process.cwd(), this.viteConfig?.root || "").replaceAll("\\", "/");
|
|
225
223
|
child.stderr?.on("data", (data) => {
|
|
226
|
-
const errorMsg = data.toString().
|
|
224
|
+
const errorMsg = data.toString().replaceAll("LOCATION_ORIGIN", srcDir);
|
|
227
225
|
process.stderr.write(red(errorMsg));
|
|
228
226
|
});
|
|
229
227
|
child.on("exit", (code) => {
|
|
@@ -262,7 +260,7 @@ class Builder {
|
|
|
262
260
|
async main() {
|
|
263
261
|
console.log(yellow("! EziApp 正在快速迭代中,当前 API 尚未稳定,请不要用于生产环境。"));
|
|
264
262
|
console.log(yellow("! EziApp is rapidly evolving, the API is not yet stable, please do not use it in production."));
|
|
265
|
-
await this.
|
|
263
|
+
await this.loadConfig();
|
|
266
264
|
switch (this.mode) {
|
|
267
265
|
case 'debug':
|
|
268
266
|
await this.dev();
|