-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --extensions flag to only build listed extensions #13203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this out. This is a great idea!
After looking at the code, I think we should remove the gulp extensions
task, and replace it with the --extensions
flag to gulp
, gulp watch
, and gulp build
. See my comments below.
gulpfile.js
Outdated
// Skip this extension; | ||
continue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a simpler way to rewrite this function:
function buildExtensions(options) {
var extensionsToBuild = [];
if (!!argv.extensions) {
extensionsToBuild = argv.extensions.split(',');
}
var results = [];
for (var key in extensions) {
if (extensionsToBuild.length > 0 &&
extensionsToBuild.indexOf(extensions[key]) == -1) {
continue;
}
var e = extensions[key];
var o = Object.assign({}, options);
o = Object.assign(o, e);
results.push(buildExtension(e.name, e.version, e.hasCss, o, e.extraGlobs));
}
return Promise.all(results);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For logging, add this code snippet to performBuild()
after the call to printConfigHelp()
:
if (!!argv.extensions) {
log(green('Building extension(s):'), cyan(argv.extensions));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, remove the line...
gulp.task('extensions', 'Build AMP Extensions', buildExtensions);
... from the bottom of the file, and add documentation to gulp watch
and gulp build
for the new --extensions
flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might also be worth adding a --noextensions
flag to gulp watch
and gulp build
that entirely skips building extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, don't forget to update DEVELOPING.md
with the new changes.
c56be70
to
eec17c8
Compare
@rsimha-amp Thanks for the comments! I've addressed them and added documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments below.
contributing/DEVELOPING.md
Outdated
@@ -42,11 +42,14 @@ The Quick Start Guide's [One-time setup](getting-started-quick.md#one-time-setu | |||
| `gulp lint --watch` | Watches for changes in files, Validates against Google Closure Linter.| | |||
| `gulp lint --fix` | Fixes simple lint warnings/errors automatically. | | |||
| `gulp build`<sup>[[1]](#footnote-1)</sup> | Builds the AMP library. | | |||
| `gulp build --extensions=<extension-name,extension-name>` | Builds the AMP library with only listed extension components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit1: Make the command gulp build --extensions=<amp-foo,amp-bar>
nit2: Make the description Builds the AMP library, with only the listed extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contributing/DEVELOPING.md
Outdated
@@ -42,11 +42,14 @@ The Quick Start Guide's [One-time setup](getting-started-quick.md#one-time-setu | |||
| `gulp lint --watch` | Watches for changes in files, Validates against Google Closure Linter.| | |||
| `gulp lint --fix` | Fixes simple lint warnings/errors automatically. | | |||
| `gulp build`<sup>[[1]](#footnote-1)</sup> | Builds the AMP library. | | |||
| `gulp build --extensions=<extension-name,extension-name>` | Builds the AMP library with only listed extension components. | |||
| `gulp build --noextensions` | Builds the AMP library with no extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add these variations to gulp
as well (above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contributing/DEVELOPING.md
Outdated
| `gulp watch`<sup>[[1]](#footnote-1)</sup> | Watches for changes in files, re-build. | | ||
| `gulp watch --extensions=<extension-name,extension-name>` | Watch for changes in files, re-build with only listed extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit1: Make the command gulp watch --extensions=<amp-foo,amp-bar>
nit2: Make the description Watches for changes in files, re-builds only the listed extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contributing/DEVELOPING.md
Outdated
| `gulp watch`<sup>[[1]](#footnote-1)</sup> | Watches for changes in files, re-build. | | ||
| `gulp watch --extensions=<extension-name,extension-name>` | Watch for changes in files, re-build with only listed extensions. | ||
| `gulp watch --noextensions` | Watch for changes in files, re-build with no extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Watches for changes in files, re-builds with no extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contributing/DEVELOPING.md
Outdated
| `gulp check-links --files foo.md,bar.md` | Reports dead links in `.md` files. | | ||
| `gulp clean` | Removes build output. | | ||
| `gulp css`<sup>[[1]](#footnote-1)</sup> | Recompiles css to build directory and builds the embedded css into js files for the AMP library. | | ||
| `gulp extensions` | Build AMP Extensions. | | ||
| `gulp watch`<sup>[[1]](#footnote-1)</sup> | Watches for changes in files, re-build. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/re-build/re-builds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
gulpfile.js
Outdated
@@ -241,8 +241,25 @@ function endBuildStep(stepName, targetName, startTime) { | |||
* @return {!Promise} | |||
*/ | |||
function buildExtensions(options) { | |||
var results = []; | |||
const results = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a const, since you're editing it below. Revert this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
gulpfile.js
Outdated
return Promise.all(results); | ||
} | ||
|
||
// --extensions flag: only build listed extensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is unnecessary, remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
gulpfile.js
Outdated
let extensionsToBuild = []; | ||
// --noextensions flag skip building extensions | ||
if (!!argv.noextensions) { | ||
return Promise.all(results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the top and return Promise.resolve();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
gulpfile.js
Outdated
// Skip this extension; | ||
continue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a cleaner version of this function with your changes:
function buildExtensions(options) {
if (!!argv.noextensions) {
return Promise.resolve();
}
var extensionsToBuild = [];
if (!!argv.extensions) {
extensionsToBuild = argv.extensions.split(',');
}
var results = [];
for (var key in extensions) {
if (extensionsToBuild.length > 0 &&
extensionsToBuild.indexOf(extensions[key]) == -1) {
continue;
}
var e = extensions[key];
var o = Object.assign({}, options);
o = Object.assign(o, e);
results.push(buildExtension(e.name, e.version, e.hasCss, o, e.extraGlobs));
}
return Promise.all(results);
}
gulpfile.js
Outdated
@@ -1349,7 +1369,6 @@ gulp.task('dist', 'Build production binaries', ['update-packages'], dist, { | |||
minimal_set: ' Only compile files needed to load article.amp.html', | |||
} | |||
}); | |||
gulp.task('extensions', 'Build AMP Extensions', buildExtensions); | |||
gulp.task('watch', 'Watches for changes in files, re-builds when detected', | |||
['update-packages'], watch, { | |||
options: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add documentation for --extensions
and --noextensions
here, and for gulp
and gulp build
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! LGTM after these documentation fixes.
This is very cool stuff. The build time just went down from a couple minutes to a few seconds. Everyone is going to be so happy when you announce this :)
contributing/DEVELOPING.md
Outdated
@@ -35,21 +35,23 @@ The Quick Start Guide's [One-time setup](getting-started-quick.md#one-time-setu | |||
| Command | Description | | |||
| ----------------------------------------------------------------------- | --------------------------------------------------------------------- | | |||
| **`gulp`**<sup>[[1]](#footnote-1)</sup> | Runs "watch" and "serve". Use this for standard local dev. | | |||
| `gulp --extensions=<amp-foo,amp-bar>` | Runs "watch" and "serve" with only listed extension components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Runs "watch" and "serve", after building only the listed extensions.
contributing/DEVELOPING.md
Outdated
@@ -35,21 +35,23 @@ The Quick Start Guide's [One-time setup](getting-started-quick.md#one-time-setu | |||
| Command | Description | | |||
| ----------------------------------------------------------------------- | --------------------------------------------------------------------- | | |||
| **`gulp`**<sup>[[1]](#footnote-1)</sup> | Runs "watch" and "serve". Use this for standard local dev. | | |||
| `gulp --extensions=<amp-foo,amp-bar>` | Runs "watch" and "serve" with only listed extension components. | |||
| `gulp --noextensions` | Runs "watch" and "serve" with no extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Runs "watch" and "serve", without building any extensions.
contributing/DEVELOPING.md
Outdated
| `gulp dist`<sup>[[1]](#footnote-1)</sup> | Builds production binaries. | | ||
| `gulp dist --fortesting`<sup>[[1]](#footnote-1)</sup> | Builds production binaries for local testing. (Allows use cases like ads, tweets, etc. to work with minified sources. Overrides `TESTING_HOST` if specified. Uses the production `AMP_CONFIG` by default.) | | ||
| `gulp dist --fortesting --config=<config>`<sup>[[1]](#footnote-1)</sup> | Builds production binaries for local testing, with the specified `AMP_CONFIG`. `config` can be `prod` or `canary`. (Defaults to `prod`.) | | ||
| `gulp lint` | Validates against Google Closure Linter. | | ||
| `gulp lint --watch` | Watches for changes in files, Validates against Google Closure Linter.| | ||
| `gulp lint --fix` | Fixes simple lint warnings/errors automatically. | | ||
| `gulp build`<sup>[[1]](#footnote-1)</sup> | Builds the AMP library. | | ||
| `gulp build --extensions=<amp-foo,amp-bar>` | Builds the AMP library, with only the listed extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For easy editing, add spaces to align the |
with the line above.
gulpfile.js
Outdated
@@ -1332,14 +1348,21 @@ function toPromise(readable) { | |||
gulp.task('build', 'Builds the AMP library', ['update-packages'], build, { | |||
options: { | |||
config: ' Sets the runtime\'s AMP_CONFIG to one of "prod" or "canary"', | |||
extensions: ' Builds only the listed extensions.', | |||
noextensions: ' Builds with no extensions.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two spaces between '
and Builds
Update the PR title to indicate the new name of the flag |
8090022
to
f50c835
Compare
f50c835
to
c32acc7
Compare
* add --extension flag to only build some extensions * address comment * fix * nit
* add --extension flag to only build some extensions * address comment * fix * nit
* add --extension flag to only build some extensions * address comment * fix * nit
The build time for local testing is getting so long with all these new extensions.
I can't find a way to not build unrelated extensions to my change. Right now I would simply comment out extensions I don't want every time I start the gulp server.
The idea is to introduce a new flag
--extension
and only build listed extensions.For example
gulp --extension=amp-ad,amp-anim
will only build amp-ad and amp-anim extension.I tested the server only with the
gulp default
command, please let me know if I miss anything : )Also I am thinking of the name
--only
vs--extension
. Since we already have--extensions
, might be confusing. Let me know, thanks!