@next2d/builder 0.0.8 → 0.0.10
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.js +93 -151
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import pc from "picocolors";
|
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import cp from "child_process";
|
|
6
6
|
import { loadConfigFromFile } from "vite";
|
|
7
|
-
import {
|
|
7
|
+
import { api } from "@electron-forge/core";
|
|
8
8
|
const recommendeVersion = 18;
|
|
9
9
|
const version = process.versions.node;
|
|
10
10
|
if (recommendeVersion > parseInt(version.split(".")[0])) {
|
|
@@ -112,23 +112,13 @@ process.env.NEXT2D_TARGET_PLATFORM = platform;
|
|
|
112
112
|
* @constant
|
|
113
113
|
*/
|
|
114
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";
|
|
125
115
|
/**
|
|
126
116
|
* @return {Promise}
|
|
127
117
|
* @method
|
|
128
118
|
* @public
|
|
129
119
|
*/
|
|
130
120
|
const loadConfig = () => {
|
|
131
|
-
return new Promise(
|
|
121
|
+
return new Promise((resolve) => {
|
|
132
122
|
const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, { "encoding": "utf8" }));
|
|
133
123
|
if (packageJson.type !== "module") {
|
|
134
124
|
packageJson.type = "module";
|
|
@@ -136,20 +126,22 @@ const loadConfig = () => {
|
|
|
136
126
|
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
137
127
|
}
|
|
138
128
|
const ext = fs.existsSync(`${process.cwd()}/vite.config.ts`) ? "ts" : "js";
|
|
139
|
-
|
|
129
|
+
loadConfigFromFile({
|
|
140
130
|
"command": "build",
|
|
141
131
|
"mode": "build"
|
|
142
|
-
}, `${process.cwd()}/vite.config.${ext}`)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
fs.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
132
|
+
}, `${process.cwd()}/vite.config.${ext}`)
|
|
133
|
+
.then((config) => {
|
|
134
|
+
// update config
|
|
135
|
+
$configObject = config;
|
|
136
|
+
$outDir = $configObject.config?.build?.outDir || "dist";
|
|
137
|
+
$buildDir = `${process.cwd()}/${$outDir}/${platformDir}/${environment}`;
|
|
138
|
+
if (!fs.existsSync(`${$buildDir}`)) {
|
|
139
|
+
fs.mkdirSync(`${$buildDir}`, { "recursive": true });
|
|
140
|
+
console.log(pc.green(`Create build directory: ${$buildDir}`));
|
|
141
|
+
console.log();
|
|
142
|
+
}
|
|
143
|
+
resolve();
|
|
144
|
+
});
|
|
153
145
|
});
|
|
154
146
|
};
|
|
155
147
|
/**
|
|
@@ -179,184 +171,134 @@ const buildWeb = () => {
|
|
|
179
171
|
});
|
|
180
172
|
};
|
|
181
173
|
/**
|
|
182
|
-
* @description
|
|
183
|
-
*
|
|
174
|
+
* @description electronがインストールされてなければインストールを実行
|
|
175
|
+
* If electron is not installed, run install.
|
|
184
176
|
*
|
|
185
|
-
* @return {
|
|
177
|
+
* @return {Promise}
|
|
186
178
|
* @method
|
|
187
179
|
* @public
|
|
188
180
|
*/
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
switch (platform) {
|
|
205
|
-
case "windows":
|
|
206
|
-
case "steam:windows":
|
|
207
|
-
if (!("win" in config)) {
|
|
208
|
-
config.win = {
|
|
209
|
-
"target": "portable"
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
if ("mac" in config) {
|
|
213
|
-
delete config.mac;
|
|
214
|
-
}
|
|
215
|
-
if ("linux" in config) {
|
|
216
|
-
delete config.linux;
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
case "macos":
|
|
220
|
-
case "steam:macos":
|
|
221
|
-
if (!("mac" in config)) {
|
|
222
|
-
config.mac = {
|
|
223
|
-
"target": "dmg"
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
if ("win" in config) {
|
|
227
|
-
delete config.win;
|
|
228
|
-
}
|
|
229
|
-
if ("linux" in config) {
|
|
230
|
-
delete config.linux;
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
case "linux":
|
|
234
|
-
case "steam:linux":
|
|
235
|
-
if (!("linux" in config)) {
|
|
236
|
-
config.linux = {
|
|
237
|
-
"target": "deb"
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
if ("win" in config) {
|
|
241
|
-
delete config.win;
|
|
242
|
-
}
|
|
243
|
-
if ("mac" in config) {
|
|
244
|
-
delete config.mac;
|
|
181
|
+
const installElectron = () => {
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
if (fs.existsSync(`${process.cwd()}/electron/node_modules`)) {
|
|
184
|
+
return resolve();
|
|
185
|
+
}
|
|
186
|
+
const stream = cp.spawn("npm", [
|
|
187
|
+
"--prefix",
|
|
188
|
+
`${process.cwd()}/electron`,
|
|
189
|
+
"install",
|
|
190
|
+
`${process.cwd()}/electron`
|
|
191
|
+
], { "stdio": "inherit" });
|
|
192
|
+
stream.on("close", (code) => {
|
|
193
|
+
if (code !== 0) {
|
|
194
|
+
reject("`Electron` installation failed.");
|
|
245
195
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
if (!("directories" in config)) {
|
|
251
|
-
config.directories = {
|
|
252
|
-
"output": "dist"
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
if (!("files" in config)) {
|
|
256
|
-
config.files = [];
|
|
257
|
-
}
|
|
258
|
-
config.files.push(`${$outDir}/${platformDir}/${environment}/`);
|
|
259
|
-
config.directories.output = `${$outDir}/${platformDir}/build`;
|
|
260
|
-
return config;
|
|
196
|
+
console.log(pc.green("`Electron` successfully installed."));
|
|
197
|
+
resolve();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
261
200
|
};
|
|
262
201
|
/**
|
|
263
|
-
* @description
|
|
264
|
-
*
|
|
202
|
+
* @description electronに含むリソースを初期化
|
|
203
|
+
* Initialize resources included in electron
|
|
265
204
|
*
|
|
266
|
-
* @return {
|
|
205
|
+
* @return {Promise}
|
|
267
206
|
* @method
|
|
268
207
|
* @public
|
|
269
208
|
*/
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
209
|
+
const removeResources = () => {
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
const stream = cp.spawn("rm", [
|
|
212
|
+
"-rf",
|
|
213
|
+
`${process.cwd()}/electron/resources/`
|
|
214
|
+
], { "stdio": "inherit" });
|
|
215
|
+
stream.on("close", (code) => {
|
|
216
|
+
if (code !== 0) {
|
|
217
|
+
reject("Failed to remove built resources.");
|
|
218
|
+
}
|
|
219
|
+
console.log(pc.green("Successfully remove built resources."));
|
|
220
|
+
resolve();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
275
223
|
};
|
|
276
224
|
/**
|
|
277
|
-
* @description
|
|
278
|
-
*
|
|
225
|
+
* @description ビルドしたリソースをコピー
|
|
226
|
+
* Copy built resources
|
|
279
227
|
*
|
|
280
|
-
* @return {
|
|
228
|
+
* @return {Promise}
|
|
281
229
|
* @method
|
|
282
230
|
* @public
|
|
283
231
|
*/
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
232
|
+
const copyResources = () => {
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
const stream = cp.spawn("cp", [
|
|
235
|
+
"-r",
|
|
236
|
+
`${$buildDir}/`,
|
|
237
|
+
`${process.cwd()}/electron/resources`
|
|
238
|
+
], { "stdio": "inherit" });
|
|
239
|
+
stream.on("close", (code) => {
|
|
240
|
+
if (code !== 0) {
|
|
241
|
+
reject("Failed to copy built resources.");
|
|
242
|
+
}
|
|
243
|
+
console.log(pc.green("Successfully copy built resources."));
|
|
244
|
+
resolve();
|
|
245
|
+
});
|
|
246
|
+
});
|
|
289
247
|
};
|
|
290
248
|
/**
|
|
291
249
|
* @description Windows用アプリの書き出し関数
|
|
292
250
|
* Export function for Windows apps
|
|
293
251
|
*
|
|
294
|
-
* @return {
|
|
252
|
+
* @return {Promise}
|
|
295
253
|
* @method
|
|
296
254
|
* @public
|
|
297
255
|
*/
|
|
298
|
-
const buildSteam = () => {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
setElectronIndexPath();
|
|
256
|
+
const buildSteam = async () => {
|
|
257
|
+
// reset
|
|
258
|
+
await removeResources();
|
|
259
|
+
// copy HTML, JavaScript
|
|
260
|
+
await copyResources();
|
|
304
261
|
if (preview) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
cp.spawn(`${process.cwd()}/node_modules/.bin/electron`, [
|
|
309
|
-
`${process.cwd()}/electron.js`
|
|
262
|
+
cp.spawn("npx", [
|
|
263
|
+
"electron",
|
|
264
|
+
`${process.cwd()}/electron/index.js`
|
|
310
265
|
], { "stdio": "inherit" });
|
|
311
|
-
setTimeout(() => {
|
|
312
|
-
if (packageJson.type !== "module") {
|
|
313
|
-
packageJson.type = "module";
|
|
314
|
-
// overwride
|
|
315
|
-
fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
316
|
-
}
|
|
317
|
-
unlinkElectronIndexPath();
|
|
318
|
-
}, 1000);
|
|
319
266
|
}
|
|
320
267
|
else {
|
|
321
|
-
|
|
322
|
-
* Electronの書き出しに必要な設定を生成
|
|
323
|
-
* Generate settings necessary for exporting Electron
|
|
324
|
-
*/
|
|
325
|
-
const config = generateElectronConfig();
|
|
268
|
+
await installElectron();
|
|
326
269
|
console.log(pc.green("Start the `Electron` build process."));
|
|
327
270
|
console.log();
|
|
328
|
-
const
|
|
329
|
-
"
|
|
330
|
-
"
|
|
271
|
+
const packageOptions = {
|
|
272
|
+
"dir": `${process.cwd()}/electron`,
|
|
273
|
+
"outDir": `${$outDir}/${platformDir}/build`,
|
|
274
|
+
"platform": "",
|
|
275
|
+
"arch": "all"
|
|
331
276
|
};
|
|
332
277
|
switch (platform) {
|
|
333
278
|
case "windows":
|
|
334
279
|
case "steam:windows":
|
|
335
|
-
|
|
280
|
+
packageOptions.platform = "win32";
|
|
336
281
|
break;
|
|
337
282
|
case "macos":
|
|
338
283
|
case "steam:macos":
|
|
339
|
-
|
|
284
|
+
packageOptions.platform = "mas";
|
|
340
285
|
break;
|
|
341
286
|
case "linux":
|
|
342
287
|
case "steam:linux":
|
|
343
|
-
|
|
288
|
+
packageOptions.platform = "linux";
|
|
344
289
|
break;
|
|
345
290
|
default:
|
|
346
|
-
unlinkElectronIndexPath();
|
|
347
291
|
console.log(pc.red("There is an error in the export platform settings."));
|
|
348
292
|
console.log();
|
|
349
293
|
process.exit(1);
|
|
350
|
-
break;
|
|
351
294
|
}
|
|
352
|
-
|
|
295
|
+
api
|
|
296
|
+
.package(packageOptions)
|
|
353
297
|
.then(() => {
|
|
354
|
-
unlinkElectronIndexPath();
|
|
355
298
|
console.log(pc.green(`Finished building \`Electron\` for ${platform}.`));
|
|
356
299
|
console.log();
|
|
357
300
|
})
|
|
358
301
|
.catch((error) => {
|
|
359
|
-
unlinkElectronIndexPath();
|
|
360
302
|
console.log(pc.red("Export of Electron failed."));
|
|
361
303
|
console.log(pc.red(error));
|
|
362
304
|
});
|
|
@@ -366,7 +308,7 @@ const buildSteam = () => {
|
|
|
366
308
|
* @description iOSのプロジェクトを生成
|
|
367
309
|
* Generate iOS project
|
|
368
310
|
*
|
|
369
|
-
* @return {Promise
|
|
311
|
+
* @return {Promise}
|
|
370
312
|
* @method
|
|
371
313
|
* @public
|
|
372
314
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
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",
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"@next2d/builder": "dist/index.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@electron-forge/core": "^6.4.2",
|
|
37
38
|
"@types/node": "^20.9.0",
|
|
38
|
-
"electron": "^27.0.4",
|
|
39
|
-
"electron-builder": "^24.6.4",
|
|
40
39
|
"picocolors": "^1.0.0",
|
|
41
40
|
"vite": "^4.5.0"
|
|
42
41
|
},
|