index.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // @ts-ignore
  2. import program from 'commander';
  3. import { execTask } from './utils/execTask';
  4. import chalk from 'chalk';
  5. import { startTask } from './tasks/core.start';
  6. import { changelogTask } from './tasks/changelog';
  7. import { cherryPickTask } from './tasks/cherrypick';
  8. import { precommitTask } from './tasks/precommit';
  9. import { templateTask } from './tasks/template';
  10. import { pluginBuildTask } from './tasks/plugin.build';
  11. import { toolkitBuildTask } from './tasks/toolkit.build';
  12. import { pluginTestTask } from './tasks/plugin.tests';
  13. import { searchTestDataSetupTask } from './tasks/searchTestDataSetup';
  14. import { closeMilestoneTask } from './tasks/closeMilestone';
  15. import { pluginDevTask } from './tasks/plugin.dev';
  16. import {
  17. ciBuildPluginTask,
  18. ciBuildPluginDocsTask,
  19. ciPackagePluginTask,
  20. ciTestPluginTask,
  21. ciPluginReportTask,
  22. } from './tasks/plugin.ci';
  23. import { buildPackageTask } from './tasks/package.build';
  24. export const run = (includeInternalScripts = false) => {
  25. if (includeInternalScripts) {
  26. program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
  27. program
  28. .command('core:start')
  29. .option('-h, --hot', 'Run front-end with HRM enabled')
  30. .option('-T, --noTsCheck', 'Run bundler without TS type checking')
  31. .option('-t, --watchTheme', 'Watch for theme changes and regenerate variables.scss files')
  32. .description('Starts Grafana front-end in development mode with watch enabled')
  33. .action(async cmd => {
  34. await execTask(startTask)({
  35. watchThemes: cmd.watchTheme,
  36. noTsCheck: cmd.noTsCheck,
  37. hot: cmd.hot,
  38. });
  39. });
  40. program
  41. .command('package:build')
  42. .option('-s, --scope <packages>', 'packages=[data|runtime|ui|toolkit]')
  43. .description('Builds @grafana/* package to packages/grafana-*/dist')
  44. .action(async cmd => {
  45. await execTask(buildPackageTask)({
  46. scope: cmd.scope,
  47. });
  48. });
  49. program
  50. .command('changelog')
  51. .option('-m, --milestone <milestone>', 'Specify milestone')
  52. .description('Builds changelog markdown')
  53. .action(async cmd => {
  54. if (!cmd.milestone) {
  55. console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
  56. return;
  57. }
  58. await execTask(changelogTask)({
  59. milestone: cmd.milestone,
  60. });
  61. });
  62. program
  63. .command('cherrypick')
  64. .description('Helps find commits to cherry pick')
  65. .action(async cmd => {
  66. await execTask(cherryPickTask)({});
  67. });
  68. program
  69. .command('precommit')
  70. .description('Executes checks')
  71. .action(async cmd => {
  72. await execTask(precommitTask)({});
  73. });
  74. program
  75. .command('debug:template')
  76. .description('Just testing')
  77. .action(async cmd => {
  78. await execTask(templateTask)({});
  79. });
  80. program
  81. .command('toolkit:build')
  82. .description('Prepares grafana/toolkit dist package')
  83. .action(async cmd => {
  84. // @ts-ignore
  85. await execTask(toolkitBuildTask)();
  86. });
  87. program
  88. .command('searchTestData')
  89. .option('-c, --count <number_of_dashboards>', 'Specify number of dashboards')
  90. .description('Setup test data for search')
  91. .action(async cmd => {
  92. await execTask(searchTestDataSetupTask)({ count: cmd.count });
  93. });
  94. program
  95. .command('close-milestone')
  96. .option('-m, --milestone <milestone>', 'Specify milestone')
  97. .description('Helps ends a milestone by removing the cherry-pick label and closing it')
  98. .action(async cmd => {
  99. if (!cmd.milestone) {
  100. console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
  101. return;
  102. }
  103. await execTask(closeMilestoneTask)({
  104. milestone: cmd.milestone,
  105. });
  106. });
  107. }
  108. program
  109. .command('plugin:build')
  110. .description('Prepares plugin dist package')
  111. .action(async cmd => {
  112. await execTask(pluginBuildTask)({ coverage: false });
  113. });
  114. program
  115. .command('plugin:dev')
  116. .option('-w, --watch', 'Run plugin development mode with watch enabled')
  117. .option('--yarnlink', 'symlink this project to the local grafana/toolkit')
  118. .description('Starts plugin dev mode')
  119. .action(async cmd => {
  120. await execTask(pluginDevTask)({
  121. watch: !!cmd.watch,
  122. yarnlink: !!cmd.yarnlink,
  123. });
  124. });
  125. program
  126. .command('plugin:test')
  127. .option('-u, --updateSnapshot', 'Run snapshots update')
  128. .option('--coverage', 'Run code coverage')
  129. .option('--watch', 'Run tests in interactive watch mode')
  130. .option('--testPathPattern <regex>', 'Run only tests with a path that matches the regex')
  131. .option('--testNamePattern <regex>', 'Run only tests with a name that matches the regex')
  132. .description('Executes plugin tests')
  133. .action(async cmd => {
  134. await execTask(pluginTestTask)({
  135. updateSnapshot: !!cmd.updateSnapshot,
  136. coverage: !!cmd.coverage,
  137. watch: !!cmd.watch,
  138. testPathPattern: cmd.testPathPattern,
  139. testNamePattern: cmd.testNamePattern,
  140. });
  141. });
  142. program
  143. .command('plugin:ci-build')
  144. .option('--backend', 'Run Makefile for backend task', false)
  145. .description('Build the plugin, leaving results in /dist and /coverage')
  146. .action(async cmd => {
  147. if (typeof cmd === 'string') {
  148. console.error(`Invalid argument: ${cmd}\nSee --help for a list of available commands.`);
  149. process.exit(1);
  150. }
  151. await execTask(ciBuildPluginTask)({
  152. backend: cmd.backend,
  153. });
  154. });
  155. program
  156. .command('plugin:ci-docs')
  157. .description('Build the HTML docs')
  158. .action(async cmd => {
  159. await execTask(ciBuildPluginDocsTask)({});
  160. });
  161. program
  162. .command('plugin:ci-package')
  163. .description('Create a zip packages for the plugin')
  164. .action(async cmd => {
  165. await execTask(ciPackagePluginTask)({});
  166. });
  167. program
  168. .command('plugin:ci-test')
  169. .option('--full', 'run all the tests (even stuff that will break)')
  170. .description('end-to-end test using bundle in /artifacts')
  171. .action(async cmd => {
  172. await execTask(ciTestPluginTask)({
  173. full: cmd.full,
  174. });
  175. });
  176. program
  177. .command('plugin:ci-report')
  178. .description('Build a report for this whole process')
  179. .option('--upload', 'upload packages also')
  180. .action(async cmd => {
  181. await execTask(ciPluginReportTask)({
  182. upload: cmd.upload,
  183. });
  184. });
  185. program.on('command:*', () => {
  186. console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
  187. process.exit(1);
  188. });
  189. program.parse(process.argv);
  190. if (program.depreciate && program.depreciate.length === 2) {
  191. console.log(
  192. chalk.yellow.bold(
  193. `[NPM script depreciation] ${program.depreciate[0]} is deprecated! Use ${program.depreciate[1]} instead!`
  194. )
  195. );
  196. }
  197. };