@@ -45,7 +45,8 @@ var STYLES_SOURCE_PATH = path.join(TOOLS_PATH, 'styles-builder/less');
45
45
46
46
var docShredder = require ( path . resolve ( TOOLS_PATH , 'doc-shredder/doc-shredder' ) ) ;
47
47
var exampleZipper = require ( path . resolve ( TOOLS_PATH , '_example-zipper/exampleZipper' ) ) ;
48
- var plunkerBuilder = require ( path . resolve ( TOOLS_PATH , 'plunker-builder/plunkerBuilder' ) ) ;
48
+ var regularPlunker = require ( path . resolve ( TOOLS_PATH , 'plunker-builder/regularPlunker' ) ) ;
49
+ var embeddedPlunker = require ( path . resolve ( TOOLS_PATH , 'plunker-builder/embeddedPlunker' ) ) ;
49
50
var fsUtils = require ( path . resolve ( TOOLS_PATH , 'fs-utils/fsUtils' ) ) ;
50
51
51
52
const isSilent = ! ! argv . silent ;
@@ -72,9 +73,10 @@ var _apiShredOptions = {
72
73
logLevel : _dgeniLogLevel
73
74
} ;
74
75
76
+ const relDartDocApiDir = path . join ( 'doc' , 'api' ) ;
75
77
var _apiShredOptionsForDart = {
76
78
lang : 'dart' ,
77
- examplesDir : path . resolve ( ngPathFor ( 'dart' ) , 'examples ' ) ,
79
+ examplesDir : path . resolve ( ngPathFor ( 'dart' ) , 'example ' ) ,
78
80
fragmentsDir : path . join ( DOCS_PATH , '_fragments/_api' ) ,
79
81
zipDir : path . join ( RESOURCES_PATH , 'zips/api' ) ,
80
82
logLevel : _dgeniLogLevel
@@ -118,22 +120,35 @@ var _styleLessName = 'a2docs.less';
118
120
// or a regex pattern to match any one of 'ts', 'js', or 'dart'.
119
121
// Default: 'ts|js' except for the "full site build" tasks (see below),
120
122
// for which it is 'all'.
121
- //
122
- var lang , langs , buildDartApiDocs = false ;
123
+
124
+ // langs and skipLangs partition ['ts', 'js', 'dart'].
125
+ var lang , langs , skipLangs , buildDartApiDocs = false ;
123
126
function configLangs ( langOption ) {
124
- const fullSiteBuildTasks = [ 'build-compile' , 'check-serve ' , 'check-deploy ' ] ;
127
+ const fullSiteBuildTasks = [ 'build-compile' , 'check-deploy ' , 'harp-compile ' ] ;
125
128
const buildAllDocs = argv [ '_' ] &&
126
129
fullSiteBuildTasks . some ( ( task ) => argv [ '_' ] . indexOf ( task ) >= 0 ) ;
127
130
const langDefault = buildAllDocs ? 'all' : 'ts|js' ;
128
- lang = ( langOption || langDefault ) . toLowerCase ( ) ;
129
- if ( lang === 'all' ) lang = 'ts|js|dart' ;
130
- langs = lang . match ( / \w + / g) ; // the languages in `lang` as an array
131
- gutil . log ( 'Building docs for: ' + lang ) ;
131
+ if ( langOption === '' ) {
132
+ lang = '' ;
133
+ langs = [ ] ;
134
+ } else {
135
+ lang = ( langOption || langDefault ) . toLowerCase ( ) ;
136
+ if ( lang === 'all' ) lang = 'ts|js|dart' ;
137
+ langs = lang . match ( / \w + / g) ; // the languages in `lang` as an array
138
+ }
139
+ gutil . log ( `Building docs for: [${ langs } ]` ) ;
132
140
if ( langs . indexOf ( 'dart' ) >= 0 ) {
133
141
buildDartApiDocs = true ;
134
142
// For Dart, be proactive about checking for the repo
135
143
checkAngularProjectPath ( ngPathFor ( 'dart' ) ) ;
144
+ } else {
145
+ argv . pub = false ;
136
146
}
147
+ skipLangs = [ ] ;
148
+ [ 'ts' , 'js' , 'dart' ] . forEach ( lang => {
149
+ if ( langs . indexOf ( lang ) < 0 ) skipLangs . push ( lang ) ;
150
+ } ) ;
151
+ gutil . log ( `Skipped languages: [${ skipLangs } ]` ) ;
137
152
}
138
153
configLangs ( argv . lang ) ;
139
154
@@ -344,10 +359,15 @@ function runE2eDartTests(appDir, outputFile) {
344
359
gutil . log ( 'http-server failed to launch over ' + deployDir ) ;
345
360
return false ;
346
361
}
347
- var pubUpgradeSpawnInfo = spawnExt ( 'pub' , [ 'upgrade' ] , { cwd : appDir } ) ;
348
- var prepPromise = pubUpgradeSpawnInfo . promise . then ( function ( data ) {
349
- return spawnExt ( 'pub' , [ 'build' ] , { cwd : appDir } ) . promise ;
350
- } ) ;
362
+ if ( argv . pub === false ) {
363
+ var prepPromise = Promise . resolve ( true ) ;
364
+ gutil . log ( 'Skipping pub upgrade and pub build (--no-pub flag present)' ) ;
365
+ } else {
366
+ var pubUpgradeSpawnInfo = spawnExt ( 'pub' , [ 'upgrade' ] , { cwd : appDir } ) ;
367
+ var prepPromise = pubUpgradeSpawnInfo . promise . then ( function ( data ) {
368
+ return spawnExt ( 'pub' , [ 'build' ] , { cwd : appDir } ) . promise ;
369
+ } ) ;
370
+ }
351
371
return runProtractor ( prepPromise , appDir , appRunSpawnInfo , outputFile ) ;
352
372
}
353
373
@@ -511,13 +531,15 @@ function installExampleAngular() {
511
531
var sources ;
512
532
var template ;
513
533
var libs = [
514
- 'core' , 'common' , 'compiler' ,
534
+ 'core' , 'common' , 'compiler' , 'compiler-cli' ,
515
535
'platform-browser' , 'platform-browser-dynamic' ,
516
536
'forms' , 'http' , 'router' , 'upgrade' ] ;
517
537
518
538
// Like: "angular/core-builds" or "@angular/core"
519
539
sources = libs . map ( lib => argv . build ? `angular/${ lib } -builds` : `@angular/${ lib } ` ) ;
520
540
541
+ if ( argv . build ) { sources . push ( '@angular/tsc-wrapped' ) ; } // tsc-wrapped needed for builds
542
+
521
543
sources . push ( '@angular/router-deprecated' ) ;
522
544
523
545
gutil . log ( `Installing Angular npm packages from ${ argv . build ? 'BUILD' : 'RELEASE' } ` ) ;
@@ -595,7 +617,8 @@ gulp.task('build-dart-api-docs', ['_shred-api-examples', 'dartdoc'], function()
595
617
} ) ;
596
618
597
619
gulp . task ( 'build-plunkers' , [ '_copy-example-boilerplate' ] , function ( ) {
598
- return plunkerBuilder . buildPlunkers ( EXAMPLES_PATH , LIVE_EXAMPLES_PATH , { errFn : gutil . log , build : argv . build } ) ;
620
+ regularPlunker . buildPlunkers ( EXAMPLES_PATH , LIVE_EXAMPLES_PATH , { errFn : gutil . log , build : argv . build } ) ;
621
+ return embeddedPlunker . buildPlunkers ( EXAMPLES_PATH , LIVE_EXAMPLES_PATH , { errFn : gutil . log , build : argv . build } ) ;
599
622
} ) ;
600
623
601
624
gulp . task ( 'build-dart-cheatsheet' , [ ] , function ( ) {
@@ -604,16 +627,17 @@ gulp.task('build-dart-cheatsheet', [], function() {
604
627
605
628
gulp . task ( 'dartdoc' , [ 'pub upgrade' ] , function ( ) {
606
629
const ngRepoPath = ngPathFor ( 'dart' ) ;
607
- if ( argv . fast && fs . existsSync ( path . resolve ( ngRepoPath , 'docs' , 'api' ) ) ) {
608
- gutil . log ( ' Skipping dartdoc: --fast flag enabled and "docs/ api" dir exists' ) ;
630
+ if ( argv . fast && fs . existsSync ( path . resolve ( ngRepoPath , relDartDocApiDir ) ) ) {
631
+ gutil . log ( ` Skipping dartdoc: --fast flag enabled and api dir exists ( ${ relDartDocApiDir } )` ) ;
609
632
return true ;
610
633
}
611
634
checkAngularProjectPath ( ngRepoPath ) ;
612
635
const topLevelLibFilePath = path . resolve ( ngRepoPath , 'lib' , 'angular2.dart' ) ;
613
636
const tmpPath = topLevelLibFilePath + '.disabled' ;
614
637
renameIfExistsSync ( topLevelLibFilePath , tmpPath ) ;
615
638
gutil . log ( `Hiding top-level angular2 library: ${ topLevelLibFilePath } ` ) ;
616
- const dartdoc = spawnExt ( 'dartdoc' , [ '--output' , 'docs/api' , '--add-crossdart' ] , { cwd : ngRepoPath } ) ;
639
+ // Remove dartdoc '--add-crossdart' flag while we are fixing links to API pages.
640
+ const dartdoc = spawnExt ( 'dartdoc' , [ '--output' , relDartDocApiDir ] , { cwd : ngRepoPath } ) ;
617
641
return dartdoc . promise . finally ( ( ) => {
618
642
gutil . log ( `Restoring top-level angular2 library: ${ topLevelLibFilePath } ` ) ;
619
643
renameIfExistsSync ( tmpPath , topLevelLibFilePath ) ;
@@ -677,20 +701,20 @@ gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
677
701
} ) ;
678
702
} ) ;
679
703
680
- gulp . task ( 'harp-compile' , [ ] , function ( ) {
704
+ gulp . task ( 'harp-compile' , ( ) => {
681
705
return harpCompile ( )
682
706
} ) ;
683
707
684
- gulp . task ( 'serve' , [ ] , function ( ) {
685
- // Harp will serve files from workspace.
708
+ gulp . task ( 'harp- serve' , ( ) => {
709
+ // Harp will watch and serve workspace files .
686
710
const cmd = 'npm run harp -- server .' ;
687
711
gutil . log ( 'Launching harp server (over project files)' ) ;
688
712
gutil . log ( ` > ${ cmd } ` ) ;
689
713
gutil . log ( 'Note: issuing this command directly from the command line will show harp comiple warnings.' ) ;
690
714
return execPromise ( cmd ) ;
691
715
} ) ;
692
716
693
- gulp . task ( 'serve-www' , [ ] , function ( ) {
717
+ gulp . task ( 'serve-www' , ( ) => {
694
718
// Serve generated site.
695
719
return execPromise ( 'npm run live-server ./www' ) ;
696
720
} ) ;
@@ -699,13 +723,6 @@ gulp.task('build-compile', ['build-docs'], function() {
699
723
return harpCompile ( ) ;
700
724
} ) ;
701
725
702
- gulp . task ( 'check-serve' , [ 'build-docs' ] , function ( ) {
703
- return harpCompile ( ) . then ( function ( ) {
704
- gutil . log ( 'Launching live-server over ./www' ) ;
705
- return execPromise ( 'npm run live-server ./www' ) ;
706
- } ) ;
707
- } ) ;
708
-
709
726
gulp . task ( 'check-deploy' , [ 'build-docs' ] , function ( ) {
710
727
return harpCompile ( ) . then ( function ( ) {
711
728
gutil . log ( 'compile ok' ) ;
@@ -801,7 +818,7 @@ gulp.task('_shred-clean-devguide', function(cb) {
801
818
gulp . task ( '_shred-api-examples' , [ '_shred-clean-api' ] , function ( ) {
802
819
const promises = [ ] ;
803
820
gutil . log ( 'Shredding API examples for languages: ' + langs . join ( ', ' ) ) ;
804
- langs . forEach ( ( lang ) => {
821
+ langs . forEach ( lang => {
805
822
if ( lang === 'js' ) return ; // JS is handled via TS.
806
823
checkAngularProjectPath ( ngPathFor ( lang ) ) ;
807
824
const options = lang == 'dart' ? _apiShredOptionsForDart : _apiShredOptions ;
@@ -851,26 +868,39 @@ gulp.task('lint', function() {
851
868
function harpCompile ( ) {
852
869
// Supposedly running in production makes harp faster
853
870
// and less likely to drown in node_modules.
854
- env ( {
855
- vars : { NODE_ENV : "production" }
856
- } ) ;
871
+ env ( { vars : { NODE_ENV : "production" } } ) ;
857
872
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
858
873
874
+ if ( skipLangs && fs . existsSync ( 'www' ) ) {
875
+ gutil . log ( `Harp site recompile: skipping recompilation of API docs for [${ skipLangs } ]` ) ;
876
+ gutil . log ( `API docs will be copied from existing www folder.` )
877
+ del . sync ( 'www-backup' ) ; // remove existing backup if it exists
878
+ renameIfExistsSync ( 'www' , 'www-backup' ) ;
879
+ } else {
880
+ gutil . log ( `Harp full site compile, including API docs for all languages.` ) ;
881
+ if ( skipLangs )
882
+ gutil . log ( `Ignoring API docs skip set (${ skipLangs } ) because full site has not been built yet.` ) ;
883
+ }
884
+
859
885
var deferred = Q . defer ( ) ;
860
886
gutil . log ( 'running harp compile...' ) ;
861
887
showHideExampleNodeModules ( 'hide' ) ;
888
+ showHideApiDir ( 'hide' ) ;
862
889
var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'harp' , '--' , 'compile' , '.' , './www' ] ) ;
863
890
spawnInfo . promise . then ( function ( x ) {
864
891
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
865
892
showHideExampleNodeModules ( 'show' ) ;
893
+ showHideApiDir ( 'show' ) ;
866
894
if ( x !== 0 ) {
867
895
deferred . reject ( x )
868
896
} else {
897
+ restoreApiHtml ( ) ;
869
898
deferred . resolve ( x ) ;
870
899
}
871
900
} ) . catch ( function ( e ) {
872
901
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
873
902
showHideExampleNodeModules ( 'show' ) ;
903
+ showHideApiDir ( 'show' ) ;
874
904
deferred . reject ( e ) ;
875
905
} ) ;
876
906
return deferred . promise ;
@@ -969,6 +999,37 @@ function showHideExampleNodeModules(showOrHide) {
969
999
}
970
1000
}
971
1001
1002
+ // Show/hide the API docs harp source folder for every lang in skipLangs.
1003
+ function showHideApiDir ( showOrHide ) {
1004
+ skipLangs . forEach ( lang => {
1005
+ _showHideApiDir ( lang , showOrHide ) ;
1006
+ } ) ;
1007
+ }
1008
+
1009
+ // Rename the API docs harp source folder for lang to/from 'api' to '_api-tmp-foo'.
1010
+ function _showHideApiDir ( lang , showOrHide ) {
1011
+ const vers = 'latest' ;
1012
+ const basePath = path . join ( DOCS_PATH , lang , vers ) ;
1013
+ const apiDirPath = path . join ( basePath , 'api' ) ;
1014
+ const disabledApiDirPath = path . join ( basePath , '_api-tmp-hide-from-jade' ) ;
1015
+ const args = showOrHide == 'hide'
1016
+ ? [ apiDirPath , disabledApiDirPath ]
1017
+ : [ disabledApiDirPath , apiDirPath ] ;
1018
+ renameIfExistsSync ( ...args ) ;
1019
+ }
1020
+
1021
+ // For each lang in skipLangs, copy the API dir from www-backup to www.
1022
+ function restoreApiHtml ( ) {
1023
+ const vers = 'latest' ;
1024
+ skipLangs . forEach ( lang => {
1025
+ const relApiDir = path . join ( 'docs' , lang , vers , 'api' ) ;
1026
+ const wwwApiSubdir = path . join ( 'www' , relApiDir ) ;
1027
+ const backupApiSubdir = path . join ( 'www-backup' , relApiDir ) ;
1028
+ gutil . log ( `cp ${ backupApiSubdir } ${ wwwApiSubdir } ` )
1029
+ fs . copySync ( backupApiSubdir , wwwApiSubdir ) ;
1030
+ } ) ;
1031
+ }
1032
+
972
1033
// Copies fileNames into destPaths, setting the mode of the
973
1034
// files at the destination as optional_destFileMode if given.
974
1035
// returns a promise
@@ -1087,11 +1148,10 @@ function watchAndSync(options, cb) {
1087
1148
1088
1149
// returns a promise;
1089
1150
function askDeploy ( ) {
1090
-
1091
1151
prompt . start ( ) ;
1092
1152
var schema = {
1093
1153
name : 'shouldDeploy' ,
1094
- description : 'Deploy to Firebase? (y/n): ' ,
1154
+ description : 'Deploy to Firebase? (y/n)' ,
1095
1155
type : 'string' ,
1096
1156
pattern : / Y | N | y | n / ,
1097
1157
message : "Respond with either a 'y' or 'n'" ,
@@ -1241,7 +1301,7 @@ function buildApiDocsForDart() {
1241
1301
log . level = _dgeniLogLevel ;
1242
1302
const dabInfo = dab . dartPkgConfigInfo ;
1243
1303
dabInfo . ngIoDartApiDocPath = path . join ( DOCS_PATH , 'dart' , vers , 'api' ) ;
1244
- dabInfo . ngDartDocPath = path . join ( ngPathFor ( 'dart' ) , 'docs' , 'api' ) ;
1304
+ dabInfo . ngDartDocPath = path . join ( ngPathFor ( 'dart' ) , relDartDocApiDir ) ;
1245
1305
// Exclude API entries for developer/internal libraries. Also exclude entries for
1246
1306
// the top-level catch all "angular2" library (otherwise every entry appears twice).
1247
1307
dabInfo . excludeLibRegExp = new RegExp ( / ^ (? ! a n g u l a r 2 ) | \. t e s t i n g | _ | c o d e g e n | ^ a n g u l a r 2 $ / ) ;
@@ -1456,8 +1516,9 @@ function checkAngularProjectPath(_ngPath) {
1456
1516
1457
1517
function renameIfExistsSync ( oldPath , newPath ) {
1458
1518
if ( fs . existsSync ( oldPath ) ) {
1459
- fs . renameSync ( oldPath , newPath ) ;
1519
+ gutil . log ( `Rename: mv ${ oldPath } ${ newPath } ` ) ;
1520
+ fs . renameSync ( oldPath , newPath ) ;
1460
1521
} else {
1461
- gutil . log ( `renameIfExistsSync cannot find file to rename : ${ oldPath } ` ) ;
1522
+ gutil . log ( `renameIfExistsSync cannot rename, path not found : ${ oldPath } ` ) ;
1462
1523
}
1463
1524
}
0 commit comments