@@ -120,22 +120,35 @@ var _styleLessName = 'a2docs.less';
120120// or a regex pattern to match any one of 'ts', 'js', or 'dart'.
121121// Default: 'ts|js' except for the "full site build" tasks (see below),
122122// 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 ;
125126function configLangs ( langOption ) {
126- const fullSiteBuildTasks = [ 'build-compile' , 'check-serve ' , 'check-deploy ' ] ;
127+ const fullSiteBuildTasks = [ 'build-compile' , 'check-deploy ' , 'harp-compile ' ] ;
127128 const buildAllDocs = argv [ '_' ] &&
128129 fullSiteBuildTasks . some ( ( task ) => argv [ '_' ] . indexOf ( task ) >= 0 ) ;
129130 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 } ]` ) ;
134140 if ( langs . indexOf ( 'dart' ) >= 0 ) {
135141 buildDartApiDocs = true ;
136142 // For Dart, be proactive about checking for the repo
137143 checkAngularProjectPath ( ngPathFor ( 'dart' ) ) ;
144+ } else {
145+ argv . pub = false ;
138146 }
147+ skipLangs = [ ] ;
148+ [ 'ts' , 'js' , 'dart' ] . forEach ( lang => {
149+ if ( langs . indexOf ( lang ) < 0 ) skipLangs . push ( lang ) ;
150+ } ) ;
151+ gutil . log ( `Skipped languages: [${ skipLangs } ]` ) ;
139152}
140153configLangs ( argv . lang ) ;
141154
@@ -688,20 +701,20 @@ gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
688701 } ) ;
689702} ) ;
690703
691- gulp . task ( 'harp-compile' , [ ] , function ( ) {
704+ gulp . task ( 'harp-compile' , ( ) => {
692705 return harpCompile ( )
693706} ) ;
694707
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 .
697710 const cmd = 'npm run harp -- server .' ;
698711 gutil . log ( 'Launching harp server (over project files)' ) ;
699712 gutil . log ( ` > ${ cmd } ` ) ;
700713 gutil . log ( 'Note: issuing this command directly from the command line will show harp comiple warnings.' ) ;
701714 return execPromise ( cmd ) ;
702715} ) ;
703716
704- gulp . task ( 'serve-www' , [ ] , function ( ) {
717+ gulp . task ( 'serve-www' , ( ) => {
705718 // Serve generated site.
706719 return execPromise ( 'npm run live-server ./www' ) ;
707720} ) ;
@@ -710,13 +723,6 @@ gulp.task('build-compile', ['build-docs'], function() {
710723 return harpCompile ( ) ;
711724} ) ;
712725
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-
720726gulp . task ( 'check-deploy' , [ 'build-docs' ] , function ( ) {
721727 return harpCompile ( ) . then ( function ( ) {
722728 gutil . log ( 'compile ok' ) ;
@@ -812,7 +818,7 @@ gulp.task('_shred-clean-devguide', function(cb) {
812818gulp . task ( '_shred-api-examples' , [ '_shred-clean-api' ] , function ( ) {
813819 const promises = [ ] ;
814820 gutil . log ( 'Shredding API examples for languages: ' + langs . join ( ', ' ) ) ;
815- langs . forEach ( ( lang ) => {
821+ langs . forEach ( lang => {
816822 if ( lang === 'js' ) return ; // JS is handled via TS.
817823 checkAngularProjectPath ( ngPathFor ( lang ) ) ;
818824 const options = lang == 'dart' ? _apiShredOptionsForDart : _apiShredOptions ;
@@ -862,27 +868,40 @@ gulp.task('lint', function() {
862868function harpCompile ( ) {
863869 // Supposedly running in production makes harp faster
864870 // and less likely to drown in node_modules.
865- env ( {
866- vars : { NODE_ENV : "production" }
867- } ) ;
871+ env ( { vars : { NODE_ENV : "production" } } ) ;
868872 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
869873
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+
870885 var deferred = Q . defer ( ) ;
871886 gutil . log ( 'running harp compile...' ) ;
872887 showHideExampleNodeModules ( 'hide' ) ;
888+ showHideApiDir ( 'hide' ) ;
873889 var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'harp' , '--' , 'compile' , '.' , './www' ] ) ;
874890 spawnInfo . promise . then ( function ( x ) {
875891 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
876892 showHideExampleNodeModules ( 'show' ) ;
877893 if ( x !== 0 ) {
878894 deferred . reject ( x )
879895 } else {
896+ restoreApiHtml ( ) ;
880897 deferred . resolve ( x ) ;
881898 }
882899 } ) . catch ( function ( e ) {
883900 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
884901 showHideExampleNodeModules ( 'show' ) ;
885902 deferred . reject ( e ) ;
903+ } ) . finally ( ( ) => {
904+ showHideApiDir ( 'show' ) ;
886905 } ) ;
887906 return deferred . promise ;
888907}
@@ -980,6 +999,37 @@ function showHideExampleNodeModules(showOrHide) {
980999 }
9811000}
9821001
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+
9831033// Copies fileNames into destPaths, setting the mode of the
9841034// files at the destination as optional_destFileMode if given.
9851035// returns a promise
@@ -1467,8 +1517,9 @@ function checkAngularProjectPath(_ngPath) {
14671517
14681518function renameIfExistsSync ( oldPath , newPath ) {
14691519 if ( fs . existsSync ( oldPath ) ) {
1470- fs . renameSync ( oldPath , newPath ) ;
1520+ gutil . log ( `Rename: mv ${ oldPath } ${ newPath } ` ) ;
1521+ fs . renameSync ( oldPath , newPath ) ;
14711522 } else {
1472- gutil . log ( `renameIfExistsSync cannot find file to rename : ${ oldPath } ` ) ;
1523+ gutil . log ( `renameIfExistsSync cannot rename, path not found : ${ oldPath } ` ) ;
14731524 }
14741525}
0 commit comments