tis-cli前端项目快速搭建命令行工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.6 KiB

const chalk = require('chalk');
const path = require('path');
const fs = require('fs-extra');
module.exports = function(projectName, templateType) {
console.log('创建项目:', projectName);
console.log('类型:', templateType);
/**
* 类型:
* 1 platform
* 2 application
* 3 component
*/
console.log(chalk.white('\n 开始初始化... \n'));
return new Promise(async (resolve, reject) => {
// 创建文件目录
const dir = `${projectName}`;
await fs.ensureDir(dir).then(res => {
// console.log('创建成功');
}).catch(err => {
console.log('创建失败');
});
// 复制文件
switch (parseInt(templateType)) {
case 1:
fs.copy(path.join(__dirname, '../../templates/platform'), projectName)
.then(() => {
console.log('\n创建成功!\n')
console.log(`\n cd ${projectName} 进行使用 \n`);
})
.catch(err => console.error(err));
break;
case 2:
fs.copy(path.join(__dirname, '../../templates/application'), projectName)
.then(() => {
console.log('\n创建成功!\n')
console.log(`\n cd ${projectName} 进行使用 \n`);
})
.catch(err => console.error(err));
break;
case 3:
fs.copy(path.join(__dirname, '../../templates/component'), projectName)
.then(() => {
console.log('\n创建成功!\n')
console.log(`\n cd ${projectName} 进行使用 \n`);
})
.catch(err => console.error(err));
break;
default:
break;
}
});
}