@next2d/builder 0.0.1 → 0.0.2

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.
@@ -13,10 +13,10 @@ name: "CodeQL"
13
13
 
14
14
  on:
15
15
  push:
16
- branches: [ main ]
16
+ branches: [ main, develop ]
17
17
  pull_request:
18
18
  # The branches below must be a subset of the branches above
19
- branches: [ main ]
19
+ branches: [ main, develop ]
20
20
  schedule:
21
21
  - cron: '38 23 * * 1'
22
22
 
@@ -4,9 +4,11 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - main
7
+ - develop
7
8
  pull_request:
8
9
  branches:
9
10
  - main
11
+ - develop
10
12
 
11
13
  jobs:
12
14
  macos-browser-test:
package/index.js CHANGED
@@ -12,9 +12,11 @@ if (15 > version.split(".")[0]) {
12
12
  process.exit(1);
13
13
  }
14
14
 
15
- const fs = require("fs");
16
- const webpackConfig = require(`${process.cwd()}/webpack.config.js`);
15
+ const fs = require("fs");
16
+ const cp = require("child_process");
17
+ const webpackConfig = require(`${process.cwd()}/webpack.config.js`);
17
18
  const electronBuilder = require("electron-builder");
19
+ const chalk = require("chalk");
18
20
 
19
21
  let platform = "";
20
22
  let environment = "";
