@fileoverview Uses Gulpjs and gulp-inject to glob files
@author Scott Nath
@requires NPM:gulp-inject
@requires ./lib/get-options
var inject = require('gulp-inject');
var mergeOptions = require('../get-options').mergeOptions;
@param | Type | Description |
---|---|---|
gulp | Object | including file should inject the gulp module |
options | Object | object of options |
Gulp stream functionality which performs globbing/injecting pipeline
function globInjectTask(gulp, options) {
'use strict';
var sources = gulp.src(options.files);
return gulp.src(options.src)
.pipe(inject(sources, options.config))
.pipe(gulp.dest(options.dest));
}
Function to get default options for an implementation of gulp-inject
var getDefaultOptions = function () {
'use strict';
var options = {
config: {
relative: true
},
src: './index.html', // source file with types of files to be glob-injected
files: [// relative paths to files to be globbed
'!./node_modules
/',
'!./_gulp/',
'./*
'
],
dest: './', // destination directory where we'll write our ammended source file
taskName: 'file-glob-inject', // default task name
dependencies: [] // gulp tasks which should be run before this task
};
return options;
};
@param | Type | Description |
---|---|---|
gulp | Object | including file should in inject the gulp module |
projectOptions | Object | object of options |
General gulp task to glob files
exports.gulpFileGlobInject = function (gulp, projectOptions) {
'use strict';
var options = mergeOptions(getDefaultOptions(), projectOptions);
gulp.task(options.taskName, options.dependencies, function () {
return globInjectTask(gulp, options);
});
};
Function to get default options for globbing scss files with gulp-inject
var getDefaultScssOptions = function () {
'use strict';
var options = {
config: {
starttag: '// inject:{{ext}}',
endtag: '// endinject',
addRootSlash: false,
relative: true,
transform: function (filepath) {
return '@import \'' + filepath + '\';';
}
},
src: './styles/style.scss',
files: [// Application scss files
'!./node_modules
/',
'!./styles/style.scss',
'./
.scss'
],
dest: './styles',
taskName: 'scss-glob-inject', // default task name
dependencies: []
};
return options;
};
@param | Type | Description |
---|---|---|
gulp | Object | including file should in inject the gulp module |
projectOptions | Object | object of options |
Gulp task to glob scss files and write css imports
exports.gulpScssGlobInject = function (gulp, projectOptions) {
'use strict';
var options = mergeOptions(getDefaultScssOptions(), projectOptions);
gulp.task(options.taskName, options.dependencies, function () {
return globInjectTask(gulp, options);
});
};