UNPKG

@airbnb/nimbus

Version:

Centralized CLI for JavaScript and TypeScript dev tools.

81 lines (80 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@beemo/core"); const constants_1 = require("../constants"); // Primarily used within CI jobs class AutoReleaseScript extends core_1.Script { blueprint() { return {}; } bootstrap() { this.task('Setting git environment variables', this.setGitEnvVars); this.task('Bumping package versions', this.versionPackages); this.task('Publishing packages to NPM', this.publishPackages); } // https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables async setGitEnvVars() { const { env } = process; let name = ''; let email = ''; try { const gitName = await this.executeCommand('git', ['config', '--get', 'user.name']); if (gitName.stdout) { name = gitName.stdout; } const gitEmail = await this.executeCommand('git', ['config', '--get', 'user.email']); if (gitEmail.stdout) { email = gitEmail.stdout; } } catch (error) { name = env.GITHUB_USER || 'Airbnb Bot'; email = env.GITHUB_EMAIL || 'airbnb-ci-bot@airbnb.com'; } Object.assign(process.env, { GIT_AUTHOR_NAME: name, GIT_AUTHOR_EMAIL: email, GIT_COMMITTER_NAME: name, GIT_COMMITTER_EMAIL: email, GIT_ASKPASS: 'echo', GIT_TERMINAL_PROMPT: '0', // Required by Lerna GH_TOKEN: env.GH_TOKEN || env.GITHUB_TOKEN, }); } // https://github.com/lerna/lerna/tree/master/commands/version#readme versionPackages() { return this.handleCommand(this.executeCommand('lerna', constants_1.LERNA_VERSION_ARGS, { extendEnv: true, preferLocal: true, })); } // https://github.com/lerna/lerna/tree/master/commands/publish#readme publishPackages() { return this.handleCommand(this.executeCommand('lerna', [ 'publish', 'from-git', '--yes', // Run pre and post scripts in each package if available '--require-scripts', ], { extendEnv: true, preferLocal: true, })); } handleCommand(promise) { return promise .then((response) => { const out = response.stdout.trim(); if (out) { this.tool.log(out); } return response; }) .catch((error) => { this.tool.log.error(error.stderr); throw error; }); } } exports.default = AutoReleaseScript;