index.ts 2.8 KB

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