@@ -8,6 +8,8 @@ var _ = require('lodash');
8
8
var Git = require ( "nodegit" ) ;
9
9
var argv = require ( 'yargs' ) . argv ;
10
10
var Q = require ( "q" ) ;
11
+ // delPromise is a 'promise' version of del
12
+ var delPromise = Q . denodeify ( del ) ;
11
13
var Minimatch = require ( "minimatch" ) . Minimatch ;
12
14
var Dgeni = require ( 'dgeni' ) ;
13
15
var fsExtra = require ( 'fs-extra' ) ;
@@ -16,15 +18,16 @@ var fs = fsExtra;
16
18
17
19
var docShredder = require ( './public/doc-shredder/doc-shredder' ) ;
18
20
19
- var _shredOptions = {
21
+ var _devguideShredOptions = {
20
22
examplesDir : './public/docs/_examples' ,
21
23
fragmentsDir : './public/docs/_fragments'
22
24
} ;
23
25
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
+
28
31
29
32
var _excludePatterns = [ "**/node_modules/**" , "**/typings/**" ] ;
30
33
@@ -35,52 +38,87 @@ var _excludeMatchers = _excludePatterns.map(function(excludePattern){
35
38
/*
36
39
Within this repo generated files are checked in so that we can avoid running the
37
40
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
39
42
a ‘partial’ shredder. It only shred’s files in directories changed during
40
43
the current session.
41
44
*/
42
45
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 ) {
44
55
45
- gulp . task ( 'serve-and-sync' , function ( cb ) {
46
56
// execCommands(['harp server'], {}, cb);
47
57
execCommands ( [ 'npm run harp' ] , { } , cb ) ;
48
58
49
59
var browserSync = require ( 'browser-sync' ) . create ( ) ;
50
60
browserSync . init ( {
51
61
proxy : 'localhost:9000' ,
52
- files : "public/docs/**/*/**/*" ,
62
+ files : [ "public/docs/**/*/**/*" ] ,
53
63
logFileChanges : true ,
54
64
reloadDelay : 500
55
65
} ) ;
56
66
57
- shredWatch ( _shredOptions , function ( ) {
67
+ devGuideExamplesWatch ( _devguideShredOptions , function ( ) {
68
+ browserSync . reload ( ) ;
69
+ } ) ;
70
+
71
+ apiSourceWatch ( function ( ) {
58
72
browserSync . reload ( ) ;
59
73
} ) ;
74
+
60
75
} ) ;
61
76
62
77
gulp . task ( 'serve-and-watch' , function ( cb ) {
63
78
execCommands ( [ 'harp server' ] , { } , cb ) ;
64
- shredWatch ( _shredOptions ) ;
79
+ devGuideExamplesWatch ( _devguideShredOptions ) ;
65
80
} ) ;
66
81
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 ) ;
69
84
} ) ;
70
85
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 ) ;
77
88
} ) ;
78
89
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/**' ] ) ;
81
105
} ) ;
82
106
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 ( ) {
84
122
var after , sha , messageSuffix ;
85
123
if ( argv . after ) {
86
124
try {
@@ -116,7 +154,7 @@ gulp.task('git-changed-examples', ['shred-full'], function(){
116
154
examplePaths = filterOutExcludedPatterns ( examplePaths , _excludeMatchers ) ;
117
155
console . log ( '\nExamples changed ' + messageSuffix ) ;
118
156
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 ) ;
120
158
var jadeExampleMap = jadeShredMapToJadeExampleMap ( jadeShredMap , examplePaths ) ;
121
159
console . log ( JSON . stringify ( jadeExampleMap , null , " " ) ) ;
122
160
console . log ( "-----" ) ;
@@ -126,10 +164,44 @@ gulp.task('git-changed-examples', ['shred-full'], function(){
126
164
} ) ;
127
165
} ) ;
128
166
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 ( ) {
133
205
try {
134
206
var dgeni = new Dgeni ( [ require ( './public/api-builder/angular.io-package' ) ] ) ;
135
207
return dgeni . generate ( ) ;
@@ -138,30 +210,37 @@ gulp.task('build-api-docs', function() {
138
210
console . log ( err . stack ) ;
139
211
throw err ;
140
212
}
141
- } ) ;
213
+ }
142
214
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 ( ) ;
147
222
} ) ;
148
223
} ) ;
149
224
}
150
225
226
+
151
227
function buildShredMaps ( shouldWrite ) {
152
- var options = _ . extend ( _shredOptions , {
228
+ var options = {
229
+ devguideExamplesDir : _devguideShredOptions . examplesDir ,
230
+ apiExamplesDir : _apiShredOptions . examplesDir ,
231
+ fragmentsDir : _devguideShredOptions . fragmentsDir ,
153
232
jadeDir : './public/docs' ,
154
233
outputDir : './public/docs' ,
155
234
writeFilesEnabled : shouldWrite
156
- } ) ;
235
+ } ;
157
236
return docShredder . buildShredMap ( options ) . then ( function ( docs ) {
158
237
return docs ;
159
238
} ) ;
160
239
}
161
240
162
241
// returns a promise containing filePaths with any changed or added examples;
163
242
function getChangedExamples ( sha ) {
164
- var examplesPath = _shredOptions . examplesDir ;
243
+ var examplesPath = _devguideShredOptions . examplesDir ;
165
244
var relativePath = path . relative ( process . cwd ( ) , examplesPath ) ;
166
245
return Git . Repository . open ( "." ) . then ( function ( repo ) {
167
246
if ( sha . length ) {
@@ -177,7 +256,7 @@ function getChangedExamples(sha) {
177
256
}
178
257
179
258
function getChangedExamplesAfter ( date , relativePath ) {
180
- var examplesPath = _shredOptions . examplesDir ;
259
+ var examplesPath = _devguideShredOptions . examplesDir ;
181
260
var relativePath = path . relative ( process . cwd ( ) , examplesPath ) ;
182
261
return Git . Repository . open ( "." ) . then ( function ( repo ) {
183
262
return repo . getHeadCommit ( ) ;
@@ -227,16 +306,7 @@ function getChangedExamplesForCommit(commit, relativePath) {
227
306
} ) ;
228
307
}
229
308
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
+
240
310
241
311
function jadeShredMapToJadeExampleMap ( jadeShredMap , examplePaths ) {
242
312
// remove dups in examplePaths
@@ -321,4 +391,4 @@ function execCommands(cmds, options, cb) {
321
391
322
392
323
393
324
- gulp . task ( 'default' , taskListing ) ;
394
+ gulp . task ( 'default' , [ 'help' ] ) ;
0 commit comments