Skip to content

Commit

Permalink
Merge pull request #16 from SimenB/default-refactor-config
Browse files Browse the repository at this point in the history
Set default options
  • Loading branch information
SimenB committed Apr 24, 2015
2 parents 563da10 + 9ceb5ac commit 43d7533
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
11 changes: 6 additions & 5 deletions bin/browserify-ftw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
'use strict';

var util = require('util')
, fs = require('fs')
, fs = require('fs')
, path = require('path')
, log = require('npmlog')
, xtend = require('xtend')
, bftw = require('../browserify-ftw')
, options
, defaultOptionsPath = path.resolve('../lib/refactor-config.js')
, defaultOptions= require(defaultOptionsPath)
, argv = require('optimist')
.options('r', {
alias : 'requirejs'
Expand All @@ -16,7 +19,7 @@ var util = require('util')
.options('c', {
alias : 'config'
, describe : 'path to config to be used for the refactoring\n(https://github.com/thlorenz/browserify-ftw#preparing-a-custom-refactor-config)'
, default : path.join(__dirname, '../lib/refactor-config.js')
, default : defaultOptionsPath
})
.options('b', {
alias : 'build'
Expand Down Expand Up @@ -71,9 +74,7 @@ try {
}

try {
options = require(fullConfig);
// Poor man's validation
if (!options.quote || !options.style) throw new Error(fullConfig + 'is not a valid refactor config');
options = xtend(defaultOptions, require(fullConfig));
} catch (e) {
log.error('browserify-ftw', 'While reading refactor-config:\n\t', e.message);
process.exit(1);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"map-stream": "0.0.5",
"npmlog": "~1.2.0",
"optimist": "~0.6.1",
"readdirp": "~1.3.0"
"readdirp": "~1.3.0",
"xtend": "~4.0.0"
},
"devDependencies": {
"tap": "~0.3.3"
Expand Down
22 changes: 6 additions & 16 deletions test/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ var test = require('tap').test
, cardinal = require('cardinal')
, upgrade = require('../lib/upgrade')
, fixtures = path.join(__dirname, 'fixtures')
, defOpts = {
quote: '\''
, style: 'var'
, indent: 2
}
, defOpts = require('../lib/refactor-config')
, commaOpts = {
quote: '\''
, style: 'comma'
Expand All @@ -22,12 +18,6 @@ var test = require('tap').test
, style: 'comma-first'
, indent: 2
}
, moveStrictTrueOpts = {
quote: '\''
, style: 'var'
, indent: 2
, moveStrict: true
}
, moveStrictFalseOpts = {
quote: '\''
, style: 'var'
Expand Down Expand Up @@ -70,12 +60,12 @@ function run(t, fixture, opts) {
, [ 'upgrades code with define wrapper function definition after wrapper' , 'define-function-after' ]
, [ 'upgrades code with define wrapper that returns a multiline object' , 'define-return-multiline-object' ]
, [ 'upgrades code with require wrapper that has dependencies but no params' , 'require-noparams' ]
, [ 'upgrades code with use strict statement at top of file' , 'use-strict', moveStrictTrueOpts ]
, [ 'upgrades code with use strict statement at top of file' , 'use-strict' ]
, [ 'upgrades code with use strict statement without moving' , 'use-strict-not-moved', moveStrictFalseOpts ]
, [ 'upgrades code with use strict statement in nested function' , 'use-strict-nested-not-moved', moveStrictTrueOpts ]
, [ 'upgrades code with use strict in the middle of the module' , 'use-strict-in-middle', moveStrictTrueOpts ]
, [ 'upgrades code with use strict at end of the module' , 'use-strict-at-bottom', moveStrictTrueOpts ]
, [ 'upgrades code with use strict without semicolon' , 'use-strict-without-semicolon', moveStrictTrueOpts ]
, [ 'upgrades code with use strict statement in nested function' , 'use-strict-nested-not-moved' ]
, [ 'upgrades code with use strict in the middle of the module' , 'use-strict-in-middle' ]
, [ 'upgrades code with use strict at end of the module' , 'use-strict-at-bottom' ]
, [ 'upgrades code with use strict without semicolon' , 'use-strict-without-semicolon' ]
].forEach(function (testcase) {
test('\n' + testcase[0], function (t) {
run(t, testcase[1], testcase[2])
Expand Down

0 comments on commit 43d7533

Please sign in to comment.