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

Support features on the command line #149

Merged
merged 4 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,38 @@ const command: Command = {
default: false,
type: 'boolean'
});

options('feature', {
describe: 'List of features to include',
alias: 'f',
array: true,
coerce: (args: string[]) => {
return args.reduce(
(newArgs, arg) => {
const parts = arg.split('=');
if (parts.length === 1) {
newArgs[arg] = true;
} else if (parts.length === 2) {
newArgs[parts[0]] = parts[1];
}
return newArgs;
},
{} as any
);
}
});
},
run(helper: Helper, args: any) {
console.log = () => {};
const rc = helper.configuration.get() || {};
let config: webpack.Configuration;
let { feature, ...remainingArgs } = args;
remainingArgs = { ...remainingArgs, features: { ...remainingArgs.features, ...feature } };
if (args.mode === 'dev') {
config = devConfigFactory({ ...rc, ...args });
config = devConfigFactory(remainingArgs);
} else if (args.mode === 'test') {
config = testConfigFactory({ ...rc, ...args });
config = testConfigFactory(remainingArgs);
} else {
config = distConfigFactory({ ...rc, ...args });
config = distConfigFactory(remainingArgs);
}

if (args.serve) {
Expand Down
8 changes: 4 additions & 4 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "index.js",
"scripts": {
"install-build-app": "npm install --no-save ../dist/dojo-cli-build-app.tgz",
"build:dist": "dojo build --mode dist --legacy",
"build:dev": "dojo build --mode dev --legacy",
"build:dist:evergreen": "dojo build --mode dist",
"build:dev:evergreen": "dojo build --mode dev",
"build:dist": "dojo build --mode dist --legacy --feature env=prod",
"build:dev": "dojo build --mode dev --legacy --feature env=ci",
"build:dist:evergreen": "dojo build --mode dist --feature env=prod",
"build:dev:evergreen": "dojo build --mode dev --feature env=ci",
"build:test": "dojo build --mode test"
},
"author": "",
Expand Down
10 changes: 9 additions & 1 deletion test-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (has('foo')) {

const btr = has('build-time-render');

App().then(result => {
App().then((result) => {
console.log(result());
console.log(require('foo/bar'));
});
Expand All @@ -29,6 +29,14 @@ if (process.env.NODE_ENV === 'production') {
div.setAttribute('nodeenv', 'production');
}

if (has('env') === 'prod') {
div.setAttribute('has-prod', 'prod');
}

if (has('env') === 'ci') {
div.setAttribute('has-ci', 'ci');
}

div.textContent = `Built with Build Time Render: ${!!div.getAttribute('hasBtr')}
Currently Rendered by BTR: ${has('build-time-render')}`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Currently Rendered by BTR: false`
cy.get('script[src^="lazy"]').should('exist');
cy.get('script[src^="src/Foo"]').should('exist');
cy.get('#div[nodeenv=production]').should(isDist ? 'exist' : 'not.exist');
cy.get('#div[has-prod=prod]').should(isDist ? 'exist' : 'not.exist');
cy.get('#div[has-ci=ci]').should(isDist ? 'not.exist' : 'exist');

cy.get('meta[name="mobile-web-app-capable"]').should(isPwa ? 'exist' : 'not.exist');
cy.get('meta[name="apple-mobile-web-app-capable"]').should(isPwa ? 'exist' : 'not.exist');
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ describe('command', () => {
});
});

it('mixes in features from command line', () => {
const main = mockModule.getModuleUnderTest().default;
return main
.run(getMockConfiguration(), { mode: 'dist', feature: { foo: true }, features: { foo: false, bar: false } })
.then(() => {
assert.isTrue(mockDistConfig.called);
assert.deepEqual(mockDistConfig.firstCall.args, [
{ mode: 'dist', features: { foo: true, bar: false } }
]);
});
});

it('rejects if an error occurs', () => {
isError = true;
const main = mockModule.getModuleUnderTest().default;
Expand Down