cmtt / gulp-di Goto Github PK
View Code? Open in Web Editor NEWgulp-di is a dependency injection framework for the Gulp streaming build system.
gulp-di is a dependency injection framework for the Gulp streaming build system.
As gulp-util is always a dependency of Gulp, it might be included in gulp-di's scope.
This would allow its users to access CLI parameters among other useful methods
contrib/help.js#L65-L70 it's always object
and why lib/di.js#L283-L284 is needed?
Please see this issue:
Gulp can be used in conjunction with ES2015 code in two ways:
- Writing ES2015+ code - the "gulpfile.js" would be written in ES2015+, as Node.js supports already a subset of the new standard.
- Writing ES2015+ code using the "Babel" transpiler - the "gulpfile.babel.js" and all imported modules would be transpiled back to ES5 code. In this case, parse-function would work as intended.
It would be also possible to make use of a JavaScript parser like esprima or acorn.
Ie the api example is:
GulpDI(object gulp, object options)
The code example is:
let di = GulpDI({
DEBUG: false, // when set to true, the plugin will log info to console. Useful for bug reporting and issue debugging
pattern: ['gulp-*', 'gulp.*'], // the glob(s) to search for
config: 'package.json', // where to find the plugins, by default searched up from process.cwd()
scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within
replaceString: /^gulp(-|\.)/, // what to remove from the name of the module when adding it to the context
rename: {}, // a mapping of plugins to rename
renameFn: function (name) { ... } // a function to handle the renaming of plugins (the default works)
}, require('gulp'));
Subsequently the error for putting them in the wrong order doesn't make it very obvious. :)
$ gulp
/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/contrib/help.js:104
return _task.apply(gulp, args);
^
TypeError: Cannot read property 'apply' of undefined
at Object.HelpTask.gulp.task (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/contrib/help.js:104:17)
at GulpDI.HelpTask (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/contrib/help.js:109:8)
at GulpDI.$injector (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/lib/di.js:56:20)
at GulpDI.inject (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/lib/di.js:192:30)
at GulpDI.parseOptions (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/lib/di.js:161:14)
at new GulpDI (/home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/lib/di.js:118:12)
at /home/adam/Programming/work/salespreso-gulp-v2/node_modules/gulp-di/lib/di.js:330:12
at module.exports (/home/adam/Programming/work/salespreso-gulp-v2/index.js:6:14)
at Object.<anonymous> (/home/adam/Programming/work/salespreso-gulp-v2/examples/jspm/gulpfile.js:4:1)
at Module._compile (module.js:413:34)
node -v
v6.5.0
{
"name": "gulpdi-test",
"version": "0.0.1",
"private": true,
"scripts": {
"gulp": "gulp"
},
"devDependencies": {
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"del": "^2.2.2",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-debug": "^2.1.2",
"gulp-di": "0.0.33",
"gulp-sass": "^2.3.2",
"make-targs": "github:pvlv/make-targs#v1.0.0",
"run-sequence": "^1.2.2"
}
}
// /tasks/styles.js
'use strict';
module.exports = (gulp, sass) => {
gulp.task('styles', () => {
return gulp.src('./fixtures/styles/*.scss')
.pipe(sass())
.pipe(gulp.dest('./results/css/'));
})
}
// /tasks/default.js
'use strict';
module.exports = function (gulp) {
gulp.task('default', gulp.parallel(
'styles'
));
}
// /gulpfile.js
const gulp = require('gulp');
const di = require('gulp-di')(gulp, {
pattern: ['gulp-*', 'gulp.*']
});
di
.tasks('./tasks')
.resolve();
module.exports = gulp;
Stack trace
assert.js:85
throw new assert.AssertionError({
^
AssertionError: Task never defined: styles
at getFunction (/data/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
at arrayMap (/data/node_modules/lodash.map/index.js:140:21)
at map (/data/node_modules/lodash.map/index.js:1836:10)
at normalizeArgs (/data/node_modules/undertaker/lib/helpers/normalizeArgs.js:19:10)
at Gulp.parallel (/data/node_modules/undertaker/lib/parallel.js:13:14)
at GulpDI.module.exports (/data/tasks/default.js:4:29)
at GulpDI.resolve (/data/node_modules/gulp-di/lib/di.js:261:34)
at Object.<anonymous> (/data/gulpfile.js:10:4)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
If install gulp 3.8.1
- gulp-di work correctly
When .byId() is used to access a module before .resolve() was called, the entire dependency injection notation will be returned. This should be avoided by throwing an error.
(In contrast, .byId can be called to access constants which were declared beforehand. This behavior allows to use .inject() calls, f.e. for configuration.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.