neo.mjs 4.0.49 → 4.0.50
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/buildScripts/createClass.mjs +191 -0
- package/package.json +2 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command } from 'commander/esm.mjs';
|
|
3
|
+
import envinfo from 'envinfo';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
const __dirname = path.resolve(),
|
|
10
|
+
cwd = process.cwd(),
|
|
11
|
+
requireJson = path => JSON.parse(fs.readFileSync((path))),
|
|
12
|
+
packageJson = requireJson(path.join(__dirname, 'package.json')),
|
|
13
|
+
insideNeo = packageJson.name === 'neo.mjs',
|
|
14
|
+
program = new Command(),
|
|
15
|
+
programName = `${packageJson.name} create-class`,
|
|
16
|
+
questions = [];
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.name(programName)
|
|
20
|
+
.version(packageJson.version)
|
|
21
|
+
.option('-i, --info', 'print environment debug info')
|
|
22
|
+
.option('-b, --baseClass <value>')
|
|
23
|
+
.option('-c, --className <value>')
|
|
24
|
+
.allowUnknownOption()
|
|
25
|
+
.on('--help', () => {
|
|
26
|
+
console.log('\nIn case you have any issues, please create a ticket here:');
|
|
27
|
+
console.log(chalk.cyan(process.env.npm_package_bugs_url));
|
|
28
|
+
})
|
|
29
|
+
.parse(process.argv);
|
|
30
|
+
|
|
31
|
+
const programOpts = program.opts();
|
|
32
|
+
|
|
33
|
+
if (programOpts.info) {
|
|
34
|
+
console.log(chalk.bold('\nEnvironment Info:'));
|
|
35
|
+
console.log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
|
|
36
|
+
console.log(` running from ${__dirname}`);
|
|
37
|
+
|
|
38
|
+
envinfo
|
|
39
|
+
.run({
|
|
40
|
+
System : ['OS', 'CPU'],
|
|
41
|
+
Binaries : ['Node', 'npm', 'Yarn'],
|
|
42
|
+
Browsers : ['Chrome', 'Edge', 'Firefox', 'Safari'],
|
|
43
|
+
npmPackages: ['neo.mjs']
|
|
44
|
+
}, {
|
|
45
|
+
duplicates : true,
|
|
46
|
+
showNotFound: true
|
|
47
|
+
})
|
|
48
|
+
.then(console.log);
|
|
49
|
+
} else {
|
|
50
|
+
console.log(chalk.green(programName));
|
|
51
|
+
|
|
52
|
+
if (!programOpts.className) {
|
|
53
|
+
questions.push({
|
|
54
|
+
type : 'input',
|
|
55
|
+
name : 'className',
|
|
56
|
+
message: 'Please choose the namespace for your class:',
|
|
57
|
+
default: 'Covid.view.FooContainer'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!programOpts.baseClass) {
|
|
62
|
+
questions.push({
|
|
63
|
+
type : 'list',
|
|
64
|
+
name : 'baseClass',
|
|
65
|
+
message: 'Please pick the base class, which you want to extend:',
|
|
66
|
+
choices: ['component.Base', 'container.Base'],
|
|
67
|
+
default: 'component.Base'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
inquirer.prompt(questions).then(answers => {
|
|
72
|
+
let baseClass = programOpts.baseClass || answers.baseClass,
|
|
73
|
+
className = programOpts.className || answers.className,
|
|
74
|
+
startDate = new Date(),
|
|
75
|
+
classFolder, file, folderDelta, ns, root, rootLowerCase;
|
|
76
|
+
|
|
77
|
+
if (className.endsWith('.mjs')) {
|
|
78
|
+
className = className.slice(0, -4);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ns = className.split('.');
|
|
82
|
+
file = ns.pop();
|
|
83
|
+
root = ns.shift();
|
|
84
|
+
rootLowerCase = root.toLowerCase();
|
|
85
|
+
|
|
86
|
+
if (root === 'Neo') {
|
|
87
|
+
console.log('todo: create the file inside the src folder');
|
|
88
|
+
} else {
|
|
89
|
+
if (fs.existsSync(path.resolve(cwd, 'apps', rootLowerCase))) {
|
|
90
|
+
classFolder = path.resolve(cwd, 'apps', rootLowerCase, ns.join('/'));
|
|
91
|
+
folderDelta = ns.length + 2;
|
|
92
|
+
|
|
93
|
+
fs.mkdirpSync(classFolder);
|
|
94
|
+
|
|
95
|
+
fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({baseClass, className, file, folderDelta, ns, root}));
|
|
96
|
+
} else {
|
|
97
|
+
console.log('\nNon existing neo app name:', chalk.red(root));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
|
|
103
|
+
console.log(`\nTotal time for ${programName}: ${processTime}s`);
|
|
104
|
+
|
|
105
|
+
process.exit();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Adds a comma to the last element of the contentArray
|
|
110
|
+
* @param {String[]} contentArray
|
|
111
|
+
*/
|
|
112
|
+
function addComma(contentArray) {
|
|
113
|
+
contentArray[contentArray.length - 1] += ',';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Creates the content of the neo-class .mjs file
|
|
118
|
+
* @param {Object} opts
|
|
119
|
+
* @param {String} opts.baseClass
|
|
120
|
+
* @param {String} opts.className
|
|
121
|
+
* @param {String} opts.file
|
|
122
|
+
* @param {String} opts.folderDelta
|
|
123
|
+
* @param {String} opts.ns
|
|
124
|
+
* @param {String} opts.root
|
|
125
|
+
* @returns {String}
|
|
126
|
+
*/
|
|
127
|
+
function createContent(opts) {
|
|
128
|
+
let baseClass = opts.baseClass,
|
|
129
|
+
baseClassNs = baseClass.split('.'),
|
|
130
|
+
baseFileName = baseClassNs.pop(),
|
|
131
|
+
className = opts.className,
|
|
132
|
+
file = opts.file,
|
|
133
|
+
i = 0,
|
|
134
|
+
importDelta = '';
|
|
135
|
+
|
|
136
|
+
for (; i < opts.folderDelta; i++) {
|
|
137
|
+
importDelta += '../';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let classContent = [
|
|
141
|
+
`import ${baseFileName} from '${importDelta}${(insideNeo ? '' : 'node_modules/neo.mjs/')}src/${baseClassNs.join('/')}/${baseFileName}.mjs';`,
|
|
142
|
+
"",
|
|
143
|
+
"/**",
|
|
144
|
+
" * @class " + className,
|
|
145
|
+
" * @extends Neo." + baseClass,
|
|
146
|
+
" */",
|
|
147
|
+
`class ${file} extends ${baseFileName} {`,
|
|
148
|
+
" static getConfig() {return {",
|
|
149
|
+
" /*",
|
|
150
|
+
` * @member {String} className='${className}'`,
|
|
151
|
+
" * @protected",
|
|
152
|
+
" */",
|
|
153
|
+
` className: '${className}'`
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
if (baseClass === 'component.Base') {
|
|
157
|
+
addComma(classContent);
|
|
158
|
+
|
|
159
|
+
classContent.push(
|
|
160
|
+
" /*",
|
|
161
|
+
" * @member {Object} _vdom",
|
|
162
|
+
" */",
|
|
163
|
+
" _vdom:",
|
|
164
|
+
" {}",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (baseClass === 'container.Base') {
|
|
169
|
+
addComma(classContent);
|
|
170
|
+
|
|
171
|
+
classContent.push(
|
|
172
|
+
" /*",
|
|
173
|
+
" * @member {Object[]} items",
|
|
174
|
+
" */",
|
|
175
|
+
" items: []",
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
classContent.push(
|
|
180
|
+
" }}",
|
|
181
|
+
"}",
|
|
182
|
+
"",
|
|
183
|
+
`Neo.applyClassConfig(${file});`,
|
|
184
|
+
"",
|
|
185
|
+
`export default ${file};`,
|
|
186
|
+
""
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
return classContent.join(os.EOL);
|
|
190
|
+
}
|
|
191
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neo.mjs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.50",
|
|
4
4
|
"description": "The webworkers driven UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"build-themes": "node ./buildScripts/buildThemes.mjs -f",
|
|
15
15
|
"build-threads": "node ./buildScripts/webpack/buildThreads.mjs -f",
|
|
16
16
|
"create-app": "node ./buildScripts/createApp.mjs",
|
|
17
|
+
"create-class": "node ./buildScripts/createClass.mjs",
|
|
17
18
|
"generate-docs-json": "node ./buildScripts/docs/jsdocx.mjs",
|
|
18
19
|
"server-start": "webpack serve -c ./buildScripts/webpack/webpack.server.config.mjs --open",
|
|
19
20
|
"test": "echo \"Error: no test specified\" && exit 1",
|