Skip to content

Commit

Permalink
feat(initial-release): adds flag for generating CHANGELOG.md on the f…
Browse files Browse the repository at this point in the history
…irst release.
  • Loading branch information
bcoe committed Apr 4, 2016
1 parent 3898f92 commit b812b44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ the workflow outlined in [conventional-changelog-cli](https://github.com/stevema
3. commits _package.json_ and _CHANGELOG.md_.
4. tags a new release.

## Initial CHANGELOG.md Generation

When you're generating your changelog for the first time, simply do:

`conventional-recommended-workflow --first-release`

## Installation

`npm i conventional-recommended-workflow`
Expand Down
42 changes: 33 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ var argv = require('yargs')
.option('infile', {
alias: 'i',
describe: 'Read the CHANGELOG from this file',
default: 'CHANGELOG.md'
default: 'CHANGELOG.md',
global: true
})
.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'
default: 'angular',
global: true
})
.option('message', {
alias: 'm',
describe: 'commit message',
type: 'string',
default: 'see changelog for details'
default: 'see changelog for details',
global: true
})
.option('first-release', {
alias: 'f',
describe: 'is this the first release',
type: 'boolean',
default: false,
global: true
})
.help()
.alias('h', 'help')
Expand All @@ -43,10 +53,16 @@ conventionalRecommendedBump({
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')
var newVersion = pkg.version
if (!argv.firstRelease) {
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')
} else {
console.log(chalk.yellow('skip package.json update on first release'))
}

outputChangelog(argv, function () {
commit(argv, function () {
Expand All @@ -64,7 +80,14 @@ function outputChangelog (argv, cb) {
.on('error', function (err) {
console.warn(chalk.yellow(err.message))
})
var changelogStream = conventionalChangelog({preset: argv.preset})

var changelogStream = conventionalChangelog({
preset: argv.preset,
outputUnreleased: true,
pkg: {
path: path.resolve(process.cwd(), './package.json')
}
})
.on('error', function (err) {
console.error(chalk.red(err.message))
process.exit(1)
Expand All @@ -86,7 +109,7 @@ function outputChangelog (argv, 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) {
exec('git add package.json ' + argv.infile + ';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
Expand Down Expand Up @@ -117,6 +140,7 @@ function createIfMissing (argv) {
} catch (err) {
if (err.code === 'ENOENT') {
console.log(chalk.green('creating ') + argv.infile)
argv.outputUnreleased = true
fs.writeFileSync(argv.infile, '', 'utf-8')
}
}
Expand Down

0 comments on commit b812b44

Please sign in to comment.