From 3185c478db7862748c9c380c922b1ffa769be15e Mon Sep 17 00:00:00 2001 From: Kimmo Brunfeldt Date: Mon, 23 Nov 2015 00:07:07 +0200 Subject: [PATCH] Switch to use releasor instead of a separate release script Fixes #12. --- CONTRIBUTING.md | 14 ++- package.json | 101 ++++++++++---------- tools/release.js | 239 ----------------------------------------------- 3 files changed, 60 insertions(+), 294 deletions(-) delete mode 100755 tools/release.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 896cca4..e6dc096 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,16 +1,20 @@ # Contributing Pull requests and contributions are warmly welcome. -Please follow existing code style and commit message conventions. Also remember to keep documentation -updated. - -**Pull requests:** You don't need to bump version numbers or modify anything related to releasing. That stuff is fully automated, just write the functionality. +Please follow existing code style and commit message conventions. +Remember to keep documentation updated. +**Pull requests:** You don't need to bump version numbers or modify anything +related to releasing. That stuff is fully automated, just write the functionality. # Maintaining ## Release * Commit all changes -* Run `./tools/release.js minor`, which will create new tag and publish code to GitHub and npm +* Run `./node_modules/.bin/releasor --bump minor`, which will create new tag and publish code to GitHub and npm + + See [releasor documentation](https://github.com/kimmobrunfeldt/releasor) + for detailed usage. + * Edit GitHub release notes diff --git a/package.json b/package.json index 0f4f77b..1b9af23 100644 --- a/package.json +++ b/package.json @@ -1,51 +1,52 @@ { - "name": "chokidar-cli", - "description": "Ultra-fast cross-platform command line utility to watch file system changes.", - "version": "1.1.1-dev", - "keywords": [ - "fs", - "watch", - "watchFile", - "watcher", - "watching", - "file", - "fsevents", - "chokidar", - "cli", - "command", - "shell", - "bash" - ], - "bin": { - "chokidar": "./index.js" - }, - "homepage": "https://github.com/kimmobrunfeldt/chokidar-cli", - "author": "Kimmo Brunfeldt (http://kimmobrunfeldt.github.io/)", - "repository": { - "type": "git", - "url": "https://github.com/kimmobrunfeldt/chokidar-cli.git" - }, - "bugs": { - "url": "http://github.com/kimmobrunfeldt/chokidar-cli/issues" - }, - "license": "MIT", - "dependencies": { - "anymatch": "^1.1.0", - "bluebird": "^2.9.24", - "chokidar": "^1.0.1", - "lodash": "^3.7.0", - "shell-quote": "^1.4.3", - "yargs": "^3.7.2" - }, - "devDependencies": { - "commander": "^2.8.0", - "mocha": "^2.2.4", - "mustache": "^2.0.0", - "semver": "^4.3.3", - "shelljs": "^0.4.0", - "string": "^3.1.1" - }, - "scripts": { - "test": "mocha" - } -} \ No newline at end of file + "name": "chokidar-cli", + "description": "Ultra-fast cross-platform command line utility to watch file system changes.", + "version": "1.1.1-dev", + "keywords": [ + "fs", + "watch", + "watchFile", + "watcher", + "watching", + "file", + "fsevents", + "chokidar", + "cli", + "command", + "shell", + "bash" + ], + "bin": { + "chokidar": "./index.js" + }, + "homepage": "https://github.com/kimmobrunfeldt/chokidar-cli", + "author": "Kimmo Brunfeldt (http://kimmobrunfeldt.github.io/)", + "repository": { + "type": "git", + "url": "https://github.com/kimmobrunfeldt/chokidar-cli.git" + }, + "bugs": { + "url": "http://github.com/kimmobrunfeldt/chokidar-cli/issues" + }, + "license": "MIT", + "dependencies": { + "anymatch": "^1.1.0", + "bluebird": "^2.9.24", + "chokidar": "^1.0.1", + "lodash": "^3.7.0", + "shell-quote": "^1.4.3", + "yargs": "^3.7.2" + }, + "devDependencies": { + "commander": "^2.8.0", + "mocha": "^2.2.4", + "mustache": "^2.0.0", + "releasor": "^1.2.1", + "semver": "^4.3.3", + "shelljs": "^0.4.0", + "string": "^3.1.1" + }, + "scripts": { + "test": "mocha" + } +} diff --git a/tools/release.js b/tools/release.js deleted file mode 100755 index 4963c4f..0000000 --- a/tools/release.js +++ /dev/null @@ -1,239 +0,0 @@ -#!/usr/bin/env node - -// Release automation script inspired by -// https://github.com/geddski/grunt-release - -var fs = require('fs'); -var path = require('path'); - -var _ = require('lodash'); -var S = require('string'); -var shell = require('shelljs'); -var Mustache = require('mustache'); -var semver = require('semver'); -var program = require('commander'); -var Promise = require('bluebird'); - - -// Message templates use https://github.com/janl/mustache.js -var config = { - releaseMessage: 'Release {{ version }}', - backToDevMessage: 'Bump to dev version', - bumpType: 'patch', - files: ['package.json'], - indentation: 4, - - // If true, don't execute anything, just tell what would have been done - dryRun: false, - - // If true, don't push commits/tags or release to npm - noPush: false, - consolePrefix: '->', - devSuffix: '-dev' -}; - -var projectRoot = path.join(__dirname, '..'); -process.chdir(projectRoot); - -function main() { - parseArgs(); - config = mergeArgsToDefaults(config); - - if (config.dryRun) status('Dry run\n'); - - var newVersion = bumpVersion(config.files, config.bumpType); - - _gitBranchName() - .then(function(stdout) { - if (stdout.trim().toLowerCase() !== 'master') { - throw new Error('You should be in master branch before running the script!'); - } - - return gitAdd(config.files); - }) - .then(function() { - var message = Mustache.render(config.releaseMessage, { - version: newVersion - }); - - return gitCommit(message); - }) - .then(function() { - return gitTag(newVersion); - }) - .then(function() { - return gitPushTag(newVersion); - }) - .then(npmPublish) - .then(function() { - bumpVersion(config.files, 'dev'); - return gitAdd(config.files); - }) - .then(function() { - return gitCommit(config.backToDevMessage); - }) - .then(function() { - gitPush(); - }) - .then(function() { - console.log(''); - status('Release successfully done!'); - }) - .catch(function(err) { - console.error('\n!! Releasing failed'); - console.trace(err); - process.exit(2); - }); -} - -function parseArgs() { - program - .usage('bump'); - - program.on('--help', function() { - console.log(' Example usage:'); - console.log(''); - console.log(' $ ./release.js minor'); - }); - - program.parse(process.argv); -} - -function mergeArgsToDefaults(config) { - if (program.args[0]) { - config.bumpType = program.args[0]; - - if (!_.contains(['major', 'minor', 'patch'], config.bumpType)) { - console.error('Error:', config.bumpType, 'is not a valid bump type'); - process.exit(1); - } - } - - return config; -} - -function status( /* arguments */ ) { - var args = Array.prototype.slice.call(arguments); - console.log(config.consolePrefix, args.join(' ')); -} - -function run(cmd, msg) { - // All calls are actually synchronous but eventually some task - // will need async stuff, so keep them promises - return new Promise(function(resolve, reject) { - if (msg) { - status(msg); - } - - if (config.dryRun) { - return resolve(); - } - - var exec = shell.exec(cmd); - var success = exec.code === 0; - - if (success) { - resolve(exec.output); - } else { - var errMsg = 'Error executing: `' + cmd + '`\nOutput:\n' + exec.output; - var err = new Error(errMsg); - reject(err); - } - }); -} - -// Task functions -// All functions should return promise - -// Bumps version in specified files. -// Files are assumed to contain JSON data which has "version" key following -// semantic versioning -function bumpVersion(files, bumpType) { - status('Bump', bumpType, 'version to files:', files.join(' ')); - if (config.dryRun) return '[not available in dry run]'; - - var newVersion; - var originalVersion; - files.forEach(function(fileName) { - var filePath = path.join(projectRoot, fileName); - - var data = JSON.parse(fs.readFileSync(filePath)); - originalVersion = data.version; - var currentVersion = data.version; - if (!semver.valid(currentVersion)) { - var msg = 'Invalid version ' + currentVersion + - ' in file ' + fileName; - var err = new Error(msg); - throw err; - } - - if (S(currentVersion).endsWith(config.devSuffix)) { - currentVersion = S(currentVersion).chompRight(config.devSuffix).s; - } - - if (bumpType === 'dev') { - newVersion = currentVersion + config.devSuffix; - } else { - newVersion = semver.inc(currentVersion, bumpType); - } - data.version = newVersion; - - var content = JSON.stringify(data, null, config.indentation); - fs.writeFileSync(filePath, content); - - status('Bump', originalVersion, '->', newVersion, 'in', - fileName); - }); - - return newVersion; -} - -function gitAdd(files) { - var cmd = 'git add ' + files.join(' '); - var msg = 'Staged ' + files.length + ' files'; - return run(cmd, msg); -} - -function gitCommit(message) { - var cmd = 'git commit -m "' + message + '"'; - var msg = 'Commit files'; - return run(cmd, msg); -} - -function gitTag(name) { - var cmd = 'git tag ' + name; - var msg = 'Created a new git tag: ' + name; - return run(cmd, msg); -} - -function gitPush() { - if (config.noPush) return; - - var cmd = 'git push'; - var msg = 'Push to remote'; - return run(cmd, msg); -} - -function gitPushTag(tagName) { - if (config.noPush) return; - - var cmd = 'git push origin ' + tagName; - var msg = 'Push created git tag to remote'; - return run(cmd, msg); -} - -function npmPublish() { - if (config.noPush) return; - - var cmd = 'npm publish'; - var msg = 'Publish to npm'; - return run(cmd, msg); -} - -function _gitBranchName() { - var cmd = 'git rev-parse --abbrev-ref HEAD'; - return run(cmd, false); -} - - -main(); \ No newline at end of file