Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit de8a8b2

Browse files
authored
Merge pull request #59 from san650/broccoli-asset-rev
Improve compatibility with broccoli-asset-rev addon
2 parents c57670f + 0ac328a commit de8a8b2

File tree

18 files changed

+101
-113
lines changed

18 files changed

+101
-113
lines changed

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ See the [documentation](#documentation) section below for more information.
3030
* [Installation](#installation)
3131
* [Example](#example)
3232
* [Configuration](#configuration)
33+
* [Disable](#disable)
34+
* [Fingerprint](#fingerprint)
3335
* [API documentation](#api-documentation)
3436
* [`name`](#name)
3537
* [`short_name`](#short_name)
@@ -107,7 +109,7 @@ It will generate the following meta tags
107109
`index.html`
108110

109111
```html
110-
<link rel="manifest" href="/manifest.json">
112+
<link rel="manifest" href="/manifest.webmanifest">
111113
<link rel="apple-touch-icon" href="/images/icons/android-chrome-192x192-883114367f2d72fc9a509409454a1e73.png" sizes="192x192">
112114
<link rel="apple-touch-icon" href="/images/icons/android-chrome-512x512-af3d768ff652dc2be589a3c22c6dc827.png" sizes="512x512">
113115
<link rel="apple-touch-icon" href="/images/icons/apple-touch-icon-36cba25bc155e8ba414265f9d85861ca.png" sizes="180x180">
@@ -117,7 +119,7 @@ It will generate the following meta tags
117119
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
118120
```
119121

120-
and the following `manifest.json` file
122+
and the following `manifest.webmanifest` file
121123

122124
```json
123125
{
@@ -145,38 +147,43 @@ and the following `manifest.json` file
145147

146148
## Configuration
147149

148-
### Manifest name
150+
### Disable
149151

150-
You can set the name of the manifest by adding a configuation option to `config/environment.js`.
152+
You can disable the addon by adding a configuration option to `ember-cli-build.js` build file.
151153

152154
```js
153-
module.exports = function(environment) {
154-
var ENV = {
155-
modulePrefix: 'dummy',
156-
environment: environment,
157-
rootURL: '/'
158-
...
159-
};
155+
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
160156

161-
ENV['ember-web-app'] = {
162-
name: 'my-awesome-manifest.json'
157+
module.exports = function(defaults) {
158+
var options = {
159+
'ember-web-app': {
160+
enabled: false
161+
}
163162
};
164163

165-
return ENV;
164+
var app = new EmberApp(defaults, options);
165+
166+
return app.toTree();
166167
};
167168
```
168169

169-
### Disable
170+
### Fingerprint
170171

171-
You can disable the addon by adding a configuration option to `ember-cli-build.js` build file.
172+
You can add fingerprint checksum to your manifest.webmanifest file by configuring [broccoli-asset-rev](https://github.com/rickharrison/broccoli-asset-rev).
173+
174+
The following example prepends with a custom domain and adds fingerprint checksum to the manifest.webmanifest file.
175+
176+
`ember-cli-build.js`
172177

173178
```js
174179
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
175180

176181
module.exports = function(defaults) {
182+
var defaultExtensions = ['js', 'css', 'png', 'jpg', 'gif', 'map'];
177183
var options = {
178-
'ember-web-app': {
179-
enabled: false
184+
fingerprint: {
185+
extensions: defaultExtensions.concat(['webmanifest']),
186+
prepend: 'https://www.example.com/'
180187
}
181188
};
182189

@@ -186,6 +193,8 @@ module.exports = function(defaults) {
186193
};
187194
```
188195

196+
Note that the `replaceExtensions` configuration from `broccoli-asset-rev` is updated internally by `ember-web-app` so you don't have to configure yourself on your project.
197+
189198
## API documentation
190199

191200
This Ember addon generates a [Web Application Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) at build time using the `config/manifest.js` configuration file.

blueprints/ember-web-app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ module.exports = {
1111
},
1212

1313
afterInstall: function() {
14-
return this.addPackageToProject('ember-web-app-rename', '^1.0.0');
14+
return this.removePackageFromProject('ember-web-app-rename');
1515
}
1616
};

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* eslint-env node */
22
'use strict';
33

4-
var constants = require('./lib/constants');
5-
var MANIFEST_TEMP_NAME = constants.MANIFEST_TEMP_NAME;
6-
var MANIFEST_NAME = constants.MANIFEST_NAME;
4+
var MANIFEST_NAME = "manifest.webmanifest";
75

86
module.exports = {
97
name: 'ember-web-app',
@@ -50,7 +48,7 @@ module.exports = {
5048

5149
var GenerateManifest = require('./lib/broccoli/generate-manifest-json');
5250

53-
return new GenerateManifest(generateManifestFromConfiguration(this.manifestConfiguration), MANIFEST_TEMP_NAME);
51+
return new GenerateManifest(generateManifestFromConfiguration(this.manifestConfiguration), MANIFEST_NAME);
5452
},
5553

5654
contentFor: function(section, config) {
@@ -74,7 +72,7 @@ module.exports = {
7472

7573
_configureFingerprint: function() {
7674
var configureFingerprint = require('./lib/configure-fingerprint');
77-
this.app.options.fingerprint = configureFingerprint(this.app.options.fingerprint, MANIFEST_TEMP_NAME);
75+
this.app.options.fingerprint = configureFingerprint(this.app.options.fingerprint, MANIFEST_NAME);
7876
},
7977

8078
_getManifestConfiguration: function() {

lib/android-link-tags.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
module.exports = androidLinkTags;
44

55
function androidLinkTags(config, manifestName) {
6-
var name = (config['ember-web-app'] && config['ember-web-app'].name) || manifestName;
6+
var resolveURL = require('./resolve-url');
77
var rootURL = config.rootURL || '/';
8+
var url = resolveURL(rootURL, manifestName);
89

910
return [
10-
`<link rel="manifest" href="${rootURL}${name}">`
11+
`<link rel="manifest" href="${url}">`
1112
];
1213
}

lib/broccoli/generate-manifest-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GenerateManifest.prototype.constructor = GenerateManifest;
1111
function GenerateManifest(manifest, manifestName) {
1212
// We don't need any input node
1313
Plugin.call(this, [], {
14-
annotation: 'generate manifest.json',
14+
annotation: 'generate manifest.webmanifest',
1515
persistentOutput: true
1616
});
1717

lib/configure-fingerprint.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ function configureFingerprint(currentOptions, manifestName) {
1717
}
1818
}
1919

20-
var exclude = fingerprint.exclude || defaultOptions.exclude;
21-
fingerprint.exclude = exclude.concat([manifestName]);
22-
2320
var replaceExtensions = fingerprint.replaceExtensions || defaultOptions.replaceExtensions;
2421
fingerprint.replaceExtensions = replaceExtensions.concat([manifestName.match(/\.(.*$)/)[1]]);
2522

lib/constants.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*jshint node:true*/
2+
'use strict';
3+
4+
module.exports = function() {
5+
return {
6+
icons: [
7+
{
8+
src: 'pio.png'
9+
}
10+
]
11+
};
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* global require, module */
2+
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
3+
4+
module.exports = function(defaults) {
5+
var options = {
6+
fingerprint: {
7+
extensions: ['png', 'webmanifest'],
8+
prepend: 'https://www.example.com/'
9+
}
10+
};
11+
12+
var app = new EmberApp(defaults, options);
13+
14+
return app.toTree();
15+
};
Loading

node-tests/acceptance/fixtures/config-name/config/environment.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

node-tests/acceptance/fixtures/config-name/config/manifest.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

node-tests/acceptance/manifest-test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ describe('Acceptance: manifest file generation', function() {
1717
app = new AddonTestApp();
1818
});
1919

20-
it('generates a manifest.json file', function() {
20+
it('generates a manifest.webmanifest file', function() {
2121
return app
2222
.create('empty', {
2323
fixturesPath: 'node-tests/acceptance/fixtures',
2424
})
2525
.then(function() {
2626
return app.runEmberCommand('build')
2727
})
28-
.then(contentOf(app, 'dist/manifest.json'))
28+
.then(contentOf(app, 'dist/manifest.webmanifest'))
2929
.then(assertJSON(app, {
3030
name: 'empty',
3131
short_name: 'empty',
@@ -47,61 +47,62 @@ describe('Acceptance: manifest file generation', function() {
4747
.then(function() {
4848
return app.runEmberCommand('build', '--prod')
4949
})
50-
.then(contentOf(app, 'dist/manifest.json'))
50+
.then(contentOf(app, 'dist/manifest.webmanifest'))
5151
.then(assertJSON(app, {
5252
icons: [ { src: "pio-8911090226e7b5522790f1218f6924a5.png" } ]
5353
}))
5454
.then(contentOf(app, 'dist/fastbootAssetMap.json'))
5555
.then(assertJSON(app, { "pio.png": "pio-0987654321.png" }));
5656
});
5757

58-
it('renames manifest.json', function() {
58+
it('doesn\'t generate the manifest.webmanifest', function() {
5959
return app
60-
.create('config-name', {
60+
.create('disabled', {
6161
fixturesPath: 'node-tests/acceptance/fixtures',
6262
})
6363
.then(function() {
6464
return app.runEmberCommand('build')
6565
})
66-
.then(contentOf(app, 'dist/my-awesome-manifest.json'))
67-
.then(assertJSON(app, {
68-
name: 'foo'
69-
}))
66+
.then(function() {
67+
assert.ok(!fs.existsSync(app.filePath('dist/manifest.webmanifest')), 'Doesn\'t generate manifest.webmanifest file');
68+
})
7069
.then(contentOf(app, 'dist/index.html'))
7170
.then(function(content) {
72-
assert.ok(content.indexOf('href="/my-awesome-manifest.json"') > -1, 'index.html uses name from configuration');
71+
assert.ok(!content.includes('apple-touch-icon'), 'Doesn\'t include meta tags');
7372
});
7473
});
7574

76-
it('doesn\'t generate the manifest.json', function() {
75+
it('uses rootURL configuration', function() {
7776
return app
78-
.create('disabled', {
77+
.create('config-root-url', {
7978
fixturesPath: 'node-tests/acceptance/fixtures',
8079
})
8180
.then(function() {
8281
return app.runEmberCommand('build')
8382
})
84-
.then(function() {
85-
assert.ok(!fs.existsSync(app.filePath('dist/manifest.json')), 'Doesn\'t generate manifest.json file');
86-
})
8783
.then(contentOf(app, 'dist/index.html'))
8884
.then(function(content) {
89-
assert.ok(!content.includes('apple-touch-icon'), 'Doesn\'t include meta tags');
85+
assert.ok(content.indexOf('href="/foo/bar/baz/manifest.webmanifest"') > -1, 'index.html uses rootURL from configuration');
9086
});
9187
});
9288

93-
it('uses rootURL configuration', function() {
89+
it('uses fingerprint configuration for manifest', function() {
9490
return app
95-
.create('config-root-url', {
91+
.create('broccoli-asset-rev', {
9692
fixturesPath: 'node-tests/acceptance/fixtures',
9793
})
9894
.then(function() {
99-
return app.runEmberCommand('build')
95+
return app.runEmberCommand('build', '--prod')
10096
})
10197
.then(contentOf(app, 'dist/index.html'))
10298
.then(function(content) {
103-
assert.ok(content.indexOf('href="/foo/bar/baz/manifest.json"') > -1, 'index.html uses rootURL from configuration');
104-
});
99+
assert.ok(content.indexOf('href="https://www.example.com/manifest-ce65942fa306b3b532ff17cf85454f3d.webmanifest"') > -1, 'checksum fingerprint is added to manifest.webmanifest file');
100+
assert.ok(content.indexOf('href="https://www.example.com/pio-8911090226e7b5522790f1218f6924a5.png"') > -1, 'checksum fingerprint is added to image file');
101+
})
102+
.then(contentOf(app, 'dist/manifest-ce65942fa306b3b532ff17cf85454f3d.webmanifest'))
103+
.then(assertJSON(app, {
104+
icons: [ { src: "https://www.example.com/pio-8911090226e7b5522790f1218f6924a5.png" } ]
105+
}));
105106
});
106107
});
107108

node-tests/broccoli/generate-manifest-json-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ describe('Broccoli: ProcessManifest', function() {
1212
fixturePath: __dirname,
1313

1414
subject: function() {
15-
return new GenerateManifest({ foo: 'bar', apple: 'baz', ms: 'qux' }, 'manifest.json');
15+
return new GenerateManifest({ foo: 'bar', apple: 'baz', ms: 'qux' }, 'manifest.webmanifest');
1616
},
1717
});
1818

1919
afterEach(function() {
2020
return cleanupBuilders();
2121
});
2222

23-
it('generates manifest.json file', function() {
23+
it('generates manifest.webmanifest file', function() {
2424
return GenerateManifestHelper()
2525
.then(function(result) {
26-
assert.deepEqual(result.files, ['manifest.json']);
26+
assert.deepEqual(result.files, ['manifest.webmanifest']);
2727
return path.join(result.directory, result.files[0]);
2828
})
2929
.then(readManifest)

node-tests/unit/android-link-tags-test.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('Unit: androidLinkTags()', function() {
88
var manifest = {};
99
var config = {};
1010
var expected = [
11-
'<link rel="manifest" href="/manifest.json">'
11+
'<link rel="manifest" href="/manifest.webmanifest">'
1212
];
1313

14-
assert.deepEqual(androidLinkTags(config, 'manifest.json'), expected);
14+
assert.deepEqual(androidLinkTags(config, 'manifest.webmanifest'), expected);
1515
});
1616

1717
it('uses rootURL if defined', function() {
@@ -20,24 +20,9 @@ describe('Unit: androidLinkTags()', function() {
2020
rootURL: '/foo/bar/'
2121
};
2222
var expected = [
23-
'<link rel="manifest" href="/foo/bar/manifest.json">'
23+
'<link rel="manifest" href="/foo/bar/manifest.webmanifest">'
2424
];
2525

26-
assert.deepEqual(androidLinkTags(config, 'manifest.json'), expected);
27-
});
28-
29-
it('uses name from configuration', function() {
30-
var manifest = {};
31-
var config = {
32-
rootURL: '/foo/bar/',
33-
'ember-web-app': {
34-
name: 'other-name.foo'
35-
}
36-
};
37-
var expected = [
38-
'<link rel="manifest" href="/foo/bar/other-name.foo">'
39-
];
40-
41-
assert.deepEqual(androidLinkTags(config, 'manifest.json'), expected);
26+
assert.deepEqual(androidLinkTags(config, 'manifest.webmanifest'), expected);
4227
});
4328
});

0 commit comments

Comments
 (0)