@next2d/builder 0.0.3 → 0.0.5
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/index.d.ts +21 -2
- package/dist/index.js +106 -61
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,16 @@ declare let $buildDir: string;
|
|
|
40
40
|
* @private
|
|
41
41
|
*/
|
|
42
42
|
declare let $outDir: string;
|
|
43
|
+
/**
|
|
44
|
+
* @type {string}
|
|
45
|
+
* @constant
|
|
46
|
+
*/
|
|
47
|
+
declare const CAPACITOR_CONFIG_NAME: string;
|
|
48
|
+
/**
|
|
49
|
+
* @type {string}
|
|
50
|
+
* @constant
|
|
51
|
+
*/
|
|
52
|
+
declare const ELECTRON_CONFIG_NAME: string;
|
|
43
53
|
/**
|
|
44
54
|
* @return {Promise}
|
|
45
55
|
* @method
|
|
@@ -104,11 +114,11 @@ declare const generateNativeProject: () => Promise<void>;
|
|
|
104
114
|
* @description iOS用アプリの書き出し関数
|
|
105
115
|
* Export function for iOS apps
|
|
106
116
|
*
|
|
107
|
-
* @return {
|
|
117
|
+
* @return {Promise}
|
|
108
118
|
* @method
|
|
109
119
|
* @public
|
|
110
120
|
*/
|
|
111
|
-
declare const runNative: () => void
|
|
121
|
+
declare const runNative: () => Promise<void>;
|
|
112
122
|
/**
|
|
113
123
|
* @description ビルドの実行関数
|
|
114
124
|
* Build Execution Functions
|
|
@@ -118,3 +128,12 @@ declare const runNative: () => void;
|
|
|
118
128
|
* @public
|
|
119
129
|
*/
|
|
120
130
|
declare const build: () => void;
|
|
131
|
+
/**
|
|
132
|
+
* @description 実行関数
|
|
133
|
+
* function execution
|
|
134
|
+
*
|
|
135
|
+
* @return {Promise}
|
|
136
|
+
* @method
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
declare const execute: () => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,16 @@ let $outDir = "dist";
|
|
|
90
90
|
// update env variables
|
|
91
91
|
process.env.NEXT2D_EBUILD_ENVIRONMENT = environment;
|
|
92
92
|
process.env.NEXT2D_TARGET_PLATFORM = platform;
|
|
93
|
+
/**
|
|
94
|
+
* @type {string}
|
|
95
|
+
* @constant
|
|
96
|
+
*/
|
|
97
|
+
const CAPACITOR_CONFIG_NAME = "capacitor.config.json";
|
|
98
|
+
/**
|
|
99
|
+
* @type {string}
|
|
100
|
+
* @constant
|
|
101
|
+
*/
|
|
102
|
+
const ELECTRON_CONFIG_NAME = "electron.build.json";
|
|
93
103
|
/**
|
|
94
104
|
* @return {Promise}
|
|
95
105
|
* @method
|
|
@@ -112,7 +122,8 @@ const loadConfig = () => {
|
|
|
112
122
|
$buildDir = `${process.cwd()}/${$outDir}/${platformDir}/${environment}`;
|
|
113
123
|
if (!fs.existsSync(`${$buildDir}`)) {
|
|
114
124
|
fs.mkdirSync(`${$buildDir}`, { "recursive": true });
|
|
115
|
-
console.log(pc.green(`
|
|
125
|
+
console.log(pc.green(`Create build directory: ${$buildDir}`));
|
|
126
|
+
console.log();
|
|
116
127
|
}
|
|
117
128
|
resolve();
|
|
118
129
|
});
|
|
@@ -126,19 +137,19 @@ const loadConfig = () => {
|
|
|
126
137
|
* @public
|
|
127
138
|
*/
|
|
128
139
|
const buildWeb = () => {
|
|
129
|
-
return new Promise((resolve) => {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
130
141
|
const command = `${process.cwd()}/node_modules/.bin/vite`;
|
|
131
142
|
const stream = cp.spawn(command, [
|
|
132
143
|
"--outDir",
|
|
133
144
|
$buildDir,
|
|
134
145
|
"build"
|
|
135
|
-
]);
|
|
136
|
-
stream.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
console.log(pc.green("`HTML` and `JavaScript` files are written out."));
|
|
146
|
+
], { "stdio": "inherit" });
|
|
147
|
+
stream.on("close", (code) => {
|
|
148
|
+
if (code !== 0) {
|
|
149
|
+
reject("Export of `HTML` and `JavaScript` failed.");
|
|
150
|
+
}
|
|
141
151
|
console.log();
|
|
152
|
+
console.log(pc.green("`HTML` and `JavaScript` files are written out."));
|
|
142
153
|
resolve();
|
|
143
154
|
});
|
|
144
155
|
});
|
|
@@ -153,16 +164,16 @@ const buildWeb = () => {
|
|
|
153
164
|
*/
|
|
154
165
|
const generateElectronConfig = () => {
|
|
155
166
|
let config = {};
|
|
156
|
-
const configPath = `${process.cwd()}
|
|
167
|
+
const configPath = `${process.cwd()}/${ELECTRON_CONFIG_NAME}`;
|
|
157
168
|
if (!fs.existsSync(configPath)) {
|
|
158
|
-
console.error(pc.red(
|
|
169
|
+
console.error(pc.red(`The file \`${ELECTRON_CONFIG_NAME}\` could not be found.`));
|
|
159
170
|
process.exit(1);
|
|
160
171
|
}
|
|
161
172
|
config = Object.assign(config, JSON.parse(fs.readFileSync(configPath, { "encoding": "utf8" })));
|
|
162
173
|
if (!config.appId) {
|
|
163
174
|
console.log();
|
|
164
175
|
console.log(pc.red("`appId` is not set."));
|
|
165
|
-
console.log(
|
|
176
|
+
console.log(`Please set \`appId\` in \`${ELECTRON_CONFIG_NAME}\`.`);
|
|
166
177
|
console.log();
|
|
167
178
|
process.exit(1);
|
|
168
179
|
}
|
|
@@ -195,6 +206,20 @@ const generateElectronConfig = () => {
|
|
|
195
206
|
delete config.linux;
|
|
196
207
|
}
|
|
197
208
|
break;
|
|
209
|
+
case "linux":
|
|
210
|
+
case "steam:linux":
|
|
211
|
+
if (!("linux" in config)) {
|
|
212
|
+
config.linux = {
|
|
213
|
+
"target": "deb"
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
if ("win" in config) {
|
|
217
|
+
delete config.win;
|
|
218
|
+
}
|
|
219
|
+
if ("mac" in config) {
|
|
220
|
+
delete config.mac;
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
198
223
|
default:
|
|
199
224
|
break;
|
|
200
225
|
}
|
|
@@ -206,7 +231,11 @@ const generateElectronConfig = () => {
|
|
|
206
231
|
if (config.directories.output.slice(-1) !== "/") {
|
|
207
232
|
config.directories.output += "/";
|
|
208
233
|
}
|
|
209
|
-
config
|
|
234
|
+
if (!("files" in config)) {
|
|
235
|
+
config.files = [];
|
|
236
|
+
}
|
|
237
|
+
config.files.push(`${$outDir}/${platformDir}/${environment}/`);
|
|
238
|
+
config.directories.output += `${platformDir}/build`;
|
|
210
239
|
return config;
|
|
211
240
|
};
|
|
212
241
|
/**
|
|
@@ -261,16 +290,16 @@ const buildSteam = () => {
|
|
|
261
290
|
if (preview) {
|
|
262
291
|
const stream = cp.spawn(`${process.cwd()}/node_modules/.bin/electron`, [
|
|
263
292
|
`${process.cwd()}/electron.js`
|
|
264
|
-
]);
|
|
265
|
-
stream.on("
|
|
266
|
-
|
|
267
|
-
// reset
|
|
268
|
-
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
269
|
-
});
|
|
270
|
-
stream.on("disconnect", () => {
|
|
293
|
+
], { "stdio": "inherit" });
|
|
294
|
+
stream.on("close", (code) => {
|
|
295
|
+
console.log("preview close.");
|
|
271
296
|
unlinkElectronIndexPath();
|
|
272
297
|
// reset
|
|
273
298
|
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
299
|
+
if (code !== 0) {
|
|
300
|
+
console.log(pc.red("Failed to start Electron."));
|
|
301
|
+
console.log();
|
|
302
|
+
}
|
|
274
303
|
});
|
|
275
304
|
}
|
|
276
305
|
else {
|
|
@@ -280,6 +309,7 @@ const buildSteam = () => {
|
|
|
280
309
|
*/
|
|
281
310
|
const config = generateElectronConfig();
|
|
282
311
|
console.log(pc.green("Start the `Electron` build process."));
|
|
312
|
+
console.log();
|
|
283
313
|
const buildObject = {
|
|
284
314
|
"projectDir": process.cwd(),
|
|
285
315
|
"config": config
|
|
@@ -297,14 +327,26 @@ const buildSteam = () => {
|
|
|
297
327
|
case "steam:linux":
|
|
298
328
|
buildObject.targets = electronBuilder.Platform.LINUX.createTarget();
|
|
299
329
|
break;
|
|
330
|
+
default:
|
|
331
|
+
console.log(pc.red("There is an error in the export platform settings."));
|
|
332
|
+
console.log();
|
|
333
|
+
break;
|
|
300
334
|
}
|
|
301
335
|
electronBuilder
|
|
302
336
|
.build(buildObject)
|
|
303
337
|
.then(() => {
|
|
304
338
|
unlinkElectronIndexPath();
|
|
305
|
-
console.log(pc.green("Finished building `Electron`."));
|
|
306
339
|
// reset
|
|
307
340
|
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
341
|
+
console.log(pc.green(`Finished building \`Electron\` for ${platform}.`));
|
|
342
|
+
console.log();
|
|
343
|
+
})
|
|
344
|
+
.catch((error) => {
|
|
345
|
+
unlinkElectronIndexPath();
|
|
346
|
+
// reset
|
|
347
|
+
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
348
|
+
console.log(pc.red("Export of Electron failed."));
|
|
349
|
+
console.log(pc.red(error));
|
|
308
350
|
});
|
|
309
351
|
}
|
|
310
352
|
};
|
|
@@ -317,22 +359,18 @@ const buildSteam = () => {
|
|
|
317
359
|
* @public
|
|
318
360
|
*/
|
|
319
361
|
const generateNativeProject = () => {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const stream = cp.spawn("npx", [
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
});
|
|
333
|
-
stream.on("exit", () => {
|
|
334
|
-
if (errorCheck) {
|
|
335
|
-
process.exit(1);
|
|
362
|
+
return new Promise((resolve, reject) => {
|
|
363
|
+
if (fs.existsSync(`${process.cwd()}/${platform}`)) {
|
|
364
|
+
return resolve();
|
|
365
|
+
}
|
|
366
|
+
const stream = cp.spawn("npx", [
|
|
367
|
+
"cap",
|
|
368
|
+
"add",
|
|
369
|
+
platform
|
|
370
|
+
], { "stdio": "inherit" });
|
|
371
|
+
stream.on("close", (code) => {
|
|
372
|
+
if (code !== 0) {
|
|
373
|
+
reject(`Failed generated ${platform} project.`);
|
|
336
374
|
}
|
|
337
375
|
console.log(pc.green(`Successfully generated ${platform} project.`));
|
|
338
376
|
console.log();
|
|
@@ -344,26 +382,28 @@ const generateNativeProject = () => {
|
|
|
344
382
|
* @description iOS用アプリの書き出し関数
|
|
345
383
|
* Export function for iOS apps
|
|
346
384
|
*
|
|
347
|
-
* @return {
|
|
385
|
+
* @return {Promise}
|
|
348
386
|
* @method
|
|
349
387
|
* @public
|
|
350
388
|
*/
|
|
351
|
-
const runNative = () => {
|
|
352
|
-
generateNativeProject()
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
389
|
+
const runNative = async () => {
|
|
390
|
+
await generateNativeProject();
|
|
391
|
+
/**
|
|
392
|
+
* Capacitorの書き出しに必要な設定を生成
|
|
393
|
+
* Generate settings necessary for exporting Capacitor
|
|
394
|
+
*/
|
|
395
|
+
const config = JSON.parse(fs.readFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, { "encoding": "utf8" }));
|
|
396
|
+
config.webDir = `${$outDir}/${platformDir}/${environment}/`;
|
|
397
|
+
fs.writeFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, JSON.stringify(config, null, 2));
|
|
398
|
+
/**
|
|
399
|
+
* 引数をcapacitorに合わせて書き換え
|
|
400
|
+
* Rewrite arguments to match capacitor
|
|
401
|
+
*/
|
|
402
|
+
const nodePath = process.argv[0];
|
|
403
|
+
const filePath = process.argv[1];
|
|
404
|
+
process.argv = [nodePath, filePath, "run", platform];
|
|
405
|
+
// run simulator
|
|
406
|
+
cli.run();
|
|
367
407
|
};
|
|
368
408
|
/**
|
|
369
409
|
* @description ビルドの実行関数
|
|
@@ -384,29 +424,34 @@ const build = () => {
|
|
|
384
424
|
buildSteam();
|
|
385
425
|
break;
|
|
386
426
|
case "ios":
|
|
387
|
-
if (preview) {
|
|
388
|
-
runNative();
|
|
389
|
-
}
|
|
390
|
-
break;
|
|
391
427
|
case "android":
|
|
392
428
|
if (preview) {
|
|
393
429
|
runNative();
|
|
394
430
|
}
|
|
395
431
|
break;
|
|
396
432
|
case "web":
|
|
397
|
-
console.log(
|
|
433
|
+
console.log();
|
|
398
434
|
break;
|
|
399
435
|
default:
|
|
400
436
|
echoHelp();
|
|
401
437
|
break;
|
|
402
438
|
}
|
|
403
439
|
};
|
|
404
|
-
|
|
405
|
-
|
|
440
|
+
/**
|
|
441
|
+
* @description 実行関数
|
|
442
|
+
* function execution
|
|
443
|
+
*
|
|
444
|
+
* @return {Promise}
|
|
445
|
+
* @method
|
|
446
|
+
* @public
|
|
447
|
+
*/
|
|
448
|
+
const execute = async () => {
|
|
449
|
+
await loadConfig();
|
|
406
450
|
buildWeb()
|
|
407
451
|
.then(build)
|
|
408
452
|
.catch((error) => {
|
|
409
453
|
console.log(pc.red(error));
|
|
410
454
|
process.exit(1);
|
|
411
455
|
});
|
|
412
|
-
}
|
|
456
|
+
};
|
|
457
|
+
execute();
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Multi-platform builder for Next2d Framework, supporting export to various platforms such as macOS, Windows, iOS, Android and Web(HTML)",
|
|
5
5
|
"author": "Toshiyuki Ienaga <ienaga@next2d.app>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
7
|
"main": "dist/index.js",
|
|
9
8
|
"types": "dist/index.d.ts",
|
|
10
9
|
"homepage": "https://next2d.app",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"dependencies": {
|
|
37
36
|
"@capacitor/cli": "^5.5.1",
|
|
38
37
|
"@types/node": "^20.9.0",
|
|
39
|
-
"electron": "^27.0.
|
|
38
|
+
"electron": "^27.0.4",
|
|
40
39
|
"electron-builder": "^24.6.4",
|
|
41
40
|
"picocolors": "^1.0.0",
|
|
42
41
|
"vite": "^4.5.0"
|