@next2d/builder 0.0.1
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/.eslintignore +1 -0
- package/.eslintrc.json +79 -0
- package/.gitattributes +1 -0
- package/.github/workflows/codeql-analysis.yml +71 -0
- package/.github/workflows/lint.yml +26 -0
- package/.github/workflows/publish.yml +19 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/SECURITY.md +3 -0
- package/index.js +528 -0
- package/package.json +37 -0
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
**/node_modules/*
|
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.js text eol=lf
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Next2D
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Multi-platform Builder
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
[](https://github.com/Next2D/builder/actions/workflows/codeql-analysis.yml)
|
|
5
|
+
[](https://github.com/Next2D/builder/actions/workflows/lint.yml)
|
|
6
|
+
[](https://github.com/Next2D/builder/releases)
|
|
7
|
+
[](https://github.com/Next2D/builder/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
[日本語]\
|
|
10
|
+
Next2D Frameworkのマルチプラットフォームビルダー、macOS、Windows、iOS、Android、Web(HTML)など、各種プラットフォームへの書き出しに対応
|
|
11
|
+
|
|
12
|
+
[English]\
|
|
13
|
+
Next2D Framework multi-platform builder, supports export to various platforms including macOS, Windows, iOS, Android, and Web (HTML)
|
|
14
|
+
|
|
15
|
+
## Supported
|
|
16
|
+
|
|
17
|
+
| platform | detail |
|
|
18
|
+
|----------|--------------------------|
|
|
19
|
+
| macOS | Export dmg file |
|
|
20
|
+
| Windows | Export an exe file |
|
|
21
|
+
| iOS | Implementing... |
|
|
22
|
+
| Android | Implementing... |
|
|
23
|
+
| web | Export minfy'd JS files |
|
|
24
|
+
|
|
25
|
+
### build example.
|
|
26
|
+
|
|
27
|
+
```linux
|
|
28
|
+
npx @next2d/builder --platform web --env prd
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### debug example.
|
|
32
|
+
|
|
33
|
+
```linux
|
|
34
|
+
npx @next2d/builder --debug --platform web --env prd
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
|
package/SECURITY.md
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@next2d/builder",
|
|
3
|
+
"version": "0.0.1",
|
|
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>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://next2d.app",
|
|
8
|
+
"bugs": "https://github.com/Next2D/view-generator/issues",
|
|
9
|
+
"main": "./index.js",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Next2D",
|
|
12
|
+
"JavaScript for MacOS",
|
|
13
|
+
"JavaScript for Windows",
|
|
14
|
+
"JavaScript for iOS",
|
|
15
|
+
"JavaScript for Android",
|
|
16
|
+
"Multi-platform"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "eslint index.js"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Next2D/builder.git"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"@next2d/builder": "index.js"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@next2d/env": "^1.0.1",
|
|
30
|
+
"@types/node": "^20.1.0",
|
|
31
|
+
"electron": "^24.2.0",
|
|
32
|
+
"electron-builder": "^23.6.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"eslint": "^8.40.0"
|
|
36
|
+
}
|
|
37
|
+
}
|