| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- // @ts-ignore
- import program from 'commander';
- import { execTask } from './utils/execTask';
- import chalk from 'chalk';
- import { startTask } from './tasks/core.start';
- import { changelogTask } from './tasks/changelog';
- import { cherryPickTask } from './tasks/cherrypick';
- import { precommitTask } from './tasks/precommit';
- import { templateTask } from './tasks/template';
- import { pluginBuildTask } from './tasks/plugin.build';
- import { toolkitBuildTask } from './tasks/toolkit.build';
- import { pluginTestTask } from './tasks/plugin.tests';
- import { searchTestDataSetupTask } from './tasks/searchTestDataSetup';
- import { closeMilestoneTask } from './tasks/closeMilestone';
- import { pluginDevTask } from './tasks/plugin.dev';
- import {
- ciBuildPluginTask,
- ciBuildPluginDocsTask,
- ciPackagePluginTask,
- ciTestPluginTask,
- ciPluginReportTask,
- } from './tasks/plugin.ci';
- import { buildPackageTask } from './tasks/package.build';
- export const run = (includeInternalScripts = false) => {
- if (includeInternalScripts) {
- program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
- program
- .command('core:start')
- .option('-h, --hot', 'Run front-end with HRM enabled')
- .option('-T, --noTsCheck', 'Run bundler without TS type checking')
- .option('-t, --watchTheme', 'Watch for theme changes and regenerate variables.scss files')
- .description('Starts Grafana front-end in development mode with watch enabled')
- .action(async cmd => {
- await execTask(startTask)({
- watchThemes: cmd.watchTheme,
- noTsCheck: cmd.noTsCheck,
- hot: cmd.hot,
- });
- });
- program
- .command('package:build')
- .option('-s, --scope <packages>', 'packages=[data|runtime|ui|toolkit]')
- .description('Builds @grafana/* package to packages/grafana-*/dist')
- .action(async cmd => {
- await execTask(buildPackageTask)({
- scope: cmd.scope,
- });
- });
- program
- .command('changelog')
- .option('-m, --milestone <milestone>', 'Specify milestone')
- .description('Builds changelog markdown')
- .action(async cmd => {
- if (!cmd.milestone) {
- console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
- return;
- }
- await execTask(changelogTask)({
- milestone: cmd.milestone,
- });
- });
- program
- .command('cherrypick')
- .description('Helps find commits to cherry pick')
- .action(async cmd => {
- await execTask(cherryPickTask)({});
- });
- program
- .command('precommit')
- .description('Executes checks')
- .action(async cmd => {
- await execTask(precommitTask)({});
- });
- program
- .command('debug:template')
- .description('Just testing')
- .action(async cmd => {
- await execTask(templateTask)({});
- });
- program
- .command('toolkit:build')
- .description('Prepares grafana/toolkit dist package')
- .action(async cmd => {
- // @ts-ignore
- await execTask(toolkitBuildTask)();
- });
- program
- .command('searchTestData')
- .option('-c, --count <number_of_dashboards>', 'Specify number of dashboards')
- .description('Setup test data for search')
- .action(async cmd => {
- await execTask(searchTestDataSetupTask)({ count: cmd.count });
- });
- program
- .command('close-milestone')
- .option('-m, --milestone <milestone>', 'Specify milestone')
- .description('Helps ends a milestone by removing the cherry-pick label and closing it')
- .action(async cmd => {
- if (!cmd.milestone) {
- console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
- return;
- }
- await execTask(closeMilestoneTask)({
- milestone: cmd.milestone,
- });
- });
- }
- program
- .command('plugin:build')
- .description('Prepares plugin dist package')
- .action(async cmd => {
- await execTask(pluginBuildTask)({ coverage: false });
- });
- program
- .command('plugin:dev')
- .option('-w, --watch', 'Run plugin development mode with watch enabled')
- .option('--yarnlink', 'symlink this project to the local grafana/toolkit')
- .description('Starts plugin dev mode')
- .action(async cmd => {
- await execTask(pluginDevTask)({
- watch: !!cmd.watch,
- yarnlink: !!cmd.yarnlink,
- });
- });
- program
- .command('plugin:test')
- .option('-u, --updateSnapshot', 'Run snapshots update')
- .option('--coverage', 'Run code coverage')
- .option('--watch', 'Run tests in interactive watch mode')
- .option('--testPathPattern <regex>', 'Run only tests with a path that matches the regex')
- .option('--testNamePattern <regex>', 'Run only tests with a name that matches the regex')
- .description('Executes plugin tests')
- .action(async cmd => {
- await execTask(pluginTestTask)({
- updateSnapshot: !!cmd.updateSnapshot,
- coverage: !!cmd.coverage,
- watch: !!cmd.watch,
- testPathPattern: cmd.testPathPattern,
- testNamePattern: cmd.testNamePattern,
- });
- });
- program
- .command('plugin:ci-build')
- .option('--backend', 'Run Makefile for backend task', false)
- .description('Build the plugin, leaving results in /dist and /coverage')
- .action(async cmd => {
- if (typeof cmd === 'string') {
- console.error(`Invalid argument: ${cmd}\nSee --help for a list of available commands.`);
- process.exit(1);
- }
- await execTask(ciBuildPluginTask)({
- backend: cmd.backend,
- });
- });
- program
- .command('plugin:ci-docs')
- .description('Build the HTML docs')
- .action(async cmd => {
- await execTask(ciBuildPluginDocsTask)({});
- });
- program
- .command('plugin:ci-package')
- .description('Create a zip packages for the plugin')
- .action(async cmd => {
- await execTask(ciPackagePluginTask)({});
- });
- program
- .command('plugin:ci-test')
- .option('--full', 'run all the tests (even stuff that will break)')
- .description('end-to-end test using bundle in /artifacts')
- .action(async cmd => {
- await execTask(ciTestPluginTask)({
- full: cmd.full,
- });
- });
- program
- .command('plugin:ci-report')
- .description('Build a report for this whole process')
- .option('--upload', 'upload packages also')
- .action(async cmd => {
- await execTask(ciPluginReportTask)({
- upload: cmd.upload,
- });
- });
- program.on('command:*', () => {
- console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
- process.exit(1);
- });
- program.parse(process.argv);
- if (program.depreciate && program.depreciate.length === 2) {
- console.log(
- chalk.yellow.bold(
- `[NPM script depreciation] ${program.depreciate[0]} is deprecated! Use ${program.depreciate[1]} instead!`
- )
- );
- }
- };
|