2020-09-09 09:01:18 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {Arguments, Argv, CommandModule} from 'yargs';
|
|
|
|
|
2021-04-12 17:50:50 -04:00
|
|
|
import {getConfig} from '../../utils/config';
|
2020-09-09 09:01:18 -04:00
|
|
|
import {error, green, info, red, yellow} from '../../utils/console';
|
|
|
|
import {addGithubTokenOption} from '../../utils/git/github-yargs';
|
2021-04-12 17:50:50 -04:00
|
|
|
import {GitClient} from '../../utils/git/index';
|
2020-10-01 19:06:56 -04:00
|
|
|
import {getReleaseConfig} from '../config/index';
|
2020-09-09 09:01:18 -04:00
|
|
|
|
|
|
|
import {CompletionState, ReleaseTool} from './index';
|
|
|
|
|
|
|
|
/** Command line options for publishing a release. */
|
|
|
|
export interface ReleasePublishOptions {
|
|
|
|
githubToken: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Yargs command builder for configuring the `ng-dev release publish` command. */
|
|
|
|
function builder(argv: Argv): Argv<ReleasePublishOptions> {
|
|
|
|
return addGithubTokenOption(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Yargs command handler for staging a release. */
|
2021-04-18 05:46:57 -04:00
|
|
|
async function handler() {
|
2021-04-12 17:50:50 -04:00
|
|
|
const git = GitClient.getInstance();
|
2020-09-09 09:01:18 -04:00
|
|
|
const config = getConfig();
|
|
|
|
const releaseConfig = getReleaseConfig(config);
|
2021-04-12 17:50:50 -04:00
|
|
|
const projectDir = git.baseDir;
|
2021-04-18 05:46:57 -04:00
|
|
|
const task = new ReleaseTool(releaseConfig, config.github, projectDir);
|
2020-09-09 09:01:18 -04:00
|
|
|
const result = await task.run();
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case CompletionState.FATAL_ERROR:
|
|
|
|
error(red(`Release action has been aborted due to fatal errors. See above.`));
|
2021-01-22 12:54:07 -05:00
|
|
|
process.exitCode = 2;
|
2020-09-09 09:01:18 -04:00
|
|
|
break;
|
|
|
|
case CompletionState.MANUALLY_ABORTED:
|
|
|
|
info(yellow(`Release action has been manually aborted.`));
|
2021-01-22 12:54:07 -05:00
|
|
|
process.exitCode = 1;
|
2020-09-09 09:01:18 -04:00
|
|
|
break;
|
|
|
|
case CompletionState.SUCCESS:
|
|
|
|
info(green(`Release action has completed successfully.`));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** CLI command module for publishing a release. */
|
|
|
|
export const ReleasePublishCommandModule: CommandModule<{}, ReleasePublishOptions> = {
|
|
|
|
builder,
|
|
|
|
handler,
|
|
|
|
command: 'publish',
|
|
|
|
describe: 'Publish new releases and configure version branches.',
|
|
|
|
};
|