Skip to content

Commit

Permalink
🏗♻️ More fixes for gulp --compiled (#27535)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Apr 3, 2020
1 parent bbb1994 commit e22492b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
4 changes: 3 additions & 1 deletion babel.config.js
Expand Up @@ -30,7 +30,9 @@ const {isTravisBuild} = require('./build-system/common/travis');
const argv = minimist(process.argv.slice(2));

const isClosureCompiler =
argv._.includes('dist') || argv._.includes('check-types');
argv._.includes('dist') ||
argv._.includes('check-types') ||
(argv._.length == 0 && argv.compiled);
const {esm} = argv;

const targets = (esm) => {
Expand Down
17 changes: 14 additions & 3 deletions build-system/tasks/build.js
Expand Up @@ -58,6 +58,18 @@ async function watch() {
);
}

/**
* Perform the prerequisite steps before starting the unminified build.
* Used by `gulp` and `gulp build`.
*
* @param {boolean} watch
*/
async function runPreBuildSteps(watch) {
await compileCss(watch);
await compileJison();
await bootstrapThirdPartyFrames(watch);
}

/**
* Unminified build. Entry point for `gulp build`.
*/
Expand All @@ -68,9 +80,7 @@ async function build() {
printNobuildHelp();
printConfigHelp('gulp build');
parseExtensionFlags();
await compileCss(argv.watch);
await compileJison();
await bootstrapThirdPartyFrames(argv.watch);
await runPreBuildSteps(argv.watch);
if (argv.core_runtime_only) {
await compileCoreRuntime(argv.watch, /* minify */ false);
} else {
Expand All @@ -84,6 +94,7 @@ async function build() {

module.exports = {
build,
runPreBuildSteps,
watch,
};

Expand Down
29 changes: 18 additions & 11 deletions build-system/tasks/default-task.js
Expand Up @@ -14,18 +14,16 @@
* limitations under the License.
*/

const argv = require('minimist')(process.argv.slice(2));
const log = require('fancy-log');
const {bootstrapThirdPartyFrames, printConfigHelp} = require('./helpers');
const {compileCss} = require('./css');
const {compileJison} = require('./compile-jison');
const {copyCss, copyParsers} = require('./dist');
const {createCtrlcHandler} = require('../common/ctrlcHandler');
const {cyan, green} = require('ansi-colors');
const {doServe} = require('./serve');
const {maybeUpdatePackages} = require('./update-packages');
const {parseExtensionFlags} = require('./extension-helpers');

const argv = require('minimist')(process.argv.slice(2));
const {printConfigHelp} = require('./helpers');
const {runPreBuildSteps} = require('./build');
const {runPreDistSteps} = require('./dist');

/**
* Prints a useful help message prior to the default gulp task
Expand All @@ -51,13 +49,11 @@ async function defaultTask() {
printConfigHelp('gulp');
printDefaultTaskHelp();
parseExtensionFlags(/* preBuild */ true);
await compileCss(/* watch */ true);
await compileJison();
if (argv.compiled) {
await copyCss();
await copyParsers();
await runPreDistSteps(/* watch */ true);
} else {
await runPreBuildSteps(/* watch */ true);
}
await bootstrapThirdPartyFrames(/* watch */ true);
await doServe(/* lazyBuild */ true);
log(green('JS and extensions will be lazily built when requested...'));
}
Expand All @@ -72,11 +68,22 @@ defaultTask.description =
'Starts the dev server, lazily builds JS and extensions when requested, and watches them for changes';
defaultTask.flags = {
compiled: ' Compiles and serves minified binaries',
pseudo_names:
' Compiles with readable names. ' +
'Great for profiling and debugging production code.',
pretty_print:
' Outputs compiled code with whitespace. ' +
'Great for debugging production code.',
fortesting: ' Compiles production binaries for local testing',
noconfig: ' Compiles production binaries without applying AMP_CONFIG',
config: ' Sets the runtime\'s AMP_CONFIG to one of "prod" or "canary"',
closure_concurrency: ' Sets the number of concurrent invocations of closure',
extensions: ' Pre-builds the given extensions, lazily builds the rest.',
extensions_from:
' Pre-builds the extensions used by the provided example page.',
full_sourcemaps: ' Includes source code content in sourcemaps',
disable_nailgun:
" Doesn't use nailgun to invoke closure compiler (much slower)",
version_override: ' Overrides the version written to AMP_CONFIG',
custom_version_mark: ' Set final digit (0-9) on auto-generated version',
};
30 changes: 19 additions & 11 deletions build-system/tasks/dist.js
Expand Up @@ -85,6 +85,23 @@ function printDistHelp() {
}
}

/**
* Perform the prerequisite steps before starting the minified build.
* Used by `gulp` and `gulp dist`.
*
* @param {boolean} watch
*/
async function runPreDistSteps(watch) {
cleanupBuildDir();
await prebuild();
await compileCss(watch);
await compileJison();
await copyCss();
await copyParsers();
await bootstrapThirdPartyFrames(watch, /* minify */ true);
await startNailgunServer(distNailgunPort, /* detached */ false);
}

/**
* Dist Build
* @return {!Promise}
Expand All @@ -96,17 +113,9 @@ async function dist() {
printNobuildHelp();
printDistHelp();

cleanupBuildDir();
await prebuild();
await compileCss();
await compileJison();

await copyCss();
await copyParsers();
await bootstrapThirdPartyFrames(argv.watch, /* minify */ true);
await runPreDistSteps(argv.watch);

