Skip to content

Commit

Permalink
Merge pull request #107 from BBVAEngineering/feature/shrink-config-en…
Browse files Browse the repository at this point in the history
…vironment

Feature/shrink config environment
  • Loading branch information
josex2r authored Jun 8, 2021
2 parents ba9de62 + b4ad1aa commit 8d26774
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ const app = new EmberAddon(defaults, {

You can further customize ember-cli-workbox by setting **workbox configurations** in your `config/environment.js` on in your `ember-cli-build.js`

*Note*: `importScriptsTransform` must be defined in your `ember-cli-build.js`.
*Note*: `importScriptsTransform` and `workbox` must be defined in your `ember-cli-build.js`.

```javascript
//app/config/environment.js
//ember-cli-build.js

ENV['workbox'] = {
globPatterns: [
'**\/*.{html,js,css}'
],
const app = new EmberAddon(defaults, {
workbox: {
globPatterns: [
'**\/*.{html,js,css}'
],

globDirectory: './',
globDirectory: './',

globIgnores: [],
// ...
};
globIgnores: [],
// ...
}
});
```

| Property | Description |
Expand Down
2 changes: 1 addition & 1 deletion addon/instance-initializers/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getConfig(appInstance) {
return {
isEnabled: getWithDefault(config, 'ember-cli-workbox.enabled', isProdBuild),
debugAddon: getWithDefault(config, 'ember-cli-workbox.debug', !isProdBuild),
swDestFile: getWithDefault(config, 'workbox.swDest', 'sw.js'),
swDestFile: getWithDefault(config, 'ember-cli-workbox.swDest', 'sw.js'),
autoRegister: getWithDefault(config, 'ember-cli-workbox.autoRegister', true)
};
}
Expand Down
6 changes: 5 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
const app = new EmberAddon(defaults, {});
const app = new EmberAddon(defaults, {
workbox: {
swDest: 'sw.js'
}
});

// Use `app.import` to add additional libraries to the generated
// output files.
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = {
isDevelopingAddon: () => true,

config(env, baseConfig) {
const workboxOptions = baseConfig.workbox || {};
const options = baseConfig['ember-cli-workbox'] || {};
const workboxOptions = this.app.options.workbox || {};
const emberCliWorkboxOptions = baseConfig['ember-cli-workbox'];
const options = emberCliWorkboxOptions || {};
const appOptions = this.app.options['ember-cli-workbox'] || {};
const projectName = baseConfig.APP && baseConfig.APP.name || 'app';

Expand Down Expand Up @@ -43,6 +44,11 @@ module.exports = {

this._options = options;
this.workboxOptions = workboxOptions;

// Append "workbox" config to "ember-cli-workbox" config
if (emberCliWorkboxOptions) {
emberCliWorkboxOptions.swDest = workboxOptions.swDest;
}
},

postprocessTree(type, tree) {
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/configuration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';

module('Acceptance | Simple Acceptance Test', (hooks) => {
setupApplicationTest(hooks);

test('"workbox" configuration is not in environment config', async function(assert) {
const config = this.owner.resolveRegistration('config:environment');

assert.notOk(config.workbox);
});

test('"workbox" configuration is setted in "ember-cli-workbox" config object', async function(assert) {
const config = this.owner.resolveRegistration('config:environment');

assert.equal(config['ember-cli-workbox'].swDest, 'sw.js');
});
});

3 changes: 0 additions & 3 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module.exports = function(environment) {
'ember-cli-workbox': {
enabled: true
},
workbox: {
swDest: 'sw.js'
},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
Expand Down

0 comments on commit 8d26774

Please sign in to comment.