#!/usr/bin/env node const execSync = require('child_process').execSync; const minimist = require('minimist'); const standardVersion = require('standard-version'); const chalk = require('chalk'); const args = minimist(process.argv.slice(2)); const DEFAULT_UPSTREAM_REPO_ORIGIN = 'origin'; const DEFAULT_UPSTREAM_REPO_BRANCH = 'master'; const origin = args['repo-origin'] || DEFAULT_UPSTREAM_REPO_ORIGIN; const branch = args['repo-branch'] || DEFAULT_UPSTREAM_REPO_BRANCH; const distTag = args['npm-dist-tag']; console.log(chalk.blue('ℹ'), `Fetching from origin '${origin}' to read upstream version...`); try { console.log(execSync(`git fetch ${origin}`).toString()); } catch (e) { console.log(chalk.red('✘'), 'Couldn\'t fetch latest commits. Please check the error above.'); return; } const localRef = execSync(`git rev-parse ${branch}`).toString(); const originRef = execSync(`git rev-parse ${origin}/${branch}`).toString(); if (localRef !== originRef) { console.log(chalk.red('✘'), `Local branch '${branch}' is not up to date with '${origin}/${branch}'. Please update your local branch first.`); return; } console.log(chalk.green('✔'), 'Release branch is up to date with remote branch.'); console.log(chalk.blue('ℹ'), 'Reinstalling node_modules just to make sure that everything is up to date...'); try { console.log(execSync('npm run install_all').toString()); console.log(chalk.green('✔'), 'Depencencies installed.'); } catch (e) { console.log(chalk.red('✘'), 'A problem occured. Please check the error above'); return; } standardVersion({ dryRun: args['dry-run'], prerelease: args.prerelease, sign: args.sign, releaseAs: args['release-as'] }).then(() => { if (!args['dry-run']) { console.log(chalk.blue('ℹ'), `Pushing release commit to origin '${origin}' on branch '${branch}'...`); try { const output = execSync(`git push ${origin} ${branch} --follow-tags`).toString(); console.log(chalk.green(output)); console.log(chalk.green('✔'), 'Successfully pushed release commit'); } catch (e) { console.log(chalk.red('✘'), 'Couldn\'t push release commit. Please check the error above.'); return { error: true }; } } else { console.log(chalk.blue('ℹ'), 'This is a dry run. Nothing\'s being pushed.'); } }).then(error => { if (error) { return error; } console.log(chalk.blue('ℹ'), 'Publishing new Embark version on npm...'); let npmPublishCommand = distTag ? `npm publish --tag ${distTag}` : 'npm publish'; npmPublishCommand += args['dry-run'] ? ' --dry-run' : ''; try { const output = execSync(npmPublishCommand).toString(); console.log(chalk.green(output)); if (args['dry-run']) { console.log(chalk.blue('ℹ'), 'This was a dry run: Successfuly published latest version.'); } else { console.log(chalk.green('✔'), 'Successfully published latest version.'); } } catch (e) { console.log(chalk.red('✘'), 'Couldn\'t publish version on npm. Please check the error above.'); return { error: true }; } }).then(error => { if (error) { console.log(chalk.red('✘'), 'Stopping right here. Make sure to clean up commits and tags if needed.'); } else { console.log(chalk.green('✔'), 'Woohoo! Done.'); } });