Skip to content

Commit

Permalink
package.json config
Browse files Browse the repository at this point in the history
Added ability to define options in package.json
Added test for package.json config
Added test for quiet mode
  • Loading branch information
mrkmg committed Jul 6, 2016
1 parent 5cef082 commit 082e2ee
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,33 @@ is an example with all default options set.
The `files_to_commit` and `files_to_version` use [node-glob](https://github.com/isaacs/node-glob). See the
documentation located there on how to format those options.

If `release_message` is true,
If `release_message` is true, then you will be prompted to write a release message via your editor of choice.

**package.json**

If you are using this for an NPM package, you can include all the above options in your package.json instead of
a dedicated file.

Place all your configuration options in `config : generateRelease`.

{
...
"config": {
"generateRelease": {
"no_confirm": false,
"remote": "origin"
}
},
...
}

**Option Precedence**

Precedence is determined in the following order:

- CLI Argument
- package.json file
- .release.json file

Building Assets, Running Tests, and Publishing Package
--------------------------------
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"minimist": "^1.2.0",
"observatory": "^1.0.0",
"rmdir": "^1.2.0",
"temp": "^0.8.3"
"temp": "^0.8.3",
"xtend": "^4.0.1"
},
"devDependencies": {
"chai": "^3.4.1",
Expand Down
11 changes: 10 additions & 1 deletion src/lib/Options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
existsSync = require 'exists-sync'
Path = require 'path'
Minimist = require 'minimist'
extend = require 'xtend'

options =
show_help:
Expand Down Expand Up @@ -101,6 +102,8 @@ class Options

# Get Release File First
@getOption 'dot_release_file_location', options.dot_release_file_location
@getOption 'package_file_location', options.package_file_location
@loadPackageConfig()
@loadFileData()
@getAllOptions()

Expand All @@ -123,7 +126,13 @@ class Options

loadFileData: ->
if existsSync @dot_release_file_location
@_file_data = require @dot_release_file_location
@_file_data = extend @_file_data, require @dot_release_file_location

loadPackageConfig: ->
if existsSync @package_file_location
package_json = require @package_file_location
if package_json.config?.generateRelease?
@_file_data = extend @_file_data, package_json.config.generateRelease

getFileValue: (key) ->
if @_file_data[key]? then @_file_data[key]
Expand Down
17 changes: 15 additions & 2 deletions test/helpers/setupTestRepo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (temp_dir) ->
FS.mkdirSync temp_dir
process.chdir temp_dir
FS.writeFileSync 'package.json', package_json
FS.writeFileSync 'alt.package.json', package_json
FS.writeFileSync 'alt.package.json', alt_package_json
FS.writeFileSync '.release.json', release_json
FS.writeFileSync '.alt.release.json', release_json
FS.writeFileSync '.all.release.json', all_release_json
Expand All @@ -26,7 +26,20 @@ TEST FILE
'''

package_json = '''
{"version":"1.2.3"}
{
"version":"1.2.3"
}
'''

alt_package_json = '''
{
"version":"1.2.3",
"config": {
"generateRelease": {
"release_message": "Alt Package Message {version}"
}
}
}
'''

release_json = '''
Expand Down
12 changes: 10 additions & 2 deletions test/specs/lib/Options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ setupTestRepo = require '../../helpers/setupTestRepo'

describe 'Options', ->

beforeEach ->
before ->
@starting_dir = process.cwd()
@temp_dir = Temp.path()
setupTestRepo @temp_dir

afterEach (cb) ->
after (cb) ->
process.chdir @starting_dir
rmdir @temp_dir, cb

Expand Down Expand Up @@ -66,6 +66,14 @@ describe 'Options', ->
assert.equal options.skip_git_push, true
assert.equal options.release_message, true

it 'should parse the release config from package.json', ->
options = new Options [
'node', 'script',
'-p', 'alt.package.json'
]

assert.equal options.release_message, 'Alt Package Message {version}'

it 'should parse release file options correctly', ->
options = new Options [
'node', 'script'
Expand Down
12 changes: 12 additions & 0 deletions test/specs/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ generate-release
describe 'run', ->
before ->
@run_arguments = ['node', 'script', '-t', 'patch', '-n', '-l', '-s', '-o', 'test']
@quiet_run_arguments = ['node', 'script', '-t', 'patch', '-n', '-l', '-s', '-o', 'test', '-q']
@help_arguments = ['node', 'script', '-h']

beforeEach ->
Expand Down Expand Up @@ -76,6 +77,17 @@ describe 'run', ->
assert not FS.existsSync "#{@temp_dir}/deleteme"
assert @exit_stub.calledWith(0)

it 'Should not output anything with quiet run', ->
output_spy = Sinon.spy process.stdout, 'write'

Promise
.try =>
main @quiet_run_arguments
.then ->
assert not output_spy.called
.finally ->
output_spy.restore()

it 'Should reset on command failure', ->
commit_stub = Sinon.stub(GitCommands.prototype, 'commit').throws()
reset_spy = Sinon.spy(GitCommands.prototype, 'reset')
Expand Down

0 comments on commit 082e2ee

Please sign in to comment.