@next2d/view-generator 1.4.0 → 1.4.2
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/index.js +132 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ const fs = require("fs-extra");
|
|
|
21
21
|
/**
|
|
22
22
|
* @return {void}
|
|
23
23
|
*/
|
|
24
|
-
const
|
|
24
|
+
const createJavaScriptFile = function ()
|
|
25
25
|
{
|
|
26
26
|
|
|
27
27
|
console.log();
|
|
@@ -132,7 +132,132 @@ export class ${name}ViewModel extends ViewModel
|
|
|
132
132
|
.factory(view)
|
|
133
133
|
.then((view) =>
|
|
134
134
|
{
|
|
135
|
-
|
|
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.js`);
|
|
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.js`);
|
|
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)
|
|
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);
|
|
136
261
|
});
|
|
137
262
|
}
|
|
138
263
|
}`);
|
|
@@ -154,7 +279,11 @@ const exec = function ()
|
|
|
154
279
|
.version(packageJson.version)
|
|
155
280
|
.parse(process.argv);
|
|
156
281
|
|
|
157
|
-
|
|
282
|
+
if (!fs.existsSync(`${process.cwd()}/src/index.ts`)) {
|
|
283
|
+
createTypeScriptFile();
|
|
284
|
+
} else {
|
|
285
|
+
createJavaScriptFile();
|
|
286
|
+
}
|
|
158
287
|
};
|
|
159
288
|
|
|
160
289
|
exec();
|