Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Merge a6a151f into 9e4357c
Browse files Browse the repository at this point in the history
  • Loading branch information
cmtt committed Nov 18, 2016
2 parents 9e4357c + a6a151f commit 4be61e8
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -19,4 +19,4 @@ before_script:

after_success: 'npm run coveralls'

script: gulp
script: npm test
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -481,7 +481,11 @@ let di = require('gulp-di')(gulp, {

## Changelog

0.0.4 - 11/11/2016
0.1.0 - 00/??/201?

- Adapting to changes in gulp 4.0 (#9)

0.0.4 - 0?/??/2016

- task() and module() may take absolute or relative paths
- using a fork of [node-introspect](https://github.com/orzarchi/node-introspect.git) instead of [parse-function](https://github.com/tunnckoCore/parse-function)
Expand Down
16 changes: 7 additions & 9 deletions contrib/help.js
Expand Up @@ -78,14 +78,9 @@ module.exports = function HelpTask (gulp) {
return line.replace(/( )*(\*|\/+)/g, '');
});
entry.description = lines;
fn.description = lines;
}
} else if (id === 'default') {
entry = {
name: 'default',
description: 'Runs the default tasks: ' + deps.join(' ')
};
}

if (entry) {
entry.deps = deps;
if (DEBUG) {
Expand All @@ -97,13 +92,12 @@ module.exports = function HelpTask (gulp) {
}
taskInfo[id] = entry;
}

return _task.apply(gulp, args);
};

// Registers the "help" task.

gulp.task('help', function () {
function HelpTask (done) {
/* Prints an overview over all available Gulp tasks. */

let lines = [''];
Expand Down Expand Up @@ -133,6 +127,7 @@ module.exports = function HelpTask (gulp) {

lines.forEach((line) => console.log(line));

done();
/**
* Maps the given array of comment lines by prepending whitespace if
* necessary.
Expand All @@ -150,5 +145,8 @@ module.exports = function HelpTask (gulp) {
return index ? str + paddingStr + line : line;
});
}
});
}

HelpTask.description = 'Displays initial help.';
gulp.task('help', HelpTask);
};
19 changes: 4 additions & 15 deletions contrib/running-tasks.js
Expand Up @@ -27,22 +27,11 @@ module.exports = function RunningTasks (gulp) {
}

this.provide('runningTasks', () => {
const registry = gulp._registry;
const args = this.options.argv || gutil.env._;
const taskNames = Object.keys(gulp.tasks);
const taskNames = Object.keys(registry.tasks());
// Filter all available task names using gutil.env._

const cliTasks = taskNames.filter((name) => args.indexOf(name) > -1);

let tasks = [];

// Include the names of depending tasks

for (let i = 0, l = cliTasks.length; i < l; i++) {
const name = cliTasks[i];
const task = gulp.tasks[name];
tasks = tasks.concat(task.dep);
tasks.push(task.name);
}
return tasks;
const cliTasks = taskNames.filter((name) => args.indexOf(name) !== -1);
return cliTasks;
});
};
1 change: 0 additions & 1 deletion gulpfile.js
Expand Up @@ -15,7 +15,6 @@
const gulp = require('gulp');
let di = require('./')(gulp, {
// DEBUG: true
// lazy : false
})
.modules('./modules')
.tasks('./tasks')
Expand Down
12 changes: 9 additions & 3 deletions lib/gulp-di.js
Expand Up @@ -139,18 +139,18 @@ module.exports = (function () {
* @method _module
* @param {string} name
* @param {function} fn
* @param {string} type
* @chainable
*/

module (name, fn) {
module (name, fn, type) {
if (typeof fn === 'string') {
try {
fn = require(normalizePath(parentDir, fn));
} catch (e) {
throw new Error(`Could not load module "${name}" from "${fn}"`);
}
}
const type = null;
if (typeof name === 'object' && typeof name.length !== 'number') {
const obj = arguments[0];
_.each(obj, (fn, key) => this.module(key, fn, type));
Expand Down Expand Up @@ -234,7 +234,13 @@ module.exports = (function () {
task (fn) {
if (typeof fn === 'object') {
const obj = arguments[0];
_.each(obj, (fn) => this.task(fn));
let keys = Object.keys(obj).sort();
const defaultIndex = keys.indexOf('default');
if (~defaultIndex) {
keys.splice(defaultIndex, 1);
keys.push('default');
}
keys.forEach((name) => this.task(obj[name]));
return this;
}
if (typeof fn === 'string') {
Expand Down
10 changes: 6 additions & 4 deletions package.json
@@ -1,10 +1,10 @@
{
"name": "gulp-di",
"version": "0.0.4",
"version": "0.1.0",
"description": "Dependency injection framework for the Gulp streaming build system",
"main": "index.js",
"scripts": {
"test": "gulp semistandard mocha",
"test": "./node_modules/gulp-cli/bin/gulp.js semistandard mocha",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"author": {
Expand Down Expand Up @@ -36,7 +36,8 @@
"chalk": "^1.1.3",
"extract-comments": "^0.10.1",
"findup-sync": "^0.4.3",
"gulp": "^3.9.1",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-cli": "^1.2.2",
"gulp-concat": "^2.6.0",
"gulp-istanbul": "^1.1.1",
"gulp-load-plugins": "^1.4.0",
Expand All @@ -52,7 +53,8 @@
"require-dir": "^0.3.1"
},
"devDependencies": {
"coveralls": "^2.11.14"
"coveralls": "^2.11.14",
"undertaker": "^1.0.0"
},
"semistandard": {
"globals": [
Expand Down
2 changes: 1 addition & 1 deletion tasks/default.js
@@ -1,5 +1,5 @@
'use strict';

module.exports = (gulp, Package, basePath) => {
gulp.task('default', ['mocha', 'semistandard']);
gulp.task('default', gulp.parallel('mocha', 'semistandard'));
};
12 changes: 7 additions & 5 deletions tasks/examples.js
Expand Up @@ -17,20 +17,21 @@ module.exports = (Package, basePath, chalk, log, gulp, taskInfo, gutil, runningT

// You can declare multiple gulp tasks in each file.

gulp.task('task-info', () => {
gulp.task('task-info', (cb) => {
/**
* Example logging task information from contrib/help.js
*/

console.log(`${Package.name}\'s task information: `);
console.log(taskInfo);
cb();
});

gulp.task('a', () => {});
gulp.task('b', ['c', 'a'], () => {});
gulp.task('c', () => {});
gulp.task('a', (cb) => cb());
gulp.task('c', (cb) => cb());
gulp.task('b', gulp.series('a', 'c'));

gulp.task('info', () => {
gulp.task('info', (cb) => {
/**
* Demonstrates logging currently running tasks.
*
Expand All @@ -52,5 +53,6 @@ module.exports = (Package, basePath, chalk, log, gulp, taskInfo, gutil, runningT
chalk.cyan(runningTasks().join(', '))
];
log(line.join(' '));
cb();
});
};
10 changes: 3 additions & 7 deletions tasks/mocha.js
@@ -1,22 +1,18 @@
'use strict';
module.exports = function (gulp, paths) {
module.exports = function (gulp, paths, mocha, istanbul) {
gulp.task('pre-test', () => {
const istanbul = this.byId('istanbul');
return gulp.src(paths.istanbul)
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});

gulp.task('mocha', ['pre-test'], () => {
const mocha = this.byId('mocha');
const istanbul = this.byId('istanbul');

gulp.task('mocha', gulp.series('pre-test', () => {
// Runs the unit tests using Mocha

return gulp.src(paths.mocha, { read: false })
.pipe(mocha({}))
.pipe(istanbul.writeReports());
});
}));
};
17 changes: 15 additions & 2 deletions test/00.js
Expand Up @@ -12,8 +12,15 @@ global.GulpDI = require(diPath);

global.getGulpInstance = () => {
delete require.cache[require.resolve('gulp')];
delete require.cache[require.resolve('gulp-util')];
return require('gulp');
delete require.cache[require.resolve('undertaker')];
delete require.cache[require.resolve('undertaker-registry')];
delete require.cache[require.resolve('last-run')];
const gulp = require('gulp');
gulp.on('error', (e) => {
console.log(e.error);
throw new Error(`Gulp runtime error:\n${JSON.stringify(e)}\n`);
});
return gulp;
};

/**
Expand All @@ -25,3 +32,9 @@ global.getDiInstance = (gulp, config) => {
global.GulpDI = require(diPath);
return new global.GulpDI(gulp, config);
};

global.hasTask = (gulp, taskId) => {
const registry = gulp._registry;
const tasks = registry.tasks();
return taskId in tasks;
};
29 changes: 15 additions & 14 deletions test/10-gulp-di.js
Expand Up @@ -26,8 +26,8 @@ describe('GulpDI', () => {

describe('Initialization', () => {
beforeEach(() => {
di = null;
gulp = getGulpInstance();
di = null;
});

it('initializes', () => {
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('GulpDI', () => {

it('options.noHelp', () => {
di = getDiInstance(gulp, { noHelp: true }).resolve();
assert.ok(!gulp.tasks.help);
assert.ok(!hasTask(gulp, 'help'));
});
});

Expand Down Expand Up @@ -229,36 +229,37 @@ describe('GulpDI', () => {
.tasks('./tasks')
.resolve();
di.inject((gulp) => {
assert.ok(gulp.tasks.semistandard, 'has "semistandard" task');
assert.ok(hasTask(gulp, 'semistandard'), 'has "semistandard" task');
done();
});
});

it('includes gulp and can run a task', (done) => {
let taskCalled = false;
gulp.on('stop', () => {
assert.equal(taskCalled, true);
done();
});

di = getDiInstance(gulp)
.task((gulp, PI, toDeg) => {
assert.ok(gulp);
gulp.task('default', () => {

gulp.task('default', (cb) => {
taskCalled = true;
assert.equal(toDeg(2 * PI), 360);
cb();
});
})
.module('toDeg', toDegModule)
.provide('PI', PI)
.provide('RAD_TO_DEG', RAD_TO_DEG)
.resolve();

gulp.start('default');
gulp.series('default', (cb) => {
assert.equal(taskCalled, true);
cb();
done();
})();
});

it('can concatenate all spec files', (done) => {
let gulp = getGulpInstance();
let di = getDiInstance(gulp, { parentDir: basePath(), lazy: false });
let s = new Stream.Transform();
let l = 0;
Expand All @@ -284,14 +285,14 @@ describe('GulpDI', () => {
// console.log('The concat command', concat)
});
});
gulp.on('stop', () => {
di.resolve();
gulp.series('concat', (cb) => {
assert.ok(ended, 'Stream was closed');
assert.ok(l > 0, 'Read more than zero bytes');
assert.equal(count, 1, 'Solely one file written');
cb();
done();
});
di.resolve();
gulp.start('concat');
})();
});
});
});

0 comments on commit 4be61e8

Please sign in to comment.