Skip to content

Commit 7e6b785

Browse files
authored
Support features on the command line (#149)
* 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)
1 parent 3213b6b commit 7e6b785

File tree

9 files changed

+725
-299
lines changed

9 files changed

+725
-299
lines changed

package-lock.json

Lines changed: 672 additions & 291 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
},
100100
"dependencies": {
101101
"@dojo/framework": "~3.0.0",
102-
"@dojo/webpack-contrib": "~3.0.1",
102+
"@dojo/webpack-contrib": "4.0.0-alpha.1",
103103
"brotli-webpack-plugin": "0.5.0",
104104
"chalk": "2.4.1",
105105
"clean-webpack-plugin": "0.1.17",

src/main.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,38 @@ const command: Command = {
202202
default: false,
203203
type: 'boolean'
204204
});
205+
206+
options('feature', {
207+
describe: 'List of features to include',
208+
alias: 'f',
209+
array: true,
210+
coerce: (args: string[]) => {
211+
return args.reduce(
212+
(newArgs, arg) => {
213+
const parts = arg.split('=');
214+
if (parts.length === 1) {
215+
newArgs[arg] = true;
216+
} else if (parts.length === 2) {
217+
newArgs[parts[0]] = parts[1];
218+
}
219+
return newArgs;
220+
},
221+
{} as any
222+
);
223+
}
224+
});
205225
},
206226
run(helper: Helper, args: any) {
207227
console.log = () => {};
208-
const rc = helper.configuration.get() || {};
209228
let config: webpack.Configuration;
229+
let { feature, ...remainingArgs } = args;
230+
remainingArgs = { ...remainingArgs, features: { ...remainingArgs.features, ...feature } };
210231
if (args.mode === 'dev') {
211-
config = devConfigFactory({ ...rc, ...args });
232+
config = devConfigFactory(remainingArgs);
212233
} else if (args.mode === 'test') {
213-
config = testConfigFactory({ ...rc, ...args });
234+
config = testConfigFactory(remainingArgs);
214235
} else {
215-
config = distConfigFactory({ ...rc, ...args });
236+
config = distConfigFactory(remainingArgs);
216237
}
217238

218239
if (args.serve) {

test-app/.dojorc-app

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"locale": "en",
55
"supportedLocales": [ "es" ],
66
"features": {
7+
"env": "ci",
78
"foo": true,
89
"bar": false
910
},

test-app/.dojorc-pwa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"locale": "en",
44
"supportedLocales": [ "es" ],
55
"features": {
6+
"env": "ci",
67
"foo": true,
78
"bar": false
89
},

test-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"install-build-app": "npm install --no-save ../dist/dojo-cli-build-app.tgz",
8-
"build:dist": "dojo build --mode dist --legacy",
8+
"build:dist": "dojo build --mode dist --legacy --feature env=prod",
99
"build:dev": "dojo build --mode dev --legacy",
10-
"build:dist:evergreen": "dojo build --mode dist",
10+
"build:dist:evergreen": "dojo build --mode dist --feature env=prod",
1111
"build:dev:evergreen": "dojo build --mode dev",
1212
"build:test": "dojo build --mode test"
1313
},

test-app/src/main.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (has('foo')) {
1212

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

15-
App().then(result => {
15+
App().then((result) => {
1616
console.log(result());
1717
console.log(require('foo/bar'));
1818
});
@@ -29,6 +29,14 @@ if (process.env.NODE_ENV === 'production') {
2929
div.setAttribute('nodeenv', 'production');
3030
}
3131

32+
if (has('env') === 'prod') {
33+
div.setAttribute('has-prod', 'prod');
34+
}
35+
36+
if (has('env') === 'ci') {
37+
div.setAttribute('has-ci', 'ci');
38+
}
39+
3240
div.textContent = `Built with Build Time Render: ${!!div.getAttribute('hasBtr')}
3341
Currently Rendered by BTR: ${has('build-time-render')}`;
3442

tests/integration/build.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Currently Rendered by BTR: false`
99
cy.get('script[src^="lazy"]').should('exist');
1010
cy.get('script[src^="src/Foo"]').should('exist');
1111
cy.get('#div[nodeenv=production]').should(isDist ? 'exist' : 'not.exist');
12+
cy.get('#div[has-prod=prod]').should(isDist ? 'exist' : 'not.exist');
13+
cy.get('#div[has-ci=ci]').should(isDist ? 'not.exist' : 'exist');
1214

1315
cy.get('meta[name="mobile-web-app-capable"]').should(isPwa ? 'exist' : 'not.exist');
1416
cy.get('meta[name="apple-mobile-web-app-capable"]').should(isPwa ? 'exist' : 'not.exist');

tests/unit/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ describe('command', () => {
133133
});
134134
});
135135

136+
it('mixes in features from command line', () => {
137+
const main = mockModule.getModuleUnderTest().default;
138+
return main
139+
.run(getMockConfiguration(), { mode: 'dist', feature: { foo: true }, features: { foo: false, bar: false } })
140+
.then(() => {
141+
assert.isTrue(mockDistConfig.called);
142+
assert.deepEqual(mockDistConfig.firstCall.args, [
143+
{ mode: 'dist', features: { foo: true, bar: false } }
144+
]);
145+
});
146+
});
147+
136148
it('rejects if an error occurs', () => {
137149
isError = true;
138150
const main = mockModule.getModuleUnderTest().default;

0 commit comments

Comments
 (0)