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

Commit 83eaea6

Browse files
committed
WIP 0.0.4: semistandard style, allowing to call module and task with absolute and relative paths
1 parent 40c4f03 commit 83eaea6

29 files changed

+372
-403
lines changed

.jshintrc

-58
This file was deleted.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ let di = require('gulp-di')(gulp, {
481481

482482
## Changelog
483483

484+
0.0.4 - 0?/??/2016
485+
486+
- task() and module() may take absolute or relative paths
487+
- using a fork of [node-introspect](https://github.com/orzarchi/node-introspect.git) instead of [parse-function](https://github.com/tunnckoCore/parse-function)
488+
- adopting [https://github.com/Flet/semistandard](semistandard) style
489+
484490
0.0.33 - 05/03/2016
485491

486492
- Updating depencendies and adapting to changes

contrib/examples/deg-to-rad.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = function (PI) {
4+
return PI / 180;
5+
};

contrib/examples/pi.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = () => Math.PI;

contrib/examples/rad-to-deg.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = function (PI) {
4+
return 180 / PI;
5+
};

contrib/examples/to-deg.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = function (RAD_TO_DEG) {
4+
return (radians) => radians * RAD_TO_DEG;
5+
};

contrib/examples/to-rad.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = function (DEG_TO_RAD) {
4+
return (degrees) => degrees * DEG_TO_RAD;
5+
};

contrib/get-path.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
function getPath (obj, key) {
10-
1110
key = typeof key !== 'undefined' ? key : null;
1211

1312
if (key === null) {

contrib/help.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
2-
/*jshint -W089 */
32

43
module.exports = function HelpTask (gulp) {
5-
64
/**
75
* Modifies the gulp.task() function and builds a list of all tasks.
86
*
@@ -32,7 +30,6 @@ module.exports = function HelpTask (gulp) {
3230
let log = this.byId('log', true) || console.log.bind(console);
3331

3432
const parseFn = require('parse-function');
35-
const util = require('util');
3633
const extractComments = require('extract-comments');
3734
const _task = gulp.task;
3835
const taskInfo = {};
@@ -69,10 +66,10 @@ module.exports = function HelpTask (gulp) {
6966
if (typeof fn === 'function') {
7067
let info = parseFn(fn.toString());
7168
entry = {
72-
name : id
69+
name: id
7370
};
74-
entry.description = util.format('Runs the %s task (no description)', id);
75-
let comments = extractComments(info.body, {first : true});
71+
entry.description = `Runs the ${id} task (no description)`;
72+
let comments = extractComments(info.body, {first: true});
7673
if (comments.length) {
7774
let comment = comments[0];
7875
let lines = comment.raw
@@ -84,17 +81,17 @@ module.exports = function HelpTask (gulp) {
8481
}
8582
} else if (id === 'default') {
8683
entry = {
87-
name : 'default',
88-
description : 'Runs the default tasks: ' + deps.join(' ')
84+
name: 'default',
85+
description: 'Runs the default tasks: ' + deps.join(' ')
8986
};
9087
}
9188

9289
if (entry) {
9390
entry.deps = deps;
9491
if (DEBUG) {
95-
let line = ['Adding', chalk.cyan(entry.name), 'task'];
92+
let line = [`Adding ${chalk.cyan(entry.name)} task`];
9693
if (deps.length) {
97-
line.push(' - depending on ',chalk.magenta(deps.join(' ')));
94+
line.push(` - depending on ${chalk.magenta(deps.join(' '))}`);
9895
}
9996
log.apply(chalk, line);
10097
}
@@ -109,7 +106,6 @@ module.exports = function HelpTask (gulp) {
109106
gulp.task('help', function () {
110107
/* Prints an overview over all available Gulp tasks. */
111108

112-
let util = require('util');
113109
let pad = require('pad');
114110
let lines = [''];
115111
let padding = 5;
@@ -124,12 +120,14 @@ module.exports = function HelpTask (gulp) {
124120
let taskIds = Object.keys(taskInfo);
125121
let taskLengths = taskIds.map(function (id) { return id.length; });
126122
let maxLength = Math.max.apply(Math, taskLengths);
127-
128-
for (let key in taskInfo) {
123+
let keys = Object.keys(taskInfo);
124+
keys.sort();
125+
for (var i = 0; i < keys.length; i++) {
126+
let key = keys[i];
129127
let entry = taskInfo[key];
130128
let paddingLength = maxLength;
131-
let str = new Array(paddingLength+2).join(' ');
132-
let descriptionLine = util.format('Runs the %s task.', key);
129+
let str = new Array(paddingLength + 2).join(' ');
130+
let descriptionLine = `Runs the ${key} task.`;
133131
if (entry.description) descriptionLine = mapDescription(str, entry.description);
134132
lines.push(' ' + pad(entry.name, maxLength) + paddingStr + descriptionLine.join('\n').trim());
135133
lines.push('');
@@ -147,13 +145,12 @@ module.exports = function HelpTask (gulp) {
147145
* @private
148146
*/
149147

150-
function mapDescription(str, lines) {
148+
function mapDescription (str, lines) {
151149
if (typeof lines === 'string') lines = [lines];
152150
return lines.map(function (line, index) {
153151
line = line.trim();
154152
return index ? str + paddingStr + line : line;
155153
});
156154
}
157155
});
158-
159156
};

contrib/running-tasks.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22

33
module.exports = function RunningTasks (gulp) {
4-
54
const DEBUG = this.options.DEBUG;
65
let log = this.byId('log', true) || console.log.bind(console);
7-
let gutil = this.byId('gutil', true) || { env : { _ : process.argv }};
6+
let gutil = this.byId('gutil', true) || { env: { _: process.argv } };
87

98
/**
109
* Adds a function returning an array of strings, containing all current
@@ -15,8 +14,8 @@ module.exports = function RunningTasks (gulp) {
1514
* ````js
1615
* module.exports = function (gulp, log, Package, runningTasks) {
1716
* gulp.task('info', function () {
18-
* log('Building ' + chalk.magenta(Package.name) + ', running: ' + chalk.cyan(runningTasks().join(' ')));
19-
* });
17+
* log('Building ' + chalk.magenta(Package.name) + ', running: ' + chalk.cyan(runningTasks().join(' ')))
18+
* })
2019
* }
2120
* ````
2221
*
@@ -33,9 +32,7 @@ module.exports = function RunningTasks (gulp) {
3332
let taskNames = Object.keys(gulp.tasks);
3433
// Filter all available task names using gutil.env._
3534

36-
let cliTasks = taskNames.filter(function (name) {
37-
return !!~args.indexOf(name);
38-
});
35+
let cliTasks = taskNames.filter((name) => args.indexOf(name) > -1);
3936

4037
// Include the names of depending tasks
4138

@@ -47,5 +44,4 @@ module.exports = function RunningTasks (gulp) {
4744
}
4845
return tasks;
4946
});
50-
5147
};

contrib/standard-task.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const path = require('path');
1717
*/
1818

1919
function standardTask (name, src, dest) {
20-
2120
let args = _.toArray(arguments).slice(3); // dependencies
2221
let stack = null;
2322
let filename = '<unknown>';
@@ -69,7 +68,7 @@ function standardTask (name, src, dest) {
6968
}
7069
7170
return gulp.src("${src}")
72-
.pipe(plugin(${ args || 'void 0' }))
71+
.pipe(plugin(${args || 'void 0'}))
7372
.pipe(gulp.dest("${dest}"));
7473
});
7574
`;

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/di');
1+
module.exports = require('./lib/gulp-di');

lib/dependency-error.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
/**
4+
* @method DependencyError
5+
* @private
6+
* @param {string} id
7+
*/
8+
9+
function DependencyError (id) {
10+
return Error('Unknown dependency: ' + id);
11+
}
12+
13+
module.exports = DependencyError;

0 commit comments

Comments
 (0)