easy-soft-develop 2.1.4 → 2.1.5
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/bin/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ const clearAllDependence = require('../src/cliCollection/clear-all-dependence');
|
|
|
14
14
|
const updatePackageFromPackage = require('../src/cliCollection/update-package-from-package');
|
|
15
15
|
const createProjectWithTemplate = require('../src/cliCollection/create-project-with-template');
|
|
16
16
|
const prompt = require('../src/cliCollection/prompt');
|
|
17
|
+
const code = require('../src/cliCollection/createCode');
|
|
17
18
|
|
|
18
19
|
const program = new Command();
|
|
19
20
|
|
|
@@ -129,4 +130,12 @@ program
|
|
|
129
130
|
createProjectWithTemplate.run(a, o);
|
|
130
131
|
});
|
|
131
132
|
|
|
133
|
+
program
|
|
134
|
+
.command('code')
|
|
135
|
+
.description('generate code source with code.json')
|
|
136
|
+
.option('--dataPath <string>', 'data json source file path')
|
|
137
|
+
.action((a, o) => {
|
|
138
|
+
code.run(a, o);
|
|
139
|
+
});
|
|
140
|
+
|
|
132
141
|
program.parse(getArgCollection());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-soft-develop",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/kityandhero/easy-soft-develop#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"commitlint": "npx commitlint --edit",
|
|
30
30
|
"test:bin:check-all-package-version": "node ./bin/cli.js check-all-package-version",
|
|
31
|
+
"test:bin:code": "node ./bin/cli.js code --dataPath ./develop/generatorCodeSource/code.json",
|
|
31
32
|
"test:bin:commit-refresh": "node ./bin/cli.js commit-refresh",
|
|
32
33
|
"test:bin:create-assist-scripts": "node ./bin/cli.js create-assist-scripts",
|
|
33
34
|
"test:bin:create-lerna-project": "node ./bin/cli.js create-lerna-project",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
/* eslint-disable no-useless-escape */
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
promptWarn,
|
|
6
|
+
checkStringIsEmpty,
|
|
7
|
+
readJsonFileSync,
|
|
8
|
+
isObject,
|
|
9
|
+
exit,
|
|
10
|
+
promptInfo,
|
|
11
|
+
} = require('../tools/meta');
|
|
12
|
+
const { generateCode } = require('../tools/createCode');
|
|
13
|
+
|
|
14
|
+
exports.run = function (s, o) {
|
|
15
|
+
const {
|
|
16
|
+
_optionValues: { dataPath = '' },
|
|
17
|
+
} = o;
|
|
18
|
+
|
|
19
|
+
if (checkStringIsEmpty(dataPath)) {
|
|
20
|
+
promptWarn('please input data json file path, use --help to get help info');
|
|
21
|
+
|
|
22
|
+
exit();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const data = readJsonFileSync(dataPath);
|
|
26
|
+
|
|
27
|
+
if (isObject(data)) {
|
|
28
|
+
if (Array.isArray(data.list)) {
|
|
29
|
+
promptInfo('Code file will create, please wait a moment');
|
|
30
|
+
|
|
31
|
+
generateCode(data.list);
|
|
32
|
+
} else {
|
|
33
|
+
const simple = {
|
|
34
|
+
list: [
|
|
35
|
+
{
|
|
36
|
+
sourceFilePath: 'componentA/index.jsx',
|
|
37
|
+
codeFilePath: 'componentA/codeSource.js',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
promptWarn(
|
|
43
|
+
`in the data json file, key "list" value is not an array, it must be like this ${JSON.stringify(
|
|
44
|
+
simple,
|
|
45
|
+
)}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exit();
|
|
51
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
/* eslint-disable no-useless-escape */
|
|
3
|
+
|
|
4
|
+
const { readFileSync } = require('node:fs');
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
promptEmptyLine,
|
|
8
|
+
promptWarn,
|
|
9
|
+
promptSuccess,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} = require('./meta');
|
|
12
|
+
|
|
13
|
+
function getCodeContent(code) {
|
|
14
|
+
const v = `${code}`.replaceAll('`', '\\`').replaceAll('$', '\\$');
|
|
15
|
+
return `export const code = \`${v}\`;
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function checkDataItem(item) {
|
|
20
|
+
if (item.sourceFilePath === undefined) {
|
|
21
|
+
promptWarn('data has error, check item: ');
|
|
22
|
+
|
|
23
|
+
console.log(item);
|
|
24
|
+
|
|
25
|
+
promptEmptyLine();
|
|
26
|
+
|
|
27
|
+
throw new Error('data has not key "sourceFilePath"');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (item.codeFilePath === undefined) {
|
|
31
|
+
promptWarn('data has error, check item: ');
|
|
32
|
+
|
|
33
|
+
console.log(item);
|
|
34
|
+
|
|
35
|
+
promptEmptyLine();
|
|
36
|
+
|
|
37
|
+
throw new Error('data has not key "codeFilePath"');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function adjustSource(o) {
|
|
42
|
+
const d = { ...o };
|
|
43
|
+
|
|
44
|
+
const sourceFilePath = d.sourceFilePath;
|
|
45
|
+
|
|
46
|
+
if (sourceFilePath === undefined) {
|
|
47
|
+
promptWarn('data has error, check item: ');
|
|
48
|
+
|
|
49
|
+
console.log(d);
|
|
50
|
+
|
|
51
|
+
promptEmptyLine();
|
|
52
|
+
|
|
53
|
+
throw new Error('data has not key "sourceFilePath"');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const codeFilePath = d.codeFilePath;
|
|
57
|
+
|
|
58
|
+
if (codeFilePath === undefined) {
|
|
59
|
+
promptWarn('data has error, check item: ');
|
|
60
|
+
|
|
61
|
+
console.log(d);
|
|
62
|
+
|
|
63
|
+
promptEmptyLine();
|
|
64
|
+
|
|
65
|
+
throw new Error('data has not key "codeFilePath"');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return d;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function generateCode(dataSource) {
|
|
72
|
+
const dataAdjust = dataSource.map((o) => adjustSource(o));
|
|
73
|
+
|
|
74
|
+
for (const o of dataAdjust) {
|
|
75
|
+
checkDataItem(o);
|
|
76
|
+
|
|
77
|
+
const { sourceFilePath, codeFilePath } = o;
|
|
78
|
+
|
|
79
|
+
const codeSource = readFileSync(sourceFilePath);
|
|
80
|
+
|
|
81
|
+
const content = getCodeContent(codeSource);
|
|
82
|
+
|
|
83
|
+
writeFileSync(codeFilePath, content, {
|
|
84
|
+
coverFile: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
promptSuccess(`Create "${codeFilePath}" complete`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = {
|
|
92
|
+
generateCode,
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function run(s: any, o: any): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function generateCode(dataSource: any): void;
|