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