Skip to content

Commit

Permalink
slight edit to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Apr 4, 2016
0 parents commit 4b4b43a
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,14 @@
Copyright (c) 2016, Contributors

Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice
appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
@@ -0,0 +1,40 @@
# Conventional Recommended Workflow

Automatic CHANGELOG.md generation, using GitHub's new squash button and
the workflow outlined in [conventional-changelog-cli](https://github.com/stevemao/conventional-changelog-cli).

**how it works:**

1. when you land commits on your `master` branch, select the _Squash and Merge_ option.
2. add a title and body that follows the [conventional-changelog conventions](https://github.com/stevemao/conventional-changelog-angular/blob/master/convention.md).
3. when you're ready to release to npm:
1. checkout `master`.
2. run `conventional-recommended-workflow`.
3. `git push --tags; git push origin master; npm publish`.

`conventional-recommended-workflow` does the following:

1. bumps the version in package.json
2. runs `conventional-changelog` and updates CHANGELOG.md.
3. commits _package.json_ and _CHANGELOG.md_.
4. tags a new release.

## Installation

`npm i conventional-recommended-workflow`

## Automating

Add this to your _package.json_

```json
{
"scripts": {
"release": "conventional-recommended-workflow"
}
}
```

## License

ISC
123 changes: 123 additions & 0 deletions index.js
@@ -0,0 +1,123 @@
#!/usr/bin/env node
var conventionalChangelog = require('conventional-changelog')
var conventionalRecommendedBump = require('conventional-recommended-bump')
var path = require('path')
var argv = require('yargs')
.usage('$0 [options]')
.option('infile', {
alias: 'i',
describe: 'Read the CHANGELOG from this file',
default: 'CHANGELOG.md'
})
.option('preset', {
alias: 'p',
describe: 'Name of the preset you want to use. Must be one of the following: angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint',
default: 'angular'
})
.option('message', {
alias: 'm',
describe: 'commit message',
type: 'string',
default: 'see changelog for details'
})
.help()
.alias('h', 'help')
.example('$0 -m "see changelog for details"', 'update changelog and tag release')
.argv

var addStream = require('add-stream')
var chalk = require('chalk')
var exec = require('child_process').exec
var fs = require('fs')
var pkgPath = path.resolve(process.cwd(), './package.json')
var pkg = require(pkgPath)
var semver = require('semver')
var tempfile = require('tempfile')
var rimraf = require('rimraf')

conventionalRecommendedBump({
preset: argv.preset
}, function (err, release) {
if (err) {
console.error(chalk.red(err.message))
return
}

var newVersion = semver.inc(pkg.version, release.releaseAs)
console.log(chalk.bold('1.') + ' bump version ' + chalk.bold(release.releaseAs) + ' in package.json (' + pkg.version + ' → ' + chalk.green(newVersion) + ')')
pkg.version = newVersion
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf-8')

outputChangelog(argv, function () {
commit(argv, function () {
return tag(newVersion, argv)
})
})
})

function outputChangelog (argv, cb) {
console.log(chalk.bold('2.') + ' update changelog (' + chalk.bold(argv.infile) + ')')

createIfMissing(argv)

var readStream = fs.createReadStream(argv.infile)
.on('error', function (err) {
console.warn(chalk.yellow(err.message))
})
var changelogStream = conventionalChangelog({preset: argv.preset})
.on('error', function (err) {
console.error(chalk.red(err.message))
process.exit(1)
})
var tmp = tempfile()

changelogStream
.pipe(addStream(readStream))
.pipe(fs.createWriteStream(tmp))
.on('finish', function () {
fs.createReadStream(tmp)
.pipe(fs.createWriteStream(argv.infile))
.on('finish', function () {
rimraf.sync(tmp)
return cb()
})
})
}

function commit (argv, cb) {
console.log(chalk.bold('3.') + ' commit ' + chalk.bold('package.json') + ' and ' + chalk.bold(argv.infile))
exec('git commit package.json ' + argv.infile + ' -m "' + argv.message + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
}
return cb()
})
}

function tag (newVersion, argv) {
console.log(chalk.bold('4.') + ' tag release (' + chalk.green(newVersion) + ')')
exec('git tag -a v' + newVersion + ' -m "' + argv.message + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
}
})
}

function createIfMissing (argv) {
try {
fs.accessSync(argv.infile, fs.F_OK)
} catch (err) {
if (err.code === 'ENOENT') {
console.log(chalk.green('creating ') + argv.infile)
fs.writeFileSync(argv.infile, '', 'utf-8')
}
}
}
38 changes: 38 additions & 0 deletions package.json
@@ -0,0 +1,38 @@
{
"name": "conventional-recommended-workflow",
"version": "1.0.0",
"description": "apply the recommended workflow outlined in conventional-changelog-cli.",
"bin": "index.js",
"main": "index.js",
"scripts": {
"test": "standard"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bcoe/conventional-recommended-workflow.git"
},
"keywords": [
"conventional-changelog",
"recommended",
"workflow"
],
"author": "Ben Coe <ben@npmjs.com>",
"license": "ISC",
"bugs": {
"url": "https://github.com/bcoe/conventional-recommended-workflow/issues"
},
"homepage": "https://github.com/bcoe/conventional-recommended-workflow#readme",
"dependencies": {
"add-stream": "^1.0.0",
"chalk": "^1.1.3",
"conventional-changelog": "^1.1.0",
"conventional-recommended-bump": "^0.2.0",
"rimraf": "^2.5.2",
"semver": "^5.1.0",
"tempfile": "^1.1.1",
"yargs": "^4.3.2"
},
"devDependencies": {
"standard": "^6.0.8"
}
}

0 comments on commit 4b4b43a

Please sign in to comment.