@next2d/builder 0.0.2 → 0.0.4

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Next2D
3
+ Copyright (c) 2021 - 2023 Next2D
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -7,10 +7,10 @@ Multi-platform Builder
7
7
  [![license](https://img.shields.io/github/license/Next2D/builder)](https://github.com/Next2D/builder/blob/main/LICENSE)
8
8
 
9
9
  [日本語]\
10
- Next2D Frameworkのマルチプラットフォームビルダー、macOS、Windows、iOS、Android、Web(HTML)など、各種プラットフォームへの書き出しに対応
10
+ Next2D Frameworkのマルチプラットフォームビルダー、Steam用のWindows、macOS、Linux、スマートフォン(iOS、Android)、Web(HTML)など、各種プラットフォームへの書き出しに対応
11
11
 
12
12
  [English]\
13
- Next2D Framework multi-platform builder, supports export to various platforms including macOS, Windows, iOS, Android, and Web (HTML)
13
+ Multi-platform builder for Next2D Framework, export to various platforms including Windows, macOS, Linux, Smartphones (iOS, Android) and Web (HTML) for Steam
14
14
 
15
15
  ## Supported
16
16
 
@@ -28,10 +28,10 @@ Next2D Framework multi-platform builder, supports export to various platforms in
28
28
  npx @next2d/builder --platform web --env prd
29
29
  ```
30
30
 
31
- ### debug example.
31
+ ### preview example.
32
32
 
33
33
  ```linux
34
- npx @next2d/builder --debug --platform web --env prd
34
+ npx @next2d/builder --preview --platform web --env prd
35
35
  ```
36
36
 
37
37
  ## License
@@ -0,0 +1,120 @@
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;
package/dist/index.js ADDED
@@ -0,0 +1,412 @@
1
+ #!/usr/bin/env node
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");
9
+ const recommendeVersion = 18;
10
+ const version = process.versions.node;
11
+ if (recommendeVersion > parseInt(version.split(".")[0])) {
12
+ pc.red(`You are running Node Version:${version}.
13
+ View Generator requires Node ${recommendeVersion} or higher.
14
+ Please update your version of Node.`);
15
+ process.exit(1);
16
+ }
17
+ let platform = "";
18
+ let environment = "";
19
+ let hasHelp = false;
20
+ let preview = false;
21
+ for (let idx = 0; idx < process.argv.length; ++idx) {
22
+ switch (process.argv[idx]) {
23
+ case "--preview":
24
+ preview = true;
25
+ break;
26
+ case "--help":
27
+ case "--h":
28
+ hasHelp = true;
29
+ break;
30
+ case "--platform":
31
+ platform = process.argv[++idx].toLowerCase();
32
+ break;
33
+ case "--env":
34
+ environment = process.argv[++idx];
35
+ break;
36
+ default:
37
+ break;
38
+ }
39
+ if (hasHelp) {
40
+ break;
41
+ }
42
+ }
43
+ if (!platform || !environment) {
44
+ hasHelp = true;
45
+ }
46
+ /**
47
+ * @description ヘルプを出力して終了
48
+ * Output help and exit
49
+ *
50
+ * @return {void}
51
+ * @method
52
+ * @public
53
+ */
54
+ const echoHelp = () => {
55
+ console.log();
56
+ console.log(pc.green("`--platform` can be specified for macOS, Windows, iOS, Android, and Web"));
57
+ console.log(pc.green("It is not case sensitive."));
58
+ console.log();
59
+ console.log("For build example:");
60
+ console.log("npx @next2d/builder --platform web --env prd");
61
+ console.log();
62
+ console.log("For preview example:");
63
+ console.log("npx @next2d/builder --preview --platform web --env prd");
64
+ console.log();
65
+ process.exit(1);
66
+ };
67
+ if (hasHelp) {
68
+ echoHelp();
69
+ }
70
+ /**
71
+ * @type {string}
72
+ * @private
73
+ */
74
+ const platformDir = platform.indexOf(":") ? platform.split(":").join("/") : platform;
75
+ /**
76
+ * @type {object}
77
+ * @private
78
+ */
79
+ let $configObject = null;
80
+ /**
81
+ * @type {string}
82
+ * @private
83
+ */
84
+ let $buildDir = "";
85
+ /**
86
+ * @type {string}
87
+ * @private
88
+ */
89
+ let $outDir = "dist";
90
+ // update env variables
91
+ process.env.NEXT2D_EBUILD_ENVIRONMENT = environment;
92
+ process.env.NEXT2D_TARGET_PLATFORM = platform;
93
+ /**
94
+ * @return {Promise}
95
+ * @method
96
+ * @public
97
+ */
98
+ const loadConfig = () => {
99
+ return new Promise(async (resolve) => {
100
+ const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, { "encoding": "utf8" }));
101
+ if (packageJson.type !== "module") {
102
+ packageJson.type = "module";
103
+ // overwride
104
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
105
+ }
106
+ const config = await vite.loadConfigFromFile({
107
+ "command": "build",
108
+ "mode": "build"
109
+ }, `${process.cwd()}/vite.config.ts`);
110
+ $configObject = config;
111
+ $outDir = $configObject.config?.build?.outDir || "dist";
112
+ $buildDir = `${process.cwd()}/${$outDir}/${platformDir}/${environment}`;
113
+ if (!fs.existsSync(`${$buildDir}`)) {
114
+ fs.mkdirSync(`${$buildDir}`, { "recursive": true });
115
+ console.log(pc.green(`create build dir: ${$buildDir}`));
116
+ }
117
+ resolve();
118
+ });
119
+ };
120
+ /**
121
+ * @description Web用アプリの書き出し関数
122
+ * Export function for web applications
123
+ *
124
+ * @return {Promise}
125
+ * @method
126
+ * @public
127
+ */
128
+ const buildWeb = () => {
129
+ return new Promise((resolve) => {
130
+ const command = `${process.cwd()}/node_modules/.bin/vite`;
131
+ const stream = cp.spawn(command, [
132
+ "--outDir",
133
+ $buildDir,
134
+ "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."));
141
+ console.log();
142
+ resolve();
143
+ });
144
+ });
145
+ };
146
+ /**
147
+ * @description Electronの書き出しに必要なconfigを生成
148
+ * Generate config for Electron export
149
+ *
150
+ * @return {object}
151
+ * @method
152
+ * @public
153
+ */
154
+ const generateElectronConfig = () => {
155
+ let config = {};
156
+ const configPath = `${process.cwd()}/electron.build.json`;
157
+ if (!fs.existsSync(configPath)) {
158
+ console.error(pc.red("The file `electron.build.json` could not be found."));
159
+ process.exit(1);
160
+ }
161
+ config = Object.assign(config, JSON.parse(fs.readFileSync(configPath, { "encoding": "utf8" })));
162
+ if (!config.appId) {
163
+ console.log();
164
+ console.log(pc.red("`appId` is not set."));
165
+ console.log("Please set `appId` in `electron.build.json`.");
166
+ console.log();
167
+ process.exit(1);
168
+ }
169
+ switch (platform) {
170
+ case "windows":
171
+ case "steam:windows":
172
+ if (!("win" in config)) {
173
+ config.win = {
174
+ "target": "portable"
175
+ };
176
+ }
177
+ if ("mac" in config) {
178
+ delete config.mac;
179
+ }
180
+ if ("linux" in config) {
181
+ delete config.linux;
182
+ }
183
+ break;
184
+ case "macos":
185
+ case "steam:macos":
186
+ if (!("mac" in config)) {
187
+ config.mac = {
188
+ "target": "dmg"
189
+ };
190
+ }
191
+ if ("win" in config) {
192
+ delete config.win;
193
+ }
194
+ if ("linux" in config) {
195
+ delete config.linux;
196
+ }
197
+ break;
198
+ default:
199
+ break;
200
+ }
201
+ if (!("directories" in config)) {
202
+ config.directories = {
203
+ "output": "dist"
204
+ };
205
+ }
206
+ if (config.directories.output.slice(-1) !== "/") {
207
+ config.directories.output += "/";
208
+ }
209
+ config.directories.output += `${platformDir}/${environment}`;
210
+ return config;
211
+ };
212
+ /**
213
+ * @description Electronで読み込むindex.htmlのファイルパスをセット
214
+ * Set the file path of index.html to be loaded by Electron
215
+ *
216
+ * @return {void}
217
+ * @method
218
+ * @public
219
+ */
220
+ const setElectronIndexPath = () => {
221
+ const htmlFilePath = `${$buildDir}/index.html`;
222
+ fs.writeFileSync(`${process.cwd()}/electron.index.json`, JSON.stringify({
223
+ "path": htmlFilePath.replace(process.cwd(), ".").trim()
224
+ }, null, 2));
225
+ };
226
+ /**
227
+ * @description Electronで読み込むindex.htmlのファイルパスを初期化
228
+ * Initialize the file path of index.html to be loaded by Electron
229
+ *
230
+ * @return {void}
231
+ * @method
232
+ * @public
233
+ */
234
+ const unlinkElectronIndexPath = () => {
235
+ const jsonPath = `${process.cwd()}/electron.index.json`;
236
+ if (fs.existsSync(jsonPath)) {
237
+ fs.unlinkSync(jsonPath);
238
+ }
239
+ };
240
+ /**
241
+ * @description Windows用アプリの書き出し関数
242
+ * Export function for Windows apps
243
+ *
244
+ * @return {void}
245
+ * @method
246
+ * @public
247
+ */
248
+ 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
+ /**
257
+ * Electronで読み込むindex.htmlのパスをセット
258
+ * Set the path to index.html to load in Electron
259
+ */
260
+ setElectronIndexPath();
261
+ if (preview) {
262
+ const stream = cp.spawn(`${process.cwd()}/node_modules/.bin/electron`, [
263
+ `${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", () => {
271
+ unlinkElectronIndexPath();
272
+ // reset
273
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
274
+ });
275
+ }
276
+ else {
277
+ /**
278
+ * Electronの書き出しに必要な設定を生成
279
+ * Generate settings necessary for exporting Electron
280
+ */
281
+ const config = generateElectronConfig();
282
+ console.log(pc.green("Start the `Electron` build process."));
283
+ const buildObject = {
284
+ "projectDir": process.cwd(),
285
+ "config": config
286
+ };
287
+ switch (platform) {
288
+ case "windows":
289
+ case "steam:windows":
290
+ buildObject.targets = electronBuilder.Platform.WINDOWS.createTarget();
291
+ break;
292
+ case "macos":
293
+ case "steam:macos":
294
+ buildObject.targets = electronBuilder.Platform.MAC.createTarget();
295
+ break;
296
+ case "linux":
297
+ case "steam:linux":
298
+ buildObject.targets = electronBuilder.Platform.LINUX.createTarget();
299
+ break;
300
+ }
301
+ electronBuilder
302
+ .build(buildObject)
303
+ .then(() => {
304
+ unlinkElectronIndexPath();
305
+ console.log(pc.green("Finished building `Electron`."));
306
+ // reset
307
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
308
+ });
309
+ }
310
+ };
311
+ /**
312
+ * @description iOSのプロジェクトを生成
313
+ * Generate iOS project
314
+ *
315
+ * @return {Promise<void>}
316
+ * @method
317
+ * @public
318
+ */
319
+ 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);
336
+ }
337
+ console.log(pc.green(`Successfully generated ${platform} project.`));
338
+ console.log();
339
+ resolve();
340
+ });
341
+ });
342
+ };
343
+ /**
344
+ * @description iOS用アプリの書き出し関数
345
+ * Export function for iOS apps
346
+ *
347
+ * @return {void}
348
+ * @method
349
+ * @public
350
+ */
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
+ });
367
+ };
368
+ /**
369
+ * @description ビルドの実行関数
370
+ * Build Execution Functions
371
+ *
372
+ * @return {void}
373
+ * @method
374
+ * @public
375
+ */
376
+ const build = () => {
377
+ switch (platform) {
378
+ case "windows":
379
+ case "macos":
380
+ case "linux":
381
+ case "steam:windows":
382
+ case "steam:macos":
383
+ case "steam:linux":
384
+ buildSteam();
385
+ break;
386
+ case "ios":
387
+ if (preview) {
388
+ runNative();
389
+ }
390
+ break;
391
+ case "android":
392
+ if (preview) {
393
+ runNative();
394
+ }
395
+ break;
396
+ case "web":
397
+ console.log(pc.green("build done."));
398
+ break;
399
+ default:
400
+ echoHelp();
401
+ break;
402
+ }
403
+ };
404
+ loadConfig()
405
+ .then(() => {
406
+ buildWeb()
407
+ .then(build)
408
+ .catch((error) => {
409
+ console.log(pc.red(error));
410
+ process.exit(1);
411
+ });
412
+ });
package/package.json CHANGED
@@ -1,39 +1,50 @@
1
1
  {
2
2
  "name": "@next2d/builder",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Multi-platform builder for Next2d Framework, supporting export to various platforms such as macOS, Windows, iOS, Android and Web(HTML)",
5
- "author": "Toshiyuki Ienaga <ienaga@tvon.jp>",
5
+ "author": "Toshiyuki Ienaga <ienaga@next2d.app>",
6
6
  "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
7
10
  "homepage": "https://next2d.app",
8
11
  "bugs": "https://github.com/Next2D/view-generator/issues",
9
- "main": "./index.js",
10
12
  "keywords": [
11
13
  "Next2D",
14
+ "JavaScript for Linux",
12
15
  "JavaScript for MacOS",
13
16
  "JavaScript for Windows",
14
17
  "JavaScript for iOS",
15
18
  "JavaScript for Android",
16
- "Multi-platform"
19
+ "JavaScript for Steam",
20
+ "Multi-platform builder"
17
21
  ],
18
22
  "scripts": {
19
- "lint": "eslint index.js"
23
+ "lint": "eslint src/index.ts",
24
+ "publish": "tsc"
20
25
  },
26
+ "files": [
27
+ "dist"
28
+ ],
21
29
  "repository": {
22
30
  "type": "git",
23
31
  "url": "git+https://github.com/Next2D/builder.git"
24
32
  },
25
33
  "bin": {
26
- "@next2d/builder": "index.js"
34
+ "@next2d/builder": "dist/index.js"
27
35
  },
28
36
  "dependencies": {
29
- "@capacitor/cli": "^5.0.3",
30
- "@next2d/env": "^1.0.1",
31
- "@types/node": "^20.1.0",
32
- "chalk": "4.1.0",
33
- "electron": "^24.2.0",
34
- "electron-builder": "^23.6.0"
37
+ "@capacitor/cli": "^5.5.1",
38
+ "@types/node": "^20.9.0",
39
+ "electron": "^27.0.4",
40
+ "electron-builder": "^24.6.4",
41
+ "picocolors": "^1.0.0",
42
+ "vite": "^4.5.0"
35
43
  },
36
44
  "devDependencies": {
37
- "eslint": "^8.40.0"
45
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
46
+ "@typescript-eslint/parser": "^6.10.0",
47
+ "eslint": "^8.53.0",
48
+ "typescript": "^5.2.2"
38
49
  }
39
50
  }
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- **/node_modules/*