@fileOverview Uses Gulpjs to clone a pattern
@author Scott Nath
@requires ./lib/utility
@requires ./lib/clone-pattern
@requires ./lib/get-options
var utility = require('../utility');
var mergeOptions = require('../get-options').mergeOptions;
var minimist = require('minimist');
var log = require('../logger').logger;
Function to get default options for an implementation of a clone-pattern task
var getDefaultOptions = function () {
'use strict';
// default options for clone-pattern gulp task
var options = {
config: {}, // empty, but a placeholder for later
taskName: 'clone-pattern',
dependencies: [] // gulp tasks which should be run before this task
};
return options;
};
var checkForClassArguments = function (args) {
'use strict';
if (!args.pattern) {
log.warn('To clone, you must include a pattern flag. example: "--pattern /path/to/pattern/directory"');
return false;
}
if (typeof args.pattern !== 'string') {
log.warn('The path to the pattern-to-clone must be a string.');
return false;
}
if (args.overwrite && ((typeof args.overwrite !== 'string') || (args.overwrite !== 'YES'))) {
log.warn('You must type YES in all caps to overwrite your local pattern');
return false;
}
return args;
};
@param | Type | Description |
---|---|---|
gulp | Object | including file should inject the gulp module |
projectOptions | Object | object of options |
Gulp task that clones a pattern-library pattern
exports.gulpClonePattern = function (gulp, projectOptions) {
'use strict';
var patternDataFile;
projectOptions = mergeOptions(getDefaultOptions(), projectOptions);
var options = utility.getProjectOptions();
options = mergeOptions(options, projectOptions);
gulp.task(options.taskName, options.dependencies, function () {
var args = checkForClassArguments(minimist(process.argv.slice(2)));
if (!args) {
log.error('Exiting without cloning.');
return;
}
// single pattern cloning
if (args.pattern) {
patternDataFile = utility.testIfSinglePattern(args.pattern, options);
if (!patternDataFile) {
log.error('The pattern you want to clone does not exist. Exiting without cloning.');
return;
}
}
// overwrite option
if (args.overwrite) {
options.config = {
overwrite: true
};
}
return gulp.src(patternDataFile)
.pipe(utility.patternCloner(options));
});
};