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.

47 lines
1.1 KiB

4 years ago
4 years ago
  1. const chalk = require('chalk');
  2. const path = require('path');
  3. const fs = require('fs-extra');
  4. module.exports = function(projectName, templateType) {
  5. console.log('创建项目:', projectName);
  6. console.log('类型:', templateType);
  7. /**
  8. * 类型
  9. * 1 platform
  10. * 2 application
  11. * 3 component
  12. */
  13. console.log(chalk.white('\n 开始初始化... \n'));
  14. return new Promise(async (resolve, reject) => {
  15. // 创建文件目录
  16. const dir = `${projectName}`;
  17. await fs.ensureDir(dir).then(res => {
  18. console.log('创建成功');
  19. console.log(res);
  20. }).catch(err => {
  21. console.log('创建失败');
  22. });
  23. // 复制文件
  24. switch (parseInt(templateType)) {
  25. case 1:
  26. console.log('框架');
  27. console.log(__dirname);
  28. fs.copy(path.join(__dirname, '../../templates/platform'), projectName)
  29. .then(() => console.log('success!'))
  30. .catch(err => console.error(err));
  31. break;
  32. case 2:
  33. console.log('应用');
  34. break;
  35. case 3:
  36. console.log('组件库');
  37. break;
  38. default:
  39. break;
  40. }
  41. });
  42. }