Minor refactor of cli tasks (core start, gui publishing)
This commit is contained in:
+40
-26
@@ -1,33 +1,47 @@
|
||||
import program from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { execTask } from './utils/execTask';
|
||||
import chalk from 'chalk';
|
||||
import { startTask } from './tasks/core.start';
|
||||
import { buildTask } from './tasks/grafanaui.build';
|
||||
import { releaseTask } from './tasks/grafanaui.release';
|
||||
|
||||
export type Task<T> = (options: T) => Promise<void>;
|
||||
program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
|
||||
|
||||
// TODO: Refactor to commander commands
|
||||
// This will enable us to have command scoped options and limit the ifs below
|
||||
program
|
||||
.option('-h, --hot', 'Runs front-end with hot reload enabled')
|
||||
.option('-t, --theme', 'Watches for theme changes and regenerates variables.scss files')
|
||||
.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','))
|
||||
.option('-b, --build', 'Created @grafana/ui build')
|
||||
.option('-r, --release', 'Releases @grafana/ui to npm')
|
||||
.parse(process.argv);
|
||||
|
||||
if (program.build) {
|
||||
execTask('grafanaui.build');
|
||||
} else if (program.release) {
|
||||
execTask('grafanaui.release');
|
||||
} else {
|
||||
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!`
|
||||
)
|
||||
);
|
||||
}
|
||||
execTask('core.start', {
|
||||
watchThemes: !!program.theme,
|
||||
hot: !!program.hot,
|
||||
.command('core:start')
|
||||
.option('-h, --hot', 'Run front-end with HRM enabled')
|
||||
.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.theme,
|
||||
hot: cmd.hot,
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
.command('gui:build')
|
||||
.description('Builds @grafana/ui package to packages/grafana-ui/dist')
|
||||
.action(async cmd => {
|
||||
await execTask(buildTask)();
|
||||
});
|
||||
|
||||
program
|
||||
.command('gui:release')
|
||||
.description('Prepares @grafana/ui release (and publishes to npm on demand)')
|
||||
.option('-p, --publish', 'Publish @grafana/ui to npm registry')
|
||||
.action(async cmd => {
|
||||
await execTask(releaseTask)({
|
||||
publishToNpm: !!cmd.publish,
|
||||
});
|
||||
});
|
||||
|
||||
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!`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user