Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 9b61d58

Browse files
committed
added browser-sync, modified shred-single-dir in doc-shredder to return a promise, updated readme.
1 parent ba7364e commit 9b61d58

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ Angular.io is currently the preview site for Angular 2. This site also includes
2828

2929
`npm install -g browser-sync --msvs_version=2013`
3030

31-
3. run `gulp serve-and-watch`
32-
4. run `browser-sync start --proxy localhost:9000 --files "public/docs/**/*/**/*" --reloadDelay 500`
33-
5. browser will launch and stay refreshed automatically.
31+
3. run `gulp serve-and-sync`
32+
4. browser will launch ( on localhost:3000 instead of localhost:9000) and stay refreshed automatically.
3433

3534
## Technology Used
3635
- Angular 1.x: The production ready version of Angular

gulpfile.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
var gulp = require('gulp');
22
var watch = require('gulp-watch');
33
var gutil = require('gulp-util');
4-
var Dgeni = require('dgeni');
54
var path = require('path');
65
var del = require('del');
76

87
var docShredder = require('./public/doc-shredder/doc-shredder');
98

10-
var shredOptions = {
9+
var _shredOptions = {
1110
basePath: path.resolve('./public/docs'),
1211
sourceDir: "_examples",
1312
destDir: "_fragments"
@@ -21,32 +20,49 @@ a ‘partial’ shredder. It only shred’s files in directories changed during
2120
the current session.
2221
*/
2322

23+
gulp.task('serve-and-sync', function (cb) {
24+
execCommands(['harp server'], {}, cb);
2425

25-
gulp.task('shred-full', ['shred-clean'], function() {
26-
docShredder.shred( shredOptions);
26+
var browserSync = require('browser-sync').create();
27+
browserSync.init({
28+
proxy: 'localhost:9000',
29+
files: "public/docs/**/*/**/*",
30+
logFileChanges: true,
31+
reloadDelay: 500
32+
});
33+
34+
shredWatch(_shredOptions, function() {
35+
browserSync.reload();
36+
});
2737
});
2838

2939
gulp.task('serve-and-watch', function (cb) {
30-
var pattern = path.join(shredOptions.basePath, shredOptions.sourceDir, "**/*.*");
31-
32-
execCommands(['harp server'])
33-
34-
watch([ pattern], function(event, done) {
35-
console.log('Event type: ' + event.event); // added, changed, or deleted
36-
console.log('Event path: ' + event.path); // The path of the modified file
37-
docShredder.shredSingleDir(shredOptions, event.path);
38-
});
40+
execCommands(['harp server'], {}, cb);
41+
shredWatch(_shredOptions);
42+
});
3943

44+
gulp.task('shred-full', ['shred-clean'], function() {
45+
docShredder.shred( _shredOptions);
4046
});
4147

4248
gulp.task('shred-clean', function(cb) {
43-
var cleanPath = path.join(shredOptions.basePath, shredOptions.destDir, '**/*.*')
49+
var cleanPath = path.join(_shredOptions.basePath, _shredOptions.destDir, '**/*.*')
4450
del([ cleanPath, '!**/*.ovr.*'], function (err, paths) {
4551
// console.log('Deleted files/folders:\n', paths.join('\n'));
4652
cb();
4753
});
4854
});
4955

56+
function shredWatch(shredOptions, postShredAction) {
57+
var pattern = path.join(shredOptions.basePath, shredOptions.sourceDir, "**/*.*");
58+
watch([pattern], function (event, done) {
59+
console.log('Event type: ' + event.event); // added, changed, or deleted
60+
console.log('Event path: ' + event.path); // The path of the modified file
61+
docShredder.shredSingleDir(shredOptions, event.path).then(function () {
62+
postShredAction && postShredAction();
63+
});
64+
});
65+
}
5066

5167
// added options are: shouldLog
5268
// cb is function(err, stdout, stderr);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"gulp-util": "^3.0.6",
2929
"gulp-watch": "^4.3.4",
3030
"lodash": "^3.10.1",
31-
"path": "^0.11.14"
31+
"path": "^0.11.14",
32+
"q": "^1.4.1"
3233
},
3334
"contributors": [
3435
"Jay Traband <[email protected]>"

public/doc-shredder/doc-shredder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
21
// Canonical path provides a consistent path (i.e. always forward slashes) across different OSes
32
var path = require('canonical-path');
4-
// var path = require('path');
3+
var Q = require('q');
54
var del = require('del');
5+
// delPromise is a 'promise' version of del
6+
var delPromise = Q.denodeify(del);
67
var Dgeni = require('dgeni');
78
var _ = require('lodash');
89

@@ -51,11 +52,10 @@ var shredSingleDir = function(shredOptions, filePath) {
5152
destDir: destDir
5253
}
5354
var cleanPath = path.join(shredOptions.basePath, destDir, '*.*')
54-
del([ cleanPath, '!**/*.ovr.*'], function (err, paths) {
55+
return delPromise([ cleanPath, '!**/*.ovr.*']).then(function(paths) {
5556
// console.log('Deleted files/folders:\n', paths.join('\n'));
5657
return shred(options);
5758
});
58-
5959
}
6060

6161
module.exports = {

0 commit comments

Comments
 (0)