index.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import program from 'commander';
  2. import { execTask } from './utils/execTask';
  3. import chalk from 'chalk';
  4. import { startTask } from './tasks/core.start';
  5. import { buildTask } from './tasks/grafanaui.build';
  6. import { releaseTask } from './tasks/grafanaui.release';
  7. import { changelogTask } from './tasks/changelog';
  8. import { cherryPickTask } from './tasks/cherrypick';
  9. import { precommitTask } from './tasks/precommit';
  10. program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
  11. program
  12. .command('core:start')
  13. .option('-h, --hot', 'Run front-end with HRM enabled')
  14. .option('-t, --watchTheme', 'Watch for theme changes and regenerate variables.scss files')
  15. .description('Starts Grafana front-end in development mode with watch enabled')
  16. .action(async cmd => {
  17. await execTask(startTask)({
  18. watchThemes: cmd.watchTheme,
  19. hot: cmd.hot,
  20. });
  21. });
  22. program
  23. .command('gui:build')
  24. .description('Builds @grafana/ui package to packages/grafana-ui/dist')
  25. .action(async cmd => {
  26. await execTask(buildTask)();
  27. });
  28. program
  29. .command('gui:release')
  30. .description('Prepares @grafana/ui release (and publishes to npm on demand)')
  31. .option('-p, --publish', 'Publish @grafana/ui to npm registry')
  32. .option('-u, --usePackageJsonVersion', 'Use version specified in package.json')
  33. .option('--createVersionCommit', 'Create and push version commit')
  34. .action(async cmd => {
  35. await execTask(releaseTask)({
  36. publishToNpm: !!cmd.publish,
  37. usePackageJsonVersion: !!cmd.usePackageJsonVersion,
  38. createVersionCommit: !!cmd.createVersionCommit,
  39. });
  40. });
  41. program
  42. .command('changelog')
  43. .option('-m, --milestone <milestone>', 'Specify milestone')
  44. .description('Builds changelog markdown')
  45. .action(async cmd => {
  46. if (!cmd.milestone) {
  47. console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
  48. return;
  49. }
  50. await execTask(changelogTask)({
  51. milestone: cmd.milestone,
  52. });
  53. });
  54. program
  55. .command('cherrypick')
  56. .description('Helps find commits to cherry pick')
  57. .action(async cmd => {
  58. await execTask(cherryPickTask)({});
  59. });
  60. program
  61. .command('precommit')
  62. .description('Executes checks')
  63. .action(async cmd => {
  64. await execTask(precommitTask)({});
  65. });
  66. program.parse(process.argv);
  67. if (program.depreciate && program.depreciate.length === 2) {
  68. console.log(
  69. chalk.yellow.bold(
  70. `[NPM script depreciation] ${program.depreciate[0]} is deprecated! Use ${program.depreciate[1]} instead!`
  71. )
  72. );
  73. }