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

Commit 6f6e837

Browse files
jtrabandnaomiblack
authored andcommitted
squashed commits for PR 222 from jtraband
- add warning when bad example tag is encountered. - shredding for api docs + refactoring of gulpfile to clarify task names. - added top level gulp tasks + error handling cleanup - added test-api-builder gulp task - added warning messages during build-shred-map processing - mixin signature change - updated styleguide ... continued. - added @exampleTabs inlinetag support + refactoring shared services between @example and @exampleTabs - added new inline tag @linkDevGuide + cleanup - added angular source watch logic for serve-and-sync and source for examples changed from test -> examples + cleanup - promisify del - styleguide explanation of @example, @exampleTabs and @linkDevGuide
1 parent 49496e4 commit 6f6e837

File tree

22 files changed

+575
-465
lines changed

22 files changed

+575
-465
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ www
77
.DS_Store
88
.idea
99
**/js/latest/api
10+
public/docs/xref-*.*
11+
1012

gulpfile.js

Lines changed: 117 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var _ = require('lodash');
88
var Git = require("nodegit");
99
var argv = require('yargs').argv;
1010
var Q = require("q");
11+
// delPromise is a 'promise' version of del
12+
var delPromise = Q.denodeify(del);
1113
var Minimatch = require("minimatch").Minimatch;
1214
var Dgeni = require('dgeni');
1315
var fsExtra = require('fs-extra');
@@ -16,15 +18,16 @@ var fs = fsExtra;
1618

1719
var docShredder = require('./public/doc-shredder/doc-shredder');
1820

