Skip to content

Commit

Permalink
Add --auto-base-path flag to build (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
keanulee authored and aomarks committed Apr 20, 2018
1 parent 9963de9 commit f14de16
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Unreleased
* `build`:
* Disable Babel `minify-constant-folding` plugin when minifying. This plugin has a bug that breaks when a constant is exported from a module (https://github.com/babel/minify/issues/820).
* Added `--auto-base-path` flag. Sets the entrypoint `<base>` tag for all builds to match the name of that build. Unlike other flags, does not necessarily trigger a single one-off build.
<!-- Add new, unreleased items here. -->

## v1.7.0-pre.13 [04-19-2018]
Expand Down
33 changes: 28 additions & 5 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import {Command, CommandOptions} from './command';

const logger = logging.getLogger('cli.command.build');

// This flag is special because it doesn't necessarily trigger a one-off single
// build.
const autoBasePath = 'auto-base-path';

export class BuildCommand implements Command {
name = 'build';
aliases = [];
Expand Down Expand Up @@ -123,6 +127,12 @@ export class BuildCommand implements Command {
type: String,
description: 'Updates the <base> tag if found in the entrypoint document.'
},
{
name: autoBasePath,
type: Boolean,
description: 'For all builds, set the entrypoint <base> tag to match ' +
'the build name. Does not necessarily trigger a one-off build.',
},
];

/**
Expand All @@ -133,6 +143,10 @@ export class BuildCommand implements Command {
ProjectBuildOptions {
const buildOptions: ProjectBuildOptions = {};
const validBuildOptions = new Set(this.args.map(({name}) => name));

// This flag is special. It affects the top-level config, not an individual build.
validBuildOptions.delete(autoBasePath);

for (const buildOption of Object.keys(options)) {
if (validBuildOptions.has(buildOption)) {
const [prefix, ...rest] = buildOption.split('-');
Expand All @@ -150,6 +164,9 @@ export class BuildCommand implements Command {
}
}
}
if (options[autoBasePath]) {
buildOptions.basePath = true;
}
return applyBuildPreset(buildOptions);
}

Expand Down Expand Up @@ -181,18 +198,24 @@ export class BuildCommand implements Command {

// If any the build command flags were passed as CLI arguments, generate
// a single build based on those flags alone.
const hasCliArgumentsPassed =
this.args.some((arg) => typeof options[arg.name] !== 'undefined');
if (hasCliArgumentsPassed) {
const hasOneOffBuildArgumentPassed = this.args.some((arg) => {
return typeof options[arg.name] !== 'undefined' &&
arg.name !== autoBasePath;
});
if (hasOneOffBuildArgumentPassed) {
await build(this.commandOptionsToBuildOptions(options), polymerProject);
return;
}

// If no build flags were passed but 1+ polymer.json build configuration(s)
// exist, generate a build for each configuration found.
if (config.builds) {
const promises = config.builds.map(
(buildOptions) => build(buildOptions, polymerProject));
const promises = config.builds.map((buildOptions) => {
if (options[autoBasePath]) {
buildOptions.basePath = true;
}
return build(buildOptions, polymerProject);
});
promises.push(mzfs.writeFile(
path.join(mainBuildDirectoryName, 'polymer.json'), config.toJSON()));
await Promise.all(promises);
Expand Down

0 comments on commit f14de16

Please sign in to comment.