forked from ninecat-ui/ninecat-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-component.js
More file actions
29 lines (24 loc) · 1.02 KB
/
Copy pathcreate-component.js
File metadata and controls
29 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const path = require('path');
const args = process.argv.splice(2);
const componentName = args[0];
let root = '../packages/';
let template = fs.readFileSync(path.join(__dirname, './component-template/template.vue'), 'utf8');
let className = 'n-' + componentName.toLowerCase();
let targetDirPathName = 'n' + componentName;
let content = template.replace(/n-ComponentName/g, className);
content = content.replace(/ComponentName/g, componentName);
let targetDirPath = path.join(__dirname, root, targetDirPathName);
let targetFilePath = path.join(__dirname, root, targetDirPathName, 'index.vue');
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath);
console.log('The ' + targetDirPath + ' folder has been created!');
}
if (!fs.existsSync(targetFilePath)) {
fs.writeFile(targetFilePath, content, (err) => {
if (err) throw err;
console.log('The ' + targetFilePath + ' folder has been created!');
});
} else {
console.error('error!\n' + targetFilePath + ' has already been existed!');
}