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