Skip to content
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

Fix the issue #181 #182

Merged
merged 5 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "gulp",
"rules": {
"max-statements": [1, 40]
"max-statements": [1, 40],
"no-console": "off"
}
}
4 changes: 0 additions & 4 deletions .jscsrc

This file was deleted.

12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
sudo: false
language: node_js
node_js:
- "10"
- "8"
- "6"
- "4"
- "0.12"
- "0.10"
before_script:
- sed -i 's/4.0.0-alpha.1/4.0.0/g' node_modules/gulp/package.json
after_script:
- npm run coveralls
- npm run lint
- if [ $(echo "${TRAVIS_NODE_VERSION}" | cut -d'.' -f1) -ge 6 ]; then
npm run coveralls;
fi

git:
depth: 10
os:
- linux
- osx
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "10"

install:
- npm install -g npm@^3
Expand Down
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,29 @@ cli.on('respawn', function(flags, child) {
log.info('Respawned to PID:', pid);
});


function run() {
cli.launch({
cli.prepare({
cwd: opts.cwd,
configPath: opts.gulpfile,
require: opts.require,
completion: opts.completion,
}, handleArguments);
}, function(env) {

var cfgLoadOrder = ['home', 'cwd'];
var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder);
opts = mergeConfigToCliFlags(opts, cfg);
env = mergeConfigToEnvFlags(env, cfg);
env.configProps = cfg;

cli.execute(env, handleArguments);
});
}

module.exports = run;

// The actual logic
function handleArguments(env) {
var cfgLoadOrder = ['home', 'cwd'];
var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder);
opts = mergeConfigToCliFlags(opts, cfg);
env = mergeConfigToEnvFlags(env, cfg);

// This translates the --continue flag in gulp
// To the settle env variable for undertaker
Expand Down Expand Up @@ -178,5 +184,6 @@ function handleArguments(env) {
}

// Load and execute the CLI version
require(path.join(__dirname, '/lib/versioned/', range, '/'))(opts, env, cfg);
var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/');
require(versionedDir)(opts, env, env.configProps);
}
2 changes: 1 addition & 1 deletion lib/versioned/^3.7.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function execute(opts, env, config) {
}
if (opts.tasksJson) {
tree = taskTree(gulpInst.tasks);
if (config.description && isString(config.description)) {
if (config.description && typeof config.description === 'string') {
phated marked this conversation as resolved.
Show resolved Hide resolved
tree.label = config.description;
} else {
tree.label = 'Tasks for ' + tildify(env.configPath);
Expand Down
2 changes: 1 addition & 1 deletion lib/versioned/^3.7.0/task-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ module.exports = function(tasks) {
task.nodes.push(child);
});
});
return { label: 'Tasks', nodes: arr, };
return { label: 'Tasks', nodes: arr };
};
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"gulp.1"
],
"scripts": {
"lint": "eslint . && jscs index.js bin/ lib/ test/",
"lint": "eslint .",
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
"pretest": "npm run lint",
"test": "mocha --async-only --timeout 5000 test/lib test",
Expand All @@ -41,7 +41,7 @@
"gulplog": "^1.0.0",
"interpret": "^1.1.0",
"isobject": "^3.0.1",
"liftoff": "^2.5.0",
"liftoff": "^3.1.0",
"matchdep": "^2.0.0",
"mute-stdout": "^1.0.0",
"pretty-hrtime": "^1.0.0",
Expand All @@ -53,17 +53,15 @@
"devDependencies": {
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.1",
"coveralls": "^2.7.0",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"coveralls": "^3.0.3",
"eslint": "^2.13.1",
"eslint-config-gulp": "^3.0.1",
"expect": "^1.20.2",
"gulp": "^4.0.0",
"gulp-test-tools": "^0.6.1",
"jscs": "^3.0.7",
"jscs-preset-gulp": "^1.0.0",
"marked-man": "^0.2.1",
"mocha": "^3.2.0",
"nyc": "^11.4.1",
"nyc": "^13.3.0",
"rimraf": "^2.6.1"
},
"keywords": [
Expand Down
5 changes: 4 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "gulp/test"
"extends": "gulp/test",
"rules": {
"no-console": "off"
}
}
21 changes: 21 additions & 0 deletions test/config-flags-gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var path = require('path');
var fixturesDir = path.join(__dirname, 'fixtures/config');

var headLines = require('gulp-test-tools').headLines;
var eraseTime = require('gulp-test-tools').eraseTime;
var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir);

describe('config: flags.gulpfile', function() {
Expand Down Expand Up @@ -88,5 +89,25 @@ describe('config: flags.gulpfile', function() {
}
});

it('Should autoload a module for loading a specified gulpfile', function(done) {
this.timeout(0);

runner
.chdir('flags/gulpfile/autoload')
.gulp('dist')
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
expect(eraseTime(stdout)).toEqual(
'Requiring external module babel-register\n' +
'clean!\n' +
'build!\n' +
'');
done(err);
}
});

});

1 change: 0 additions & 1 deletion test/config-flags-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var path = require('path');
var skipLines = require('gulp-test-tools').skipLines;
var eraseTime = require('gulp-test-tools').eraseTime;
var eraseLapse = require('gulp-test-tools').eraseLapse;
var runner = require('gulp-test-tools').gulpRunner;

var fixturesDir = path.join(__dirname, 'fixtures/config');
var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir);
Expand Down
2 changes: 1 addition & 1 deletion test/exports-as-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('exports as tasks', function() {
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
// Remove babel/register lines
stdout = eraseTime(skipLines(stdout, 4));
stdout = eraseTime(skipLines(stdout, 2));
expect(stdout).toEqual(expected);
done(err);
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/config/flags/gulpfile/autoload/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"flags": {
"silent": true,
"gulpfile": "other_folder/gulpfile-exports.babel.js"
phated marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

import gulp from 'gulp';

export function clean(done) { console.log('clean!'); done(); };
export function build(done) { console.log('build!'); done(); };
export const string = 'no function';
export const dist = gulp.series(clean, build);
6 changes: 3 additions & 3 deletions test/fixtures/gulpfiles/with-desc-and-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ clean.description = 'Delete dist folder';
gulp.task(clean);

gulp.task('scripts', scripts);
function scripts() {};
function scripts() {}
scripts.description = 'Bundles JavaScript';

var styles = function() {};
Expand All @@ -24,13 +24,13 @@ build.flags = {
gulp.task('build', build);

gulp.task('serve', serve);
function serve() {};
function serve() {}
serve.description = 'Serves files reloading';
serve.flags = {
'--lr': 'with live reloading',
};

function watch() {};
function watch() {}
gulp.task('watch', watch);
watch.description = 'Watch files and build on change';

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/test-error-module.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint no-unreachable: off */
throw new Error('from error module');
console.log('inside error module');
6 changes: 3 additions & 3 deletions test/lib/task-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ describe('lib: taskTree', function() {
label: 'test',
type: 'task',
nodes: [
{ label: 'dep1', type: 'task', nodes: [], },
{ label: 'dep2', type: 'task', nodes: [], },
{ label: 'dep1', type: 'task', nodes: [] },
{ label: 'dep2', type: 'task', nodes: [] },
],
},
{
label: 'test2',
type: 'task',
nodes: [
{ label: 'dep3', type: 'task', nodes: [], },
{ label: 'dep3', type: 'task', nodes: [] },
],
},
{
Expand Down