@next2d/view-generator 1.5.3 → 2.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Next2D
3
+ Copyright (c) 2021 - 2023 Next2D
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ import pc from "picocolors";
4
+ import path from "path";
5
+ import fs from "fs";
6
+ const recommendeVersion = 18;
7
+ const version = process.versions.node;
8
+ if (recommendeVersion > parseInt(version.split(".")[0])) {
9
+ pc.red(`You are running Node Version:${version}.
10
+ View Generator requires Node ${recommendeVersion} or higher.
11
+ Please update your version of Node.`);
12
+ process.exit(1);
13
+ }
14
+ /**
15
+ * @params {string} dir
16
+ * @return {void}
17
+ * @method
18
+ * @public
19
+ */
20
+ const createDirectory = (dir) => {
21
+ if (!fs.existsSync(dir)) {
22
+ console.log(`${pc.green(`Create a new Directory ${dir}.`)}`);
23
+ console.log();
24
+ // create new dir.
25
+ fs.mkdirSync(dir, { "recursive": true });
26
+ }
27
+ };
28
+ /**
29
+ * @params {string} name
30
+ * @return {string}
31
+ * @method
32
+ * @public
33
+ */
34
+ const createViewFileForJavaScript = (name) => {
35
+ return `import { View } from "@next2d/framework";
36
+
37
+ /**
38
+ * @class
39
+ * @extends {View}
40
+ */
41
+ export class ${name}View extends View
42
+ {
43
+ /**
44
+ * @constructor
45
+ * @public
46
+ */
47
+ constructor ()
48
+ {
49
+ super();
50
+ }
51
+ }`;
52
+ };
53
+ /**
54
+ * @params {string} name
55
+ * @return {string}
56
+ * @method
57
+ * @public
58
+ */
59
+ const createViewModelFileForJavaScript = (name) => {
60
+ return `import { ViewModel } from "@next2d/framework";
61
+
62
+ /**
63
+ * @class
64
+ * @extends {ViewModel}
65
+ */
66
+ export class ${name}ViewModel extends ViewModel
67
+ {
68
+ /**
69
+ * @param {View} view
70
+ * @return {void}
71
+ * @method
72
+ * @public
73
+ */
74
+ unbind (view)
75
+ {
76
+ console.log(view);
77
+ }
78
+
79
+ /**
80
+ * @param {View} view
81
+ * @return {Promise}
82
+ * @method
83
+ * @public
84
+ */
85
+ bind (view)
86
+ {
87
+ return this
88
+ .factory(view)
89
+ .then((view) =>
90
+ {
91
+ return Promise.resolve(view);
92
+ });
93
+ }
94
+ }`;
95
+ };
96
+ /**
97
+ * @params {string} name
98
+ * @return {string}
99
+ * @method
100
+ * @public
101
+ */
102
+ const createViewFileForTypeScript = (name) => {
103
+ return `import { View } from "@next2d/framework";
104
+
105
+ /**
106
+ * @class
107
+ * @extends {View}
108
+ */
109
+ export class ${name}View extends View
110
+ {
111
+ /**
112
+ * @constructor
113
+ * @public
114
+ */
115
+ constructor ()
116
+ {
117
+ super();
118
+ }
119
+ }`;
120
+ };
121
+ /**
122
+ * @params {string} name
123
+ * @return {string}
124
+ * @method
125
+ * @public
126
+ */
127
+ const createViewModelFileForTypeScript = (name) => {
128
+ return `import { View, ViewModel } from "@next2d/framework";
129
+
130
+ /**
131
+ * @class
132
+ * @extends {ViewModel}
133
+ */
134
+ export class ${name}ViewModel extends ViewModel
135
+ {
136
+ /**
137
+ * @param {View} view
138
+ * @return {void}
139
+ * @method
140
+ * @public
141
+ */
142
+ unbind (view: View): void
143
+ {
144
+ console.log(view);
145
+ }
146
+
147
+ /**
148
+ * @param {View} view
149
+ * @return {Promise}
150
+ * @method
151
+ * @public
152
+ */
153
+ bind (view: View): Promise<View>
154
+ {
155
+ return this
156
+ .factory(view)
157
+ .then((view: View): Promise<View> =>
158
+ {
159
+ return Promise.resolve(view);
160
+ });
161
+ }
162
+ }`;
163
+ };
164
+ /**
165
+ * @return {void}
166
+ * @method
167
+ * @public
168
+ */
169
+ const execute = () => {
170
+ console.log(pc.green("Generate the View, ViewModel class required for routing."));
171
+ console.log();
172
+ console.log(pc.green("Begin research."));
173
+ console.log();
174
+ const cwd = `${process.cwd()}/src/`;
175
+ const routingPath = path.join(cwd, "config/routing.json");
176
+ if (!fs.existsSync(routingPath)) {
177
+ console.log(pc.red("Could not find routing.json."));
178
+ console.log();
179
+ return;
180
+ }
181
+ const useTypeScript = fs.existsSync(`${process.cwd()}/src/index.ts`);
182
+ const ext = useTypeScript ? "ts" : "js";
183
+ const routing = JSON.parse(fs.readFileSync(routingPath, { "encoding": "utf8" }));
184
+ const keys = Object.keys(routing);
185
+ for (let idx = 0; idx < keys.length; ++idx) {
186
+ const names = keys[idx].split(/-|\//);
187
+ if (names[0].charAt(0) === "@") {
188
+ continue;
189
+ }
190
+ const viewDir = path.join(cwd, `view/${names[0]}`);
191
+ createDirectory(viewDir);
192
+ let name = "";
193
+ for (let idx = 0; names.length > idx; ++idx) {
194
+ const base = names[idx];
195
+ name += base
196
+ .charAt(0)
197
+ .toUpperCase() + base.slice(1);
198
+ }
199
+ // create View file
200
+ const viewFile = path.join(viewDir, `${name}View.${ext}`);
201
+ if (!fs.existsSync(viewFile)) {
202
+ console.log(`Create a new View Class ${viewFile}.`);
203
+ console.log();
204
+ fs.writeFileSync(viewFile, useTypeScript
205
+ ? createViewFileForTypeScript(name)
206
+ : createViewFileForJavaScript(name));
207
+ }
208
+ // create ViewModel file
209
+ const viewModelFile = path.join(viewDir, `${name}ViewModel.${ext}`);
210
+ if (!fs.existsSync(viewModelFile)) {
211
+ console.log(`Create a new ViewModel Class ${viewModelFile}.`);
212
+ console.log();
213
+ fs.writeFileSync(viewModelFile, useTypeScript
214
+ ? createViewModelFileForTypeScript(name)
215
+ : createViewModelFileForJavaScript(name));
216
+ }
217
+ }
218
+ console.log(pc.green("Finished."));
219
+ console.log();
220
+ };
221
+ execute();
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@next2d/view-generator",
3
- "version": "1.5.3",
3
+ "version": "2.0.1",
4
4
  "description": "Generate the View class required for routing.",
5
- "author": "Toshiyuki Ienaga<ienaga@tvon.jp>",
5
+ "author": "Toshiyuki Ienaga<ienaga@next2d.app>",
6
6
  "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "type": "module",
7
10
  "homepage": "https://next2d.app",
8
11
  "bugs": "https://github.com/Next2D/view-generator/issues",
9
12
  "keywords": [
@@ -11,21 +14,26 @@
11
14
  "view-generator"
12
15
  ],
13
16
  "scripts": {
14
- "lint": "eslint index.js"
17
+ "publish": "tsc"
15
18
  },
19
+ "files": [
20
+ "dist"
21
+ ],
16
22
  "repository": {
17
23
  "type": "git",
18
24
  "url": "git+https://github.com/Next2D/view-generator.git"
19
25
  },
20
26
  "bin": {
21
- "@next2d/view-generator": "index.js"
27
+ "@next2d/view-generator": "dist/index.js"
22
28
  },
23
29
  "devDependencies": {
24
- "eslint": "^8.22.0"
30
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
31
+ "@typescript-eslint/parser": "^6.10.0",
32
+ "eslint": "^8.53.0",
33
+ "typescript": "^5.2.2"
25
34
  },
26
35
  "dependencies": {
27
- "chalk": "4.1.2",
28
- "commander": "^9.4.0",
29
- "fs-extra": "^10.1.0"
36
+ "@types/node": "^20.9.0",
37
+ "picocolors": "^1.0.0"
30
38
  }
31
39
  }
