antd-management-fast-develop 1.1.86 → 1.1.89
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 +14 -0
- package/package.json +3 -2
- package/src/cliCollection/generateTemplate.js +83 -0
- package/src/tools/generateTemplate.js +58 -0
package/bin/cli.js
CHANGED
@@ -8,6 +8,7 @@ const { Command } = require('commander');
|
|
8
8
|
const { getArgCollection } = require('easy-soft-develop');
|
9
9
|
|
10
10
|
const generator = require('../src/cliCollection/generate');
|
11
|
+
const templateGenerator = require('../src/cliCollection/generateTemplate');
|
11
12
|
|
12
13
|
const program = new Command();
|
13
14
|
|
@@ -28,4 +29,17 @@ program
|
|
28
29
|
generator.run(a, o);
|
29
30
|
});
|
30
31
|
|
32
|
+
program
|
33
|
+
.command('generateByTemplate')
|
34
|
+
.description('generate file by template')
|
35
|
+
.option('--dataPath <string>', 'data json source file path')
|
36
|
+
.option('--templatePath <string>', 'template file path')
|
37
|
+
.option(
|
38
|
+
'--relativeFolder <bool>',
|
39
|
+
'file will be generate by the relative folder path, default is "."',
|
40
|
+
)
|
41
|
+
.action((a, o) => {
|
42
|
+
templateGenerator.run(a, o);
|
43
|
+
});
|
44
|
+
|
31
45
|
program.parse(getArgCollection());
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "antd-management-fast-develop",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.89",
|
4
4
|
"description": "",
|
5
5
|
"license": "ISC",
|
6
6
|
"author": "",
|
@@ -18,9 +18,10 @@
|
|
18
18
|
"types/"
|
19
19
|
],
|
20
20
|
"scripts": {
|
21
|
-
"ejs:test": "node ./bin/cli.js generate --dataPath ./src/data.json --dataExtraPath ./src/data.extra.json",
|
22
21
|
"precommit": "npm run z:lint:staged:quiet",
|
23
22
|
"publish:npm": "npm publish --registry https://registry.npmjs.org/",
|
23
|
+
"test:ejs:generate": "node ./bin/cli.js generate --dataPath ./src/data.json --dataExtraPath ./src/data.extra.json",
|
24
|
+
"test:ejs:generateByTemplate": "node ./bin/cli.js generateByTemplate --dataPath ./data/generateByTemplate.data.json --templatePath ./data/generateByTemplate.template.ejs --relativeFolder ./temp",
|
24
25
|
"z:auto:adjust:file": "echo can exec some file adjust command with here",
|
25
26
|
"prez:documentation:generate": "npx easy-soft-develop rimraf ./docs && npm run z:documentation:lint",
|
26
27
|
"z:documentation:generate": "npx documentation build src/** -f html --github -o docs",
|
@@ -0,0 +1,83 @@
|
|
1
|
+
/* eslint-disable no-undef */
|
2
|
+
/* eslint-disable unicorn/prefer-module */
|
3
|
+
/* eslint-disable no-useless-escape */
|
4
|
+
const { readFileSync } = require('node:fs');
|
5
|
+
const {
|
6
|
+
promptWarn,
|
7
|
+
checkStringIsEmpty,
|
8
|
+
readJsonFileSync,
|
9
|
+
isObject,
|
10
|
+
exit,
|
11
|
+
promptInfo,
|
12
|
+
exec,
|
13
|
+
resolvePath,
|
14
|
+
promptLine,
|
15
|
+
promptEmptyLine,
|
16
|
+
} = require('easy-soft-develop');
|
17
|
+
const { generate } = require('../tools/generateTemplate');
|
18
|
+
|
19
|
+
exports.run = function (s, o) {
|
20
|
+
const {
|
21
|
+
_optionValues: { dataPath = '', templatePath = '', relativeFolder = '.' },
|
22
|
+
} = o;
|
23
|
+
|
24
|
+
if (checkStringIsEmpty(dataPath)) {
|
25
|
+
promptWarn(
|
26
|
+
'please input data json file path or data extra json file path, use --help to get help info',
|
27
|
+
);
|
28
|
+
|
29
|
+
exit();
|
30
|
+
}
|
31
|
+
|
32
|
+
promptLine();
|
33
|
+
promptEmptyLine();
|
34
|
+
|
35
|
+
promptInfo(`template path: "${resolvePath(templatePath)}".`);
|
36
|
+
promptWarn(`template encoding make sure is utf-8.`);
|
37
|
+
|
38
|
+
const templateContent = readFileSync(resolvePath(templatePath), {
|
39
|
+
encoding: 'utf8',
|
40
|
+
});
|
41
|
+
|
42
|
+
promptLine();
|
43
|
+
|
44
|
+
promptInfo(templateContent);
|
45
|
+
|
46
|
+
promptLine();
|
47
|
+
|
48
|
+
promptEmptyLine();
|
49
|
+
|
50
|
+
let crateFileSuccess = false;
|
51
|
+
|
52
|
+
if (!checkStringIsEmpty(dataPath)) {
|
53
|
+
const data = readJsonFileSync(dataPath);
|
54
|
+
|
55
|
+
if (isObject(data) && Array.isArray(data.list)) {
|
56
|
+
promptInfo('File will generate, please wait a moment.');
|
57
|
+
|
58
|
+
generate(data.list, templateContent, relativeFolder);
|
59
|
+
|
60
|
+
crateFileSuccess = true;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
if (crateFileSuccess) {
|
65
|
+
promptLine();
|
66
|
+
|
67
|
+
const cmdEslint = `npx eslint --fix --cache --ext .js,.jsx,.ts,.tsx ${relativeFolder}/`;
|
68
|
+
|
69
|
+
promptInfo(`Eslint generated file: "${cmdEslint}".`);
|
70
|
+
|
71
|
+
exec(cmdEslint);
|
72
|
+
|
73
|
+
promptLine();
|
74
|
+
|
75
|
+
const cmdFormat = `npx prettier --cache --write ${relativeFolder}/`;
|
76
|
+
|
77
|
+
promptInfo(`Format generated file: "${cmdFormat}".`);
|
78
|
+
|
79
|
+
exec(cmdFormat);
|
80
|
+
}
|
81
|
+
|
82
|
+
exit();
|
83
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/* eslint-disable no-undef */
|
2
|
+
/* eslint-disable unicorn/prefer-module */
|
3
|
+
/* eslint-disable no-useless-escape */
|
4
|
+
|
5
|
+
const { compile } = require('ejs');
|
6
|
+
const {
|
7
|
+
writeFileSync,
|
8
|
+
mkdirSync,
|
9
|
+
promptSuccess,
|
10
|
+
promptWarn,
|
11
|
+
promptEmptyLine,
|
12
|
+
} = require('easy-soft-develop');
|
13
|
+
|
14
|
+
function generate(dataSource, templateContent, relativeFolder) {
|
15
|
+
const dataAdjust = dataSource.map((o) => adjustSource(o));
|
16
|
+
|
17
|
+
for (const o of dataAdjust) {
|
18
|
+
let content = compile(templateContent)({ o });
|
19
|
+
|
20
|
+
mkdirSync(`${relativeFolder}/${o.folder}`);
|
21
|
+
|
22
|
+
const { fileName, coverFile } = {
|
23
|
+
fileName: 'index.jsx',
|
24
|
+
coverFile: false,
|
25
|
+
...o,
|
26
|
+
};
|
27
|
+
|
28
|
+
writeFileSync(`${relativeFolder}/${o.folder}/index.jsx`, content, {
|
29
|
+
coverFile: coverFile || false,
|
30
|
+
});
|
31
|
+
|
32
|
+
promptSuccess(
|
33
|
+
`Generate complete: "${relativeFolder}/${o.folder}/${fileName || 'index.jsx'}".`,
|
34
|
+
);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
function adjustSource(o) {
|
39
|
+
const d = { ...o };
|
40
|
+
|
41
|
+
const folder = d.folder;
|
42
|
+
|
43
|
+
if (folder === undefined) {
|
44
|
+
promptWarn('data has error, check item: ');
|
45
|
+
|
46
|
+
console.log(d);
|
47
|
+
|
48
|
+
promptEmptyLine();
|
49
|
+
|
50
|
+
throw new Error('data has not key "functionSegment"');
|
51
|
+
}
|
52
|
+
|
53
|
+
return d;
|
54
|
+
}
|
55
|
+
|
56
|
+
module.exports = {
|
57
|
+
generate,
|
58
|
+
};
|