// Steps that use closure compiler. Small ones before large (parallel) ones.
await startNailgunServer(distNailgunPort, /* detached */ false);
if (argv.core_runtime_only) {
await compileCoreRuntime(argv.watch, /* minify */ true);
} else {
Expand Down Expand Up @@ -419,8 +428,7 @@ function preBuildLoginDoneVersion(version) {

module.exports = {
dist,
copyCss,
copyParsers,
runPreDistSteps,
};

/* eslint "google-camelcase/google-camelcase": 0 */
Expand Down
12 changes: 1 addition & 11 deletions build-system/tasks/serve.js
Expand Up @@ -23,20 +23,15 @@ const minimist = require('minimist');
const morgan = require('morgan');
const path = require('path');
const watch = require('gulp-watch');
const {
distNailgunPort,
startNailgunServer,
stopNailgunServer,
} = require('./nailgun');
const {
lazyBuildExtensions,
lazyBuildJs,
preBuildRuntimeFiles,
preBuildExtensions,
} = require('../server/lazy-build');
const {cleanupBuildDir} = require('../compile/compile');
const {createCtrlcHandler} = require('../common/ctrlcHandler');
const {cyan, green, red} = require('ansi-colors');
const {distNailgunPort, stopNailgunServer} = require('./nailgun');
const {exec} = require('../common/exec');
const {logServeMode, setServeMode} = require('../server/app-utils');

Expand Down Expand Up @@ -118,11 +113,6 @@ async function startServer(
url = `http${options.https ? 's' : ''}://${options.host}:${options.port}`;
log(green('Started'), cyan(options.name), green('at'), cyan(url));
logServeMode();

if (lazyBuild && argv.compiled) {
cleanupBuildDir();
await startNailgunServer(distNailgunPort, /* detached */ false);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Expand Up @@ -88,7 +88,8 @@ function createTask(name, taskFunc) {
* @param {function} taskFunc
*/
function checkFlags(name, taskFunc) {
if (!argv._.includes(name)) {
const isDefaultTask = name == 'default' && argv._.length == 0;
if (!argv._.includes(name) && !isDefaultTask) {
return; // This isn't the task being run.
}
const validFlags = taskFunc.flags ? Object.keys(taskFunc.flags) : [];
Expand Down

0 comments on commit e22492b

Please sign in to comment.