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

Commit

Permalink
Merge 7885f0e into 40c4f03
Browse files Browse the repository at this point in the history
  • Loading branch information
cmtt committed Sep 25, 2016
2 parents 40c4f03 + 7885f0e commit 0bb9552
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 472 deletions.
58 changes: 0 additions & 58 deletions .jshintrc

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ let di = require('gulp-di')(gulp, {

## Changelog

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)
- adopting [https://github.com/Flet/semistandard](semistandard) style

0.0.33 - 05/03/2016

- Updating depencendies and adapting to changes
Expand Down
5 changes: 5 additions & 0 deletions contrib/examples/deg-to-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function (PI) {
return PI / 180;
};
5 changes: 5 additions & 0 deletions contrib/examples/pi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function () {
return Math.PI;
};
5 changes: 5 additions & 0 deletions contrib/examples/rad-to-deg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function (PI) {
return 180 / PI;
};
5 changes: 5 additions & 0 deletions contrib/examples/to-deg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function (RAD_TO_DEG) {
return (radians) => radians * RAD_TO_DEG;
};
5 changes: 5 additions & 0 deletions contrib/examples/to-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function (DEG_TO_RAD) {
return (degrees) => degrees * DEG_TO_RAD;
};
5 changes: 2 additions & 3 deletions contrib/get-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

function getPath (obj, key) {

key = typeof key !== 'undefined' ? key : null;

if (key === null) {
Expand All @@ -19,16 +18,16 @@ function getPath (obj, key) {
/**
* Returns a payload or a nested property of any provided payload.
* @method step
* @private
* @param {*} object
* @param {string[]} depPath
* @private
*/

function step (object, depPath) {
return depPath.length ? step(object[depPath.shift()], depPath) : object;
}

let depPath = key.split(/\./g);
const depPath = key.split(/\./g);
return step(obj, depPath);
}

Expand Down
75 changes: 35 additions & 40 deletions contrib/help.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
/*jshint -W089 */
const pad = require('pad');
const LINE_PADDING = 5;

module.exports = function HelpTask (gulp) {

/**
* Modifies the gulp.task() function and builds a list of all tasks.
*
Expand All @@ -16,8 +16,8 @@ module.exports = function HelpTask (gulp) {
* // Copies ./README.md to ./tmp
*
* return gulp.src('./README.md')
* .pipe(gulp.dest('./tmp'));
* };
* .pipe(gulp.dest('./tmp'))
* }
* ````
*
* This module needs to be injected before each successive require('gulp')
Expand All @@ -27,12 +27,11 @@ module.exports = function HelpTask (gulp) {
* experimental.
*/

let Package = this.byId('Package', true) || {};
let chalk = this.byId('chalk', true);
let log = this.byId('log', true) || console.log.bind(console);
const Package = this.byId('Package', true) || {};
const chalk = this.byId('chalk', true);
const log = this.byId('log', true) || console.log.bind(console);

const parseFn = require('parse-function');
const util = require('util');
const extractComments = require('extract-comments');
const _task = gulp.task;
const taskInfo = {};
Expand All @@ -57,7 +56,7 @@ module.exports = function HelpTask (gulp) {
*/

gulp.task = function (id, deps, fn) {
let args = [].slice.apply(arguments);
const args = [].slice.apply(arguments);

if (typeof deps === 'function') {
fn = arguments[1];
Expand All @@ -67,34 +66,32 @@ module.exports = function HelpTask (gulp) {
let entry = null;

if (typeof fn === 'function') {
let info = parseFn(fn.toString());
entry = {
name : id
};
entry.description = util.format('Runs the %s task (no description)', id);
let comments = extractComments(info.body, {first : true});
const info = parseFn(fn.toString());
entry = { name: id };
entry.description = `Runs the ${id} task (no description)`;
const comments = extractComments(info.body, {first: true});
if (comments.length) {
let comment = comments[0];
let lines = comment.raw
.split(RGX_LF)
.map(function (line) {
return line.replace(/(\ )*(\*|\/+)/g, '');
});
const comment = comments[0];
const lines = comment.raw
.split(RGX_LF)
.map(function (line) {
return line.replace(/( )*(\*|\/+)/g, '');
});
entry.description = lines;
}
} else if (id === 'default') {
entry = {
name : 'default',
description : 'Runs the default tasks: ' + deps.join(' ')
name: 'default',
description: 'Runs the default tasks: ' + deps.join(' ')
};
}

if (entry) {
entry.deps = deps;
if (DEBUG) {
let line = ['Adding', chalk.cyan(entry.name), 'task'];
let line = [`Adding ${chalk.cyan(entry.name)} task`];
if (deps.length) {
line.push(' - depending on ',chalk.magenta(deps.join(' ')));
line.push(` - depending on ${chalk.magenta(deps.join(' '))}`);
}
log.apply(chalk, line);
}
Expand All @@ -109,27 +106,26 @@ module.exports = function HelpTask (gulp) {
gulp.task('help', function () {
/* Prints an overview over all available Gulp tasks. */

let util = require('util');
let pad = require('pad');
let lines = [''];
let padding = 5;
let paddingStr = new Array(padding).join(' ');
const paddingStr = new Array(LINE_PADDING).join(' ');

lines.push(' ' + Package.name + ' ' + Package.version, '');

if (Package.description && Package.description.length) {
lines.push(' ' + Package.description, '');
}

let taskIds = Object.keys(taskInfo);
let taskLengths = taskIds.map(function (id) { return id.length; });
let maxLength = Math.max.apply(Math, taskLengths);

for (let key in taskInfo) {
let entry = taskInfo[key];
let paddingLength = maxLength;
let str = new Array(paddingLength+2).join(' ');
let descriptionLine = util.format('Runs the %s task.', key);
const taskIds = Object.keys(taskInfo);
const taskLengths = taskIds.map(function (id) { return id.length; });
const maxLength = Math.max.apply(Math, taskLengths);
const keys = Object.keys(taskInfo);
keys.sort();
for (var i = 0; i < keys.length; i++) {
const key = keys[i];
const entry = taskInfo[key];
const paddingLength = maxLength;
const str = new Array(paddingLength + 2).join(' ');
let descriptionLine = `Runs the ${key} task.`;
if (entry.description) descriptionLine = mapDescription(str, entry.description);
lines.push(' ' + pad(entry.name, maxLength) + paddingStr + descriptionLine.join('\n').trim());
lines.push('');
Expand All @@ -147,13 +143,12 @@ module.exports = function HelpTask (gulp) {
* @private
*/

function mapDescription(str, lines) {
function mapDescription (str, lines) {
if (typeof lines === 'string') lines = [lines];
return lines.map(function (line, index) {
line = line.trim();
return index ? str + paddingStr + line : line;
});
}
});

};
25 changes: 11 additions & 14 deletions contrib/running-tasks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

module.exports = function RunningTasks (gulp) {

const DEBUG = this.options.DEBUG;
let log = this.byId('log', true) || console.log.bind(console);
let gutil = this.byId('gutil', true) || { env : { _ : process.argv }};
const log = this.byId('log', true) || console.log.bind(console);
const gutil = this.byId('gutil', true) || { env: { _: process.argv } };

/**
* Adds a function returning an array of strings, containing all current
Expand All @@ -15,8 +14,8 @@ module.exports = function RunningTasks (gulp) {
* ````js
* module.exports = function (gulp, log, Package, runningTasks) {
* gulp.task('info', function () {
* log('Building ' + chalk.magenta(Package.name) + ', running: ' + chalk.cyan(runningTasks().join(' ')));
* });
* log('Building ' + chalk.magenta(Package.name) + ', running: ' + chalk.cyan(runningTasks().join(' ')))
* })
* }
* ````
*
Expand All @@ -28,24 +27,22 @@ module.exports = function RunningTasks (gulp) {
}

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

let cliTasks = taskNames.filter(function (name) {
return !!~args.indexOf(name);
});
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++) {
let name = cliTasks[i];
let task = gulp.tasks[name];
const name = cliTasks[i];
const task = gulp.tasks[name];
tasks = tasks.concat(task.dep);
tasks.push(task.name);
}
return tasks;
});

};
6 changes: 3 additions & 3 deletions contrib/standard-task.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-eval */
'use strict';

const parseStack = require('parse-stack');
Expand All @@ -17,7 +18,6 @@ const path = require('path');
*/

function standardTask (name, src, dest) {

let args = _.toArray(arguments).slice(3); // dependencies
let stack = null;
let filename = '<unknown>';
Expand Down Expand Up @@ -59,7 +59,7 @@ function standardTask (name, src, dest) {
gulp.task("${name}", () => {
/**
* ${name} task, declared at ${filename}${line ? ':' + line : ''}
* ${name} task, declared at ${filename}${line ? ':' + line : ''}
*/
let plugin = this.byId("${name}");
Expand All @@ -69,7 +69,7 @@ function standardTask (name, src, dest) {
}
return gulp.src("${src}")
.pipe(plugin(${ args || 'void 0' }))
.pipe(plugin(${args || 'void 0'}))
.pipe(gulp.dest("${dest}"));
});
`;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/di');
module.exports = require('./lib/gulp-di');
13 changes: 13 additions & 0 deletions lib/dependency-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/**
* @method DependencyError
* @private
* @param {string} id
*/

const DependencyError = function (id) {
return new Error('Unknown dependency: ' + id);
};

module.exports = DependencyError;

0 comments on commit 0bb9552

Please sign in to comment.