Skip to content
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

Merged
merged 4 commits into from
Feb 2, 2018

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Feb 1, 2018

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!

@zhouyx zhouyx changed the title add --extension flag to only build some extensions Enable --extension flag to only build some extensions Feb 1, 2018
Copy link
Contributor

@rsimha rsimha left a 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;
}
}
Copy link
Contributor

@rsimha rsimha Feb 1, 2018

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);
}

Copy link
Contributor

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));
  }

Copy link
Contributor

@rsimha rsimha Feb 1, 2018

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@zhouyx
Copy link
Contributor Author

zhouyx commented Feb 2, 2018

@rsimha-amp Thanks for the comments! I've addressed them and added documentation.

Copy link
Contributor

@rsimha rsimha left a 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.

@@ -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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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.
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

| `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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

| `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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

| `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. |
Copy link
Contributor

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

Copy link
Contributor Author

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 = [];
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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();

Copy link
Contributor Author

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;
}
}
Copy link
Contributor

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: {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@rsimha rsimha left a 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 :)

@@ -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.
Copy link
Contributor

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.

@@ -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.
Copy link
Contributor

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.

| `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.
Copy link
Contributor

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.',
Copy link
Contributor

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

@rsimha
Copy link
Contributor

rsimha commented Feb 2, 2018

Update the PR title to indicate the new name of the flag --extensions.

@zhouyx zhouyx changed the title Enable --extension flag to only build some extensions Add --extensions flag to only build listed extensions Feb 2, 2018
@zhouyx zhouyx merged commit 60c7428 into ampproject:master Feb 2, 2018
protonate pushed a commit to protonate/amphtml that referenced this pull request Feb 26, 2018
* add --extension flag to only build some extensions

* address comment

* fix

* nit
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* add --extension flag to only build some extensions

* address comment

* fix

* nit
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
* add --extension flag to only build some extensions

* address comment

* fix

* nit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants