create-next2d-app 1.2.4 → 1.2.6
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/README.md +2 -2
- package/dist/index.d.ts +66 -0
- package/dist/index.js +351 -0
- package/package.json +16 -7
- package/SECURITY.md +0 -3
- package/index.js +0 -457
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
declare const version: number;
|
|
3
|
+
declare const chalk: any;
|
|
4
|
+
declare const commander: any;
|
|
5
|
+
declare const execSync: any;
|
|
6
|
+
declare const fs: any;
|
|
7
|
+
declare const os: any;
|
|
8
|
+
declare const path: any;
|
|
9
|
+
declare const semver: any;
|
|
10
|
+
declare const spawn: any;
|
|
11
|
+
declare const validateProjectName: any;
|
|
12
|
+
declare const packageJson: any;
|
|
13
|
+
declare let projectName: string;
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} app_name
|
|
16
|
+
* @return {void}
|
|
17
|
+
* @method
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare const checkAppName: (app_name: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* @return {boolean}
|
|
23
|
+
* @method
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare const checkThatNpmCanReadCwd: () => boolean;
|
|
27
|
+
interface NpmVersion {
|
|
28
|
+
hasMinNpm: boolean;
|
|
29
|
+
npmVersion: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @return {object}
|
|
33
|
+
* @method
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
declare const checkNpmVersion: () => NpmVersion;
|
|
37
|
+
interface Packages {
|
|
38
|
+
dependencies?: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface TemplateJson {
|
|
43
|
+
package?: Packages;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} root
|
|
47
|
+
* @param {string} app_name
|
|
48
|
+
* @param {string} template
|
|
49
|
+
* @param {array} dependencies
|
|
50
|
+
* @return {void}
|
|
51
|
+
*/
|
|
52
|
+
declare const install: (root: string, app_name: string, template: string, dependencies: string[]) => void;
|
|
53
|
+
/**
|
|
54
|
+
* @param {string} app_name
|
|
55
|
+
* @param {string} [template="@next2d/framework-template"]
|
|
56
|
+
* @return {void}
|
|
57
|
+
* @method
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
declare const createApp: (app_name: string, template?: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* @return {void}
|
|
63
|
+
* @method
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
declare const execute: () => void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const version = +process.versions.node.split(".")[0];
|
|
4
|
+
if (15 > version) {
|
|
5
|
+
console.error("You are running Node Version:" + version + ".\n" +
|
|
6
|
+
"Create Next2d App requires Node 15 or higher. \n" +
|
|
7
|
+
"Please update your version of Node.");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const chalk = require("chalk");
|
|
11
|
+
const commander = require("commander");
|
|
12
|
+
const execSync = require("child_process").execSync;
|
|
13
|
+
const fs = require("fs-extra");
|
|
14
|
+
const os = require("os");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const semver = require("semver");
|
|
17
|
+
const spawn = require("cross-spawn");
|
|
18
|
+
const validateProjectName = require("validate-npm-package-name");
|
|
19
|
+
const packageJson = require("../package.json");
|
|
20
|
+
let projectName = "";
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} app_name
|
|
23
|
+
* @return {void}
|
|
24
|
+
* @method
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
const checkAppName = (app_name) => {
|
|
28
|
+
const validationResult = validateProjectName(app_name);
|
|
29
|
+
if (!validationResult.validForNewPackages) {
|
|
30
|
+
console.error(chalk.red(`Cannot create a project named ${chalk.green(`"${app_name}"`)} because of npm naming restrictions:\n`));
|
|
31
|
+
[
|
|
32
|
+
...validationResult.errors || [],
|
|
33
|
+
...validationResult.warnings || []
|
|
34
|
+
].forEach((error) => {
|
|
35
|
+
console.error(chalk.red(` * ${error}`));
|
|
36
|
+
});
|
|
37
|
+
console.error(chalk.red("\nPlease choose a different project name."));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const dependencies = [
|
|
41
|
+
"next2d",
|
|
42
|
+
"next2d-player",
|
|
43
|
+
"next2d-framework"
|
|
44
|
+
].sort();
|
|
45
|
+
if (dependencies.includes(app_name)) {
|
|
46
|
+
console.error(chalk.red(`Cannot create a project named ${chalk.green(`"${app_name}"`)} because a dependency with the same name exists.\n` +
|
|
47
|
+
"Due to the way npm works, the following names are not allowed:\n\n") +
|
|
48
|
+
chalk.cyan(dependencies.map((depName) => ` ${depName}`).join("\n")) +
|
|
49
|
+
chalk.red("\n\nPlease choose a different project name."));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @return {boolean}
|
|
55
|
+
* @method
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
const checkThatNpmCanReadCwd = () => {
|
|
59
|
+
const cwd = process.cwd();
|
|
60
|
+
let childOutput = "";
|
|
61
|
+
try {
|
|
62
|
+
childOutput = spawn.sync("npm", ["config", "list"]).output.join("");
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (typeof childOutput !== "string") {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
const lines = childOutput.split("\n");
|
|
71
|
+
const prefix = "; cwd = ";
|
|
72
|
+
const line = lines.find((line) => line.startsWith(prefix));
|
|
73
|
+
if (typeof line !== "string") {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
const npmCWD = line.substring(prefix.length);
|
|
77
|
+
if (npmCWD === cwd) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
console.error(chalk.red("Could not start an npm process in the right directory.\n\n" +
|
|
81
|
+
`The current directory is: ${chalk.bold(cwd)}\n` +
|
|
82
|
+
`However, a newly started npm process runs in: ${chalk.bold(npmCWD)}\n\n` +
|
|
83
|
+
"This is probably caused by a misconfigured system terminal shell."));
|
|
84
|
+
if (process.platform === "win32") {
|
|
85
|
+
console.error(chalk.red("On Windows, this can usually be fixed by running:\n\n") +
|
|
86
|
+
` ${chalk.cyan("reg")} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n` +
|
|
87
|
+
` ${chalk.cyan("reg")} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n\n` +
|
|
88
|
+
chalk.red("Try to run the above two lines in the terminal.\n") +
|
|
89
|
+
chalk.red("To learn more about this problem, read: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/"));
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @return {object}
|
|
95
|
+
* @method
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
const checkNpmVersion = () => {
|
|
99
|
+
let hasMinNpm = false;
|
|
100
|
+
let npmVersion = "0.0.0";
|
|
101
|
+
try {
|
|
102
|
+
npmVersion = execSync("npm --version").toString().trim();
|
|
103
|
+
hasMinNpm = semver.gte(npmVersion, "6.0.0");
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
// ignore
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
"hasMinNpm": hasMinNpm,
|
|
110
|
+
"npmVersion": npmVersion
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @param {string} root
|
|
115
|
+
* @param {string} app_name
|
|
116
|
+
* @param {string} template
|
|
117
|
+
* @param {array} dependencies
|
|
118
|
+
* @return {void}
|
|
119
|
+
*/
|
|
120
|
+
const install = (root, app_name, template, dependencies) => {
|
|
121
|
+
console.log("Installing packages. This may take a few minutes.");
|
|
122
|
+
const command = "npm";
|
|
123
|
+
new Promise((resolve, reject) => {
|
|
124
|
+
const args = [
|
|
125
|
+
"install",
|
|
126
|
+
"--no-audit",
|
|
127
|
+
"--save",
|
|
128
|
+
"--save-exact",
|
|
129
|
+
"--loglevel",
|
|
130
|
+
"error",
|
|
131
|
+
template
|
|
132
|
+
];
|
|
133
|
+
const child = spawn(command, args, { "stdio": "inherit" });
|
|
134
|
+
child
|
|
135
|
+
.on("close", (code) => {
|
|
136
|
+
if (code !== 0) {
|
|
137
|
+
reject({ "command": `${command} ${args.join(" ")}` });
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
console.log();
|
|
142
|
+
console.log(`Installing template: ${chalk.green(template)}`);
|
|
143
|
+
const templatePath = path.dirname(require.resolve(`${template}/package.json`, { "paths": [root] }));
|
|
144
|
+
const templateJsonPath = path.join(templatePath, "template.json");
|
|
145
|
+
let templateJson = {};
|
|
146
|
+
if (fs.existsSync(templateJsonPath)) {
|
|
147
|
+
templateJson = require(templateJsonPath);
|
|
148
|
+
}
|
|
149
|
+
// base package.json
|
|
150
|
+
const packageJson = require(`${root}/package.json`);
|
|
151
|
+
const templatePackage = templateJson.package;
|
|
152
|
+
if (templatePackage) {
|
|
153
|
+
const templateDependencies = templatePackage.dependencies;
|
|
154
|
+
if (templateDependencies) {
|
|
155
|
+
const keys = Object.keys(templateDependencies);
|
|
156
|
+
for (let idx = 0; idx < keys.length; ++idx) {
|
|
157
|
+
const name = keys[idx];
|
|
158
|
+
if (templateDependencies[name] === "*") {
|
|
159
|
+
dependencies.push(name);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
packageJson.dependencies[name] = templateDependencies[name];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(packageJson, null, 2) + os.EOL);
|
|
168
|
+
const templateDir = path.join(templatePath, "template");
|
|
169
|
+
if (fs.existsSync(templateDir)) {
|
|
170
|
+
fs.copySync(templateDir, root);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.error(`Could not locate supplied template: ${chalk.green(templateDir)}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const args = [
|
|
177
|
+
"uninstall",
|
|
178
|
+
"--no-audit",
|
|
179
|
+
"--save",
|
|
180
|
+
"--save-exact",
|
|
181
|
+
"--loglevel",
|
|
182
|
+
"error",
|
|
183
|
+
template
|
|
184
|
+
];
|
|
185
|
+
const child = spawn(command, args, { "stdio": "inherit" });
|
|
186
|
+
child
|
|
187
|
+
.on("close", (code) => {
|
|
188
|
+
if (code !== 0) {
|
|
189
|
+
reject({
|
|
190
|
+
"command": `${command} ${args.join(" ")}`
|
|
191
|
+
});
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
resolve();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
})
|
|
200
|
+
.then(() => {
|
|
201
|
+
const args = [
|
|
202
|
+
"install",
|
|
203
|
+
"--no-audit",
|
|
204
|
+
"--save",
|
|
205
|
+
"--save-exact",
|
|
206
|
+
"--loglevel",
|
|
207
|
+
"error"
|
|
208
|
+
].concat(dependencies);
|
|
209
|
+
const child = spawn(command, args, { "stdio": "inherit" });
|
|
210
|
+
child
|
|
211
|
+
.on("close", (code) => {
|
|
212
|
+
if (code !== 0) {
|
|
213
|
+
console.log();
|
|
214
|
+
console.error(`${command} ${args.join(" ")}`);
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
console.log();
|
|
219
|
+
console.log(`Success! Created ${chalk.green(app_name)} at ${chalk.green(root)}`);
|
|
220
|
+
console.log();
|
|
221
|
+
console.log("you can run several commands:");
|
|
222
|
+
console.log();
|
|
223
|
+
console.log(` ${chalk.green("npm start")}`);
|
|
224
|
+
console.log(" Starts the development server.");
|
|
225
|
+
console.log();
|
|
226
|
+
console.log(` ${chalk.green("npm run generate")}`);
|
|
227
|
+
console.log(" Generate the necessary View and ViewModel classes from the routing JSON file.");
|
|
228
|
+
console.log();
|
|
229
|
+
console.log(` ${chalk.green("npm run [ios|android|windows|macos] -- --env prd")}`);
|
|
230
|
+
console.log(" Start the emulator for each platform.");
|
|
231
|
+
console.log();
|
|
232
|
+
console.log(` ${chalk.green("npm run build -- --platform [windows|macos|web] --env prd")}`);
|
|
233
|
+
console.log(" Export a production version for each platform.");
|
|
234
|
+
console.log();
|
|
235
|
+
console.log(` ${chalk.green("npm test")}`);
|
|
236
|
+
console.log(" Starts the test runner.");
|
|
237
|
+
console.log();
|
|
238
|
+
console.log("We suggest that you begin by typing:");
|
|
239
|
+
console.log(` ${chalk.green("cd")} ${app_name}`);
|
|
240
|
+
console.log(` ${chalk.green("npm start")}`);
|
|
241
|
+
console.log();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* @param {string} app_name
|
|
248
|
+
* @param {string} [template="@next2d/framework-template"]
|
|
249
|
+
* @return {void}
|
|
250
|
+
* @method
|
|
251
|
+
* @public
|
|
252
|
+
*/
|
|
253
|
+
const createApp = (app_name, template = "@next2d/framework-template") => {
|
|
254
|
+
const root = path.resolve(app_name);
|
|
255
|
+
const appName = path.basename(root);
|
|
256
|
+
checkAppName(appName);
|
|
257
|
+
fs.ensureDirSync(app_name);
|
|
258
|
+
console.log();
|
|
259
|
+
console.log(`Creating a new Next2D app in ${chalk.green(root)}.`);
|
|
260
|
+
console.log();
|
|
261
|
+
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify({
|
|
262
|
+
"name": appName,
|
|
263
|
+
"description": `Details of ${appName}`,
|
|
264
|
+
"version": "0.0.1",
|
|
265
|
+
"private": true,
|
|
266
|
+
"main": "src/index.js",
|
|
267
|
+
"scripts": {
|
|
268
|
+
"start": "webpack serve",
|
|
269
|
+
"ios": "npx @next2d/builder run ios --platform ios --debug",
|
|
270
|
+
"android": "npx @next2d/builder run android --platform android --debug",
|
|
271
|
+
"macos": "npx @next2d/builder --platform macos --debug",
|
|
272
|
+
"windows": "npx @next2d/builder --platform windows --debug",
|
|
273
|
+
"build": "npx @next2d/builder",
|
|
274
|
+
"lint": "eslint src/**/*.js",
|
|
275
|
+
"test": "npx jest",
|
|
276
|
+
"generate": "npx @next2d/view-generator"
|
|
277
|
+
}
|
|
278
|
+
}, null, 2) + os.EOL);
|
|
279
|
+
process.chdir(root);
|
|
280
|
+
if (!checkThatNpmCanReadCwd()) {
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
const npmInfo = checkNpmVersion();
|
|
284
|
+
if (!npmInfo.hasMinNpm) {
|
|
285
|
+
if (npmInfo.npmVersion) {
|
|
286
|
+
console.log(chalk.yellow(`You are using npm ${npmInfo.npmVersion} so the project will be bootstrapped with an old unsupported version of tools.\n\n` +
|
|
287
|
+
"Please update to npm 6 or higher for a better, fully supported experience.\n"));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const ignoreList = [
|
|
291
|
+
"node_modules",
|
|
292
|
+
"coverage",
|
|
293
|
+
"dist",
|
|
294
|
+
".DS_Store",
|
|
295
|
+
".idea",
|
|
296
|
+
"Thumbs.db",
|
|
297
|
+
"npm-debug.log*",
|
|
298
|
+
"yarn-debug.log*",
|
|
299
|
+
"yarn-error.log*",
|
|
300
|
+
"src/config/Config.js",
|
|
301
|
+
"src/Packages.js",
|
|
302
|
+
"electron.index.json"
|
|
303
|
+
];
|
|
304
|
+
fs.writeFileSync(path.join(root, ".gitignore"), ignoreList.join(os.EOL));
|
|
305
|
+
install(root, appName, template, [
|
|
306
|
+
"@next2d/framework",
|
|
307
|
+
"@next2d/env",
|
|
308
|
+
"electron",
|
|
309
|
+
"webpack",
|
|
310
|
+
"webpack-cli",
|
|
311
|
+
"webpack-dev-server",
|
|
312
|
+
"@capacitor/cli",
|
|
313
|
+
"@capacitor/core",
|
|
314
|
+
"@capacitor/ios",
|
|
315
|
+
"@capacitor/android"
|
|
316
|
+
]);
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* @return {void}
|
|
320
|
+
* @method
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
const execute = () => {
|
|
324
|
+
const program = new commander.Command(packageJson.name)
|
|
325
|
+
.version(packageJson.version)
|
|
326
|
+
.arguments("<project-directory>")
|
|
327
|
+
.usage(`${chalk.green("<project-directory>")} [options]`)
|
|
328
|
+
.action((name) => { projectName = name; })
|
|
329
|
+
.option("--info", "print environment debug info")
|
|
330
|
+
.option("--template <path-to-template>", "specify a template for the created project")
|
|
331
|
+
.on("--help", () => {
|
|
332
|
+
console.log();
|
|
333
|
+
console.log(` A custom ${chalk.cyan("--template")} can be one of:`);
|
|
334
|
+
console.log(` - a custom template published on npm default: ${chalk.green("@next2d/framework-template")}`);
|
|
335
|
+
console.log();
|
|
336
|
+
console.log(" If you have any problems, do not hesitate to file an issue:");
|
|
337
|
+
console.log(` ${chalk.cyan("https://github.com/Next2D/create-next2d-app/issues/new")}`);
|
|
338
|
+
console.log();
|
|
339
|
+
})
|
|
340
|
+
.parse(process.argv);
|
|
341
|
+
if (typeof projectName === "undefined") {
|
|
342
|
+
console.error("Please specify the project directory:");
|
|
343
|
+
console.log(` npx ${chalk.cyan(program.name())} ${chalk.green("<project-directory>")}`);
|
|
344
|
+
console.log();
|
|
345
|
+
console.log("For example:");
|
|
346
|
+
console.log(` npx ${chalk.cyan(program.name())} ${chalk.green("my-next2d-app")}`);
|
|
347
|
+
process.exit(1);
|
|
348
|
+
}
|
|
349
|
+
createApp(projectName, program.template);
|
|
350
|
+
};
|
|
351
|
+
execute();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-next2d-app",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "Create Next2D apps with no build configuration.",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@tvon.jp>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,25 +11,34 @@
|
|
|
11
11
|
"create-next2d-app"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"lint": "eslint
|
|
14
|
+
"lint": "eslint src/**/*.ts",
|
|
15
|
+
"build": "tsc"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
18
19
|
"url": "git+https://github.com/Next2D/create-next2d-app.git"
|
|
19
20
|
},
|
|
21
|
+
"types": "dist",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
20
25
|
"bin": {
|
|
21
|
-
"create-next2d-app": "index.js"
|
|
26
|
+
"create-next2d-app": "dist/index.js"
|
|
22
27
|
},
|
|
23
28
|
"dependencies": {
|
|
24
|
-
"chalk": "4.1.
|
|
29
|
+
"chalk": "4.1.2",
|
|
25
30
|
"commander": "4.1.1",
|
|
26
31
|
"cross-spawn": "7.0.3",
|
|
27
32
|
"fs-extra": "9.0.1",
|
|
28
|
-
"semver": "7.3
|
|
33
|
+
"semver": "7.5.3",
|
|
29
34
|
"tar-pack": "3.4.1",
|
|
30
|
-
"validate-npm-package-name": "
|
|
35
|
+
"validate-npm-package-name": "5.0.0"
|
|
31
36
|
},
|
|
32
37
|
"devDependencies": {
|
|
33
|
-
"
|
|
38
|
+
"@types/node": "^20.4.0",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.61.0",
|
|
41
|
+
"eslint": "^8.1.0",
|
|
42
|
+
"typescript": "^5.1.6"
|
|
34
43
|
}
|
|
35
44
|
}
|
package/SECURITY.md
DELETED
package/index.js
DELETED
|
@@ -1,457 +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
|
-
"Create Next2d App requires Node 15 or higher. \n" +
|
|
10
|
-
"Please update your version of Node."
|
|
11
|
-
);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const chalk = require("chalk");
|
|
16
|
-
const commander = require("commander");
|
|
17
|
-
const execSync = require("child_process").execSync;
|
|
18
|
-
const fs = require("fs-extra");
|
|
19
|
-
const os = require("os");
|
|
20
|
-
const path = require("path");
|
|
21
|
-
const semver = require("semver");
|
|
22
|
-
const spawn = require("cross-spawn");
|
|
23
|
-
const validateProjectName = require("validate-npm-package-name");
|
|
24
|
-
|
|
25
|
-
const packageJson = require("./package.json");
|
|
26
|
-
|
|
27
|
-
let projectName;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @param {string} app_name
|
|
31
|
-
*/
|
|
32
|
-
const checkAppName = function (app_name)
|
|
33
|
-
{
|
|
34
|
-
const validationResult = validateProjectName(app_name);
|
|
35
|
-
if (!validationResult.validForNewPackages) {
|
|
36
|
-
console.error(
|
|
37
|
-
chalk.red(
|
|
38
|
-
`Cannot create a project named ${chalk.green(
|
|
39
|
-
`"${app_name}"`
|
|
40
|
-
)} because of npm naming restrictions:\n`
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
[
|
|
44
|
-
...validationResult.errors || [],
|
|
45
|
-
...validationResult.warnings || []
|
|
46
|
-
].forEach((error) => {
|
|
47
|
-
console.error(chalk.red(` * ${error}`));
|
|
48
|
-
});
|
|
49
|
-
console.error(chalk.red("\nPlease choose a different project name."));
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const dependencies = ["next2d", "next2d-player", "next2d-framework"].sort();
|
|
54
|
-
if (dependencies.includes(app_name)) {
|
|
55
|
-
console.error(
|
|
56
|
-
chalk.red(
|
|
57
|
-
`Cannot create a project named ${chalk.green(
|
|
58
|
-
`"${app_name}"`
|
|
59
|
-
)} because a dependency with the same name exists.\n` +
|
|
60
|
-
"Due to the way npm works, the following names are not allowed:\n\n"
|
|
61
|
-
) +
|
|
62
|
-
chalk.cyan(dependencies.map((depName) => ` ${depName}`).join("\n")) +
|
|
63
|
-
chalk.red("\n\nPlease choose a different project name.")
|
|
64
|
-
);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @return {boolean}
|
|
71
|
-
*/
|
|
72
|
-
const checkThatNpmCanReadCwd = function ()
|
|
73
|
-
{
|
|
74
|
-
const cwd = process.cwd();
|
|
75
|
-
let childOutput = null;
|
|
76
|
-
try {
|
|
77
|
-
childOutput = spawn.sync("npm", ["config", "list"]).output.join("");
|
|
78
|
-
} catch (err) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeof childOutput !== "string") {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const lines = childOutput.split("\n");
|
|
87
|
-
const prefix = "; cwd = ";
|
|
88
|
-
const line = lines.find((line) => line.startsWith(prefix));
|
|
89
|
-
if (typeof line !== "string") {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const npmCWD = line.substring(prefix.length);
|
|
94
|
-
if (npmCWD === cwd) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
console.error(
|
|
99
|
-
chalk.red(
|
|
100
|
-
"Could not start an npm process in the right directory.\n\n" +
|
|
101
|
-
`The current directory is: ${chalk.bold(cwd)}\n` +
|
|
102
|
-
`However, a newly started npm process runs in: ${chalk.bold(
|
|
103
|
-
npmCWD
|
|
104
|
-
)}\n\n` +
|
|
105
|
-
"This is probably caused by a misconfigured system terminal shell."
|
|
106
|
-
)
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (process.platform === "win32") {
|
|
110
|
-
console.error(
|
|
111
|
-
chalk.red("On Windows, this can usually be fixed by running:\n\n") +
|
|
112
|
-
` ${chalk.cyan(
|
|
113
|
-
"reg"
|
|
114
|
-
)} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n` +
|
|
115
|
-
` ${chalk.cyan(
|
|
116
|
-
"reg"
|
|
117
|
-
)} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n\n` +
|
|
118
|
-
chalk.red("Try to run the above two lines in the terminal.\n") +
|
|
119
|
-
chalk.red(
|
|
120
|
-
"To learn more about this problem, read: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/"
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return false;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @return {object}
|
|
130
|
-
*/
|
|
131
|
-
const checkNpmVersion = function ()
|
|
132
|
-
{
|
|
133
|
-
let hasMinNpm = false;
|
|
134
|
-
let npmVersion = null;
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
npmVersion = execSync("npm --version").toString().trim();
|
|
138
|
-
hasMinNpm = semver.gte(npmVersion, "6.0.0");
|
|
139
|
-
} catch (err) {
|
|
140
|
-
// ignore
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
"hasMinNpm": hasMinNpm,
|
|
145
|
-
"npmVersion": npmVersion
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @param {string} root
|
|
151
|
-
* @param {string} app_name
|
|
152
|
-
* @param {string} template
|
|
153
|
-
* @param {array} dependencies
|
|
154
|
-
* @return {Promise<unknown>}
|
|
155
|
-
*/
|
|
156
|
-
const install = function (root, app_name, template, dependencies)
|
|
157
|
-
{
|
|
158
|
-
console.log("Installing packages. This may take a few minutes.");
|
|
159
|
-
|
|
160
|
-
const command = "npm";
|
|
161
|
-
new Promise((resolve, reject) =>
|
|
162
|
-
{
|
|
163
|
-
const args = [
|
|
164
|
-
"install",
|
|
165
|
-
"--no-audit",
|
|
166
|
-
"--save",
|
|
167
|
-
"--save-exact",
|
|
168
|
-
"--loglevel",
|
|
169
|
-
"error",
|
|
170
|
-
template
|
|
171
|
-
];
|
|
172
|
-
|
|
173
|
-
const child = spawn(command, args, { "stdio": "inherit" });
|
|
174
|
-
child
|
|
175
|
-
.on("close", (code) =>
|
|
176
|
-
{
|
|
177
|
-
if (code !== 0) {
|
|
178
|
-
|
|
179
|
-
reject({ "command": `${command} ${args.join(" ")}` });
|
|
180
|
-
process.exit(1);
|
|
181
|
-
|
|
182
|
-
} else {
|
|
183
|
-
|
|
184
|
-
console.log();
|
|
185
|
-
console.log(`Installing template: ${chalk.green(template)}`);
|
|
186
|
-
|
|
187
|
-
const templatePath = path.dirname(
|
|
188
|
-
require.resolve(`${template}/package.json`, { "paths": [root] })
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
const templateJsonPath = path.join(templatePath, "template.json");
|
|
192
|
-
|
|
193
|
-
let templateJson = {};
|
|
194
|
-
if (fs.existsSync(templateJsonPath)) {
|
|
195
|
-
templateJson = require(templateJsonPath);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const packageJson = require(`${root}/package.json`);
|
|
199
|
-
|
|
200
|
-
const templatePackage = templateJson.package || {};
|
|
201
|
-
const templateDependencies = templatePackage.dependencies || {};
|
|
202
|
-
const keys = Object.keys(templateDependencies);
|
|
203
|
-
for (let idx = 0; idx < keys.length; ++idx) {
|
|
204
|
-
|
|
205
|
-
const name = keys[idx];
|
|
206
|
-
if (templateDependencies[name] === "*") {
|
|
207
|
-
dependencies.push(name);
|
|
208
|
-
} else {
|
|
209
|
-
packageJson.dependencies[name] = templateDependencies[name];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
fs.writeFileSync(
|
|
214
|
-
path.join(root, "package.json"),
|
|
215
|
-
JSON.stringify(packageJson, null, 2) + os.EOL
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
const templateDir = path.join(templatePath, "template");
|
|
219
|
-
if (fs.existsSync(templateDir)) {
|
|
220
|
-
fs.copySync(templateDir, root);
|
|
221
|
-
} else {
|
|
222
|
-
console.error(
|
|
223
|
-
`Could not locate supplied template: ${chalk.green(templateDir)}`
|
|
224
|
-
);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const args = [
|
|
229
|
-
"uninstall",
|
|
230
|
-
"--no-audit",
|
|
231
|
-
"--save",
|
|
232
|
-
"--save-exact",
|
|
233
|
-
"--loglevel",
|
|
234
|
-
"error",
|
|
235
|
-
template
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
const child = spawn(command, args, { "stdio": "inherit" });
|
|
239
|
-
child
|
|
240
|
-
.on("close", (code) =>
|
|
241
|
-
{
|
|
242
|
-
if (code !== 0) {
|
|
243
|
-
reject({
|
|
244
|
-
"command": `${command} ${args.join(" ")}`
|
|
245
|
-
});
|
|
246
|
-
process.exit(1);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
resolve();
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
})
|
|
254
|
-
.then(() =>
|
|
255
|
-
{
|
|
256
|
-
const args = [
|
|
257
|
-
"install",
|
|
258
|
-
"--no-audit",
|
|
259
|
-
"--save",
|
|
260
|
-
"--save-exact",
|
|
261
|
-
"--loglevel",
|
|
262
|
-
"error"
|
|
263
|
-
].concat(dependencies);
|
|
264
|
-
|
|
265
|
-
const child = spawn(command, args, { "stdio": "inherit" });
|
|
266
|
-
child
|
|
267
|
-
.on("close", (code) =>
|
|
268
|
-
{
|
|
269
|
-
if (code !== 0) {
|
|
270
|
-
|
|
271
|
-
console.log();
|
|
272
|
-
console.error(`${command} ${args.join(" ")}`);
|
|
273
|
-
process.exit(1);
|
|
274
|
-
|
|
275
|
-
} else {
|
|
276
|
-
|
|
277
|
-
console.log();
|
|
278
|
-
console.log(`Success! Created ${chalk.green(app_name)} at ${chalk.green(root)}`);
|
|
279
|
-
|
|
280
|
-
console.log();
|
|
281
|
-
console.log("you can run several commands:");
|
|
282
|
-
|
|
283
|
-
console.log();
|
|
284
|
-
console.log(` ${chalk.green("npm start")}`);
|
|
285
|
-
console.log(" Starts the development server.");
|
|
286
|
-
|
|
287
|
-
console.log();
|
|
288
|
-
console.log(` ${chalk.green("npm run generate")}`);
|
|
289
|
-
console.log(" Generate the necessary View and ViewModel classes from the routing JSON file.");
|
|
290
|
-
|
|
291
|
-
console.log();
|
|
292
|
-
console.log(` ${chalk.green("npm run [ios|android|windows|macos] -- --env prd")}`);
|
|
293
|
-
console.log(" Start the emulator for each platform.");
|
|
294
|
-
|
|
295
|
-
console.log();
|
|
296
|
-
console.log(` ${chalk.green("npm run build -- --platform [windows|macos|web] --env prd")}`);
|
|
297
|
-
console.log(" Export a production version for each platform.");
|
|
298
|
-
|
|
299
|
-
console.log();
|
|
300
|
-
console.log(` ${chalk.green("npm test")}`);
|
|
301
|
-
console.log(" Starts the test runner.");
|
|
302
|
-
|
|
303
|
-
console.log();
|
|
304
|
-
console.log("We suggest that you begin by typing:");
|
|
305
|
-
console.log(` ${chalk.green("cd")} ${app_name}`);
|
|
306
|
-
console.log(` ${chalk.green("npm start")}`);
|
|
307
|
-
console.log();
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @param {string} app_name
|
|
315
|
-
* @param {string} [template="@next2d/framework-template"]
|
|
316
|
-
*/
|
|
317
|
-
const createApp = function (app_name, template = "@next2d/framework-template")
|
|
318
|
-
{
|
|
319
|
-
const root = path.resolve(app_name);
|
|
320
|
-
const appName = path.basename(root);
|
|
321
|
-
|
|
322
|
-
checkAppName(appName);
|
|
323
|
-
fs.ensureDirSync(app_name);
|
|
324
|
-
|
|
325
|
-
console.log();
|
|
326
|
-
console.log(`Creating a new Next2D app in ${chalk.green(root)}.`);
|
|
327
|
-
console.log();
|
|
328
|
-
|
|
329
|
-
fs.writeFileSync(
|
|
330
|
-
path.join(root, "package.json"),
|
|
331
|
-
JSON.stringify({
|
|
332
|
-
"name": appName,
|
|
333
|
-
"description": `Details of ${appName}`,
|
|
334
|
-
"version": "0.0.1",
|
|
335
|
-
"private": true,
|
|
336
|
-
"main": "src/index.js",
|
|
337
|
-
"scripts": {
|
|
338
|
-
"start": "webpack serve",
|
|
339
|
-
"ios": "npx @next2d/builder run ios --platform ios --debug",
|
|
340
|
-
"android": "npx @next2d/builder run android --platform android --debug",
|
|
341
|
-
"macos": "npx @next2d/builder --platform macos --debug",
|
|
342
|
-
"windows": "npx @next2d/builder --platform windows --debug",
|
|
343
|
-
"build": "npx @next2d/builder",
|
|
344
|
-
"lint": "eslint src/**/*.js",
|
|
345
|
-
"test": "npx jest",
|
|
346
|
-
"generate": "npx @next2d/view-generator"
|
|
347
|
-
}
|
|
348
|
-
}, null, 2) + os.EOL
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
process.chdir(root);
|
|
352
|
-
if (!checkThatNpmCanReadCwd()) {
|
|
353
|
-
process.exit(1);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const npmInfo = checkNpmVersion();
|
|
357
|
-
if (!npmInfo.hasMinNpm) {
|
|
358
|
-
if (npmInfo.npmVersion) {
|
|
359
|
-
console.log(
|
|
360
|
-
chalk.yellow(
|
|
361
|
-
`You are using npm ${npmInfo.npmVersion} so the project will be bootstrapped with an old unsupported version of tools.\n\n` +
|
|
362
|
-
"Please update to npm 6 or higher for a better, fully supported experience.\n"
|
|
363
|
-
)
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const ignoreList = [
|
|
369
|
-
"node_modules",
|
|
370
|
-
"coverage",
|
|
371
|
-
"dist",
|
|
372
|
-
".DS_Store",
|
|
373
|
-
".idea",
|
|
374
|
-
"Thumbs.db",
|
|
375
|
-
"npm-debug.log*",
|
|
376
|
-
"yarn-debug.log*",
|
|
377
|
-
"yarn-error.log*",
|
|
378
|
-
"src/config/Config.js",
|
|
379
|
-
"src/Packages.js",
|
|
380
|
-
"electron.index.json"
|
|
381
|
-
];
|
|
382
|
-
|
|
383
|
-
fs.writeFileSync(
|
|
384
|
-
path.join(root, ".gitignore"),
|
|
385
|
-
ignoreList.join(os.EOL)
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
install(root, appName, template, [
|
|
389
|
-
"@next2d/framework",
|
|
390
|
-
"@next2d/env",
|
|
391
|
-
"electron",
|
|
392
|
-
"webpack",
|
|
393
|
-
"webpack-cli",
|
|
394
|
-
"webpack-dev-server",
|
|
395
|
-
"@capacitor/cli",
|
|
396
|
-
"@capacitor/core",
|
|
397
|
-
"@capacitor/ios",
|
|
398
|
-
"@capacitor/android"
|
|
399
|
-
]);
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* @return {void}
|
|
404
|
-
*/
|
|
405
|
-
const exec = function ()
|
|
406
|
-
{
|
|
407
|
-
const program = new commander.Command(packageJson.name)
|
|
408
|
-
.version(packageJson.version)
|
|
409
|
-
.arguments("<project-directory>")
|
|
410
|
-
.usage(`${chalk.green("<project-directory>")} [options]`)
|
|
411
|
-
.action((name) => { projectName = name })
|
|
412
|
-
.option("--info", "print environment debug info")
|
|
413
|
-
.option(
|
|
414
|
-
"--template <path-to-template>",
|
|
415
|
-
"specify a template for the created project"
|
|
416
|
-
)
|
|
417
|
-
.on("--help", () =>
|
|
418
|
-
{
|
|
419
|
-
console.log();
|
|
420
|
-
console.log(` A custom ${chalk.cyan("--template")} can be one of:`);
|
|
421
|
-
console.log(
|
|
422
|
-
` - a custom template published on npm default: ${chalk.green(
|
|
423
|
-
"@next2d/framework-template"
|
|
424
|
-
)}`
|
|
425
|
-
);
|
|
426
|
-
|
|
427
|
-
console.log();
|
|
428
|
-
console.log(
|
|
429
|
-
" If you have any problems, do not hesitate to file an issue:"
|
|
430
|
-
);
|
|
431
|
-
console.log(
|
|
432
|
-
` ${chalk.cyan(
|
|
433
|
-
"https://github.com/Next2D/create-next2d-app/issues/new"
|
|
434
|
-
)}`
|
|
435
|
-
);
|
|
436
|
-
console.log();
|
|
437
|
-
})
|
|
438
|
-
.parse(process.argv);
|
|
439
|
-
|
|
440
|
-
if (typeof projectName === "undefined") {
|
|
441
|
-
|
|
442
|
-
console.error("Please specify the project directory:");
|
|
443
|
-
console.log(
|
|
444
|
-
` npx ${chalk.cyan(program.name())} ${chalk.green("<project-directory>")}`
|
|
445
|
-
);
|
|
446
|
-
console.log();
|
|
447
|
-
console.log("For example:");
|
|
448
|
-
console.log(
|
|
449
|
-
` npx ${chalk.cyan(program.name())} ${chalk.green("my-next2d-app")}`
|
|
450
|
-
);
|
|
451
|
-
process.exit(1);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
createApp(projectName, program.template);
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
exec();
|