diff --git a/README.md b/README.md index bde183fd..78ae7453 100644 --- a/README.md +++ b/README.md @@ -101,21 +101,21 @@ The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched fr Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. -Configuration from the home directory (`~`) and current working directory (`cwd`) are merged with `cwd` taking precedence. +A configuration file from the current working directory (`cwd`) or above are selected before a configuration file from the home directory (`~`). Supported configurations properties: | Property | Description | |--------------------|-------------| | description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") | +| gulpfile | Set a default gulpfile | +| preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | | flags.continue | Continue execution of tasks upon failure by default. | | flags.compactTasks | Reduce the output of task dependency tree by default. | | flags.tasksDepth | Set default depth of task dependency tree. | -| flags.gulpfile | Set a default gulpfile | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | -| flags.preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | -| flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags diff --git a/index.js b/index.js index 6ff75f34..1ace11ea 100644 --- a/index.js +++ b/index.js @@ -10,16 +10,16 @@ var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); var chalk = require('chalk'); + var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); +var arrayFind = require('./lib/shared/array-find'); var makeTitle = require('./lib/shared/make-title'); var cliOptions = require('./lib/shared/options/cli-options'); var completion = require('./lib/shared/completion'); var cliVersion = require('./package.json').version; var toConsole = require('./lib/shared/log/to-console'); - -var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); +var mergeCliOpts = require('./lib/shared/config/cli-flags'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -34,23 +34,19 @@ var cli = new Liftoff({ completions: completion, extensions: interpret.jsVariants, v8flags: v8flags, - configFiles: { - project: [ - { - name: '.gulp', - path: '.', - extensions: interpret.extensions, - findUp: true, - }, - ], - userHome: [ - { - name: '.gulp', - path: '~', - extensions: interpret.extensions, - }, - ], - }, + configFiles: [ + { + name: '.gulp', + path: '.', + extensions: interpret.extensions, + findUp: true, + }, + { + name: '.gulp', + path: '~', + extensions: interpret.extensions, + }, + ], }); var usage = @@ -127,33 +123,41 @@ function run() { module.exports = run; +function isDefined(cfg) { + return cfg != null; +} + function onPrepare(env) { - var cfg = mergeProjectAndUserHomeConfigs(env); - env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + // We only use the first config found, which is a departure from + // the previous implementation that merged with the home + var cfg = arrayFind(env.config, isDefined); + var flags = mergeCliOpts(opts, cfg); - // Set up event listeners for logging again after configuring. - toConsole(log, env.config.flags); + // Set up event listeners for logging after configuring. + toConsole(log, flags); - cli.execute(env, env.nodeFlags, onExecute); + cli.execute(env, cfg.nodeFlags, function (env) { + onExecute(env, cfg, flags); + }); } // The actual logic -function onExecute(env) { +function onExecute(env, cfg, flags) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile // Can know about the flag - if (env.config.flags.continue) { + if (flags.continue) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (env.config.flags.help) { + if (flags.help) { parser.showHelp(console.log); exit(0); } // Anything that needs to print outside of the logging mechanism should use console.log - if (env.config.flags.version) { + if (flags.version) { console.log('CLI version:', cliVersion); console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); @@ -215,5 +219,5 @@ function onExecute(env) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(env); + require(versionedDir)(env, cfg, flags); } diff --git a/lib/shared/array-find.js b/lib/shared/array-find.js new file mode 100644 index 00000000..0596268c --- /dev/null +++ b/lib/shared/array-find.js @@ -0,0 +1,19 @@ +'use strict'; + +function arrayFind(arr, fn) { + if (!Array.isArray(arr)) { + return; + } + + var idx = 0; + while (idx < arr.length) { + var result = fn(arr[idx]); + if (result) { + // TODO: This is wrong in Liftoff + return arr[idx]; + } + idx++; + } +} + +module.exports = arrayFind; diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js deleted file mode 100644 index 59b4d4be..00000000 --- a/lib/shared/config/env-flags.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -var path = require('path'); -var copyProps = require('copy-props'); - -var mergeCliOpts = require('./cli-flags'); - -var toEnvFromConfig = { - configPath: 'flags.gulpfile', - configBase: 'flags.gulpfile', - preload: 'flags.preload', - nodeFlags: 'flags.nodeFlags', -}; - -function overrideEnvFlags(env, config, cliOpts) { - cliOpts = mergeCliOpts(cliOpts, config); - - // This must reverse because `flags.gulpfile` determines 2 different properties - var reverse = true; - env = copyProps(env, config, toEnvFromConfig, convert, reverse); - - env.config = { - flags: cliOpts, - }; - if (config.description) { - env.config.description = config.description; - } - return env - - function convert(configInfo, envInfo) { - if (envInfo.keyChain === 'configBase') { - if (cliOpts.gulpfile === undefined) { - return path.dirname(configInfo.value); - } - return; - } - - if (envInfo.keyChain === 'configPath') { - if (cliOpts.gulpfile === undefined) { - return configInfo.value; - } - return; - } - - if (envInfo.keyChain === 'preload') { - return [].concat(envInfo.value, configInfo.value); - } - - /* istanbul ignore else */ - if (envInfo.keyChain === 'nodeFlags') { - return [].concat(configInfo.value || []); - } - } -} - -module.exports = overrideEnvFlags; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js deleted file mode 100644 index 8202f182..00000000 --- a/lib/shared/config/merge-configs.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function mergeConfigs(env) { - var cfg = {}; - if (env.configFiles.userHome) { - copyConfig(env.config.userHome, cfg, env.configFiles.userHome); - } - if (env.configFiles.project) { - copyConfig(env.config.project, cfg, env.configFiles.project); - } - return cfg; -} - -function copyConfig(src, dest, filePath) { - return copyProps(src, dest, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } -} - -module.exports = mergeConfigs; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index a5cc2a9f..397bd579 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -17,9 +17,7 @@ var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -53,8 +51,8 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -64,8 +62,8 @@ function execute(env) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index d6883587..137ad438 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -19,9 +19,7 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(env) { - var opts = env.config.flags; - +function execute(env, cfg, opts) { var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -55,8 +53,8 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } @@ -65,8 +63,8 @@ function execute(env) { } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (env.config.description && typeof env.config.description === 'string') { - tree.label = env.config.description; + if (cfg.description && typeof cfg.description === 'string') { + tree.label = cfg.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/package.json b/package.json index 47ff7595..dace639b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "fancy-log": "^2.0.0", "gulplog": "^2.0.1", "interpret": "^3.1.1", - "liftoff": "^4.0.0", + "liftoff": "^5.0.0", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", diff --git a/test/config-flags-compact-tasks.js b/test/config-flags-compact-tasks.js index 06945128..57fd19a1 100644 --- a/test/config-flags-compact-tasks.js +++ b/test/config-flags-compact-tasks.js @@ -20,8 +20,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -35,8 +35,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -50,8 +50,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -65,8 +65,8 @@ describe('config: flags.compactTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = sliceLines(expected, 1); - stdout = sliceLines(stdout, 1); + expected = sliceLines(expected, 2); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index ae04b7f6..4d62031c 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -10,7 +10,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); var prjDir = path.join(baseDir, 'prj'); -describe('config: flags.gulpfile', function() { +describe('config: gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { var opts = { cwd: prjDir }; @@ -19,9 +19,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + prjDir + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -49,9 +49,9 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 2, 4)).toEqual( + expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + - 'The current directory : ' + path.join(prjDir, 'findup') + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } @@ -126,8 +126,8 @@ describe('config: flags.gulpfile', function() { expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Loaded external module: @babel/register'); - expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); - expect(sliceLines(stdout, 7, 8)).toEqual('build!'); + expect(sliceLines(stdout, 5, 6)).toEqual('clean!'); + expect(sliceLines(stdout, 8, 9)).toEqual('build!'); done(err); } }); @@ -152,7 +152,7 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 3, 4)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); + expect(sliceLines(stdout, 2, 3)).toEqual(path.join(opts.cwd, 'gulpfile-2.js')); done(err); } }); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 47942363..e406da09 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -9,7 +9,7 @@ var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/preload'); -describe('config: flags.preload', function() { +describe('config: preload', function() { it('Should configure with an array in a .gulp.* file', function(done) { var opts = { cwd: path.join(baseDir, 'array') }; diff --git a/test/config-flags-sort-tasks.js b/test/config-flags-sort-tasks.js index 01eada8d..197f8d39 100644 --- a/test/config-flags-sort-tasks.js +++ b/test/config-flags-sort-tasks.js @@ -20,7 +20,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -46,7 +46,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -59,7 +59,7 @@ describe('config: flags.sortTasks', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js index 944766c2..68a09037 100644 --- a/test/config-flags-tasks-depth.js +++ b/test/config-flags-tasks-depth.js @@ -20,7 +20,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } @@ -33,7 +33,7 @@ describe('config: flags.tasksDepth', function() { function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(sliceLines(stdout, 2)).toEqual(sliceLines(expected, 2)); expect(stderr).toEqual(''); done(err); } diff --git a/test/expected/flags-tasks-compact.txt b/test/expected/flags-tasks-compact.txt index 45bc48d3..d15def9b 100644 --- a/test/expected/flags-tasks-compact.txt +++ b/test/expected/flags-tasks-compact.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-depth2.txt b/test/expected/flags-tasks-depth2.txt index ffd130ef..3edbdf74 100644 --- a/test/expected/flags-tasks-depth2.txt +++ b/test/expected/flags-tasks-depth2.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └── diff --git a/test/expected/flags-tasks-depth4.txt b/test/expected/flags-tasks-depth4.txt index b1550ad5..6d79eb1e 100644 --- a/test/expected/flags-tasks-depth4.txt +++ b/test/expected/flags-tasks-depth4.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/expected/flags-tasks-sorted.txt b/test/expected/flags-tasks-sorted.txt index 65d61c0c..1bdc4cfd 100644 --- a/test/expected/flags-tasks-sorted.txt +++ b/test/expected/flags-tasks-sorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ default │ └─┬ diff --git a/test/expected/flags-tasks-unsorted.txt b/test/expected/flags-tasks-unsorted.txt index fe916931..edd85682 100644 --- a/test/expected/flags-tasks-unsorted.txt +++ b/test/expected/flags-tasks-unsorted.txt @@ -1,3 +1,4 @@ +Working directory changed to gulp-cli/test/fixtures/gulpfiles gulp-cli/test/fixtures/gulpfiles ├─┬ taskC │ └─┬ diff --git a/test/fixtures/config/flags/compactTasks/f/.gulp.js b/test/fixtures/config/flags/compactTasks/f/.gulp.js index 53447e50..9fef64e2 100644 --- a/test/fixtures/config/flags/compactTasks/f/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/f/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: false, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/compactTasks/t/.gulp.js b/test/fixtures/config/flags/compactTasks/t/.gulp.js index 70c8de7d..8ac27e43 100644 --- a/test/fixtures/config/flags/compactTasks/t/.gulp.js +++ b/test/fixtures/config/flags/compactTasks/t/.gulp.js @@ -1,8 +1,8 @@ 'use strict'; module.exports = { + gulpfile: '../../../../gulpfiles/gulpfile-4.js', flags: { compactTasks: true, - gulpfile: '../../../../gulpfiles/gulpfile-4.js', }, }; diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json index 10707925..42846df5 100644 --- a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "./other_dir/gulpfile.coffee" - } + "gulpfile": "./other_dir/gulpfile.coffee" } diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json index 0d5c0009..10c5b586 100644 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "other_folder/gulpfile-exports.babel.js" - } + "gulpfile": "other_folder/gulpfile-exports.babel.js" } diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json index 231d1a67..7f0181dd 100644 --- a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json index f071d31d..fb737ede 100644 --- a/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/override-by-cliflag/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../cwd/gulpfile.js" - } + "gulpfile": "../cwd/gulpfile.js" } diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json index 64535ec4..625bb7c1 100644 --- a/test/fixtures/config/flags/gulpfile/prj/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" - } + "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" } diff --git a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js index 0cbce526..8e905bea 100644 --- a/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js +++ b/test/fixtures/config/flags/gulpfile/use-current-cfg/current-dir/.gulp.js @@ -1,5 +1,3 @@ module.exports = { - flags: { - gulpfile: './gulpfile-2.js', - }, + gulpfile: './gulpfile-2.js', }; diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.json b/test/fixtures/config/flags/nodeFlags/array/.gulp.json index f327928a..79cd530d 100644 --- a/test/fixtures/config/flags/nodeFlags/array/.gulp.json +++ b/test/fixtures/config/flags/nodeFlags/array/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "nodeFlags": ["--lazy", "--trace-deprecation"] - } + "nodeFlags": ["--lazy", "--trace-deprecation"] } diff --git a/test/fixtures/config/flags/nodeFlags/null/.gulp.js b/test/fixtures/config/flags/nodeFlags/null/.gulp.js index 1b0bdfb1..4f613ce0 100644 --- a/test/fixtures/config/flags/nodeFlags/null/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/null/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: null, - }, + nodeFlags: null, }; diff --git a/test/fixtures/config/flags/nodeFlags/string/.gulp.js b/test/fixtures/config/flags/nodeFlags/string/.gulp.js index 608862dd..f14523e4 100644 --- a/test/fixtures/config/flags/nodeFlags/string/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/string/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: '--lazy', - }, + nodeFlags: '--lazy', }; diff --git a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js index 35082449..78532965 100644 --- a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js +++ b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js @@ -1,7 +1,5 @@ 'use strict'; module.exports = { - flags: { - nodeFlags: undefined, - }, + nodeFlags: undefined, }; diff --git a/test/fixtures/config/flags/preload/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.json index 0031374c..2f4855e1 100644 --- a/test/fixtures/config/flags/preload/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.json @@ -1,8 +1,6 @@ { - "flags": { - "preload": [ - "./preload_one", - "./preload_two" - ] - } + "preload": [ + "./preload_one", + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json index 83d17ccf..63405ae5 100644 --- a/test/fixtures/config/flags/preload/join-flags/.gulp.json +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.json @@ -1,7 +1,5 @@ { - "flags": { - "preload": [ - "./preload_two" - ] - } + "preload": [ + "./preload_two" + ] } diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json index 9b061f1f..22886303 100644 --- a/test/fixtures/config/flags/preload/string/.gulp.json +++ b/test/fixtures/config/flags/preload/string/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "./preload" - } + "preload": "./preload" } diff --git a/test/fixtures/config/flags/preload/with-absolute/.gulp.js b/test/fixtures/config/flags/preload/with-absolute/.gulp.js index c0e29e8a..1e7872b2 100644 --- a/test/fixtures/config/flags/preload/with-absolute/.gulp.js +++ b/test/fixtures/config/flags/preload/with-absolute/.gulp.js @@ -1,7 +1,5 @@ var path = require('path'); module.exports = { - flags: { - preload: path.join(__dirname, '../preload'), - }, + preload: path.join(__dirname, '../preload'), }; diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json index d43feab5..c92f9743 100644 --- a/test/fixtures/config/flags/preload/with-cwd/.gulp.json +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.json @@ -1,5 +1,3 @@ { - "flags": { - "preload": "../preload" - } + "preload": "../preload" } diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.json b/test/fixtures/config/flags/sortTasks/f/.gulp.json index ac703623..daa8a926 100644 --- a/test/fixtures/config/flags/sortTasks/f/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/f/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": false, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": false } } diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.json b/test/fixtures/config/flags/sortTasks/t/.gulp.json index 7e801098..254cd26a 100644 --- a/test/fixtures/config/flags/sortTasks/t/.gulp.json +++ b/test/fixtures/config/flags/sortTasks/t/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../../gulpfiles/gulpfile-4.js", "flags": { - "sortTasks": true, - "gulpfile": "../../../../gulpfiles/gulpfile-4.js" + "sortTasks": true } } diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.json b/test/fixtures/config/flags/tasksDepth/.gulp.json index 5a9da057..bc309203 100644 --- a/test/fixtures/config/flags/tasksDepth/.gulp.json +++ b/test/fixtures/config/flags/tasksDepth/.gulp.json @@ -1,6 +1,6 @@ { + "gulpfile": "../../../gulpfiles/gulpfile-4.js", "flags": { - "tasksDepth": 4, - "gulpfile": "../../../gulpfiles/gulpfile-4.js" + "tasksDepth": 4 } } diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 4a1c689f..270b5ffc 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -81,7 +81,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -99,7 +99,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -117,7 +117,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -135,7 +135,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); @@ -153,7 +153,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expect(sliceLines(stdout, 1)).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); done(err); } }); diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js deleted file mode 100644 index d8062c08..00000000 --- a/test/lib/config-env-flags.js +++ /dev/null @@ -1,112 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var overrideEnvFlags = require('../../lib/shared/config/env-flags'); - -describe('lib: config/env-flags', function() { - - it('Should copy only config props specified to env flags', function(done) { - var env = {}; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: true, - gulpfile: '/path/to/gulpfile', - }, - }; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - configPath: '/path/to/gulpfile', - configBase: '/path/to', - config: { - description: 'DESCRIPTION.', - flags: { - silent: true, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should take into account forced gulpfile opts from flags', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = { - description: 'DESCRIPTION.', - flags: { - silent: false, - gulpfile: '/path/to/gulpfile', - preload: ['a', 'b'], - }, - }; - - var opts = { - gulpfile: env.configPath, - }; - - var result = overrideEnvFlags(env, config, opts); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: ['preload', 'a', 'b'], - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - description: "DESCRIPTION.", - flags: { - gulpfile: "/path/of/config/path", - silent: false, - }, - }, - }); - expect(result).toBe(env); - done(); - }); - - it('Should not cause error if config is empty', function(done) { - var env = { - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - }; - - var config = {}; - - var result = overrideEnvFlags(env, config, {}); - expect(result).toEqual({ - cwd: '/path/to/cwd', - preload: 'preload', - configNameSearch: 'configNameSearch', - configPath: '/path/of/config/path', - configBase: '/path/of/config/base', - modulePath: '/path/of/module/path', - modulePackage: { name: 'modulePackage' }, - configFiles: { aaa: {} }, - config: { - flags: {}, - }, - }); - expect(result).toBe(env); - done(); - }); -}); diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js deleted file mode 100644 index 6d0a4bea..00000000 --- a/test/lib/merge-configs.js +++ /dev/null @@ -1,119 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var mergeConfigs = require('../../lib/shared/config/merge-configs'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/merge-configs', function() { - - it('Should get merged config when there is only project config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - }, - userHome: {}, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/.gulp.js'), - userHome: undefined, - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - }); - done(); - }); - - it('Should get merged config when there is only user-home config', function(done) { - var config = { - project: {}, - userHome: { - description: 'description by .gulp.js in directory user home', - }, - }; - var configFiles = { - project: undefined, - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory user home', - }); - done(); - }); - - it('Should get merged config when there are both project and user-home config', function(done) { - var config = { - project: { - description: 'description by .gulp.js in directory project', - flags: { - series: true, - }, - }, - userHome: { - description: 'description by .gulp.js in directory user home', - flags: { - silent: true, - }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'project/gulp.js'), - userHome: path.join(fixturesDir, 'user/home/.gulp.js'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory project', - flags: { - series: true, - silent: true, - }, - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { - var config = { - project: { - flags: { gulpfile: './is/here/mygulpfile.js' }, - }, - }; - var configFiles = { - project: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - var env = { - config: config, - configFiles: configFiles, - }; - - var cfg = mergeConfigs(env); - - expect(cfg).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -});