Skip to content
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 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
sudo: false
language: node_js
node_js:
- "stable"
- "6"
- "5"
- "4"
- "0.12"
- "0.10"
Expand Down
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ environment:
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"

install:
- IF %nodejs_version% EQU 0.10 npm -g install npm@2
- IF %nodejs_version% EQU 0.10 set PATH=%APPDATA%\npm;%PATH%
- npm -g install npm@latest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure you want to be using npm 3? It's so much slower, and appveyor is already extremely slow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm install EPERM errors frequently occured on appveyor, and it seems that this error can be fixed by using npm3.

ref. npm/npm#9696

- set PATH=%APPDATA%\npm;%PATH%
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- for %%f in (test\*.js) do node_modules\.bin\lab %%f -v -m 5000 & if errorlevel 1 exit /b 1
- for %%f in (test\*.js) do node_modules\.bin\lab %%f -v -m 5000 -I Reflect & if errorlevel 1 exit /b 1

build: off

Expand Down
11 changes: 3 additions & 8 deletions lib/shared/log/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
var archy = require('archy');
var chalk = require('chalk');
var log = require('gulplog');
var sortBy = require('lodash.sortby');

function isString(val) {
return typeof val === 'string';
}

function isObject(val) {
return typeof val === 'object' && !Array.isArray(val);
}
var sortBy = require('lodash.sortby');
var isString = require('lodash.isstring');
var isObject = require('lodash.isplainobject');

function logTasks(tree, depth, getTask) {
depth = (typeof depth !== 'number') ? null : ((depth < 1) ? 1 : depth);
Expand Down
6 changes: 3 additions & 3 deletions lib/versioned/^4.0.0-alpha.2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var logSyncTask = require('../^4.0.0/log/syncTask');
var logTasksSimple = require('../^4.0.0/log/tasksSimple');
var registerExports = require('../../shared/registerExports');

var getTask = require('../^4.0.0/log/getTask');

function execute(opts, env) {

var tasks = opts._;
Expand Down Expand Up @@ -48,9 +50,7 @@ function execute(opts, env) {
tree = gulpInst.tree({ deep: true });
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));

return logTasks(tree, opts.depth, function(taskname) {
return gulpInst.task(taskname);
});
return logTasks(tree, opts.depth, getTask(gulpInst));
}
if (opts.tasksJson) {
tree = gulpInst.tree({ deep: true });
Expand Down
6 changes: 3 additions & 3 deletions lib/versioned/^4.0.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var logSyncTask = require('./log/syncTask');
var logTasksSimple = require('./log/tasksSimple');
var registerExports = require('../../shared/registerExports');

var getTask = require('./log/getTask');

function execute(opts, env) {

var tasks = opts._;
Expand Down Expand Up @@ -48,9 +50,7 @@ function execute(opts, env) {
tree = gulpInst.tree({ deep: true });
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));

return logTasks(tree, opts.depth, function(taskname) {
return gulpInst.task(taskname);
});
return logTasks(tree, opts.depth, getTask(gulpInst));
}
if (opts.tasksJson) {
tree = gulpInst.tree({ deep: true });
Expand Down
43 changes: 43 additions & 0 deletions lib/versioned/^4.0.0/log/getTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

var isString = require('lodash.isstring');
var isObject = require('lodash.isplainobject');
var isFunction = require('lodash.isfunction');

function getTask(gulpInst) {
return function(name) {
var task = gulpInst.task(name);
return {
description: getDescription(task),
flags: getFlags(task),
};
};
}

function getDescription(task) {
if (isString(task.description)) {
return task.description;
}
if (isFunction(task.unwrap)) {
var origFn = task.unwrap();
if (isString(origFn.description)) {
return origFn.description;
}
}
return undefined;
}

function getFlags(task) {
if (isObject(task.flags)) {
return task.flags;
}
if (isFunction(task.unwrap)) {
var origFn = task.unwrap();
if (isObject(origFn.flags)) {
return origFn.flags;
}
}
return undefined;
}

module.exports = getTask;
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint": "eslint . && jscs index.js bin/ lib/ test/",
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
"pretest": "npm run lint",
"test": "lab test/*.js -cv",
"test": "lab test/*.js -cv -I Reflect",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is annoying. These tests will need to be switch to mocha like all the other repositories. This is a fine fix for now.

"changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body"
},
"dependencies": {
Expand All @@ -37,7 +37,10 @@
"gulplog": "^1.0.0",
"interpret": "^1.0.0",
"liftoff": "^2.1.0",
"lodash.sortby": "^4.0.1",
"lodash.isfunction": "^3.0.8",
"lodash.isplainobject": "^4.0.4",
"lodash.isstring": "^4.0.1",
"lodash.sortby": "^4.5.0",
"matchdep": "^1.0.0",
"mute-stdout": "^1.0.0",
"pretty-hrtime": "^1.0.0",
Expand Down
15 changes: 15 additions & 0 deletions test/expected/flags-tasks/by-unwrap-and-not-by-unwrap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
gulp-cli/test
├─┬ default
│ └─┬ <series>
│ ├── task1
│ └─┬ <parallel>
│ ├── task2
│ └── task3
├── no-desc
├── task1 Description for gulp.task("task1")
│ --flag-of-task1 …Description for flag of task1
├── task2 Description for gulp.task("task2").unwrap()
│ --flag-of-task2 …Description for flag of task2
└── task3 Use gulp.task("task3").description preferentially
--flag0-of-task3 …Description for flag0 of task3
--flag1-of-task3 …Use gulp.task("task3").flags preferentially
57 changes: 57 additions & 0 deletions test/fixtures/flags-tasks/by-unwrap-and-not-by-unwrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

var gulp = require('gulp');

// Test case when description and flags are gotten by gulp.task(name)
gulp.task('task1', function() {});
gulp.task('task1').description = 'Description for gulp.task("task1")';
gulp.task('task1').flags = {
'--flag-of-task1': 'Description for flag of task1',
};

// Test case when description and flags are gotten by gulp.task(name).unwrap()
gulp.task('task2', function() {});
if (!gulp.task('task2').unwrap) {
var fn2 = function() {};
gulp.task('task2').unwrap = function() {
return fn2;
};
}
gulp.task('task2').unwrap().description =
'Description for gulp.task("task2").unwrap()';
gulp.task('task2').unwrap().flags = {
'--flag-of-task2': 'Description for flag of task2',
};

// Test case when description and flags are gotten by both gulp.task(name) and
// gulp.task(name).unwrap() => Use things by gulp.task(name) preferentially.
gulp.task('task3', function() {});
if (!gulp.task('task3').unwrap) {
var fn3 = function() {};
gulp.task('task3').unwrap = function() {
return fn3;
};
}
gulp.task('task3').description =
'Use gulp.task("task3").description preferentially';
gulp.task('task3').flags = {
'--flag0-of-task3': 'Description for flag0 of task3',
'--flag1-of-task3': 'Use gulp.task("task3").flags preferentially',
};
gulp.task('task3').unwrap().description =
'This description should not output';
gulp.task('task3').unwrap().flags = {
'--flag1-of-task3': 'This description should not output',
'--flag2-of-task3': 'This description should not output',
};

gulp.task('no-desc', function() {});
if (!gulp.task('no-desc').unwrap) {
var fn4 = function() {};
gulp.task('no-desc').unwrap = function() {
return fn4;
};
}

gulp.task('default', gulp.series('task1', gulp.parallel('task2', 'task3')));

24 changes: 0 additions & 24 deletions test/flags-tasks-with-desc.js

This file was deleted.

37 changes: 35 additions & 2 deletions test/flags-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,55 @@
var lab = exports.lab = require('lab').script();
var code = require('code');
var fs = require('fs');
var path = require('path');
var child = require('child_process');

var output = fs.readFileSync(__dirname + '/expected/flags-tasks.txt', 'utf8').replace(/(\r\n|\n|\r)/gm,'\n');
var expectedFiles = [
path.join(__dirname, 'expected/flags-tasks.txt'),
path.join(__dirname, 'expected/flags-tasks/with-desc-and-flags.txt'),
path.join(__dirname, 'expected/flags-tasks/by-unwrap-and-not-by-unwrap.txt'),
];

var outputs = [];
expectedFiles.forEach(function(file, i) {
outputs[i] = fs.readFileSync(file, 'utf8').replace(/(\r\n|\n|\r)/gm,'\n');
});

lab.experiment('flag: --tasks', function() {

lab.test('prints the task list', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --cwd ./test/fixtures', 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');
var outputArray = outputs[0].split('\n');
for (var i = 0; i < stdout.length; i++) {
code.expect(stdout[i]).to.contain(outputArray[i]);
}
done(err);
});
});

lab.test('prints the task list with description and flags', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --gulpfile ./test/fixtures/flags-tasks/with-desc-and-flags.js --cwd ./test/fixtures', function(err, stdout) {
code.expect(stdout).to.contain('Tasks for');
stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n');
var outputArray = outputs[1].split('\n');
for (var i = 0; i < stdout.length; i++) {
code.expect(stdout[i]).to.contain(outputArray[i]);
}
done(err);
});
});

lab.test('prints the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --gulpfile ./test/fixtures/flags-tasks/by-unwrap-and-not-by-unwrap.js --cwd ./test/fixtures', function(err, stdout) {
code.expect(stdout).to.contain('Tasks for');
stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n');
var outputArray = outputs[2].split('\n');
for (var i = 0; i < stdout.length; i++) {
code.expect(stdout[i]).to.contain(outputArray[i]);
}
done(err);
});
});
});
54 changes: 54 additions & 0 deletions test/taskTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,58 @@ lab.experiment('taskTree()', function() {
code.expect(taskTree(tasks)).to.deep.equal(expectTree);
done();
});

lab.test('processes children recursively.', function(done) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did this test come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is what I forgot to include in previous PR and for coverage 100%.

var tasks = {
test: {
dep: ['test2', 'test3'],
},
test2: {
dep: ['test3'],
},
test3: {
dep: [],
},
};

var expectTree = {
label: 'Tasks',
nodes: [
{
label: 'test',
nodes: [
{
label: 'test2',
nodes: [
{
label: 'test3',
nodes: [],
},
],
},
{
label: 'test3',
nodes: [],
},
],
},
{
label: 'test2',
nodes: [
{
label: 'dep3',
nodes: [],
},
],
},
{
label: 'test3',
nodes: [],
},
],
};

code.expect(taskTree(tasks)).to.deep.equal(expectTree);
done();
});
});