Skip to content

Commit

Permalink
Support features on the command line (#149)
Browse files Browse the repository at this point in the history
* Support features on the command line

* Add test for the command line features

* Add ci to dojorc and override using features

* Upgrade to webpack contrib next (4.0.0-alpha.1)
  • Loading branch information
agubler authored Aug 29, 2018
1 parent 3213b6b commit 7e6b785
Show file tree
Hide file tree
Showing 9 changed files with 725 additions and 299 deletions.
963 changes: 672 additions & 291 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
"dependencies": {
"@dojo/framework": "~3.0.0",
"@dojo/webpack-contrib": "~3.0.1",
"@dojo/webpack-contrib": "4.0.0-alpha.1",
"brotli-webpack-plugin": "0.5.0",
"chalk": "2.4.1",
"clean-webpack-plugin": "0.1.17",
Expand Down
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
1 change: 1 addition & 0 deletions test-app/.dojorc-app
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"locale": "en",
"supportedLocales": [ "es" ],
"features": {
"env": "ci",
"foo": true,
"bar": false
},
Expand Down
1 change: 1 addition & 0 deletions test-app/.dojorc-pwa
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"locale": "en",
"supportedLocales": [ "es" ],
"features": {
"env": "ci",
"foo": true,
"bar": false
},
Expand Down
4 changes: 2 additions & 2 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"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:dist": "dojo build --mode dist --legacy --feature env=prod",
"build:dev": "dojo build --mode dev --legacy",
"build:dist:evergreen": "dojo build --mode dist",
"build:dist:evergreen": "dojo build --mode dist --feature env=prod",
"build:dev:evergreen": "dojo build --mode dev",
"build:test": "dojo build --mode test"
},
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

0 comments on commit 7e6b785

Please sign in to comment.