@next2d/builder 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -16,8 +16,9 @@ Multi-platform builder for Next2D Framework, export to various platforms includi
16
16
 
17
17
  | platform | detail |
18
18
  |----------|--------------------------|
19
- | macOS | Export dmg file |
20
19
  | Windows | Export an exe file |
20
+ | macOS | Export dmg, app file |
21
+ | Linux | Export deb file |
21
22
  | iOS | Implementing... |
22
23
  | Android | Implementing... |
23
24
  | web | Export minfy'd JS files |
package/dist/index.d.ts CHANGED
@@ -1,120 +1,2 @@
1
1
  #!/usr/bin/env node
2
- declare const cli: any;
3
- declare const pc: any;
4
- declare const fs: any;
5
- declare const cp: any;
6
- declare const vite: any;
7
- declare const electronBuilder: any;
8
- declare const recommendeVersion: number;
9
- declare const version: string;
10
- declare let platform: string;
11
- declare let environment: string;
12
- declare let hasHelp: boolean;
13
- declare let preview: boolean;
14
- /**
15
- * @description ヘルプを出力して終了
16
- * Output help and exit
17
- *
18
- * @return {void}
19
- * @method
20
- * @public
21
- */
22
- declare const echoHelp: () => void;
23
- /**
24
- * @type {string}
25
- * @private
26
- */
27
- declare const platformDir: string;
28
- /**
29
- * @type {object}
30
- * @private
31
- */
32
- declare let $configObject: any | null;
33
- /**
34
- * @type {string}
35
- * @private
36
- */
37
- declare let $buildDir: string;
38
- /**
39
- * @type {string}
40
- * @private
41
- */
42
- declare let $outDir: string;
43
- /**
44
- * @return {Promise}
45
- * @method
46
- * @public
47
- */
48
- declare const loadConfig: () => Promise<void>;
49
- /**
50
- * @description Web用アプリの書き出し関数
51
- * Export function for web applications
52
- *
53
- * @return {Promise}
54
- * @method
55
- * @public
56
- */
57
- declare const buildWeb: () => Promise<void>;
58
- /**
59
- * @description Electronの書き出しに必要なconfigを生成
60
- * Generate config for Electron export
61
- *
62
- * @return {object}
63
- * @method
64
- * @public
65
- */
66
- declare const generateElectronConfig: () => any;
67
- /**
68
- * @description Electronで読み込むindex.htmlのファイルパスをセット
69
- * Set the file path of index.html to be loaded by Electron
70
- *
71
- * @return {void}
72
- * @method
73
- * @public
74
- */
75
- declare const setElectronIndexPath: () => void;
76
- /**
77
- * @description Electronで読み込むindex.htmlのファイルパスを初期化
78
- * Initialize the file path of index.html to be loaded by Electron
79
- *
80
- * @return {void}
81
- * @method
82
- * @public
83
- */
84
- declare const unlinkElectronIndexPath: () => void;
85
- /**
86
- * @description Windows用アプリの書き出し関数
87
- * Export function for Windows apps
88
- *
89
- * @return {void}
90
- * @method
91
- * @public
92
- */
93
- declare const buildSteam: () => void;
94
- /**
95
- * @description iOSのプロジェクトを生成
96
- * Generate iOS project
97
- *
98
- * @return {Promise<void>}
99
- * @method
100
- * @public
101
- */
102
- declare const generateNativeProject: () => Promise<void>;
103
- /**
104
- * @description iOS用アプリの書き出し関数
105
- * Export function for iOS apps
106
- *
107
- * @return {void}
108
- * @method
109
- * @public
110
- */
111
- declare const runNative: () => void;
112
- /**
113
- * @description ビルドの実行関数
114
- * Build Execution Functions
115
- *
116
- * @return {void}
117
- * @method
118
- * @public
119
- */
120
- declare const build: () => void;
2
+ export {};
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- const cli = require("@capacitor/cli");
4
- const pc = require("picocolors");
5
- const fs = require("fs");
6
- const cp = require("child_process");
7
- const vite = require("vite");
8
- const electronBuilder = require("electron-builder");
3
+ import pc from "picocolors";
4
+ import fs from "fs";
5
+ import cp from "child_process";
6
+ import { loadConfigFromFile } from "vite";
7
+ import { Platform, build as electronBuilder } from "electron-builder";
9
8
  const recommendeVersion = 18;
