-
-
Notifications
You must be signed in to change notification settings - Fork 112
Restrict config properties (Implementation for Issue #92) #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ead18c6
2984265
9337fd6
e5bafdd
be189e3
4758c86
23677c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
var copyProps = require('copy-props'); | ||
|
||
var fromto = { | ||
'flags.silent': 'silent', | ||
}; | ||
|
||
function mergeConfigToCliFlags(opt, config) { | ||
return copyProps(config, opt, fromto); | ||
} | ||
|
||
module.exports = mergeConfigToCliFlags; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var copyProps = require('copy-props'); | ||
|
||
var toFrom = { | ||
configPath: 'flags.gulpfile', | ||
configBase: 'flags.gulpfile', | ||
}; | ||
|
||
function mergeConfigToEnvFlags(env, config) { | ||
return copyProps(env, config, toFrom, convert, true); | ||
} | ||
|
||
function convert(value, configKey, envKey) { | ||
if (envKey === 'configBase') { | ||
return path.dirname(value); | ||
} | ||
return value; | ||
} | ||
|
||
module.exports = mergeConfigToEnvFlags; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var copyProps = require('copy-props'); | ||
var path = require('path'); | ||
|
||
function loadConfigFiles(configFiles, configFileOrder) { | ||
var config = {}; | ||
|
||
configFileOrder.forEach(function(key) { | ||
var filePath = configFiles[key]; | ||
if (!filePath) { | ||
return; | ||
} | ||
|
||
copyProps(require(filePath), config, function(value, name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Named function (I can make this change during merge). |
||
if (name === 'flags.gulpfile') { | ||
return path.resolve(path.dirname(filePath), value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh interesting, this is making the path in the config file relative its location. |
||
} | ||
return value; | ||
}); | ||
}); | ||
|
||
return config; | ||
} | ||
|
||
module.exports = loadConfigFiles; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ var levels = [ | |
]; | ||
|
||
function toConsole(log, opts) { | ||
// Remove previous listeners to enable to call this twice. | ||
log.removeAllListeners(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be more specific to avoid removing other listeners someone else might have attached (we are using a global, after all). I can change this in the merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you are exactly right. Thanks. |
||
|
||
// Return immediately if logging is | ||
// not desired. | ||
if (opts.tasksSimple || opts.silent) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict'; | ||
|
||
var expect = require('expect'); | ||
|
||
var path = require('path'); | ||
var fixturesDir = path.join(__dirname, 'fixtures/config'); | ||
|
||
var headLines = require('gulp-test-tools').headLines; | ||
var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); | ||
|
||
describe('config: flags.gulpfile', function() { | ||
|
||
it('Should configure with a .gulp.* file', function(done) { | ||
runner | ||
.chdir('flags/gulpfile') | ||
.gulp() | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
stdout = headLines(stdout, 2, 2); | ||
expect(stdout).toEqual( | ||
'This gulpfile : ' + | ||
path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + | ||
'\n' + | ||
'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') | ||
); | ||
expect(stderr).toEqual(''); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('Should configure with a .gulp.* file in the directory specified by ' + | ||
'\n\t--cwd', function(done) { | ||
runner | ||
.gulp('--cwd ./flags/gulpfile') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
stdout = headLines(stdout, 2, 3); | ||
expect(stdout).toEqual( | ||
'This gulpfile : ' + | ||
path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + | ||
'\n' + | ||
'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') | ||
); | ||
expect(stderr).toEqual(''); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('Should ignore a ./gulp.* file if another directory is specified by ' + | ||
'\n\t--cwd', function(done) { | ||
runner | ||
.chdir('./flags/gulpfile') | ||
.gulp('--cwd ./cwd') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
stdout = headLines(stdout, 1, 3); | ||
expect(stdout).toEqual( | ||
'Another gulpfile : ' + | ||
path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') | ||
); | ||
expect(stderr).toEqual(''); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('Should ignore a ./.gulp.* file if another gulpfile is specified by ' + | ||
'\n\t--gulpfile', function(done) { | ||
runner | ||
.chdir('./flags/gulpfile') | ||
.gulp('--gulpfile ./cwd/gulpfile.js') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
stdout = headLines(stdout, 1, 3); | ||
expect(stdout).toEqual( | ||
'Another gulpfile : ' + | ||
path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') | ||
); | ||
expect(stderr).toEqual(''); | ||
done(err); | ||
} | ||
}); | ||
|
||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Named function (I can make this change during merge).