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.

56 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
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. }).catch(err => {
  20. console.log('创建失败');
  21. });
  22. // 复制文件
  23. switch (parseInt(templateType)) {
  24. case 1:
  25. fs.copy(path.join(__dirname, '../../templates/platform'), projectName)
  26. .then(() => {
  27. console.log('\n创建成功!\n')
  28. console.log(`\n cd ${projectName} 进行使用 \n`);
  29. })
  30. .catch(err => console.error(err));
  31. break;
  32. case 2:
  33. fs.copy(path.join(__dirname, '../../templates/application'), projectName)
  34. .then(() => {
  35. console.log('\n创建成功!\n')
  36. console.log(`\n cd ${projectName} 进行使用 \n`);
  37. })
  38. .catch(err => console.error(err));
  39. break;
  40. case 3:
  41. fs.copy(path.join(__dirname, '../../templates/component'), projectName)
  42. .then(() => {
  43. console.log('\n创建成功!\n')
  44. console.log(`\n cd ${projectName} 进行使用 \n`);
  45. })
  46. .catch(err => console.error(err));
  47. break;
  48. default:
  49. break;
  50. }
  51. });
  52. }