10
9
  const version = process.versions.node;
11
10
  if (recommendeVersion > parseInt(version.split(".")[0])) {
@@ -67,6 +66,24 @@ const echoHelp = () => {
67
66
  if (hasHelp) {
68
67
  echoHelp();
69
68
  }
69
+ if (!platform || !environment) {
70
+ echoHelp();
71
+ }
72
+ switch (platform) {
73
+ case "windows":
74
+ case "macos":
75
+ case "linux":
76
+ case "steam:windows":
77
+ case "steam:macos":
78
+ case "steam:linux":
79
+ case "ios":
80
+ case "android":
81
+ case "web":
82
+ break;
83
+ default:
84
+ echoHelp();
85
+ break;
86
+ }
70
87
  /**
71
88
  * @type {string}
72
89
  * @private
@@ -90,6 +107,21 @@ let $outDir = "dist";
90
107
  // update env variables
91
108
  process.env.NEXT2D_EBUILD_ENVIRONMENT = environment;
92
109
  process.env.NEXT2D_TARGET_PLATFORM = platform;
110
+ /**
111
+ * @type {string}
112
+ * @constant
113
+ */
114
+ const CAPACITOR_CONFIG_NAME = "capacitor.config.json";
115
+ /**
116
+ * @type {string}
117
+ * @constant
118
+ */
119
+ const ELECTRON_BUILD_CONFIG_NAME = "electron.build.json";
120
+ /**
121
+ * @type {string}
122
+ * @constant
123
+ */
124
+ const ELECTRON_INDEX_CONFIG_NAME = "electron.index.json";
93
125
  /**
94
126
  * @return {Promise}
95
127
  * @method
@@ -103,16 +135,18 @@ const loadConfig = () => {
103
135
  // overwride
104
136
  fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
105
137
  }
106
- const config = await vite.loadConfigFromFile({
138
+ const config = await loadConfigFromFile({
107
139
  "command": "build",
108
140
  "mode": "build"
109
141
  }, `${process.cwd()}/vite.config.ts`);
142
+ // update config
110
143
  $configObject = config;
111
144
  $outDir = $configObject.config?.build?.outDir || "dist";
112
145
  $buildDir = `${process.cwd()}/${$outDir}/${platformDir}/${environment}`;
113
146
  if (!fs.existsSync(`${$buildDir}`)) {
114
147
  fs.mkdirSync(`${$buildDir}`, { "recursive": true });
115
- console.log(pc.green(`create build dir: ${$buildDir}`));
148
+ console.log(pc.green(`Create build directory: ${$buildDir}`));
149
+ console.log();
116
150
  }
117
151
  resolve();
118
152
  });
@@ -126,19 +160,19 @@ const loadConfig = () => {
126
160
  * @public
127
161
  */
128
162
  const buildWeb = () => {
129
- return new Promise((resolve) => {
163
+ return new Promise((resolve, reject) => {
130
164
  const command = `${process.cwd()}/node_modules/.bin/vite`;
131
165
  const stream = cp.spawn(command, [
132
166
  "--outDir",
133
167
  $buildDir,
134
168
  "build"
135
- ]);
136
- stream.stdout.on("data", (data) => {
137
- console.log(data.toString());
138
- });
139
- stream.on("exit", () => {
140
- console.log(pc.green("`HTML` and `JavaScript` files are written out."));
169
+ ], { "stdio": "inherit" });
170
+ stream.on("close", (code) => {
171
+ if (code !== 0) {
172
+ reject("Export of `HTML` and `JavaScript` failed.");
173
+ }
141
174
  console.log();
175
+ console.log(pc.green("`HTML` and `JavaScript` files are written out."));
142
176
  resolve();
143
177
  });
144
178
  });
@@ -153,16 +187,16 @@ const buildWeb = () => {
153
187
  */
154
188
  const generateElectronConfig = () => {
155
189
  let config = {};
156
- const configPath = `${process.cwd()}/electron.build.json`;
190
+ const configPath = `${process.cwd()}/${ELECTRON_BUILD_CONFIG_NAME}`;
157
191
  if (!fs.existsSync(configPath)) {
158
- console.error(pc.red("The file `electron.build.json` could not be found."));
192
+ console.error(pc.red(`The file \`${ELECTRON_BUILD_CONFIG_NAME}\` could not be found.`));
159
193
  process.exit(1);
160
194
  }
161
195
  config = Object.assign(config, JSON.parse(fs.readFileSync(configPath, { "encoding": "utf8" })));
162
196
  if (!config.appId) {
163
197
  console.log();
164
198
  console.log(pc.red("`appId` is not set."));
165
- console.log("Please set `appId` in `electron.build.json`.");
199
+ console.log(`Please set \`appId\` in \`${ELECTRON_BUILD_CONFIG_NAME}\`.`);
166
200
  console.log();
167
201
  process.exit(1);
168
202
  }
@@ -195,6 +229,20 @@ const generateElectronConfig = () => {
195
229
  delete config.linux;
196
230
  }
197
231
  break;
232
+ case "linux":
233
+ case "steam:linux":
234
+ if (!("linux" in config)) {
235
+ config.linux = {
236
+ "target": "deb"
237
+ };
238
+ }
239
+ if ("win" in config) {
240
+ delete config.win;
241
+ }
242
+ if ("mac" in config) {
243
+ delete config.mac;
244
+ }
245
+ break;
198
246
  default:
199
247
  break;
200
248
  }
@@ -203,10 +251,11 @@ const generateElectronConfig = () => {
203
251
  "output": "dist"
204
252
  };
205
253
  }
206
- if (config.directories.output.slice(-1) !== "/") {
207
- config.directories.output += "/";
254
+ if (!("files" in config)) {
255
+ config.files = [];
208
256
  }
209
- config.directories.output += `${platformDir}/${environment}`;
257
+ config.files.push(`${$outDir}/${platformDir}/${environment}/`);
258
+ config.directories.output = `${$outDir}/${platformDir}/build`;
210
259
  return config;
211
260
  };
212
261
  /**
@@ -219,7 +268,7 @@ const generateElectronConfig = () => {
219
268
  */
220
269
  const setElectronIndexPath = () => {
221
270
  const htmlFilePath = `${$buildDir}/index.html`;
222
- fs.writeFileSync(`${process.cwd()}/electron.index.json`, JSON.stringify({
271
+ fs.writeFileSync(`${process.cwd()}/${ELECTRON_INDEX_CONFIG_NAME}`, JSON.stringify({
223
272
  "path": htmlFilePath.replace(process.cwd(), ".").trim()
224
273
  }, null, 2));
225
274
  };
@@ -232,7 +281,7 @@ const setElectronIndexPath = () => {
232
281
  * @public
233
282
  */
234
283
  const unlinkElectronIndexPath = () => {
235
- const jsonPath = `${process.cwd()}/electron.index.json`;
284
+ const jsonPath = `${process.cwd()}/${ELECTRON_INDEX_CONFIG_NAME}`;
236
285
  if (fs.existsSync(jsonPath)) {
237
286
  fs.unlinkSync(jsonPath);
238
287
  }
@@ -246,32 +295,26 @@ const unlinkElectronIndexPath = () => {
246
295
  * @public
247
296
  */
248
297
  const buildSteam = () => {
249
- const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, { "encoding": "utf8" }));
250
- // edit type
251
- packageJson.type = "commonjs";
252
- // overwride
253
- fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
254
- // revert type
255
- packageJson.type = "module";
256
298
  /**
257
299
  * Electronで読み込むindex.htmlのパスをセット
258
300
  * Set the path to index.html to load in Electron
259
301
  */
260
302
  setElectronIndexPath();
261
303
  if (preview) {
262
- const stream = cp.spawn(`${process.cwd()}/node_modules/.bin/electron`, [
304
+ const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, { "encoding": "utf8" }));
305
+ packageJson.type = "commonjs";
306
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
307
+ cp.spawn(`${process.cwd()}/node_modules/.bin/electron`, [
263
308
  `${process.cwd()}/electron.js`
264
- ]);
265
- stream.on("exit", () => {
266
- unlinkElectronIndexPath();
267
- // reset
268
- fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
269
- });
270
- stream.on("disconnect", () => {
309
+ ], { "stdio": "inherit" });
310
+ setTimeout(() => {
311
+ if (packageJson.type !== "module") {
312
+ packageJson.type = "module";
313
+ // overwride
314
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
315
+ }
271
316
  unlinkElectronIndexPath();
272
- // reset
273
- fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
274
- });
317
+ }, 1000);
275
318
  }
276
319
  else {
277
320
  /**
@@ -280,6 +323,7 @@ const buildSteam = () => {
280
323
  */
281
324
  const config = generateElectronConfig();
282
325
  console.log(pc.green("Start the `Electron` build process."));
326
+ console.log();
283
327
  const buildObject = {
284
328
  "projectDir": process.cwd(),
285
329
  "config": config
@@ -287,24 +331,33 @@ const buildSteam = () => {
287
331
  switch (platform) {
288
332
  case "windows":
289
333
  case "steam:windows":
290
- buildObject.targets = electronBuilder.Platform.WINDOWS.createTarget();
334
+ buildObject.targets = Platform.WINDOWS.createTarget();
291
335
  break;
292
336
  case "macos":
293
337
  case "steam:macos":
294
- buildObject.targets = electronBuilder.Platform.MAC.createTarget();
338
+ buildObject.targets = Platform.MAC.createTarget();
295
339
  break;
296
340
  case "linux":
297
341
  case "steam:linux":
298
- buildObject.targets = electronBuilder.Platform.LINUX.createTarget();
342
+ buildObject.targets = Platform.LINUX.createTarget();
343
+ break;
344
+ default:
345
+ unlinkElectronIndexPath();
346
+ console.log(pc.red("There is an error in the export platform settings."));
347
+ console.log();
348
+ process.exit(1);
299
349
  break;
300
350
  }
301
- electronBuilder
302
- .build(buildObject)
351
+ electronBuilder(buildObject)
303
352
  .then(() => {
304
353
  unlinkElectronIndexPath();
305
- console.log(pc.green("Finished building `Electron`."));
306
- // reset
307
- fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
354
+ console.log(pc.green(`Finished building \`Electron\` for ${platform}.`));
355
+ console.log();
356
+ })
357
+ .catch((error) => {
358
+ unlinkElectronIndexPath();
359
+ console.log(pc.red("Export of Electron failed."));
360
+ console.log(pc.red(error));
308
361
  });
309
362
  }
310
363
  };
@@ -317,22 +370,18 @@ const buildSteam = () => {
317
370
  * @public
318
371
  */
319
372
  const generateNativeProject = () => {
320
- if (fs.existsSync(`${process.cwd()}/${platform}`)) {
321
- return Promise.resolve();
322
- }
323
- return new Promise((resolve) => {
324
- const stream = cp.spawn("npx", ["cap", "add", platform]);
325
- let errorCheck = false;
326
- stream.stderr.on("data", (error) => {
327
- errorCheck = true;
328
- console.error(pc.red(error.toString()));
329
- });
330
- stream.stdout.on("data", (data) => {
331
- console.log(data.toString());
332
- });
333
- stream.on("exit", () => {
334
- if (errorCheck) {
335
- process.exit(1);
373
+ return new Promise((resolve, reject) => {
374
+ if (fs.existsSync(`${process.cwd()}/${platform}`)) {
375
+ return resolve();
376
+ }
377
+ const stream = cp.spawn("npx", [
378
+ "cap",
379
+ "add",
380
+ platform
381
+ ], { "stdio": "inherit" });
382
+ stream.on("close", (code) => {
383
+ if (code !== 0) {
384
+ reject(`Failed generated ${platform} project.`);
336
385
  }
337
386
  console.log(pc.green(`Successfully generated ${platform} project.`));
338
387
  console.log();
@@ -344,26 +393,24 @@ const generateNativeProject = () => {
344
393
  * @description iOS用アプリの書き出し関数
345
394
  * Export function for iOS apps
346
395
  *
347
- * @return {void}
396
+ * @return {Promise}
348
397
  * @method
349
398
  * @public
350
399
  */
351
- const runNative = () => {
352
- generateNativeProject()
353
- .then(() => {
354
- /**
355
- * Capacitorの書き出しに必要な設定を生成
356
- * Generate settings necessary for exporting Capacitor
357
- */
358
- const config = JSON.parse(fs.readFileSync(`${process.cwd()}/capacitor.config.json`, { "encoding": "utf8" }));
359
- config.webDir = `${$outDir}/${platformDir}/${environment}/`;
360
- fs.writeFileSync(`${process.cwd()}/capacitor.config.json`, JSON.stringify(config, null, 2));
361
- const nodePath = process.argv[0];
362
- const filePath = process.argv[1];
363
- process.argv = [nodePath, filePath, "run", platform];
364
- // run simulator
365
- cli.run();
366
- });
400
+ const runNative = async () => {
401
+ await generateNativeProject();
402
+ /**
403
+ * Capacitorの書き出しに必要な設定を生成
404
+ * Generate settings necessary for exporting Capacitor
405
+ */
406
+ const config = JSON.parse(fs.readFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, { "encoding": "utf8" }));
407
+ config.webDir = `${$outDir}/${platformDir}/${environment}/`;
408
+ fs.writeFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, JSON.stringify(config, null, 2));
409
+ cp.spawn("npx", [
410
+ "cap",
411
+ "run",
412
+ platform
413
+ ], { "stdio": "inherit" });
367
414
  };
368
415
  /**
369
416
  * @description ビルドの実行関数
@@ -373,7 +420,7 @@ const runNative = () => {
373
420
  * @method
374
421
  * @public
375
422
  */
376
- const build = () => {
423
+ const multiBuild = () => {
377
424
  switch (platform) {
378
425
  case "windows":
379
426
  case "macos":
@@ -384,29 +431,34 @@ const build = () => {
384
431
  buildSteam();
385
432
  break;
386
433
  case "ios":
387
- if (preview) {
388
- runNative();
389
- }
390
- break;
391
434
  case "android":
392
435
  if (preview) {
393
436
  runNative();
394
437
  }
395
438
  break;
396
439
  case "web":
397
- console.log(pc.green("build done."));
440
+ console.log();
398
441
  break;
399
442
  default:
400
443
  echoHelp();
401
444
  break;
402
445
  }
403
446
  };
404
- loadConfig()
405
- .then(() => {
447
+ /**
448
+ * @description 実行関数
449
+ * function execution
450
+ *
451
+ * @return {Promise}
452
+ * @method
453
+ * @public
454
+ */
455
+ const execute = async () => {
456
+ await loadConfig();
406
457
  buildWeb()
407
- .then(build)
458
+ .then(multiBuild)
408
459
  .catch((error) => {
409
460
  console.log(pc.red(error));
410
461
  process.exit(1);
411
462
  });
412
- });
463
+ };
464
+ execute();
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@next2d/builder",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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",
9
+ "type": "module",
10
10
  "homepage": "https://next2d.app",
11
11
  "bugs": "https://github.com/Next2D/view-generator/issues",
12
12
  "keywords": [