@@ -119,32 +121,36 @@ const buildWeb = () =>
119
121
  {
120
122
  return new Promise((resolve) =>
121
123
  {
122
- const cp = require("child_process");
123
-
124
124
  const command = `${process.cwd()}/node_modules/.bin/webpack`;
125
125
 
126
+ const mode = debug ? "development" : "production";
126
127
  const stream = cp.spawn(command, [
127
128
  "--mode",
128
- "production",
129
+ mode,
129
130
  "--env",
130
131
  environment
131
132
  ]);
132
133
 
133
- stream.on("error", (error) =>
134
+ let errorCheck = false;
135
+ stream.stderr.on("data", (error) =>
134
136
  {
135
- console.error(error);
136
- process.exit(1);
137
+ errorCheck = true;
138
+ console.error(chalk.red(error.toString()));
137
139
  });
138
140
 
139
- stream.on("data", (data) =>
141
+ stream.stdout.on("data", (data) =>
140
142
  {
141
- console.log("koko");
142
143
  console.log(data.toString());
143
144
  });
144
145
 
145
146
  stream.on("exit", () =>
146
147
  {
147
- console.log("build web app.");
148
+ if (errorCheck) {
149
+ process.exit(1);
150
+ }
151
+
152
+ console.log(chalk.green("Build web app."));
153
+ console.log();
148
154
  resolve();
149
155
  });
150
156
  });
@@ -163,13 +169,15 @@ const generateElectronConfig = (platform) =>
163
169
  let config = {};
164
170
 
165
171
  const configPath = `${process.cwd()}/electron.build.js`;
166
- if (fs.existsSync(configPath)) {
167
- config = Object.assign(config, require(configPath));
172
+ if (!fs.existsSync(configPath)) {
173
+ console.error(chalk.red("The file `electron.build.js` could not be found."));
174
+ process.exit(1);
168
175
  }
169
176
 
177
+ config = Object.assign(config, require(configPath));
170
178
  if (!config.appId) {
171
179
  console.log();
172
- console.log("`appId` is not set.");
180
+ console.log(chalk.red("`appId` is not set."));
173
181
  console.log("Please set `appId` in `electron.build.js`.");
174
182
  console.log();
175
183
  process.exit(1);
@@ -204,10 +212,6 @@ const generateElectronConfig = (platform) =>
204
212
  break;
205
213
 
206
214
  default:
207
- console.log();
208
- console.log("The specified platform could not be found.");
209
- console.log();
210
- process.exit(1);
211
215
  break;
212
216
 
213
217
  }
@@ -300,7 +304,6 @@ const buildWindow = () =>
300
304
 
301
305
  if (debug) {
302
306
 
303
- const cp = require("child_process");
304
307
  const stream = cp.spawn(
305
308
  `${process.cwd()}/node_modules/.bin/electron`,
306
309
  [
@@ -319,7 +322,7 @@ const buildWindow = () =>
319
322
  unlinkElectronIndexPath();
320
323
  });
321
324
 
322
- stream.on("destroy", () =>
325
+ stream.on("disconnect", () =>
323
326
  {
324
327
  if (generatedHTML) {
325
328
  fs.unlinkSync(htmlFile);
@@ -387,8 +390,6 @@ const buildMac = () =>
387
390
 
388
391
  if (debug) {
389
392
 
390
- const cp = require("child_process");
391
-
392
393
  const stream = cp.spawn(
393
394
  `${process.cwd()}/node_modules/.bin/electron`,
394
395
  [
@@ -407,7 +408,7 @@ const buildMac = () =>
407
408
  unlinkElectronIndexPath();
408
409
  });
409
410
 
410
- stream.on("destroy", () =>
411
+ stream.on("disconnect", () =>
411
412
  {
412
413
  if (generatedHTML) {
413
414
  fs.unlinkSync(htmlFile);
@@ -438,43 +439,106 @@ const buildMac = () =>
438
439
  };
439
440
 
440
441
  /**
441
- * @description Steam用アプリの書き出し関数
442
- * Export function for Steam apps
442
+ * @description iOSのプロジェクトを生成
443
+ * Generate iOS project
443
444
  *
445
+ * @return {Promise<void>}
444
446
  * @method
445
447
  * @public
446
448
  */
447
- const buildSteam = () =>
449
+ const generateNativeProject = () =>
448
450
  {
449
- buildWeb();
451
+ if (fs.existsSync(`${process.cwd()}/${platform}`)) {
452
+ return Promise.resolve();
453
+ }
454
+
455
+ return new Promise((resolve) =>
456
+ {
457
+ const stream = cp.spawn("npx", ["cap", "add", platform]);
458
+
459
+ let errorCheck = false;
460
+ stream.stderr.on("data", (error) =>
461
+ {
462
+ errorCheck = true;
463
+ console.error(chalk.red(error.toString()));
464
+ });
465
+
466
+ stream.stdout.on("data", (data) =>
467
+ {
468
+ console.log(data.toString());
469
+ });
470
+
471
+ stream.on("exit", () =>
472
+ {
473
+ if (errorCheck) {
474
+ process.exit(1);
475
+ }
476
+
477
+ console.log(chalk.green(`Successfully generated ${platform} project.`));
478
+ console.log();
479
+
480
+ resolve();
481
+ });
482
+ });
450
483
  };
451
484
 
452
485
  /**
453
486
  * @description iOS用アプリの書き出し関数
454
487
  * Export function for iOS apps
455
488
  *
489
+ * @return {void}
456
490
  * @method
457
491
  * @public
458
492
  */
459
- const buildIOS = () =>
493
+ const runNative = () =>
460
494
  {
461
- buildWeb();
495
+ generateNativeProject()
496
+ .then(() =>
497
+ {
498
+ return buildWeb();
499
+ })
500
+ .then(() =>
501
+ {
502
+ /**
503
+ * Capacitorの書き出しに必要な設定を生成
504
+ * Generate settings necessary for exporting Capacitor
505
+ */
506
+ const config = JSON.parse(
507
+ fs.readFileSync(`${process.cwd()}/capacitor.config.json`, { "encoding": "utf8" })
508
+ );
462
509
 
463
- // TODO
464
- };
510
+ /**
511
+ * 読み込みようのindex.htmlファイルがなければ生成
512
+ * If there is no index.html file to load, generate one.
513
+ */
514
+ const htmlFile = `${webpackConfig.output.path}/index.html`;
515
+ const generatedHTML = buildHTML(htmlFile, config.appName);
465
516
 
466
- /**
467
- * @description android用アプリの書き出し関数
468
- * Export function for android apps
469
- *
470
- * @method
471
- * @public
472
- */
473
- const buildAndroid = () =>
474
- {
475
- buildWeb();
517
+ config.webDir = htmlFile
518
+ .replace(process.cwd(), ".")
519
+ .replace("index.html", "")
520
+ .trim();
521
+
522
+ fs.writeFileSync(
523
+ `${process.cwd()}/capacitor.config.json`,
524
+ JSON.stringify(config, null, 2)
525
+ );
526
+
527
+ return Promise.resolve(generatedHTML);
476
528
 
477
- // TODO
529
+ })
530
+ .then((generated_html) =>
531
+ {
532
+ process.on("exit", () =>
533
+ {
534
+ if (generated_html) {
535
+ fs.unlinkSync(`${webpackConfig.output.path}/index.html`);
536
+ }
537
+ });
538
+
539
+ const { run } = require("@capacitor/cli");
540
+ run();
541
+ });
478
542
  };
479
543
 
480
544
  switch (platform) {
@@ -488,11 +552,15 @@ switch (platform) {
488
552
  break;
489
553
 
490
554
  case "ios":
491
- buildIOS();
555
+ if (debug) {
556
+ runNative();
557
+ }
492
558
  break;
493
559
 
494
560
  case "android":
495
- buildAndroid();
561
+ if (debug) {
562
+ runNative();
563
+ }
496
564
  break;
497
565
 
498
566
  case "web":
@@ -507,10 +575,6 @@ switch (platform) {
507
575
  });
508
576
  break;
509
577
 
510
- case "steam":
511
- buildSteam();
512
- break;
513
-
514
578
  default:
515
579
  console.log();
516
580
  console.log("`--platform` can be specified for macOS, Windows, iOS, Android, and Web");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/builder",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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@tvon.jp>",
6
6
  "license": "MIT",
@@ -26,8 +26,10 @@
26
26
  "@next2d/builder": "index.js"
27
27
  },
28
28
  "dependencies": {
29
+ "@capacitor/cli": "^5.0.3",
29
30
  "@next2d/env": "^1.0.1",
30
31
  "@types/node": "^20.1.0",
32
+ "chalk": "4.1.0",
31
33
  "electron": "^24.2.0",
32
34
  "electron-builder": "^23.6.0"
33
35
  },