@@ -120,22 +120,35 @@ var _styleLessName = 'a2docs.less';
120
120
// or a regex pattern to match any one of 'ts', 'js', or 'dart'.
121
121
// Default: 'ts|js' except for the "full site build" tasks (see below),
122
122
// for which it is 'all'.
123
- //
124
- var lang , langs , buildDartApiDocs = false ;
123
+
124
+ // langs and skipLangs partition ['ts', 'js', 'dart'].
125
+ var lang , langs , skipLangs , buildDartApiDocs = false ;
125
126
function configLangs ( langOption ) {
126
- const fullSiteBuildTasks = [ 'build-compile' , 'check-serve ' , 'check-deploy ' ] ;
127
+ const fullSiteBuildTasks = [ 'build-compile' , 'check-deploy ' , 'harp-compile ' ] ;
127
128
const buildAllDocs = argv [ '_' ] &&
128
129
fullSiteBuildTasks . some ( ( task ) => argv [ '_' ] . indexOf ( task ) >= 0 ) ;
129
130
const langDefault = buildAllDocs ? 'all' : 'ts|js' ;
130
- lang = ( langOption || langDefault ) . toLowerCase ( ) ;
131
- if ( lang === 'all' ) lang = 'ts|js|dart' ;
132
- langs = lang . match ( / \w + / g) ; // the languages in `lang` as an array
133
- 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 } ]` ) ;
134
140
if ( langs . indexOf ( 'dart' ) >= 0 ) {
135
141
buildDartApiDocs = true ;
136
142
// For Dart, be proactive about checking for the repo
137
143
checkAngularProjectPath ( ngPathFor ( 'dart' ) ) ;
144
+ } else {
145
+ argv . pub = false ;
138
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 } ]` ) ;
139
152
}
140
153
configLangs ( argv . lang ) ;
141
154
@@ -688,20 +701,20 @@ gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
688
701
} ) ;
689
702
} ) ;
690
703
691
- gulp . task ( 'harp-compile' , [ ] , function ( ) {
704
+ gulp . task ( 'harp-compile' , ( ) => {
692
705
return harpCompile ( )
693
706
} ) ;
694
707
695
- gulp . task ( 'serve' , [ ] , function ( ) {
696
- // Harp will serve files from workspace.
708
+ gulp . task ( 'harp- serve' , ( ) => {
709
+ // Harp will watch and serve workspace files .
697
710
const cmd = 'npm run harp -- server .' ;
698
711
gutil . log ( 'Launching harp server (over project files)' ) ;
699
712
gutil . log ( ` > ${ cmd } ` ) ;
700
713
gutil . log ( 'Note: issuing this command directly from the command line will show harp comiple warnings.' ) ;
701
714
return execPromise ( cmd ) ;
702
715
} ) ;
703
716
704
- gulp . task ( 'serve-www' , [ ] , function ( ) {
717
+ gulp . task ( 'serve-www' , ( ) => {
705
718
// Serve generated site.
706
719
return execPromise ( 'npm run live-server ./www' ) ;
707
720
} ) ;
@@ -710,13 +723,6 @@ gulp.task('build-compile', ['build-docs'], function() {
710
723
return harpCompile ( ) ;
711
724
} ) ;
712
725
713
- gulp . task ( 'check-serve' , [ 'build-docs' ] , function ( ) {
714
- return harpCompile ( ) . then ( function ( ) {
715
- gutil . log ( 'Launching live-server over ./www' ) ;
716
- return execPromise ( 'npm run live-server ./www' ) ;
717
- } ) ;
718
- } ) ;
719
-
720
726
gulp . task ( 'check-deploy' , [ 'build-docs' ] , function ( ) {
721
727
return harpCompile ( ) . then ( function ( ) {
722
728
gutil . log ( 'compile ok' ) ;
@@ -812,7 +818,7 @@ gulp.task('_shred-clean-devguide', function(cb) {
812
818
gulp . task ( '_shred-api-examples' , [ '_shred-clean-api' ] , function ( ) {
813
819
const promises = [ ] ;
814
820
gutil . log ( 'Shredding API examples for languages: ' + langs . join ( ', ' ) ) ;
815
- langs . forEach ( ( lang ) => {
821
+ langs . forEach ( lang => {
816
822
if ( lang === 'js' ) return ; // JS is handled via TS.
817
823
checkAngularProjectPath ( ngPathFor ( lang ) ) ;
818
824
const options = lang == 'dart' ? _apiShredOptionsForDart : _apiShredOptions ;
@@ -862,26 +868,39 @@ gulp.task('lint', function() {
862
868
function harpCompile ( ) {
863
869
// Supposedly running in production makes harp faster
864
870
// and less likely to drown in node_modules.
865
- env ( {
866
- vars : { NODE_ENV : "production" }
867
- } ) ;
871
+ env ( { vars : { NODE_ENV : "production" } } ) ;
868
872
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
869
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
+
870
885
var deferred = Q . defer ( ) ;
871
886
gutil . log ( 'running harp compile...' ) ;
872
887
showHideExampleNodeModules ( 'hide' ) ;
888
+ showHideApiDir ( 'hide' ) ;
873
889
var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'harp' , '--' , 'compile' , '.' , './www' ] ) ;
874
890
spawnInfo . promise . then ( function ( x ) {
875
891
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
876
892
showHideExampleNodeModules ( 'show' ) ;
893
+ showHideApiDir ( 'show' ) ;
877
894
if ( x !== 0 ) {
878
895
deferred . reject ( x )
879
896
} else {
897
+ restoreApiHtml ( ) ;
880
898
deferred . resolve ( x ) ;
881
899
}
882
900
} ) . catch ( function ( e ) {
883
901
gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
884
902
showHideExampleNodeModules ( 'show' ) ;
903
+ showHideApiDir ( 'show' ) ;
885
904
deferred . reject ( e ) ;
886
905
} ) ;
887
906
return deferred . promise ;
@@ -980,6 +999,37 @@ function showHideExampleNodeModules(showOrHide) {
980
999
}
981
1000
}
982
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
+
983
1033
// Copies fileNames into destPaths, setting the mode of the
984
1034
// files at the destination as optional_destFileMode if given.
985
1035
// returns a promise
@@ -1098,11 +1148,10 @@ function watchAndSync(options, cb) {
1098
1148
1099
1149
// returns a promise;
1100
1150
function askDeploy ( ) {
1101
-
1102
1151
prompt . start ( ) ;
1103
1152
var schema = {
1104
1153
name : 'shouldDeploy' ,
1105
- description : 'Deploy to Firebase? (y/n): ' ,
1154
+ description : 'Deploy to Firebase? (y/n)' ,
1106
1155
type : 'string' ,
1107
1156
pattern : / Y | N | y | n / ,
1108
1157
message : "Respond with either a 'y' or 'n'" ,
@@ -1467,8 +1516,9 @@ function checkAngularProjectPath(_ngPath) {
1467
1516
1468
1517
function renameIfExistsSync ( oldPath , newPath ) {
1469
1518
if ( fs . existsSync ( oldPath ) ) {
1470
- fs . renameSync ( oldPath , newPath ) ;
1519
+ gutil . log ( `Rename: mv ${ oldPath } ${ newPath } ` ) ;
1520
+ fs . renameSync ( oldPath , newPath ) ;
1471
1521
} else {
1472
- gutil . log ( `renameIfExistsSync cannot find file to rename : ${ oldPath } ` ) ;
1522
+ gutil . log ( `renameIfExistsSync cannot rename, path not found : ${ oldPath } ` ) ;
1473
1523
}
1474
1524
}
0 commit comments