Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit e4ed1ce

Browse files
chalinwardbell
authored andcommitted
chore(site): support site build w/o recompiling API docs (#2202)
* chore(site): support site build w/o recompiling API docs If the site has already been built once, then rebuild the site without re-harp-compiling the API docs use: `gulp check-deploy —lang=‘’` Otherwise specify the languages whose API docs are to be rebuilt; as usual, omitting the `—lang` flag is equivalent to `—lang=all` which is equivalent to `—lang=‘ts|js|dart’`. Other changes to gulp tasks: - Renamed `serve` to `harp-serve`. - Removed `check-serve`. Use `harp-compile` followed by `serve-www’ instead. - `harp-compile` now also defaults to `—lang=all`. * post-review updates - Ensure that the deploy prompt can be seen.
1 parent 907f848 commit e4ed1ce

File tree

2 files changed

+77
-27
lines changed

2 files changed

+77
-27
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _.*
2121
**/resources/zips
2222
public/docs/xref-*.*
2323
_zip-output
24-
www
24+
www*
2525
npm-debug*.log*
2626
*.plnkr.html
2727
plnkr.html

gulpfile.js

+76-26
Original file line numberDiff line numberDiff line change
@@ -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;
125126
function 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
}
140153
configLangs(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-
720726
gulp.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) {
812818
gulp.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,26 +868,39 @@ gulp.task('lint', function() {
862868
function 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');
893+
showHideApiDir('show');
877894
if (x !== 0) {
878895
deferred.reject(x)
879896
} else {
897+
restoreApiHtml();
880898
deferred.resolve(x);
881899
}
882900
}).catch(function(e) {
883901
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
884902
showHideExampleNodeModules('show');
903+
showHideApiDir('show');
885904
deferred.reject(e);
886905
});
887906
return deferred.promise;
@@ -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
@@ -1098,11 +1148,10 @@ function watchAndSync(options, cb) {
10981148

10991149
// returns a promise;
11001150
function askDeploy() {
1101-
11021151
prompt.start();
11031152
var schema = {
11041153
name: 'shouldDeploy',
1105-
description: 'Deploy to Firebase? (y/n): ',
1154+
description: 'Deploy to Firebase? (y/n)',
11061155
type: 'string',
11071156
pattern: /Y|N|y|n/,
11081157
message: "Respond with either a 'y' or 'n'",
@@ -1467,8 +1516,9 @@ function checkAngularProjectPath(_ngPath) {
14671516

14681517
function renameIfExistsSync(oldPath, newPath) {
14691518
if (fs.existsSync(oldPath)) {
1470-
fs.renameSync(oldPath, newPath);
1519+
gutil.log(`Rename: mv ${oldPath} ${newPath}`);
1520+
fs.renameSync(oldPath, newPath);
14711521
} else {
1472-
gutil.log(`renameIfExistsSync cannot find file to rename: ${oldPath}`);
1522+
gutil.log(`renameIfExistsSync cannot rename, path not found: ${oldPath}`);
14731523
}
14741524
}

0 commit comments

Comments
 (0)