Skip to content

Commit

Permalink
feat(release): Add post-install steps
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Oct 16, 2017
1 parent d963f9d commit 9a3377c
Showing 1 changed file with 55 additions and 12 deletions.
67 changes: 55 additions & 12 deletions release.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ require('./util').packageDir();
require('shelljs/global');

const readlineSync = require('readline-sync');
const shelljs = require('shelljs');
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const packageJson = JSON.parse(fs.readFileSync('package.json'));

const yargs = require('yargs')
.option('allowdirty', {
description: 'Ignore dirty working copy',
.option('dryrun', {
alias: ['dry-run', 'd'],
description: 'Dry run: Ignores dirty working copy and does not commit or publish anything.',
boolean: true,
})
.option('deps', {
Expand All @@ -22,7 +24,9 @@ const yargs = require('yargs')
const util = require('./util');
const _exec = util._exec;

if (!yargs.argv.allowdirty) {
if (yargs.argv.dryrun) {
console.log('Dry run mode...')
} else {
util.ensureCleanMaster('master');
}

Expand All @@ -36,8 +40,9 @@ if (!versionBump) {
process.exit(1);
}

let version = currentVersion;
if (versionBump !== 'none') {
const version = semver.inc(currentVersion, versionBump);
version = semver.inc(currentVersion, versionBump);

console.log(`Bumping version: ${version}`);

Expand All @@ -47,11 +52,12 @@ if (versionBump !== 'none') {


// Generate changelog
if (readlineSync.keyInYN('Update CHANGELOG?')) {
let changelog;
if (readlineSync.keyInYN('\n\nUpdate CHANGELOG?')) {
const depsArg = yargs.argv.deps ? `--deps ${yargs.argv.deps}` : '';
const show_changelog = path.resolve(__dirname, 'show_changelog.js');

const changelog = _exec(`${show_changelog} ${depsArg}`, true).stdout;
changelog = _exec(`${show_changelog} ${depsArg}`, true).stdout;

console.log('CHANGELOG:\n\n');
console.log(changelog);
Expand All @@ -67,17 +73,54 @@ if (readlineSync.keyInYN('Update CHANGELOG?')) {

// Commit and push changes
if (!readlineSync.keyInYN('Ready to publish?')) {
console.log('Undo changes:\n\ngit checkout CHANGELOG.md package.json\n\n');
console.log('\n\nUndo changes:\n\ngit checkout CHANGELOG.md package.json\n\n');
process.exit(1);
}

if (!yargs.argv.dryrun) {
_exec(`git ci -m ${version} package.json CHANGELOG.md`);
}

if (!yargs.argv.allowdirty) {
if (!yargs.argv.dryrun) {
util.ensureCleanMaster('master');
}

_exec(`npm publish`);
_exec(`git tag ${version}`);
_exec(`git push origin master`);
_exec(`git push origin ${version}`);

// Publish to NPM and push to github
if (!yargs.argv.dryrun) {
_exec(`npm publish`);
_exec(`git tag ${version}`);
_exec(`git push origin master`);
_exec(`git push origin ${version}`);
}


// Help with manual steps
let githuburl = packageJson.repository && packageJson.repository.url;
githuburl = githuburl && githuburl.replace(/^git\+/, '').replace(/\.git$/, '');

if (githuburl) {
if (changelog) {
const haspbcopy = shelljs.exec(`which pbcopy`, true).code === 0;
console.log(`\n\n1) Update the GitHub tag with release notes/CHANGELOG`);

if (haspbcopy) {
fs.writeFileSync('CHANGELOG.tmp', changelog);
_exec('pbcopy < CHANGELOG.tmp', true);
fs.unlinkSync('CHANGELOG.tmp');
console.log(`(The CHANGELOG has been copied to your clipboard)`);
} else {
console.log('CHANGELOG:\n\n');
console.log(changelog);
}
console.log(`\n${githuburl}/releases/tag/${version}`);
}

console.log(`\n\n2) Check for milestones`);
console.log(`\n${githuburl}/milestones`);

console.log(`\n\n\n`);
} else {
console.log("Could not determine github URL from package.json")
}

0 comments on commit 9a3377c

Please sign in to comment.