From 23ff8aaca8e2351ce21a26178a0a2d53dbbb7141 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Tue, 6 Sep 2016 11:22:29 -0700 Subject: [PATCH] chore: improve UX of build w/o API (#2265) Just do a full build if no API docs currently exist rather than building the site and then aborting with an error message at the end of it all. --- gulpfile.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9ab9e4a2bb..366310ec49 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -889,7 +889,7 @@ function harpCompile() { env({ vars: { NODE_ENV: "production" } }); gutil.log("NODE_ENV: " + process.env.NODE_ENV); - if(skipLangs && fs.existsSync('www')) { + if(skipLangs && fs.existsSync('www') && backupApiHtmlFilesExist('www')) { gutil.log(`Harp site recompile: skipping recompilation of API docs for [${skipLangs}]`); gutil.log(`API docs will be copied from existing www folder.`) del.sync('www-backup'); // remove existing backup if it exists @@ -897,7 +897,8 @@ function harpCompile() { } else { gutil.log(`Harp full site compile, including API docs for all languages.`); if (skipLangs) - gutil.log(`Ignoring API docs skip set (${skipLangs}) because full site has not been built yet.`); + gutil.log(`Ignoring API docs skip set (${skipLangs}) because full ` + + `site has not been built yet or some API HTML files are missing.`); } var deferred = Q.defer(); @@ -1048,6 +1049,21 @@ function restoreApiHtml() { }); } +// For each lang in skipLangs, ensure API dir exists in www-backup +function backupApiHtmlFilesExist(folderName) { + const vers = 'latest'; + var result = 1; + skipLangs.forEach(lang => { + const relApiDir = path.join('docs', lang, vers, 'api'); + const backupApiSubdir = path.join(folderName, relApiDir); + if (!fs.existsSync(backupApiSubdir)) { + gutil.log(`WARNING: API docs HTML folder doesn't exist: ${backupApiSubdir}`); + result = 0; + } + }); + return result; +} + // Copies fileNames into destPaths, setting the mode of the // files at the destination as optional_destFileMode if given. // returns a promise