package/SECURITY.md DELETED
@@ -1,3 +0,0 @@
1
- # Reporting Security Issues
2
-
3
- If you believe you have found a security vulnerability in Next2D, we encourage you to let us know right away. We will investigate all legitimate reports and do our best to quickly fix the problem.
package/index.js DELETED
@@ -1,289 +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
- "View Generator requires Node 14 or higher. \n" +
10
- "Please update your version of Node."
11
- );
12
- process.exit(1);
13
- }
14
-
15
- const chalk = require("chalk");
16
- const { Command } = require("commander");
17
- const packageJson = require("./package.json");
18
- const path = require("path");
19
- const fs = require("fs-extra");
20
-
21
- /**
22
- * @return {void}
23
- */
24
- const createJavaScriptFile = function ()
25
- {
26
-
27
- console.log();
28
- console.log(`${chalk.green("Begin research.")}`);
29
- console.log();
30
-
31
- const cwd = `${process.cwd()}/src/`;
32
-
33
- const routingPath = path.join(cwd, "config/routing.json");
34
- if (!fs.existsSync(routingPath)) {
35
- console.log(`${chalk.red("Could not find routing.json.")}`);
36
- console.log();
37
- return ;
38
- }
39
-
40
- const routing = require(routingPath);
41
- const keys = Object.keys(routing);
42
-
43
- for (let idx = 0; idx < keys.length; ++idx) {
44
-
45
- const names = keys[idx].split(/-|\//);
46
-
47
- if (names[0].charAt(0) === "@") {
48
- continue;
49
- }
50
-
51
- const viewDir = path.join(cwd, `view/${names[0]}`);
52
- if (!fs.existsSync(viewDir)) {
53
-
54
- console.log(`${chalk.green(`Create a new Directory ${viewDir}.`)}`);
55
- console.log();
56
-
57
- fs.ensureDirSync(viewDir);
58
- }
59
-
60
- let name = "";
61
- for (let idx = 0; names.length > idx; ++idx) {
62
-
63
- const base = names[idx];
64
-
65
- name += base
66
- .charAt(0)
67
- .toUpperCase() + base.slice(1);
68
-
69
- }
70
-
71
- // create View file
72
- const viewFile = path.join(viewDir, `${name}View.js`);
73
- if (!fs.existsSync(viewFile)) {
74
-
75
- console.log(`Create a new View Class ${viewFile}.`);
76
- console.log();
77
-
78
- fs.writeFileSync(viewFile, `import { View } from "@next2d/framework";
79
-
80
- /**
81
- * @class
82
- * @extends {View}
83
- */
84
- export class ${name}View extends View
85
- {
86
- /**
87
- * @constructor
88
- * @public
89
- */
90
- constructor ()
91
- {
92
- super();
93
- }
94
- }`);
95
- }
96
-
97
- // create ViewModel file
98
- const viewModelFile = path.join(viewDir, `${name}ViewModel.js`);
99
- if (!fs.existsSync(viewModelFile)) {
100
-
101
- console.log(`Create a new ViewModel Class ${viewModelFile}.`);
102
- console.log();
103
-
104
- fs.writeFileSync(viewModelFile, `import { ViewModel } from "@next2d/framework";
105
-
106
- /**
107
- * @class
108
- * @extends {ViewModel}
109
- */
110
- export class ${name}ViewModel extends ViewModel
111
- {
112
- /**
113
- * @param {View} view
114
- * @return {void}
115
- * @method
116
- * @public
117
- */
118
- unbind (view)
119
- {
120
- console.log(view);
121
- }
122
-
123
- /**
124
- * @param {View} view
125
- * @return {Promise}
126
- * @method
127
- * @public
128
- */
129
- bind (view)
130
- {
131
- return this
132
- .factory(view)
133
- .then((view) =>
134
- {
135
- return Promise.resolve(view);
136
- });
137
- }
138
- }`);
139
- }
140
- }
141
-
142
- console.log(`${chalk.green("Finished.")}`);
143
- console.log();
144
- };
145
-
146
- /**
147
- * @return {void}
148
- */
149
- const createTypeScriptFile = function ()
150
- {
151
-
152
- console.log();
153
- console.log(`${chalk.green("Begin research.")}`);
154
- console.log();
155
-
156
- const cwd = `${process.cwd()}/src/`;
157
-
158
- const routingPath = path.join(cwd, "config/routing.json");
159
- if (!fs.existsSync(routingPath)) {
160
- console.log(`${chalk.red("Could not find routing.json.")}`);
161
- console.log();
162
- return ;
163
- }
164
-
165
- const routing = require(routingPath);
166
- const keys = Object.keys(routing);
167
-
168
- for (let idx = 0; idx < keys.length; ++idx) {
169
-
170
- const names = keys[idx].split(/-|\//);
171
-
172
- if (names[0].charAt(0) === "@") {
173
- continue;
174
- }
175
-
176
- const viewDir = path.join(cwd, `view/${names[0]}`);
177
- if (!fs.existsSync(viewDir)) {
178
-
179
- console.log(`${chalk.green(`Create a new Directory ${viewDir}.`)}`);
180
- console.log();
181
-
182
- fs.ensureDirSync(viewDir);
183
- }
184
-
185
- let name = "";
186
- for (let idx = 0; names.length > idx; ++idx) {
187
-
188
- const base = names[idx];
189
-
190
- name += base
191
- .charAt(0)
192
- .toUpperCase() + base.slice(1);
193
-
194
- }
195
-
196
- // create View file
197
- const viewFile = path.join(viewDir, `${name}View.ts`);
198
- if (!fs.existsSync(viewFile)) {
199
-
200
- console.log(`Create a new View Class ${viewFile}.`);
201
- console.log();
202
-
203
- fs.writeFileSync(viewFile, `import { View } from "@next2d/framework";
204
-
205
- /**
206
- * @class
207
- * @extends {View}
208
- */
209
- export class ${name}View extends View
210
- {
211
- /**
212
- * @constructor
213
- * @public
214
- */
215
- constructor ()
216
- {
217
- super();
218
- }
219
- }`);
220
- }
221
-
222
- // create ViewModel file
223
- const viewModelFile = path.join(viewDir, `${name}ViewModel.ts`);
224
- if (!fs.existsSync(viewModelFile)) {
225
-
226
- console.log(`Create a new ViewModel Class ${viewModelFile}.`);
227
- console.log();
228
-
229
- fs.writeFileSync(viewModelFile, `import { View, ViewModel } from "@next2d/framework";
230
-
231
- /**
232
- * @class
233
- * @extends {ViewModel}
234
- */
235
- export class ${name}ViewModel extends ViewModel
236
- {
237
- /**
238
- * @param {View} view
239
- * @return {void}
240
- * @method
241
- * @public
242
- */
243
- unbind (view: View): void
244
- {
245
- console.log(view);
246
- }
247
-
248
- /**
249
- * @param {View} view
250
- * @return {Promise}
251
- * @method
252
- * @public
253
- */
254
- bind (view: View): Promise<View>
255
- {
256
- return this
257
- .factory(view)
258
- .then((view) =>
259
- {
260
- return Promise.resolve(view);
261
- });
262
- }
263
- }`);
264
- }
265
- }
266
-
267
- console.log(`${chalk.green("Finished.")}`);
268
- console.log();
269
- };
270
-
271
- /**
272
- * @return {void}
273
- */
274
- const exec = function ()
275
- {
276
- new Command()
277
- .name(packageJson.name)
278
- .description("Generate the View, ViewModel class required for routing.")
279
- .version(packageJson.version)
280
- .parse(process.argv);
281
-
282
- if (fs.existsSync(`${process.cwd()}/src/index.ts`)) {
283
- createTypeScriptFile();
284
- } else {
285
- createJavaScriptFile();
286
- }
287
- };
288
-
289
- exec();