19-
var _shredOptions = {
21+
var _devguideShredOptions = {
2022
examplesDir: './public/docs/_examples',
2123
fragmentsDir: './public/docs/_fragments'
2224
};
2325

24-
//var _apiShredOptions = {
25-
// basePath: path.resolve('../angular/modules/angular2'),
26-
// examplesDir: "test"
27-
//}
26+
var _apiShredOptions = {
27+
examplesDir: '../angular/modules/angular2/examples',
28+
fragmentsDir: './public/docs/_fragments/_api'
29+
};
30+
2831

2932
var _excludePatterns = ["**/node_modules/**", "**/typings/**"];
3033

@@ -35,52 +38,87 @@ var _excludeMatchers = _excludePatterns.map(function(excludePattern){
3538
/*
3639
Within this repo generated files are checked in so that we can avoid running the
3740
shredder over the entire _examples dir each time someone refreshes the repo
38-
( the ‘shred-full’ gulp task). The gulp ‘serve-and-watch’ shredder is only
41+
( the ‘shred-devguide-examples’ gulp task). The gulp ‘serve-and-watch’ shredder is only
3942
a ‘partial’ shredder. It only shred’s files in directories changed during
4043
the current session.
4144
*/
4245

43-
gulp.task('help', taskListing);
46+
gulp.task('help', taskListing.withFilters(function(taskName) {
47+
var isSubTask = taskName.substr(0,1) == "_";
48+
return isSubTask;
49+
}, function(taskName) {
50+
var shouldRemove = taskName === 'default';
51+
return shouldRemove;
52+
}));
53+
54+
gulp.task('serve-and-sync', ['build-docs'], function (cb) {
4455

45-
gulp.task('serve-and-sync', function (cb) {
4656
// execCommands(['harp server'], {}, cb);
4757
execCommands(['npm run harp'], {}, cb);
4858

4959
var browserSync = require('browser-sync').create();
5060
browserSync.init({
5161
proxy: 'localhost:9000',
52-
files: "public/docs/**/*/**/*",
62+
files: ["public/docs/**/*/**/*" ],
5363
logFileChanges: true,
5464
reloadDelay: 500
5565
});
5666

57-
shredWatch(_shredOptions, function() {
67+
devGuideExamplesWatch(_devguideShredOptions, function() {
68+
browserSync.reload();
69+
});
70+
71+
apiSourceWatch(function() {
5872
browserSync.reload();
5973
});
74+
6075
});
6176

6277
gulp.task('serve-and-watch', function (cb) {
6378
execCommands(['harp server'], {}, cb);
64-
shredWatch(_shredOptions);
79+
devGuideExamplesWatch(_devguideShredOptions);
6580
});
6681

67-
gulp.task('shred-full', ['shred-clean'], function() {
68-
return docShredder.shred( _shredOptions);
82+
gulp.task('build-docs', ['_shred-devguide-examples', 'build-api-docs'], function() {
83+
return buildShredMaps(true);
6984
});
7085

71-
gulp.task('shred-clean', function(cb) {
72-
var cleanPath = path.join(_shredOptions.fragmentsDir, '**/*.*')
73-
del([ cleanPath, '!**/*.ovr.*'], function (err, paths) {
74-
// console.log('Deleted files/folders:\n', paths.join('\n'));
75-
cb();
76-
});
86+
gulp.task('build-devguide-docs', ['_shred-devguide-examples'], function() {
87+
return buildShredMaps(true);
7788
});
7889

79-
gulp.task('build-shred-maps', ['shred-full'], function() {
80-
return buildShredMaps(true);
90+
gulp.task('build-api-docs', ['_shred-api-examples'], function() {
91+
if (!fs.existsSync('../angular')) {
92+
throw new Error('build-api-docs task requires the angular2 repo to be at ' + path.resolve('../angular'));
93+
}
94+
return buildApiDocs();
95+
});
96+
97+
98+
gulp.task('_shred-devguide-examples', ['_shred-clean-devguide'], function() {
99+
return docShredder.shred( _devguideShredOptions);
100+
});
101+
102+
gulp.task('_shred-clean-devguide', function(cb) {
103+
var cleanPath = path.join(_devguideShredOptions.fragmentsDir, '**/*.*')
104+
return delPromise([ cleanPath, '!**/*.ovr.*', '!**/_api/**']);
81105
});
82106

83-
gulp.task('git-changed-examples', ['shred-full'], function(){
107+
gulp.task('_shred-api-examples', ['_shred-clean-api'], function() {
108+
return docShredder.shred( _apiShredOptions);
109+
});
110+
111+
gulp.task('_shred-clean-api', function(cb) {
112+
var cleanPath = path.join(_apiShredOptions.fragmentsDir, '**/*.*')
113+
return delPromise([ cleanPath, '!**/*.ovr.*' ]);
114+
});
115+
116+
gulp.task('_build-shred-maps', function() {
117+
return build-shred-maps(true);
118+
});
119+
120+
121+
gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
84122
var after, sha, messageSuffix;
85123
if (argv.after) {
86124
try {
@@ -116,7 +154,7 @@ gulp.task('git-changed-examples', ['shred-full'], function(){
116154
examplePaths = filterOutExcludedPatterns(examplePaths, _excludeMatchers);
117155
console.log('\nExamples changed ' + messageSuffix);
118156
console.log(examplePaths)
119-
console.log("\nJade files and associated changed example files " + messageSuffix);
157+
console.log("\nJade files affected by changed example files " + messageSuffix);
120158
var jadeExampleMap = jadeShredMapToJadeExampleMap(jadeShredMap, examplePaths);
121159
console.log(JSON.stringify(jadeExampleMap, null, " "));
122160
console.log("-----");
@@ -126,10 +164,44 @@ gulp.task('git-changed-examples', ['shred-full'], function(){
126164
});
127165
});
128166

129-
gulp.task('build-api-docs', function() {
130-
if (!fs.existsSync('../angular')) {
131-
throw new Error('build-api-docs task requires the angular2 repo to be at ' + path.resolve('../angular'));
132-
}
167+
168+
169+
gulp.task('test-api-builder', function (cb) {
170+
execCommands(['npm run test-api-builder'], {}, cb);
171+
});
172+
173+
function filterOutExcludedPatterns(fileNames, excludeMatchers) {
174+
return fileNames.filter(function(fileName) {
175+
return !excludeMatchers.some(function(excludeMatcher) {
176+
return excludeMatcher.match(fileName);
177+
});
178+
});
179+
}
180+
181+
function apiSourceWatch(postShredAction) {
182+
var srcPattern = ['../angular/modules/angular2/src/**/*.*'];
183+
watch(srcPattern, function (event, done) {
184+
console.log('Event type: ' + event.event); // added, changed, or deleted
185+
console.log('Event path: ' + event.path); // The path of the modified file
186+
// need to run just build
187+
buildApiDocs().then(done);
188+
});
189+
var examplesPattern = ['../angular/modules/angular2/examples/**/*.*'];
190+
watch(examplesPattern, function (event, done) {
191+
console.log('Event type: ' + event.event); // added, changed, or deleted
192+
console.log('Event path: ' + event.path); // The path of the modified file
193+
// need to run shredder
194+
var cleanPath = path.join(_apiShredOptions.fragmentsDir, '**/*.*');
195+
return delPromise([ cleanPath, '!**/*.ovr.*' ]).then(function() {
196+
return docShredder.shred(_apiShredOptions);
197+
}).then(function() {
198+
postShredAction && postShredAction();
199+
});
200+
});
201+
202+
}
203+
204+
function buildApiDocs() {
133205
try {
134206
var dgeni = new Dgeni([require('./public/api-builder/angular.io-package')]);
135207
return dgeni.generate();
@@ -138,30 +210,37 @@ gulp.task('build-api-docs', function() {
138210
console.log(err.stack);
139211
throw err;
140212
}
141-
});
213+
}
142214

143-
function filterOutExcludedPatterns(fileNames, excludeMatchers) {
144-
return fileNames.filter(function(fileName) {
145-
return !excludeMatchers.some(function(excludeMatcher) {
146-
return excludeMatcher.match(fileName);
215+
function devGuideExamplesWatch(shredOptions, postShredAction) {
216+
var pattern = path.join(shredOptions.examplesDir, "**/*.*");
217+
watch([pattern], function (event, done) {
218+
console.log('Event type: ' + event.event); // added, changed, or deleted
219+
console.log('Event path: ' + event.path); // The path of the modified file
220+
docShredder.shredSingleDir(shredOptions, event.path).then(function () {
221+
postShredAction && postShredAction();
147222
});
148223
});
149224
}
150225

226+
151227
function buildShredMaps(shouldWrite) {
152-
var options = _.extend(_shredOptions, {
228+
var options = {
229+
devguideExamplesDir: _devguideShredOptions.examplesDir,
230+
apiExamplesDir: _apiShredOptions.examplesDir,
231+
fragmentsDir: _devguideShredOptions.fragmentsDir,
153232
jadeDir: './public/docs',
154233
outputDir: './public/docs',
155234
writeFilesEnabled: shouldWrite
156-
});
235+
};
157236
return docShredder.buildShredMap(options).then(function(docs) {
158237
return docs;
159238
});
160239
}
161240

162241
// returns a promise containing filePaths with any changed or added examples;
163242
function getChangedExamples(sha) {
164-
var examplesPath = _shredOptions.examplesDir;
243+
var examplesPath = _devguideShredOptions.examplesDir;
165244
var relativePath = path.relative(process.cwd(), examplesPath);
166245
return Git.Repository.open(".").then(function(repo) {
167246
if (sha.length) {
@@ -177,7 +256,7 @@ function getChangedExamples(sha) {
177256
}
178257

179258
function getChangedExamplesAfter(date, relativePath) {
180-
var examplesPath = _shredOptions.examplesDir;
259+
var examplesPath = _devguideShredOptions.examplesDir;
181260
var relativePath = path.relative(process.cwd(), examplesPath);
182261
return Git.Repository.open(".").then(function(repo) {
183262
return repo.getHeadCommit();
@@ -227,16 +306,7 @@ function getChangedExamplesForCommit(commit, relativePath) {
227306
});
228307
}
229308

230-
function shredWatch(shredOptions, postShredAction) {
231-
var pattern = path.join(shredOptions.examplesDir, "**/*.*");
232-
watch([pattern], function (event, done) {
233-
console.log('Event type: ' + event.event); // added, changed, or deleted
234-
console.log('Event path: ' + event.path); // The path of the modified file
235-
docShredder.shredSingleDir(shredOptions, event.path).then(function () {
236-
postShredAction && postShredAction();
237-
});
238-
});
239-
}
309+
240310

241311
function jadeShredMapToJadeExampleMap(jadeShredMap, examplePaths) {
242312
// remove dups in examplePaths
@@ -321,4 +391,4 @@ function execCommands(cmds, options, cb) {
321391

322392

323393

324-
gulp.task('default', taskListing);
394+
gulp.task('default', ['help']);

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "index.js",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
9-
"harp": "harp server ."
9+
"harp": "harp server .",
10+
"test-api-builder": "jasmine-node public/api-builder"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -22,7 +23,7 @@
2223
"url": ""
2324
},
2425
"devDependencies": {
25-
"browser-sync": "^2.8.2",
26+
"browser-sync": "^2.9.3",
2627
"canonical-path": "0.0.2",
2728
"del": "^1.2.0",
2829
"dgeni": "^0.4.0",
@@ -33,11 +34,13 @@
3334
"gulp-task-listing": "^1.0.1",
3435
"gulp-util": "^3.0.6",
3536
"gulp-watch": "^4.3.4",
37+
"harp": "^0.18.0",
3638
"html2jade": "^0.8.4",
3739
"indent-string": "^2.1.0",
38-
"harp": "^0.18.0",
3940
"jasmine-core": "^2.3.4",
40-
"karma": "^0.13.8",
41+
"jasmine-node": "^1.14.5",
42+
"jsonfile": "^2.2.2",
43+
"karma": "^0.13.9",
4144
"karma-chrome-launcher": "^0.2.0",
4245
"karma-jasmine": "^0.3.6",
4346
"lodash": "^3.10.1",

0 commit comments

Comments
 (0)