@rajzik/lumos
Version:
Centralized CLI for JavaScript and TypeScript dev tools.
82 lines (81 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */
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);
}
async setGitEnvVars() {
var _a, _b, _c;
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 = (_a = env.GITHUB_USER) !== null && _a !== void 0 ? _a : 'Lumos Bot';
email = (_b = env.GITHUB_EMAIL) !== null && _b !== void 0 ? _b : 'lumos-ci-bot@lumos.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: (_c = env.GH_TOKEN) !== null && _c !== void 0 ? _c : 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;