-
-
Notifications
You must be signed in to change notification settings - Fork 112
Implement .gulprc support #90
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
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 |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ var Liftoff = require('liftoff'); | |
| var tildify = require('tildify'); | ||
| var interpret = require('interpret'); | ||
| var v8flags = require('v8flags'); | ||
| var merge = require('lodash.merge'); | ||
| var sortBy = require('lodash.sortby'); | ||
| var isString = require('lodash.isstring'); | ||
| var findRange = require('semver-greatest-satisfied-range'); | ||
| var exit = require('./lib/shared/exit'); | ||
| var cliOptions = require('./lib/shared/cliOptions'); | ||
|
|
@@ -34,6 +37,18 @@ var cli = new Liftoff({ | |
| completions: completion, | ||
| extensions: interpret.jsVariants, | ||
| v8flags: v8flags, | ||
| configFiles: { | ||
| '.gulp': { | ||
| home: { | ||
| path: '~', | ||
| extensions: interpret.extensions, | ||
| }, | ||
| cwd: { | ||
| path: '.', | ||
| extensions: interpret.extensions, | ||
|
Member
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. Do we want to support
Contributor
Author
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. Yes, I think so. For example, there were some issues which wanted to specify the path of
Contributor
Author
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. But it would be good to add 'cwd' latar until it is needed.
Member
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. If we support
Contributor
Author
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 mistook. When
Member
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. Sounds good to me. |
||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| var usage = | ||
|
|
@@ -82,6 +97,12 @@ module.exports = run; | |
|
|
||
| // The actual logic | ||
| function handleArguments(env) { | ||
|
|
||
| var configFilePaths = sortBy(env.configFiles['.gulp'], ['home', 'cwd']); | ||
| configFilePaths.filter(isString).forEach(function(filePath) { | ||
| merge(opts, require(filePath)); | ||
| }); | ||
|
|
||
| if (opts.help) { | ||
| console.log(parser.help()); | ||
| exit(0); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 'use strict'; | ||
|
|
||
| var lab = exports.lab = require('lab').script(); | ||
| var expect = require('code').expect; | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
|
|
||
| var skipLines = require('./tools/skip-lines'); | ||
| var eraseTime = require('./tools/erase-time'); | ||
| var runner = require('./tools/run-gulp'); | ||
|
|
||
| var fixturesDir = path.join(__dirname, 'fixtures', 'config'); | ||
| var expectedDir = path.join(__dirname, 'expected', 'config'); | ||
|
|
||
| lab.experiment('gulp configuration', function() { | ||
|
|
||
| lab.test('Should configure with a .gulp.* file in cwd', | ||
| function(done) { | ||
| runner({ verbose: false }) | ||
| .basedir(fixturesDir) | ||
| .chdir('foo/bar') | ||
| .gulp('--tasks') | ||
| .run(cb); | ||
|
|
||
| function cb(err, stdout) { | ||
| var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), | ||
| 'utf-8'); | ||
| stdout = eraseTime(stdout); | ||
| expect(stdout).to.equal(expected); | ||
| done(err); | ||
| } | ||
| }); | ||
|
|
||
| lab.test('Should configure with a .gulp.* file in cwd found up', | ||
| function(done) { | ||
| runner({ verbose: false }) | ||
| .basedir(fixturesDir) | ||
| .chdir('foo/bar/baz') | ||
| .gulp('--tasks') | ||
| .run(cb); | ||
|
|
||
| function cb(err, stdout) { | ||
| var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), | ||
| 'utf-8'); | ||
| stdout = eraseTime(skipLines(stdout, 1)); | ||
| expect(stdout).to.equal(expected); | ||
| done(err); | ||
| } | ||
| }); | ||
|
|
||
| lab.test('Should configure with a .gulp.* file in cwd by --cwd', | ||
| function(done) { | ||
| runner({ verbose: false }) | ||
| .basedir(fixturesDir) | ||
| .chdir('qux') | ||
| .gulp('--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .') | ||
| .run(cb); | ||
|
|
||
| function cb(err, stdout) { | ||
| var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), | ||
| 'utf-8'); | ||
| stdout = eraseTime(stdout); | ||
| expect(stdout).to.equal(expected); | ||
| done(err); | ||
| } | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| gulp-cli/test | ||
| gulp-cli/test/fixtures | ||
| ├─┬ default | ||
| │ └─┬ <series> | ||
| │ ├── task1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Description by .gulp.json in directory foo/bar | ||
| └── default |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| description by .gulp.js in directory qux | ||
| └── default |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"label":"Tasks for {{path}}","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]} | ||
| {"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| gulp-cli/test | ||
| gulp-cli/test/fixtures/gulpfiles | ||
| ├─┬ default | ||
| │ └─┬ <series> | ||
| │ ├─┬ test1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| gulp-cli/test | ||
| gulp-cli/test/fixtures/gulpfiles | ||
| ├── build | ||
| ├── clean | ||
| └─┬ dist | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,31 @@ | ||
| 'use strict'; | ||
|
|
||
| var lab = exports.lab = require('lab').script(); | ||
| var code = require('code'); | ||
| var expect = require('code').expect; | ||
| var fs = require('fs'); | ||
| var child = require('child_process'); | ||
| var path = require('path'); | ||
| var skipLines = require('./tools/skip-lines'); | ||
| var eraseTime = require('./tools/erase-time'); | ||
| var runner = require('./tools/run-gulp'); | ||
|
|
||
| var output = fs.readFileSync(__dirname + '/expected/tasks-as-exports.txt', 'utf8').replace(/(\r\n|\n|\r)/gm,'\n'); | ||
| var expectedDir = path.join(__dirname, 'expected'); | ||
|
|
||
| // Long timeout is required because parse time is slow | ||
| lab.experiment('exports as tasks', { timeout: 0 }, function() { | ||
|
|
||
| lab.test('prints the task list', function(done) { | ||
| runner({ verbose: false }) | ||
| .gulp('--tasks', | ||
| '--gulpfile ./fixtures/gulpfiles/gulpfile-exports.babel.js') | ||
| .run(cb); | ||
|
|
||
| child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --gulpfile "./test/fixtures/gulpfile-exports.babel.js"', function(err, stdout) { | ||
| code.expect(stdout).to.contain('Tasks for'); | ||
| stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n'); | ||
| var outputArray = output.split('\n'); | ||
| for (var i = 0; i < stdout.length; i++) { | ||
| code.expect(stdout[i]).to.contain(outputArray[i]); | ||
| } | ||
| done(err); | ||
| }); | ||
| function cb(err, stdout) { | ||
| var filepath = path.join(expectedDir, 'tasks-as-exports.txt'); | ||
| var expected = fs.readFileSync(filepath, 'utf-8'); | ||
| stdout = eraseTime(skipLines(stdout, 2)); | ||
| expect(stdout).to.equal(expected); | ||
| done(); | ||
| } | ||
| }); | ||
|
|
||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "description" : "gulp-cli/test/fixtures" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "description": "Description by .gulp.json in directory foo/bar" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // jscs:disable | ||
|
|
||
| exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 'use strict'; | ||
|
|
||
| var gulp = require('gulp'); | ||
|
|
||
| gulp.task('default', function(done) { | ||
| done(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| description: 'description by .gulp.js in directory qux', | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "description" : "gulp-cli/test/fixtures/gulpfiles" | ||
| } |
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.
we only want to support the
jsVariantsso we should allow this to be defaulted by the top-levelextensions. No need to specify again.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.
But
jsVariantsdoesn't contain'.json'( js-interpret/index.js#L106 )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.
Good catch! I actually want to write my configs as
.gulp.ymlwhich also isn't supported injsVariants. Please leave it asinterpret.extensions.