From 9b61d586bf53734c281ad736627b8ddf728841b4 Mon Sep 17 00:00:00 2001 From: Jay Traband Date: Sat, 8 Aug 2015 13:55:53 -0700 Subject: [PATCH] added browser-sync, modified shred-single-dir in doc-shredder to return a promise, updated readme. --- README.md | 5 ++-- gulpfile.js | 44 ++++++++++++++++++++--------- package.json | 3 +- public/doc-shredder/doc-shredder.js | 8 +++--- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4b82430bcf..83b6c9e370 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,8 @@ Angular.io is currently the preview site for Angular 2. This site also includes `npm install -g browser-sync --msvs_version=2013` - 3. run `gulp serve-and-watch` - 4. run `browser-sync start --proxy localhost:9000 --files "public/docs/**/*/**/*" --reloadDelay 500` - 5. browser will launch and stay refreshed automatically. + 3. run `gulp serve-and-sync` + 4. browser will launch ( on localhost:3000 instead of localhost:9000) and stay refreshed automatically. ## Technology Used - Angular 1.x: The production ready version of Angular diff --git a/gulpfile.js b/gulpfile.js index 0251ed5a73..01435336a0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,12 @@ var gulp = require('gulp'); var watch = require('gulp-watch'); var gutil = require('gulp-util'); -var Dgeni = require('dgeni'); var path = require('path'); var del = require('del'); var docShredder = require('./public/doc-shredder/doc-shredder'); -var shredOptions = { +var _shredOptions = { basePath: path.resolve('./public/docs'), sourceDir: "_examples", destDir: "_fragments" @@ -21,32 +20,49 @@ a ‘partial’ shredder. It only shred’s files in directories changed during the current session. */ +gulp.task('serve-and-sync', function (cb) { + execCommands(['harp server'], {}, cb); -gulp.task('shred-full', ['shred-clean'], function() { - docShredder.shred( shredOptions); + var browserSync = require('browser-sync').create(); + browserSync.init({ + proxy: 'localhost:9000', + files: "public/docs/**/*/**/*", + logFileChanges: true, + reloadDelay: 500 + }); + + shredWatch(_shredOptions, function() { + browserSync.reload(); + }); }); gulp.task('serve-and-watch', function (cb) { - var pattern = path.join(shredOptions.basePath, shredOptions.sourceDir, "**/*.*"); - - execCommands(['harp server']) - - 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); - }); + execCommands(['harp server'], {}, cb); + shredWatch(_shredOptions); +}); +gulp.task('shred-full', ['shred-clean'], function() { + docShredder.shred( _shredOptions); }); gulp.task('shred-clean', function(cb) { - var cleanPath = path.join(shredOptions.basePath, shredOptions.destDir, '**/*.*') + var cleanPath = path.join(_shredOptions.basePath, _shredOptions.destDir, '**/*.*') del([ cleanPath, '!**/*.ovr.*'], function (err, paths) { // console.log('Deleted files/folders:\n', paths.join('\n')); cb(); }); }); +function shredWatch(shredOptions, postShredAction) { + var pattern = path.join(shredOptions.basePath, shredOptions.sourceDir, "**/*.*"); + 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).then(function () { + postShredAction && postShredAction(); + }); + }); +} // added options are: shouldLog // cb is function(err, stdout, stderr); diff --git a/package.json b/package.json index 84ab91fab5..3fa599d421 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "gulp-util": "^3.0.6", "gulp-watch": "^4.3.4", "lodash": "^3.10.1", - "path": "^0.11.14" + "path": "^0.11.14", + "q": "^1.4.1" }, "contributors": [ "Jay Traband " diff --git a/public/doc-shredder/doc-shredder.js b/public/doc-shredder/doc-shredder.js index d1c20635ba..77a590270d 100644 --- a/public/doc-shredder/doc-shredder.js +++ b/public/doc-shredder/doc-shredder.js @@ -1,8 +1,9 @@ - // Canonical path provides a consistent path (i.e. always forward slashes) across different OSes var path = require('canonical-path'); -// var path = require('path'); +var Q = require('q'); var del = require('del'); +// delPromise is a 'promise' version of del +var delPromise = Q.denodeify(del); var Dgeni = require('dgeni'); var _ = require('lodash'); @@ -51,11 +52,10 @@ var shredSingleDir = function(shredOptions, filePath) { destDir: destDir } var cleanPath = path.join(shredOptions.basePath, destDir, '*.*') - del([ cleanPath, '!**/*.ovr.*'], function (err, paths) { + return delPromise([ cleanPath, '!**/*.ovr.*']).then(function(paths) { // console.log('Deleted files/folders:\n', paths.join('\n')); return shred(options); }); - } module.exports = {