@@ -45,7 +45,8 @@ var STYLES_SOURCE_PATH = path.join(TOOLS_PATH, 'styles-builder/less');
4545
4646var docShredder = require ( path . resolve ( TOOLS_PATH , 'doc-shredder/doc-shredder' ) ) ;
4747var 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' ) ) ;
4950var fsUtils = require ( path . resolve ( TOOLS_PATH , 'fs-utils/fsUtils' ) ) ;
5051
5152const isSilent = ! ! argv . silent ;
@@ -72,9 +73,10 @@ var _apiShredOptions = {
7273 logLevel : _dgeniLogLevel
7374} ;
7475
76+ const relDartDocApiDir = path . join ( 'doc' , 'api' ) ;
7577var _apiShredOptionsForDart = {
7678 lang : 'dart' ,
77- examplesDir : path . resolve ( ngPathFor ( 'dart' ) , 'examples ' ) ,
79+ examplesDir : path . resolve ( ngPathFor ( 'dart' ) , 'example ' ) ,
7880 fragmentsDir : path . join ( DOCS_PATH , '_fragments/_api' ) ,
7981 zipDir : path . join ( RESOURCES_PATH , 'zips/api' ) ,
8082 logLevel : _dgeniLogLevel
@@ -118,22 +120,35 @@ var _styleLessName = 'a2docs.less';
118120// or a regex pattern to match any one of 'ts', 'js', or 'dart'.
119121// Default: 'ts|js' except for the "full site build" tasks (see below),
120122// 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 ;
123126function configLangs ( langOption ) {
124- const fullSiteBuildTasks = [ 'build-compile' , 'check-serve ' , 'check-deploy ' ] ;
127+ const fullSiteBuildTasks = [ 'build-compile' , 'check-deploy ' , 'harp-compile ' ] ;
125128 const buildAllDocs = argv [ '_' ] &&
126129 fullSiteBuildTasks . some ( ( task ) => argv [ '_' ] . indexOf ( task ) >= 0 ) ;
127130 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 } ]` ) ;
132140 if ( langs . indexOf ( 'dart' ) >= 0 ) {
133141 buildDartApiDocs = true ;
134142 // For Dart, be proactive about checking for the repo
135143 checkAngularProjectPath ( ngPathFor ( 'dart' ) ) ;
144+ } else {
145+ argv . pub = false ;
136146 }
147+ skipLangs = [ ] ;
148+ [ 'ts' , 'js' , 'dart' ] . forEach ( lang => {
149+ if ( langs . indexOf ( lang ) < 0 ) skipLangs . push ( lang ) ;
150+ } ) ;
151+ gutil . log ( `Skipped languages: [${ skipLangs } ]` ) ;
137152}
138153configLangs ( argv . lang ) ;
139154
@@ -344,10 +359,15 @@ function runE2eDartTests(appDir, outputFile) {
344359 gutil . log ( 'http-server failed to launch over ' + deployDir ) ;
345360 return false ;
346361 }
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+ }
351371 return runProtractor ( prepPromise , appDir , appRunSpawnInfo , outputFile ) ;
352372}
353373
@@ -511,13 +531,15 @@ function installExampleAngular() {
511531 var sources ;
512532 var template ;
513533 var libs = [
514- 'core' , 'common' , 'compiler' ,
534+ 'core' , 'common' , 'compiler' , 'compiler-cli' ,
515535 'platform-browser' , 'platform-browser-dynamic' ,
516536 'forms' , 'http' , 'router' , 'upgrade' ] ;
517537
518538 // Like: "angular/core-builds" or "@angular/core"
519539 sources = libs . map ( lib => argv . build ? `angular/${ lib } -builds` : `@angular/${ lib } ` ) ;
520540
541+ if ( argv . build ) { sources . push ( '@angular/tsc-wrapped' ) ; } // tsc-wrapped needed for builds
542+
521543 sources . push ( '@angular/router-deprecated' ) ;
522544
523545 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()
595617} ) ;
596618
597619gulp . 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 } ) ;
599622} ) ;
600623
601624gulp . task ( 'build-dart-cheatsheet' , [ ] , function ( ) {
@@ -604,16 +627,17 @@ gulp.task('build-dart-cheatsheet', [], function() {
604627
605628gulp . task ( 'dartdoc' , [ 'pub upgrade' ] , function ( ) {
606629 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 } )` ) ;
609632 return true ;
610633 }
611634 checkAngularProjectPath ( ngRepoPath ) ;
612635 const topLevelLibFilePath = path . resolve ( ngRepoPath , 'lib' , 'angular2.dart' ) ;
613636 const tmpPath = topLevelLibFilePath + '.disabled' ;
614637 renameIfExistsSync ( topLevelLibFilePath , tmpPath ) ;
615638 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 } ) ;
617641 return dartdoc . promise . finally ( ( ) => {
618642 gutil . log ( `Restoring top-level angular2 library: ${ topLevelLibFilePath } ` ) ;
619643 renameIfExistsSync ( tmpPath , topLevelLibFilePath ) ;
@@ -677,20 +701,20 @@ gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
677701 } ) ;
678702} ) ;
679703
680- gulp . task ( 'harp-compile' , [ ] , function ( ) {
704+ gulp . task ( 'harp-compile' , ( ) => {
681705 return harpCompile ( )
682706} ) ;
683707
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 .
686710 const cmd = 'npm run harp -- server .' ;
687711 gutil . log ( 'Launching harp server (over project files)' ) ;
688712 gutil . log ( ` > ${ cmd } ` ) ;
689713 gutil . log ( 'Note: issuing this command directly from the command line will show harp comiple warnings.' ) ;
690714 return execPromise ( cmd ) ;
691715} ) ;
692716
693- gulp . task ( 'serve-www' , [ ] , function ( ) {
717+ gulp . task ( 'serve-www' , ( ) => {
694718 // Serve generated site.
695719 return execPromise ( 'npm run live-server ./www' ) ;
696720} ) ;
@@ -699,13 +723,6 @@ gulp.task('build-compile', ['build-docs'], function() {
699723 return harpCompile ( ) ;
700724} ) ;
701725
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-
709726gulp . task ( 'check-deploy' , [ 'build-docs' ] , function ( ) {
710727 return harpCompile ( ) . then ( function ( ) {
711728 gutil . log ( 'compile ok' ) ;
@@ -801,7 +818,7 @@ gulp.task('_shred-clean-devguide', function(cb) {
801818gulp . task ( '_shred-api-examples' , [ '_shred-clean-api' ] , function ( ) {
802819 const promises = [ ] ;
803820 gutil . log ( 'Shredding API examples for languages: ' + langs . join ( ', ' ) ) ;
804- langs . forEach ( ( lang ) => {
821+ langs . forEach ( lang => {
805822 if ( lang === 'js' ) return ; // JS is handled via TS.
806823 checkAngularProjectPath ( ngPathFor ( lang ) ) ;
807824 const options = lang == 'dart' ? _apiShredOptionsForDart : _apiShredOptions ;
@@ -851,26 +868,39 @@ gulp.task('lint', function() {
851868function harpCompile ( ) {
852869 // Supposedly running in production makes harp faster
853870 // and less likely to drown in node_modules.
854- env ( {
855- vars : { NODE_ENV : "production" }
856- } ) ;
871+ env ( { vars : { NODE_ENV : "production" } } ) ;
857872 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
858873
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+
859885 var deferred = Q . defer ( ) ;
860886 gutil . log ( 'running harp compile...' ) ;
861887 showHideExampleNodeModules ( 'hide' ) ;
888+ showHideApiDir ( 'hide' ) ;
862889 var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'harp' , '--' , 'compile' , '.' , './www' ] ) ;
863890 spawnInfo . promise . then ( function ( x ) {
864891 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
865892 showHideExampleNodeModules ( 'show' ) ;
893+ showHideApiDir ( 'show' ) ;
866894 if ( x !== 0 ) {
867895 deferred . reject ( x )
868896 } else {
897+ restoreApiHtml ( ) ;
869898 deferred . resolve ( x ) ;
870899 }
871900 } ) . catch ( function ( e ) {
872901 gutil . log ( "NODE_ENV: " + process . env . NODE_ENV ) ;
873902 showHideExampleNodeModules ( 'show' ) ;
903+ showHideApiDir ( 'show' ) ;
874904 deferred . reject ( e ) ;
875905 } ) ;
876906 return deferred . promise ;
@@ -969,6 +999,37 @@ function showHideExampleNodeModules(showOrHide) {
969999 }
9701000}
9711001
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+
9721033// Copies fileNames into destPaths, setting the mode of the
9731034// files at the destination as optional_destFileMode if given.
9741035// returns a promise
@@ -1087,11 +1148,10 @@ function watchAndSync(options, cb) {
10871148
10881149// returns a promise;
10891150function askDeploy ( ) {
1090-
10911151 prompt . start ( ) ;
10921152 var schema = {
10931153 name : 'shouldDeploy' ,
1094- description : 'Deploy to Firebase? (y/n): ' ,
1154+ description : 'Deploy to Firebase? (y/n)' ,
10951155 type : 'string' ,
10961156 pattern : / Y | N | y | n / ,
10971157 message : "Respond with either a 'y' or 'n'" ,
@@ -1241,7 +1301,7 @@ function buildApiDocsForDart() {
12411301 log . level = _dgeniLogLevel ;
12421302 const dabInfo = dab . dartPkgConfigInfo ;
12431303 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 ) ;
12451305 // Exclude API entries for developer/internal libraries. Also exclude entries for
12461306 // the top-level catch all "angular2" library (otherwise every entry appears twice).
12471307 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) {
14561516
14571517function renameIfExistsSync ( oldPath , newPath ) {
14581518 if ( fs . existsSync ( oldPath ) ) {
1459- fs . renameSync ( oldPath , newPath ) ;
1519+ gutil . log ( `Rename: mv ${ oldPath } ${ newPath } ` ) ;
1520+ fs . renameSync ( oldPath , newPath ) ;
14601521 } else {
1461- gutil . log ( `renameIfExistsSync cannot find file to rename : ${ oldPath } ` ) ;
1522+ gutil . log ( `renameIfExistsSync cannot rename, path not found : ${ oldPath } ` ) ;
14621523 }
14631524}
0 commit comments