Skip to content

Commit 7cae6ac

Browse files
authored
Merge pull request #3 from web-csq/main
优化生成组件模板逻辑
2 parents 641458b + 385e88f commit 7cae6ac

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

public/static/attributes/IText.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"classId": "idm.componet.basics.text",
2+
"classId": "idm.component.basics.text",
33
"comName": "文本",
44
"className": "IText",
55
"comType": "common",

public/static/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"className": "basics",
66
"module": [
77
{
8-
"classId": "idm.componet.basics.text",
8+
"classId": "idm.component.basics.text",
99
"comName": "文本",
1010
"className": "IText",
1111
"comType": "common",

scripts/generateComponent.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,40 @@ log(`Please enter the IDM component's className/comName to be generated, like IT
3131
process.stdin.on('data', async (chunk) => {
3232
const inputStr = String(chunk).trim().toString()
3333
const dataArray = inputStr && inputStr.split('/')
34-
if(dataArray.length !== 2) {
34+
if(!Array.isArray(dataArray) || dataArray.length !== 2) {
3535
log('Please enter the correct data format')
3636
return
3737
}
3838
// 组件类名
39-
const className = inputStr.split('/')[0]
39+
const className = dataArray[0]
4040
// 组件中文名
41-
const comName = inputStr.split('/')[1]
42-
// 组件路径
43-
const componentPath = resolve('../src/components')
41+
const comName = dataArray[1]
4442
// vue文件
45-
const vueFile = resolve(componentPath, `${className}.vue`)
43+
const vueFile = resolve('../src/components', `${className}.vue`)
4644
// json文件
4745
const jsonFile = resolve('../public/static/attributes', `${className}.json`)
4846
// configJson文件
4947
const configJson = resolve('../public/static/config.json')
5048
// 判断组件文件夹是否存在
5149
let fileExists = fs.existsSync(vueFile)
5250
if (fileExists) {
53-
errorLog(`${className}vue component already exists, please re-enter`)
51+
errorLog(`${className} vue component already exists, please re-enter`)
5452
return
5553
}
5654
// 配置json是否存在
5755
fileExists = fs.existsSync(jsonFile)
5856
if (fileExists) {
59-
errorLog(`${className}json already exists, please re-enter`)
57+
errorLog(`${className} json already exists, please re-enter`)
6058
return
6159
}
6260
// static/config.json内是否已经配置
6361
const configIndex = jsonObj.module.findIndex(el => el.className === className || el.comName === comName)
6462
if(configIndex > -1) {
65-
errorLog(`static/config.json already exists, please re-enter`)
63+
errorLog(`static/config.json has configured, please re-enter`)
6664
return
6765
}
6866

6967
try {
70-
7168
const packageName = jsonObj.className
7269
// 获取组件名
7370
log(`Generating vue file ${vueFile}`)

scripts/template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default {
127127
},
128128
jsonTemplate: (componentInfo) => {
129129
return `{
130-
"classId": "idm.componet.${componentInfo.packageName}.${componentInfo.className.toLowerCase()}",
130+
"classId": "idm.component.${componentInfo.packageName}.${componentInfo.className.toLowerCase()}",
131131
"comName": "${componentInfo.comName}",
132132
"className": "${componentInfo.className}",
133133
"comType": "common",
@@ -416,7 +416,7 @@ export default {
416416
},
417417
configItem: (componentInfo) => {
418418
return {
419-
classId: `idm.componet.${componentInfo.packageName}.${componentInfo.className.toLowerCase()}`,
419+
classId: `idm.component.${componentInfo.packageName}.${componentInfo.className.toLowerCase()}`,
420420
comName: `${componentInfo.comName}`,
421421
className: `${componentInfo.className}`,
422422
comType: 'common',

0 commit comments

Comments
 (0)