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.

58 lines
1.2 KiB

4 years ago
4 years ago
  1. #!/usr/bin/env node
  2. const { Command } = require('commander');
  3. const Prompt = require('inquirer');
  4. const Create = require('./command/create');
  5. const program = new Command();
  6. const handleExit = () => {
  7. process.exit();
  8. };
  9. const handleError = (e) => {
  10. console.error('ERROR! 执行过程中出现错误');
  11. console.error(e);
  12. console.log('退出执行...');
  13. process.exit(1);
  14. };
  15. process.on('SIGINT', handleExit);
  16. process.on('uncaughtException', handleError);
  17. const Cli = program.command('tis-cli');
  18. Cli.version(require('../package.json').version).usage('<command> [options]');
  19. // 选项
  20. const templateOpts = [
  21. {
  22. type: 'list',
  23. name: 'templateType',
  24. message: '模板类型',
  25. choices: [
  26. {
  27. value: 1, name: 'platform 框架模板'
  28. },
  29. {
  30. value: 2, name: 'application 应用模板'
  31. },
  32. {
  33. value: 3, name: 'component 组件库模板'
  34. }
  35. ]
  36. }
  37. ];
  38. // 通过模板创建项目
  39. Cli
  40. .command('create <projectName>')
  41. .description('通过选择模板类型,创建新的项目')
  42. .action(async (projectName) => {
  43. Prompt.prompt(templateOpts).then(result => {
  44. // 创建
  45. Create(projectName, result.templateType);
  46. })
  47. });
  48. Cli.parse(process.argv)