jsc.js 785 B

123456789101112131415161718192021222324252627282930313233343536
  1. // js调用cli 兼容调用ts
  2. const { sh } = require('tasksfile');
  3. const { argv } = require('yargs');
  4. let command = ``;
  5. Object.keys(argv).forEach((key) => {
  6. if (!/^\$/.test(key) && key !== '_') {
  7. // @ts-ignore
  8. if (argv[key]) {
  9. command += `--${key} `;
  10. }
  11. }
  12. });
  13. // 执行任务名称
  14. let taskList = argv._;
  15. let NODE_ENV = process.env.NODE_ENV || 'development';
  16. if (taskList.includes('build') || taskList.includes('report') || taskList.includes('preview')) {
  17. NODE_ENV = 'production';
  18. }
  19. if (taskList && Array.isArray(taskList) && taskList.length) {
  20. sh(
  21. `cross-env NODE_ENV=${NODE_ENV} ts-node --project ./build/tsconfig.json ./build/script/cli.ts ${taskList.join(
  22. ' '
  23. )} ${command}`,
  24. {
  25. async: true,
  26. nopipe: true,
  27. }
  28. );
  29. }