antd-management-fast-develop 1.0.5 → 1.0.6
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/package.json
CHANGED
@@ -8,6 +8,8 @@ const {
|
|
8
8
|
readJsonFileSync,
|
9
9
|
isObject,
|
10
10
|
exit,
|
11
|
+
promptInfo,
|
12
|
+
exec,
|
11
13
|
} = require('easy-soft-develop');
|
12
14
|
const { generate } = require('../tools/generate');
|
13
15
|
|
@@ -26,7 +28,13 @@ exports.run = function (s, o) {
|
|
26
28
|
|
27
29
|
if (isObject(data)) {
|
28
30
|
if (Array.isArray(data.list)) {
|
31
|
+
promptInfo('File will generate, please wait a moment');
|
32
|
+
|
29
33
|
generate(data.list, relativeFolder);
|
34
|
+
|
35
|
+
promptInfo('Format generated file:');
|
36
|
+
|
37
|
+
exec(`npx prettier --write ${relativeFolder}/**`);
|
30
38
|
} else {
|
31
39
|
const simple = {
|
32
40
|
list: [
|
package/src/tools/generate.js
CHANGED
@@ -7,18 +7,22 @@ const {
|
|
7
7
|
writeFileSync,
|
8
8
|
mkdirSync,
|
9
9
|
promptSuccess,
|
10
|
+
promptWarn,
|
11
|
+
promptEmptyLine,
|
10
12
|
} = require('easy-soft-develop');
|
11
13
|
|
12
14
|
let { templateContent } = require('../template');
|
13
15
|
|
14
|
-
mkdirSync('./FunctionExtra', {
|
15
|
-
recursive: true,
|
16
|
-
});
|
17
|
-
|
18
16
|
function generate(dataSource, relativeFolder) {
|
17
|
+
mkdirSync(`${relativeFolder}/FunctionExtra`, {
|
18
|
+
recursive: true,
|
19
|
+
});
|
20
|
+
|
19
21
|
const dataAdjust = dataSource.map((o) => adjustSource(o));
|
20
22
|
|
21
23
|
for (const o of dataAdjust) {
|
24
|
+
checkDataItem(o);
|
25
|
+
|
22
26
|
let content = compile(templateContent)({ o });
|
23
27
|
|
24
28
|
mkdirSync(`${relativeFolder}/FunctionExtra/${o.functionSegment}`);
|
@@ -32,7 +36,7 @@ function generate(dataSource, relativeFolder) {
|
|
32
36
|
);
|
33
37
|
|
34
38
|
promptSuccess(
|
35
|
-
`
|
39
|
+
`Generate "${relativeFolder}/FunctionExtra/${o.functionSegment}/index.jsx" complete`,
|
36
40
|
);
|
37
41
|
}
|
38
42
|
}
|
@@ -40,6 +44,18 @@ function generate(dataSource, relativeFolder) {
|
|
40
44
|
function adjustSource(o) {
|
41
45
|
const d = { ...o };
|
42
46
|
|
47
|
+
const functionSegment = d.functionSegment;
|
48
|
+
|
49
|
+
if (functionSegment === undefined) {
|
50
|
+
promptWarn('data has error, check item: ');
|
51
|
+
|
52
|
+
console.log(d);
|
53
|
+
|
54
|
+
promptEmptyLine();
|
55
|
+
|
56
|
+
throw new Error('data has not key "functionSegment"');
|
57
|
+
}
|
58
|
+
|
43
59
|
d.defineName = toLowerFirst(d.functionSegment);
|
44
60
|
|
45
61
|
return d;
|
@@ -49,6 +65,48 @@ function toLowerFirst(o) {
|
|
49
65
|
return `${o.charAt(0)}`.toLowerCase() + o.slice(1);
|
50
66
|
}
|
51
67
|
|
68
|
+
function checkDataItem(item) {
|
69
|
+
if (item.functionSegment === undefined) {
|
70
|
+
promptWarn('data has error, check item: ');
|
71
|
+
|
72
|
+
console.log(item);
|
73
|
+
|
74
|
+
promptEmptyLine();
|
75
|
+
|
76
|
+
throw new Error('data has not key "functionSegment"');
|
77
|
+
}
|
78
|
+
|
79
|
+
if (item.defineName === undefined) {
|
80
|
+
promptWarn('data has error, check item: ');
|
81
|
+
|
82
|
+
console.log(item);
|
83
|
+
|
84
|
+
promptEmptyLine();
|
85
|
+
|
86
|
+
throw new Error('data has not key "defineName"');
|
87
|
+
}
|
88
|
+
|
89
|
+
if (item.label === undefined) {
|
90
|
+
promptWarn('data has error, check item: ');
|
91
|
+
|
92
|
+
console.log(item);
|
93
|
+
|
94
|
+
promptEmptyLine();
|
95
|
+
|
96
|
+
throw new Error('data has not key "label"');
|
97
|
+
}
|
98
|
+
|
99
|
+
if (item.name === undefined) {
|
100
|
+
promptWarn('data has error, check item: ');
|
101
|
+
|
102
|
+
console.log(item);
|
103
|
+
|
104
|
+
promptEmptyLine();
|
105
|
+
|
106
|
+
throw new Error('data has not key "name"');
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
52
110
|
module.exports = {
|
53
111
|
generate,
|
54
112
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export function run(s: any, o: any): void;
|
package/types/index.d.ts
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
export const templateContent: "\nimport {\n isInvalid,\n isNull,\n isUndefined,\n refitCommonData,\n searchFromList,\n} from 'easy-soft-utility';\n\nimport {\n unknownLabel,\n unlimitedWithStringFlag,\n} from 'antd-management-fast-common';\nimport {\n buildFlexRadio,\n buildFlexSelect,\n buildFormRadio,\n buildFormSelect,\n buildOptionItem,\n buildRadioItem,\n buildSearchFormSelect,\n} from 'antd-management-fast-component';\n\nexport function refit<%= o.functionSegment %>List({ metaData, withUnlimited = true }) {\n const { <%= o.defineName %>List: list } = {\n <%= o.defineName %>List: [],\n ...metaData,\n };\n\n if (withUnlimited) {\n return refitCommonData(list, unlimitedWithStringFlag);\n }\n\n return refitCommonData(list);\n}\n\nexport function get<%= o.functionSegment %>Name({ metaData, value, defaultValue = '' }) {\n if (isInvalid(value)) {\n return defaultValue;\n }\n\n const item = searchFromList(\n 'flag',\n `${isNull(isUndefined(value) ? null : value) ? '' : value}`,\n refit<%= o.functionSegment %>List({ metaData, withUnlimited: false }),\n );\n\n return item == null ? '未知' : item.name;\n}\n\nexport function render<%= o.functionSegment %>Option({\n metaData,\n withUnlimited = true,\n adjustListDataCallback = null,\n}) {\n const listData = refit<%= o.functionSegment %>List({ metaData, withUnlimited });\n\n return buildOptionItem({ list: listData, adjustListDataCallback });\n}\n\nexport function render<%= o.functionSegment %>Radio({\n metaData,\n withUnlimited = true,\n adjustListDataCallback = null,\n}) {\n const listData = refit<%= o.functionSegment %>List({ metaData, withUnlimited });\n\n return buildRadioItem({ list: listData, adjustListDataCallback });\n}\n\nexport function renderSearch<%= o.functionSegment %>Select({\n metaData = null,\n withUnlimited = true,\n label = '<%= o.label %>',\n name = '<%= o.name %>',\n helper = null,\n}) {\n const title = label || unknownLabel;\n\n return buildSearchFormSelect({\n label: title,\n name,\n helper,\n list: refit<%= o.functionSegment %>List({ metaData, withUnlimited }),\n dataConvert: (o) => o,\n });\n}\n\nexport function renderCustom<%= o.functionSegment %>Select({\n metaData = null,\n label = '<%= o.label %>',\n separator = ':',\n size = 'middle',\n onChange: onChangeCallback,\n innerProps: innerProperties = null,\n}) {\n return buildFlexSelect({\n label,\n defaultValue: null,\n separator,\n size,\n list: refit<%= o.functionSegment %>List({ metaData, withUnlimited: true }),\n dataConvert: (o, index) => {\n const { flag, name } = o;\n\n return { index, label: name, value: flag, disabled: false, ...o };\n },\n renderItem: null,\n onChange: onChangeCallback,\n innerProps: innerProperties,\n });\n}\n\nexport function renderForm<%= o.functionSegment %>Select({\n metaData = null,\n helper = null,\n onChange: onChangeCallback,\n label = '<%= o.label %>',\n formItemLayout = null,\n required = true,\n name = '<%= o.name %>',\n innerProps: innerProperties = null,\n}) {\n const title = label || unknownLabel;\n\n return buildFormSelect({\n label: title,\n name,\n helper,\n list: refit<%= o.functionSegment %>List({ metaData, withUnlimited: false }),\n dataConvert: (o, index) => {\n const { flag, name } = o;\n\n return { index, label: name, value: flag, disabled: false, ...o };\n },\n onChange: onChangeCallback,\n formItemLayout,\n required,\n innerProps: innerProperties,\n });\n}\n\nexport function renderCustom<%= o.functionSegment %>Radio({\n metaData = null,\n label = '<%= o.label %>',\n separator = ': ',\n size = 'middle',\n onChange: onChangeCallback,\n innerProps: innerProperties = null,\n}) {\n return buildFlexRadio({\n label,\n defaultValue: null,\n separator,\n size,\n list: refit<%= o.functionSegment %>List({ metaData, withUnlimited: true }),\n dataConvert: (o, index) => {\n const { flag, name } = o;\n\n return { index, label: name, value: flag, disabled: false, ...o };\n },\n renderItem: null,\n onChange: onChangeCallback,\n innerProps: innerProperties,\n });\n}\n\nexport function renderForm<%= o.functionSegment %>Radio({\n metaData = null,\n helper = null,\n onChange: onChangeCallback,\n label = '<%= o.label %>',\n formItemLayout = null,\n required = true,\n name = '<%= o.name %>',\n innerProps: innerProperties = null,\n}) {\n const title = label || unknownLabel;\n\n return buildFormRadio({\n label: title,\n name,\n helper,\n list: refit<%= o.functionSegment %>List({ metaData, withUnlimited: false }),\n dataConvert: (o, index) => {\n const { flag, name } = o;\n\n return { index, label: name, value: flag, disabled: false, ...o };\n },\n onChange: onChangeCallback,\n formItemLayout,\n required,\n innerProps: innerProperties,\n });\n}\n";
|
@@ -0,0 +1 @@
|
|
1
|
+
export function generate(dataSource: any, relativeFolder: any): void;
|