Skip to content

Commit

Permalink
🏗 Watch and rebuild amp-a4a when an ad network extension is being w…
Browse files Browse the repository at this point in the history
…atched (#26721)
  • Loading branch information
rsimha committed Feb 11, 2020
1 parent 1644c32 commit 24d7dcf
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions build-system/tasks/extension-helpers.js
Expand Up @@ -368,6 +368,32 @@ async function doBuildExtension(extensions, extension, options) {
);
}

/**
* Watches the contents of an extension directory. When a file in the given path
* changes, the extension is rebuilt.
*
* @param {string} path
* @param {string} name
* @param {string} version
* @param {string} latestVersion
* @param {boolean} hasCss
* @param {?Object} options
*/
function watchExtension(path, name, version, latestVersion, hasCss, options) {
watch(path + '/**/*', function() {
const bundleComplete = buildExtension(
name,
version,
latestVersion,
hasCss,
{...options, continueOnError: true}
);
if (options.onWatchBuild) {
options.onWatchBuild(bundleComplete);
}
});
}

/**
* Copies extensions from
* extensions/$name/$version/$name.js
Expand Down Expand Up @@ -408,18 +434,12 @@ async function buildExtension(
// recompiles JS.
if (options.watch) {
options.watch = false;
watch(path + '/**/*', function() {
const bundleComplete = buildExtension(
name,
version,
latestVersion,
hasCss,
{...options, continueOnError: true}
);
if (options.onWatchBuild) {
options.onWatchBuild(bundleComplete);
}
});
watchExtension(path, name, version, latestVersion, hasCss, options);
// When an ad network extension is being watched, also watch amp-a4a.
if (name.match(/amp-ad-network-.*-impl/)) {
const a4aPath = `extensions/amp-a4a/${version}`;
watchExtension(a4aPath, name, version, latestVersion, hasCss, options);
}
}
if (hasCss) {
mkdirSync('build');
Expand Down

0 comments on commit 24d7dcf

Please sign in to comment.