2015-08-03 17:45:58 -07:00
|
|
|
|
var gulp = require('gulp');
|
2015-08-06 12:45:50 -07:00
|
|
|
|
var watch = require('gulp-watch');
|
2015-08-03 17:45:58 -07:00
|
|
|
|
var gutil = require('gulp-util');
|
2015-09-15 23:21:55 -07:00
|
|
|
|
var Dgeni = require('dgeni');
|
2015-08-06 12:45:50 -07:00
|
|
|
|
var path = require('path');
|
|
|
|
|
|
var del = require('del');
|
2016-10-03 14:58:50 -07:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
var docShredder = require('./public/doc-shredder/doc-shredder');
|
2016-04-25 22:42:22 -07:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
var shredOptions = {
|
|
|
|
|
|
basePath: path.resolve('./public/docs'),
|
|
|
|
|
|
sourceDir: "_examples",
|
|
|
|
|
|
destDir: "_fragments"
|
2015-08-03 17:45:58 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Within this repo generated files are checked in so that we can avoid running the
|
|
|
|
|
|
shredder over the entire _examples dir each time someone refreshes the repo
|
|
|
|
|
|
( the ‘shred-full’ gulp task). The gulp ‘serve-and-watch’ shredder is only
|
|
|
|
|
|
a ‘partial’ shredder. It only shred’s files in directories changed during
|
|
|
|
|
|
the current session.
|
|
|
|
|
|
*/
|
2015-11-13 08:38:32 +00:00
|
|
|
|
|
2015-08-03 17:45:58 -07:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
gulp.task('shred-full', ['shred-clean'], function() {
|
|
|
|
|
|
docShredder.shred( shredOptions);
|
2015-08-03 17:45:58 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
gulp.task('serve-and-watch', function (cb) {
|
|
|
|
|
|
var pattern = path.join(shredOptions.basePath, shredOptions.sourceDir, "**/*.*");
|
2015-11-06 21:40:30 +00:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
execCommands(['harp server'])
|
2015-11-30 17:24:16 -08:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
watch([ pattern], function(event, done) {
|
|
|
|
|
|
console.log('Event type: ' + event.event); // added, changed, or deleted
|
|
|
|
|
|
console.log('Event path: ' + event.path); // The path of the modified file
|
|
|
|
|
|
docShredder.shredSingleDir(shredOptions, event.path);
|
2015-08-08 13:55:53 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2016-07-15 14:10:12 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
gulp.task('shred-clean', function(cb) {
|
|
|
|
|
|
var cleanPath = path.join(shredOptions.basePath, shredOptions.destDir, '**/*.*')
|
|
|
|
|
|
del([ cleanPath, '!**/*.ovr.*'], function (err, paths) {
|
|
|
|
|
|
// console.log('Deleted files/folders:\n', paths.join('\n'));
|
|
|
|
|
|
cb();
|
2015-09-25 01:28:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-11-02 16:16:35 -07:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
// added options are: shouldLog
|
|
|
|
|
|
// cb is function(err, stdout, stderr);
|
2015-08-03 17:45:58 -07:00
|
|
|
|
function execCommands(cmds, options, cb) {
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
options.shouldThrow = options.shouldThrow == null ? true : options.shouldThrow;
|
|
|
|
|
|
options.shouldLog = options.shouldLog == null ? true : options.shouldLog;
|
|
|
|
|
|
if (!cmds || cmds.length == 0) cb(null, null, null);
|
|
|
|
|
|
var exec = require('child_process').exec; // just to make it more portable.
|
|
|
|
|
|
exec(cmds[0], options, function(err, stdout, stderr) {
|
|
|
|
|
|
if (err == null) {
|
|
|
|
|
|
if (options.shouldLog) {
|
|
|
|
|
|
gutil.log('cmd: ' + cmds[0]);
|
|
|
|
|
|
gutil.log('stdout: ' + stdout);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cmds.length == 1) {
|
|
|
|
|
|
cb(err, stdout, stderr);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
execCommands(cmds.slice(1), options, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (options.shouldLog) {
|
|
|
|
|
|
gutil.log('exec error on cmd: ' + cmds[0]);
|
|
|
|
|
|
gutil.log('exec error: ' + err);
|
|
|
|
|
|
if (stdout) gutil.log('stdout: ' + stdout);
|
|
|
|
|
|
if (stderr) gutil.log('stderr: ' + stderr);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (err && options.shouldThrow) throw err;
|
|
|
|
|
|
cb(err, stdout, stderr);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-15 14:10:12 -07:00
|
|
|
|
|
2016-08-10 10:36:23 -07:00
|
|
|
|
|
2015-08-06 12:45:50 -07:00
|
|
|
|
gulp.task('default', ['shred-full']);
|