diff --git a/index.js b/index.js index 0ec95ba4e..5b56f3c42 100755 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ module.exports = function standardVersion (argv) { var defaults = require('./defaults') var args = Object.assign({}, defaults, argv) - return runLifecycleScript(args, 'prebump', null, args) + return runLifecycleScript(args, 'prebump', null) .then((stdout) => { if (stdout && stdout.trim().length) args.releaseAs = stdout.trim() return bumpVersion(args.releaseAs) @@ -61,7 +61,7 @@ module.exports = function standardVersion (argv) { * attempt to update the version # in a collection of common config * files, e.g., package.json, bower.json. * - * @param argv config object + * @param args config object * @param newVersion version # to update to. * @return {string} */ @@ -171,18 +171,18 @@ function bumpVersion (releaseAs, callback) { }) } -function outputChangelog (argv, newVersion) { +function outputChangelog (args, newVersion) { return new Promise((resolve, reject) => { - createIfMissing(argv) + createIfMissing(args) var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n' - var oldContent = argv.dryRun ? '' : fs.readFileSync(argv.infile, 'utf-8') + var oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8') // find the position of the last release and remove header: if (oldContent.indexOf(' { - return runExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : (argv.infile + toAdd)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"') + return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (args.infile + toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"') }) } @@ -228,31 +228,31 @@ function formatCommitMessage (msg, newVersion) { return String(msg).indexOf('%s') !== -1 ? util.format(msg, newVersion) : msg } -function tag (newVersion, pkgPrivate, argv) { +function tag (newVersion, pkgPrivate, args) { var tagOption - if (argv.sign) { + if (args.sign) { tagOption = '-s ' } else { tagOption = '-a ' } - checkpoint(argv, 'tagging release %s', [newVersion]) - return runExec(argv, 'git tag ' + tagOption + argv.tagPrefix + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"') + checkpoint(args, 'tagging release %s', [newVersion]) + return runExec(args, 'git tag ' + tagOption + args.tagPrefix + newVersion + ' -m "' + formatCommitMessage(args.message, newVersion) + '"') .then(() => { var message = 'git push --follow-tags origin master' if (pkgPrivate !== true) message += '; npm publish' - checkpoint(argv, 'Run `%s` to publish', [message], chalk.blue(figures.info)) + checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info)) }) } -function createIfMissing (argv) { +function createIfMissing (args) { try { - accessSync(argv.infile, fs.F_OK) + accessSync(args.infile, fs.F_OK) } catch (err) { if (err.code === 'ENOENT') { - checkpoint(argv, 'created %s', [argv.infile]) - argv.outputUnreleased = true - writeFile(argv, argv.infile, '\n') + checkpoint(args, 'created %s', [args.infile]) + args.outputUnreleased = true + writeFile(args, args.infile, '\n') } } } diff --git a/lib/checkpoint.js b/lib/checkpoint.js index 634c8b5f7..516ab568f 100644 --- a/lib/checkpoint.js +++ b/lib/checkpoint.js @@ -2,10 +2,10 @@ const chalk = require('chalk') const figures = require('figures') const util = require('util') -module.exports = function (argv, msg, args, figure) { +module.exports = function (args, msg, vars, figure) { const defaultFigure = args.dryRun ? chalk.yellow(figures.tick) : chalk.green(figures.tick) - if (!argv.silent) { - console.info((figure || defaultFigure) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) { + if (!args.silent) { + console.info((figure || defaultFigure) + ' ' + util.format.apply(util, [msg].concat(vars.map(function (arg) { return chalk.bold(arg) })))) } diff --git a/lib/print-error.js b/lib/print-error.js index 983aeacc5..84aaa8257 100644 --- a/lib/print-error.js +++ b/lib/print-error.js @@ -1,7 +1,7 @@ const chalk = require('chalk') -module.exports = function (argv, msg, opts) { - if (!argv.silent) { +module.exports = function (args, msg, opts) { + if (!args.silent) { opts = Object.assign({ level: 'error', color: 'red' diff --git a/lib/run-exec.js b/lib/run-exec.js index 46c2134b7..4ce3cb09f 100644 --- a/lib/run-exec.js +++ b/lib/run-exec.js @@ -1,18 +1,18 @@ const exec = require('child_process').exec const printError = require('./print-error') -module.exports = function (argv, cmd) { - if (argv.dryRun) return Promise.resolve() +module.exports = function (args, cmd) { + if (args.dryRun) return Promise.resolve() return new Promise((resolve, reject) => { // Exec given cmd and handle possible errors exec(cmd, function (err, stdout, stderr) { // If exec returns content in stderr, but no error, print it as a warning // If exec returns an error, print it and exit with return code 1 if (err) { - printError(argv, stderr || err.message) + printError(args, stderr || err.message) return reject(err) } else if (stderr) { - printError(argv, stderr, {level: 'warn', color: 'yellow'}) + printError(args, stderr, {level: 'warn', color: 'yellow'}) } return resolve(stdout) }) diff --git a/lib/run-lifecycle-hook.js b/lib/run-lifecycle-hook.js index caaeeba06..17efd336a 100644 --- a/lib/run-lifecycle-hook.js +++ b/lib/run-lifecycle-hook.js @@ -3,10 +3,10 @@ const checkpoint = require('./checkpoint') const figures = require('figures') const runExec = require('./run-exec') -module.exports = function (argv, hookName, newVersion, hooks, cb) { +module.exports = function (args, hookName, newVersion, hooks, cb) { if (!hooks[hookName]) return Promise.resolve() var command = hooks[hookName] + ' --new-version="' + newVersion + '"' - checkpoint(argv, 'Running lifecycle hook "%s"', [hookName]) - checkpoint(argv, '- hook command: "%s"', [command], chalk.blue(figures.info)) - return runExec(argv, command) + checkpoint(args, 'Running lifecycle hook "%s"', [hookName]) + checkpoint(args, '- hook command: "%s"', [command], chalk.blue(figures.info)) + return runExec(args, command) } diff --git a/lib/run-lifecycle-script.js b/lib/run-lifecycle-script.js index 46a7bc92f..f4c2baa07 100644 --- a/lib/run-lifecycle-script.js +++ b/lib/run-lifecycle-script.js @@ -3,12 +3,12 @@ const checkpoint = require('./checkpoint') const figures = require('figures') const runExec = require('./run-exec') -module.exports = function (argv, hookName, newVersion, args) { +module.exports = function (args, hookName, newVersion) { const scripts = args.scripts if (!scripts || !scripts[hookName]) return Promise.resolve() var command = scripts[hookName] if (newVersion) command += ' --new-version="' + newVersion + '"' - checkpoint(argv, 'Running lifecycle script "%s"', [hookName]) - checkpoint(argv, '- execute command: "%s"', [command], chalk.blue(figures.info)) - return runExec(argv, command) + checkpoint(args, 'Running lifecycle script "%s"', [hookName]) + checkpoint(args, '- execute command: "%s"', [command], chalk.blue(figures.info)) + return runExec(args, command) } diff --git a/lib/write-file.js b/lib/write-file.js index b84566995..b6aaa19f7 100644 --- a/lib/write-file.js +++ b/lib/write-file.js @@ -1,6 +1,6 @@ const fs = require('fs') -module.exports = function (argv, filePath, content) { - if (argv.dryRun) return +module.exports = function (args, filePath, content) { + if (args.dryRun) return fs.writeFileSync(filePath, content, 'utf8') }