index.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 { closeMilestoneTask } from './tasks/closeMilestone';
  10. import { precommitTask } from './tasks/precommit';
  11. import { searchTestDataSetupTask } from './tasks/searchTestDataSetup';
  12. program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
  13. program
  14. .command('core:start')
  15. .option('-h, --hot', 'Run front-end with HRM enabled')
  16. .option('-t, --watchTheme', 'Watch for theme changes and regenerate variables.scss files')
  17. .description('Starts Grafana front-end in development mode with watch enabled')
  18. .action(async cmd => {
  19. await execTask(startTask)({
  20. watchThemes: cmd.watchTheme,
  21. hot: cmd.hot,
  22. });
  23. });
  24. program
  25. .command('gui:build')
  26. .description('Builds @grafana/ui package to packages/grafana-ui/dist')
  27. .action(async cmd => {
  28. await execTask(buildTask)();
  29. });
  30. program
  31. .command('gui:release')
  32. .description('Prepares @grafana/ui release (and publishes to npm on demand)')
  33. .option('-p, --publish', 'Publish @grafana/ui to npm registry')
  34. .option('-u, --usePackageJsonVersion', 'Use version specified in package.json')
  35. .option('--createVersionCommit', 'Create and push version commit')
  36. .action(async cmd => {
  37. await execTask(releaseTask)({
  38. publishToNpm: !!cmd.publish,
  39. usePackageJsonVersion: !!cmd.usePackageJsonVersion,
  40. createVersionCommit: !!cmd.createVersionCommit,
  41. });
  42. });
  43. program
  44. .command('changelog')
  45. .option('-m, --milestone <milestone>', 'Specify milestone')
  46. .description('Builds changelog markdown')
  47. .action(async cmd => {
  48. if (!cmd.milestone) {
  49. console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
  50. return;
  51. }
  52. await execTask(changelogTask)({
  53. milestone: cmd.milestone,
  54. });
  55. });
  56. program
  57. .command('cherrypick')
  58. .description('Helps find commits to cherry pick')
  59. .action(async cmd => {
  60. await execTask(cherryPickTask)({});
  61. });
  62. program
  63. .command('close-milestone')
  64. .option('-m, --milestone <milestone>', 'Specify milestone')
  65. .description('Helps ends a milestone by removing the cherry-pick label and closing it')
  66. .action(async cmd => {
  67. if (!cmd.milestone) {
  68. console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
  69. return;
  70. }
  71. await execTask(closeMilestoneTask)({
  72. milestone: cmd.milestone,
  73. });
  74. });
  75. program
  76. .command('precommit')
  77. .description('Executes checks')
  78. .action(async cmd => {
  79. await execTask(precommitTask)({});
  80. });
  81. program
  82. .command('searchTestData')
  83. .option('-c, --count <number_of_dashboards>', 'Specify number of dashboards')
  84. .description('Setup test data for search')
  85. .action(async cmd => {
  86. await execTask(searchTestDataSetupTask)({ count: cmd.count });
  87. });
  88. program.parse(process.argv);
  89. if (program.depreciate && program.depreciate.length === 2) {
  90. console.log(
  91. chalk.yellow.bold(
  92. `[NPM script depreciation] ${program.depreciate[0]} is deprecated! Use ${program.depreciate[1]} instead!`
  93. )
  94. );
  95. }