@next2d/builder 0.0.1 → 0.0.3
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 +1 -1
- package/README.md +4 -4
- package/dist/index.d.ts +120 -0
- package/dist/index.js +412 -0
- package/package.json +24 -11
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -79
- package/.gitattributes +0 -1
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.github/workflows/lint.yml +0 -26
- package/.github/workflows/publish.yml +0 -19
- package/SECURITY.md +0 -3
- package/index.js +0 -528
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@ Multi-platform Builder
|
|
|
7
7
|
[](https://github.com/Next2D/builder/blob/main/LICENSE)
|
|
8
8
|
|
|
9
9
|
[日本語]\
|
|
10
|
-
Next2D Frameworkのマルチプラットフォームビルダー、macOS、
|
|
10
|
+
Next2D Frameworkのマルチプラットフォームビルダー、Steam用のWindows、macOS、Linux、スマートフォン(iOS、Android)、Web(HTML)など、各種プラットフォームへの書き出しに対応
|
|
11
11
|
|
|
12
12
|
[English]\
|
|
13
|
-
|
|
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
|
-
###
|
|
31
|
+
### preview example.
|
|
32
32
|
|
|
33
33
|
```linux
|
|
34
|
-
npx @next2d/builder --
|
|
34
|
+
npx @next2d/builder --preview --platform web --env prd
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## License
|
package/dist/index.d.ts
ADDED
|
@@ -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,37 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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@
|
|
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
|
-
"
|
|
19
|
+
"JavaScript for Steam",
|
|
20
|
+
"Multi-platform builder"
|
|
17
21
|
],
|
|
18
22
|
"scripts": {
|
|
19
|
-
"lint": "eslint index.
|
|
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
|
-
"@
|
|
30
|
-
"@types/node": "^20.
|
|
31
|
-
"electron": "^
|
|
32
|
-
"electron-builder": "^
|
|
37
|
+
"@capacitor/cli": "^5.5.1",
|
|
38
|
+
"@types/node": "^20.9.0",
|
|
39
|
+
"electron": "^27.0.3",
|
|
40
|
+
"electron-builder": "^24.6.4",
|
|
41
|
+
"picocolors": "^1.0.0",
|
|
42
|
+
"vite": "^4.5.0"
|
|
33
43
|
},
|
|
34
44
|
"devDependencies": {
|
|
35
|
-
"eslint": "^
|
|
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"
|
|
36
49
|
}
|
|
37
50
|
}
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
**/node_modules/*
|
package/.eslintrc.json
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"es6": true
|
|
4
|
-
},
|
|
5
|
-
"extends": "eslint:recommended",
|
|
6
|
-
"rules": {
|
|
7
|
-
"no-var": "error",
|
|
8
|
-
"semi": ["error", "always", { "omitLastInOneLineBlock": true }],
|
|
9
|
-
"block-spacing": "error",
|
|
10
|
-
"indent": ["error", 4, { "SwitchCase": 1 }],
|
|
11
|
-
"no-mixed-spaces-and-tabs": "error",
|
|
12
|
-
"no-multiple-empty-lines": ["error" , { "max": 1 }],
|
|
13
|
-
"no-trailing-spaces": "error",
|
|
14
|
-
"space-infix-ops": "error",
|
|
15
|
-
"dot-notation": "error",
|
|
16
|
-
"eqeqeq": "error",
|
|
17
|
-
"quotes": ["error", "double"],
|
|
18
|
-
"no-else-return": "error",
|
|
19
|
-
"no-loop-func": "error",
|
|
20
|
-
"arrow-parens": "error",
|
|
21
|
-
"arrow-spacing": "error",
|
|
22
|
-
"no-undef": "off",
|
|
23
|
-
"comma-dangle": "warn",
|
|
24
|
-
"no-unused-vars": ["error", { "vars": "local", "args": "all" }],
|
|
25
|
-
"no-use-before-define": "error",
|
|
26
|
-
"no-const-assign": "error",
|
|
27
|
-
"space-before-blocks": "error",
|
|
28
|
-
"no-unexpected-multiline": "error",
|
|
29
|
-
"object-curly-spacing": ["error", "always"],
|
|
30
|
-
"quote-props": ["error", "always"],
|
|
31
|
-
"max-len": ["error", {
|
|
32
|
-
"code": 200,
|
|
33
|
-
"ignoreStrings": true,
|
|
34
|
-
"ignoreComments": true,
|
|
35
|
-
"ignoreTemplateLiterals": true
|
|
36
|
-
}],
|
|
37
|
-
"no-debugger": "error",
|
|
38
|
-
"no-dupe-keys": "error",
|
|
39
|
-
"no-duplicate-case": "error",
|
|
40
|
-
"no-empty": "error",
|
|
41
|
-
"no-extra-parens": "error",
|
|
42
|
-
"no-func-assign": "error",
|
|
43
|
-
"no-irregular-whitespace": "error",
|
|
44
|
-
"no-sparse-arrays": "error",
|
|
45
|
-
"no-unreachable": "error",
|
|
46
|
-
"no-unsafe-negation": "error",
|
|
47
|
-
"use-isnan": "error",
|
|
48
|
-
"block-scoped-var": "error",
|
|
49
|
-
"no-caller": "error",
|
|
50
|
-
"curly": "error",
|
|
51
|
-
"no-case-declarations": "error",
|
|
52
|
-
"no-floating-decimal": "error",
|
|
53
|
-
"no-eq-null": "error",
|
|
54
|
-
"no-empty-function": "error",
|
|
55
|
-
"no-empty-pattern": "error",
|
|
56
|
-
"no-extend-native": "error",
|
|
57
|
-
"dot-location": ["error", "property"],
|
|
58
|
-
"no-global-assign": "error",
|
|
59
|
-
"no-implicit-globals": "error",
|
|
60
|
-
"no-invalid-this": "error",
|
|
61
|
-
"no-lone-blocks": "error",
|
|
62
|
-
"no-iterator": "error",
|
|
63
|
-
"no-new": "error",
|
|
64
|
-
"no-proto": "error",
|
|
65
|
-
"no-return-assign": "error",
|
|
66
|
-
"no-self-assign": "error",
|
|
67
|
-
"no-self-compare": "error",
|
|
68
|
-
"no-useless-concat": "error",
|
|
69
|
-
"no-useless-call": "error",
|
|
70
|
-
"no-useless-return": "error",
|
|
71
|
-
"no-unused-expressions": "error",
|
|
72
|
-
"no-class-assign": "error",
|
|
73
|
-
"no-sequences": "error",
|
|
74
|
-
"no-dupe-args": "error",
|
|
75
|
-
"no-extra-boolean-cast": "error",
|
|
76
|
-
"no-obj-calls": "error",
|
|
77
|
-
"no-extra-semi": "warn"
|
|
78
|
-
}
|
|
79
|
-
}
|
package/.gitattributes
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*.js text eol=lf
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
-
# to commit it to your repository.
|
|
3
|
-
#
|
|
4
|
-
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
-
# or to provide custom queries or build logic.
|
|
6
|
-
#
|
|
7
|
-
# ******** NOTE ********
|
|
8
|
-
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
-
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
-
# supported CodeQL languages.
|
|
11
|
-
#
|
|
12
|
-
name: "CodeQL"
|
|
13
|
-
|
|
14
|
-
on:
|
|
15
|
-
push:
|
|
16
|
-
branches: [ main ]
|
|
17
|
-
pull_request:
|
|
18
|
-
# The branches below must be a subset of the branches above
|
|
19
|
-
branches: [ main ]
|
|
20
|
-
schedule:
|
|
21
|
-
- cron: '38 23 * * 1'
|
|
22
|
-
|
|
23
|
-
jobs:
|
|
24
|
-
analyze:
|
|
25
|
-
name: Analyze
|
|
26
|
-
runs-on: ubuntu-latest
|
|
27
|
-
permissions:
|
|
28
|
-
actions: read
|
|
29
|
-
contents: read
|
|
30
|
-
security-events: write
|
|
31
|
-
|
|
32
|
-
strategy:
|
|
33
|
-
fail-fast: false
|
|
34
|
-
matrix:
|
|
35
|
-
languages: [ 'javascript' ]
|
|
36
|
-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
37
|
-
# Learn more:
|
|
38
|
-
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
|
39
|
-
|
|
40
|
-
steps:
|
|
41
|
-
- name: Checkout repository
|
|
42
|
-
uses: actions/checkout@v3
|
|
43
|
-
|
|
44
|
-
# Initializes the CodeQL tools for scanning.
|
|
45
|
-
- name: Initialize CodeQL
|
|
46
|
-
uses: github/codeql-action/init@v2
|
|
47
|
-
with:
|
|
48
|
-
languages: ${{ matrix.language }}
|
|
49
|
-
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
50
|
-
# By default, queries listed here will override any specified in a config file.
|
|
51
|
-
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
52
|
-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
53
|
-
|
|
54
|
-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
55
|
-
# If this step fails, then you should remove it and run the build manually (see below)
|
|
56
|
-
- name: Autobuild
|
|
57
|
-
uses: github/codeql-action/autobuild@v2
|
|
58
|
-
|
|
59
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
|
60
|
-
# 📚 https://git.io/JvXDl
|
|
61
|
-
|
|
62
|
-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
63
|
-
# and modify them (or add more) to build your code if your project
|
|
64
|
-
# uses a compiled language
|
|
65
|
-
|
|
66
|
-
#- run: |
|
|
67
|
-
# make bootstrap
|
|
68
|
-
# make release
|
|
69
|
-
|
|
70
|
-
- name: Perform CodeQL Analysis
|
|
71
|
-
uses: github/codeql-action/analyze@v2
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
name: Lint
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
macos-browser-test:
|
|
13
|
-
runs-on: macos-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v3
|
|
16
|
-
- uses: actions/setup-node@v3
|
|
17
|
-
- run: npm install
|
|
18
|
-
- run: npm run lint
|
|
19
|
-
|
|
20
|
-
windows-browser-test:
|
|
21
|
-
runs-on: windows-latest
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v3
|
|
24
|
-
- uses: actions/setup-node@v3
|
|
25
|
-
- run: npm install
|
|
26
|
-
- run: npm run lint
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name: Publish Package
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- publish
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v3
|
|
13
|
-
- uses: actions/setup-node@v3
|
|
14
|
-
with:
|
|
15
|
-
node-version: "18.x"
|
|
16
|
-
registry-url: "https://registry.npmjs.org"
|
|
17
|
-
- run: npm publish --access public
|
|
18
|
-
env:
|
|
19
|
-
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
|
package/SECURITY.md
DELETED
package/index.js
DELETED
|
@@ -1,528 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
const version = process.versions.node;
|
|
6
|
-
if (15 > version.split(".")[0]) {
|
|
7
|
-
console.error(
|
|
8
|
-
"You are running Node Version:" + version + ".\n" +
|
|
9
|
-
"this command requires Node 15 or higher. \n" +
|
|
10
|
-
"Please update your version of Node."
|
|
11
|
-
);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const fs = require("fs");
|
|
16
|
-
const webpackConfig = require(`${process.cwd()}/webpack.config.js`);
|
|
17
|
-
const electronBuilder = require("electron-builder");
|
|
18
|
-
|
|
19
|
-
let platform = "";
|
|
20
|
-
let environment = "";
|
|
21
|
-
let hasHelp = false;
|
|
22
|
-
let debug = false;
|
|
23
|
-
|
|
24
|
-
for (let idx = 0; idx < process.argv.length; ++idx) {
|
|
25
|
-
|
|
26
|
-
switch (process.argv[idx]) {
|
|
27
|
-
|
|
28
|
-
case "--debug":
|
|
29
|
-
debug = true;
|
|
30
|
-
break;
|
|
31
|
-
|
|
32
|
-
case "--help":
|
|
33
|
-
case "--h":
|
|
34
|
-
hasHelp = true;
|
|
35
|
-
break;
|
|
36
|
-
|
|
37
|
-
case "--platform":
|
|
38
|
-
platform = process.argv[++idx].toLowerCase();
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
case "--env":
|
|
42
|
-
environment = process.argv[++idx];
|
|
43
|
-
break;
|
|
44
|
-
|
|
45
|
-
default:
|
|
46
|
-
break;
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (hasHelp) {
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!platform || !environment) {
|
|
56
|
-
hasHelp = true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (hasHelp) {
|
|
60
|
-
console.log();
|
|
61
|
-
console.log("Export with `--platform` and `--env` arguments.");
|
|
62
|
-
console.log();
|
|
63
|
-
console.log("For build example:");
|
|
64
|
-
console.log("npx @next2d/builder --platform web --env prd");
|
|
65
|
-
console.log();
|
|
66
|
-
console.log("For debug example:");
|
|
67
|
-
console.log("npx @next2d/builder --debug --platform web --env prd");
|
|
68
|
-
console.log();
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!fs.existsSync(`${webpackConfig.output.path}`)) {
|
|
73
|
-
fs.mkdirSync(`${webpackConfig.output.path}`, { "recursive": true });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @description 一時的に読み込みようのHTMLを生成
|
|
78
|
-
* Generate HTML for temporary loading
|
|
79
|
-
*
|
|
80
|
-
* @param {string} file_path
|
|
81
|
-
* @param {string} product_name
|
|
82
|
-
* @return {boolean}
|
|
83
|
-
* @method
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
const buildHTML = (file_path, product_name) =>
|
|
87
|
-
{
|
|
88
|
-
if (!fs.existsSync(file_path)) {
|
|
89
|
-
|
|
90
|
-
fs.writeFileSync(
|
|
91
|
-
file_path,
|
|
92
|
-
`<!DOCTYPE html>
|
|
93
|
-
<html>
|
|
94
|
-
<head>
|
|
95
|
-
<meta charset="utf-8"/>
|
|
96
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
97
|
-
<title>${product_name}</title>
|
|
98
|
-
<script src="./app.js"></script>
|
|
99
|
-
</head>
|
|
100
|
-
<body style="margin: 0; padding: 0;">
|
|
101
|
-
</body>
|
|
102
|
-
</html>`);
|
|
103
|
-
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @description Web用アプリの書き出し関数
|
|
112
|
-
* Export function for web applications
|
|
113
|
-
*
|
|
114
|
-
* @return {Promise}
|
|
115
|
-
* @method
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
const buildWeb = () =>
|
|
119
|
-
{
|
|
120
|
-
return new Promise((resolve) =>
|
|
121
|
-
{
|
|
122
|
-
const cp = require("child_process");
|
|
123
|
-
|
|
124
|
-
const command = `${process.cwd()}/node_modules/.bin/webpack`;
|
|
125
|
-
|
|
126
|
-
const stream = cp.spawn(command, [
|
|
127
|
-
"--mode",
|
|
128
|
-
"production",
|
|
129
|
-
"--env",
|
|
130
|
-
environment
|
|
131
|
-
]);
|
|
132
|
-
|
|
133
|
-
stream.on("error", (error) =>
|
|
134
|
-
{
|
|
135
|
-
console.error(error);
|
|
136
|
-
process.exit(1);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
stream.on("data", (data) =>
|
|
140
|
-
{
|
|
141
|
-
console.log("koko");
|
|
142
|
-
console.log(data.toString());
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
stream.on("exit", () =>
|
|
146
|
-
{
|
|
147
|
-
console.log("build web app.");
|
|
148
|
-
resolve();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @description Electronの書き出しに必要なconfigを生成
|
|
155
|
-
* Generate config for Electron export
|
|
156
|
-
*
|
|
157
|
-
* @return {object}
|
|
158
|
-
* @method
|
|
159
|
-
* @public
|
|
160
|
-
*/
|
|
161
|
-
const generateElectronConfig = (platform) =>
|
|
162
|
-
{
|
|
163
|
-
let config = {};
|
|
164
|
-
|
|
165
|
-
const configPath = `${process.cwd()}/electron.build.js`;
|
|
166
|
-
if (fs.existsSync(configPath)) {
|
|
167
|
-
config = Object.assign(config, require(configPath));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!config.appId) {
|
|
171
|
-
console.log();
|
|
172
|
-
console.log("`appId` is not set.");
|
|
173
|
-
console.log("Please set `appId` in `electron.build.js`.");
|
|
174
|
-
console.log();
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
switch (platform) {
|
|
179
|
-
|
|
180
|
-
case "windows":
|
|
181
|
-
if (!("win" in config)) {
|
|
182
|
-
config.win = {
|
|
183
|
-
"target": "nsis"
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if ("mac" in config) {
|
|
188
|
-
delete config.mac;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
case "macos":
|
|
194
|
-
if (!("mac" in config)) {
|
|
195
|
-
config.mac = {
|
|
196
|
-
"target": "dmg"
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if ("win" in config) {
|
|
201
|
-
delete config.win;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
break;
|
|
205
|
-
|
|
206
|
-
default:
|
|
207
|
-
console.log();
|
|
208
|
-
console.log("The specified platform could not be found.");
|
|
209
|
-
console.log();
|
|
210
|
-
process.exit(1);
|
|
211
|
-
break;
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (!("directories" in config)) {
|
|
216
|
-
config.directories = {
|
|
217
|
-
"output": "dist"
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (config.directories.output.slice(-1) !== "/") {
|
|
222
|
-
config.directories.output += "/";
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
config.directories.output += `${platform}/${environment}`;
|
|
226
|
-
|
|
227
|
-
return config;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* @description Electronで読み込むindex.htmlのファイルパスをセット
|
|
232
|
-
* Set the file path of index.html to be loaded by Electron
|
|
233
|
-
*
|
|
234
|
-
* @return {void}
|
|
235
|
-
* @method
|
|
236
|
-
* @public
|
|
237
|
-
*/
|
|
238
|
-
const setElectronIndexPath = () =>
|
|
239
|
-
{
|
|
240
|
-
const htmlFilePath = `${webpackConfig.output.path}/index.html`;
|
|
241
|
-
fs.writeFileSync(
|
|
242
|
-
`${process.cwd()}/electron.index.json`,
|
|
243
|
-
JSON.stringify({
|
|
244
|
-
"path": htmlFilePath.replace(process.cwd(), ".").trim()
|
|
245
|
-
}, null, 2)
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @description Electronで読み込むindex.htmlのファイルパスを初期化
|
|
251
|
-
* Initialize the file path of index.html to be loaded by Electron
|
|
252
|
-
*
|
|
253
|
-
* @return {void}
|
|
254
|
-
* @method
|
|
255
|
-
* @public
|
|
256
|
-
*/
|
|
257
|
-
const unlinkElectronIndexPath = () =>
|
|
258
|
-
{
|
|
259
|
-
const jsonPath = `${process.cwd()}/electron.index.json`;
|
|
260
|
-
if (fs.existsSync(jsonPath)) {
|
|
261
|
-
fs.unlinkSync(jsonPath);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @description Windows用アプリの書き出し関数
|
|
267
|
-
* Export function for Windows apps
|
|
268
|
-
*
|
|
269
|
-
* @return {void}
|
|
270
|
-
* @method
|
|
271
|
-
* @public
|
|
272
|
-
*/
|
|
273
|
-
const buildWindow = () =>
|
|
274
|
-
{
|
|
275
|
-
/**
|
|
276
|
-
* web版の書き出し
|
|
277
|
-
* Exporting the web version
|
|
278
|
-
*/
|
|
279
|
-
buildWeb()
|
|
280
|
-
.then(() =>
|
|
281
|
-
{
|
|
282
|
-
/**
|
|
283
|
-
* Electronの書き出しに必要な設定を生成
|
|
284
|
-
* Generate settings necessary for exporting Electron
|
|
285
|
-
*/
|
|
286
|
-
const config = generateElectronConfig("windows");
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* 読み込みようのindex.htmlファイルがなければ生成
|
|
290
|
-
* If there is no index.html file to load, generate one.
|
|
291
|
-
*/
|
|
292
|
-
const htmlFile = `${webpackConfig.output.path}/index.html`;
|
|
293
|
-
const generatedHTML = buildHTML(htmlFile, config.productName);
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Electronで読み込むindex.htmlのパスをセット
|
|
297
|
-
* Set the path to index.html to load in Electron
|
|
298
|
-
*/
|
|
299
|
-
setElectronIndexPath();
|
|
300
|
-
|
|
301
|
-
if (debug) {
|
|
302
|
-
|
|
303
|
-
const cp = require("child_process");
|
|
304
|
-
const stream = cp.spawn(
|
|
305
|
-
`${process.cwd()}/node_modules/.bin/electron`,
|
|
306
|
-
[
|
|
307
|
-
`${process.cwd()}/electron.js`,
|
|
308
|
-
"--env",
|
|
309
|
-
environment
|
|
310
|
-
]
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
stream.on("close", () =>
|
|
314
|
-
{
|
|
315
|
-
if (generatedHTML) {
|
|
316
|
-
fs.unlinkSync(htmlFile);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
unlinkElectronIndexPath();
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
stream.on("destroy", () =>
|
|
323
|
-
{
|
|
324
|
-
if (generatedHTML) {
|
|
325
|
-
fs.unlinkSync(htmlFile);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
unlinkElectronIndexPath();
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
} else {
|
|
332
|
-
|
|
333
|
-
electronBuilder
|
|
334
|
-
.build({
|
|
335
|
-
"projectDir": process.cwd(),
|
|
336
|
-
"targets": electronBuilder.Platform.WINDOWS.createTarget(),
|
|
337
|
-
"config": config
|
|
338
|
-
})
|
|
339
|
-
.then(() =>
|
|
340
|
-
{
|
|
341
|
-
if (generatedHTML) {
|
|
342
|
-
fs.unlinkSync(htmlFile);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
unlinkElectronIndexPath();
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* @description macOS用アプリの書き出し関数
|
|
354
|
-
* Export function for macOS apps
|
|
355
|
-
*
|
|
356
|
-
* @return {void}
|
|
357
|
-
* @method
|
|
358
|
-
* @public
|
|
359
|
-
*/
|
|
360
|
-
const buildMac = () =>
|
|
361
|
-
{
|
|
362
|
-
/**
|
|
363
|
-
* web版の書き出し
|
|
364
|
-
* Exporting the web version
|
|
365
|
-
*/
|
|
366
|
-
buildWeb()
|
|
367
|
-
.then(() =>
|
|
368
|
-
{
|
|
369
|
-
/**
|
|
370
|
-
* Electronの書き出しに必要な設定を生成
|
|
371
|
-
* Generate settings necessary for exporting Electron
|
|
372
|
-
*/
|
|
373
|
-
const config = generateElectronConfig("macos");
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* 読み込みようのindex.htmlファイルがなければ生成
|
|
377
|
-
* If there is no index.html file to load, generate one.
|
|
378
|
-
*/
|
|
379
|
-
const htmlFile = `${webpackConfig.output.path}/index.html`;
|
|
380
|
-
const generatedHTML = buildHTML(htmlFile, config.productName);
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Electronで読み込むindex.htmlのパスをセット
|
|
384
|
-
* Set the path to index.html to load in Electron
|
|
385
|
-
*/
|
|
386
|
-
setElectronIndexPath();
|
|
387
|
-
|
|
388
|
-
if (debug) {
|
|
389
|
-
|
|
390
|
-
const cp = require("child_process");
|
|
391
|
-
|
|
392
|
-
const stream = cp.spawn(
|
|
393
|
-
`${process.cwd()}/node_modules/.bin/electron`,
|
|
394
|
-
[
|
|
395
|
-
`${process.cwd()}/electron.js`,
|
|
396
|
-
"--env",
|
|
397
|
-
environment
|
|
398
|
-
]
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
stream.on("close", () =>
|
|
402
|
-
{
|
|
403
|
-
if (generatedHTML) {
|
|
404
|
-
fs.unlinkSync(htmlFile);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
unlinkElectronIndexPath();
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
stream.on("destroy", () =>
|
|
411
|
-
{
|
|
412
|
-
if (generatedHTML) {
|
|
413
|
-
fs.unlinkSync(htmlFile);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
unlinkElectronIndexPath();
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
} else {
|
|
420
|
-
|
|
421
|
-
electronBuilder
|
|
422
|
-
.build({
|
|
423
|
-
"projectDir": process.cwd(),
|
|
424
|
-
"targets": electronBuilder.Platform.MAC.createTarget(),
|
|
425
|
-
"config": config
|
|
426
|
-
})
|
|
427
|
-
.then(() =>
|
|
428
|
-
{
|
|
429
|
-
if (generatedHTML) {
|
|
430
|
-
fs.unlinkSync(htmlFile);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
unlinkElectronIndexPath();
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* @description Steam用アプリの書き出し関数
|
|
442
|
-
* Export function for Steam apps
|
|
443
|
-
*
|
|
444
|
-
* @method
|
|
445
|
-
* @public
|
|
446
|
-
*/
|
|
447
|
-
const buildSteam = () =>
|
|
448
|
-
{
|
|
449
|
-
buildWeb();
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* @description iOS用アプリの書き出し関数
|
|
454
|
-
* Export function for iOS apps
|
|
455
|
-
*
|
|
456
|
-
* @method
|
|
457
|
-
* @public
|
|
458
|
-
*/
|
|
459
|
-
const buildIOS = () =>
|
|
460
|
-
{
|
|
461
|
-
buildWeb();
|
|
462
|
-
|
|
463
|
-
// TODO
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* @description android用アプリの書き出し関数
|
|
468
|
-
* Export function for android apps
|
|
469
|
-
*
|
|
470
|
-
* @method
|
|
471
|
-
* @public
|
|
472
|
-
*/
|
|
473
|
-
const buildAndroid = () =>
|
|
474
|
-
{
|
|
475
|
-
buildWeb();
|
|
476
|
-
|
|
477
|
-
// TODO
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
switch (platform) {
|
|
481
|
-
|
|
482
|
-
case "windows":
|
|
483
|
-
buildWindow();
|
|
484
|
-
break;
|
|
485
|
-
|
|
486
|
-
case "macos":
|
|
487
|
-
buildMac();
|
|
488
|
-
break;
|
|
489
|
-
|
|
490
|
-
case "ios":
|
|
491
|
-
buildIOS();
|
|
492
|
-
break;
|
|
493
|
-
|
|
494
|
-
case "android":
|
|
495
|
-
buildAndroid();
|
|
496
|
-
break;
|
|
497
|
-
|
|
498
|
-
case "web":
|
|
499
|
-
buildWeb()
|
|
500
|
-
.then(() =>
|
|
501
|
-
{
|
|
502
|
-
console.log("build done.");
|
|
503
|
-
})
|
|
504
|
-
.catch((error) => {
|
|
505
|
-
console.error(error);
|
|
506
|
-
process.exit(1);
|
|
507
|
-
});
|
|
508
|
-
break;
|
|
509
|
-
|
|
510
|
-
case "steam":
|
|
511
|
-
buildSteam();
|
|
512
|
-
break;
|
|
513
|
-
|
|
514
|
-
default:
|
|
515
|
-
console.log();
|
|
516
|
-
console.log("`--platform` can be specified for macOS, Windows, iOS, Android, and Web");
|
|
517
|
-
console.log("It is not case sensitive.");
|
|
518
|
-
console.log();
|
|
519
|
-
console.log("For example:");
|
|
520
|
-
console.log("npx @next2d/builder --platform web --env prd");
|
|
521
|
-
console.log();
|
|
522
|
-
console.log("For Debug example:");
|
|
523
|
-
console.log("npx @next2d/builder --debug --platform web --env prd");
|
|
524
|
-
console.log();
|
|
525
|
-
process.exit(1);
|
|
526
|
-
break;
|
|
527
|
-
|
|
528
|
-
}
|