Skip to content

Commit

Permalink
Add Embroider support
Browse files Browse the repository at this point in the history
  • Loading branch information
bobisjan committed Aug 30, 2021
1 parent 34b11fb commit c62cf1a
Show file tree
Hide file tree
Showing 19 changed files with 201 additions and 47 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ module.exports = {
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
rules: {
'node/no-missing-require': [
'error',
{
allowModules: ['ember-web-app'],
},
],
},
},
// mocha files
{
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
lint:
name: Linting
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v1
Expand All @@ -23,6 +24,7 @@ jobs:
test-ember:
name: Tests / Ember
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v1
Expand All @@ -34,6 +36,7 @@ jobs:
test-node:
name: Tests / Node
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v1
Expand All @@ -49,6 +52,7 @@ jobs:
test-float:
name: Tests / floating dependencies
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v1
Expand All @@ -61,17 +65,20 @@ jobs:
name: Tests / ${{ matrix.ember-try-scenario }}
runs-on: ubuntu-latest
needs: [lint, test-ember]
timeout-minutes: 10

strategy:
matrix:
ember-try-scenario:
- ember-lts-3.16
- ember-lts-3.20
- ember-release
- ember-beta
- ember-canary
# - ember-beta
# - ember-canary
- ember-default-with-jquery
- ember-classic
- embroider-safe
# - embroider-optimized

steps:
- uses: actions/checkout@v1
Expand Down
26 changes: 24 additions & 2 deletions blueprints/ember-web-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { EOL } = require('os');
const path = require('path');
const Manifest = require('../../lib/manifest');
const Browserconfig = require('../../lib/browserconfig');
const pkg = require('../../index');

module.exports = {
description: 'Generates a configuration for web app manifest.',
Expand All @@ -29,11 +30,32 @@ module.exports = {
};
},

afterInstall() {
async afterInstall() {
await Promise.all([
this._insertIntoAppIndexHTML(),
this._insertIntoEmberCLIBuildJS(),
]);
},

async _insertIntoAppIndexHTML() {
let index = path.join('app', 'index.html');
let content = `${EOL} ${Manifest.tag}${EOL} ${Browserconfig.tag}`;
let after = `{{content-for "head"}}${EOL}`;

return this.insertIntoFile(index, content, { after });
await this.insertIntoFile(index, content, { after });
},

async _insertIntoEmberCLIBuildJS() {
await this.insertIntoFile(
'ember-cli-build.js',
`const { treeForManifest } = require('${pkg.name}');`,
{
after: `const EmberApp = require('ember-cli/lib/broccoli/ember-app');${EOL}`,
}
);

await this.insertIntoFile('ember-cli-build.js', '[treeForManifest(app)]', {
after: 'app.toTree(',
});
},
};
3 changes: 3 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');

module.exports = async function () {
return {
Expand Down Expand Up @@ -74,6 +75,8 @@ module.exports = async function () {
},
},
},
embroiderSafe(),
embroiderOptimized(),
],
};
};
6 changes: 5 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const { maybeEmbroider } = require('@embroider/test-setup');
const { treeForManifest } = require('./index');

module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
Expand All @@ -14,5 +16,7 @@ module.exports = function (defaults) {
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
return maybeEmbroider(app, {
extraPublicTrees: [treeForManifest(app)],
});
};
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const BroccoliMergeTrees = require('broccoli-merge-trees');
const Manifest = require('./lib/manifest');
const Browserconfig = require('./lib/browserconfig');
const tags = require('./lib/tags');
const pkg = require('./package');

module.exports = {
name: require('./package').name,
name: pkg.name,

shouldIncludeChildAddon(childAddon) {
if (childAddon.name === 'broccoli-asset-rev') {
Expand All @@ -15,8 +16,7 @@ module.exports = {
return this._super.shouldIncludeChildAddon.apply(this, arguments);
},

included(app) {
this.app = app;
_treeForManifest(app) {
app.options = app.options || {};
app.options[this.name] = app.options[this.name] || {};

Expand All @@ -26,19 +26,19 @@ module.exports = {
this.manifest.configureFingerprint();
this.browserconfig.configureFingerprint();

this._super.included.apply(this, arguments);
},

treeForPublic() {
let manifest = this.manifest.toTree();
let browserconfig = this.browserconfig.toTree();

return new BroccoliMergeTrees([manifest, browserconfig]);
return new BroccoliMergeTrees([
this.manifest.toTree(),
this.browserconfig.toTree(),
]);
},

contentFor(section) {
if (section === 'head') {
if (this.manifest && section === 'head') {
return tags(this.manifest.configuration);
}
},
};

module.exports.treeForManifest = function treeForManifest(app) {
return app.project.findAddonByName(pkg.name)._treeForManifest(app);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let options = {
Expand All @@ -10,5 +11,5 @@ module.exports = function (defaults) {

let app = new EmberApp(defaults, options);

return app.toTree();
return app.toTree([treeForManifest(app)]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults);

return app.toTree([treeForManifest(app)]);
};
8 changes: 8 additions & 0 deletions node-tests/acceptance/fixtures/dummy/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults);

return app.toTree([treeForManifest(app)]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults);

return app.toTree([treeForManifest(app)]);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function (defaults) {
let options = {
Expand All @@ -9,5 +10,5 @@ module.exports = function (defaults) {

let app = new EmberApp(defaults, options);

return app.toTree();
return app.toTree([treeForManifest(app)]);
};
21 changes: 9 additions & 12 deletions node-tests/blueprints/ember-web-app-test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
'use strict';
const { EOL } = require('os');
const { expect } = require('ember-cli-blueprint-test-helpers/chai');

const {
setupTestHooks,
emberNew,
emberGenerate,
emberGenerateDestroy,
emberDestroy,
} = require('ember-cli-blueprint-test-helpers/helpers');

describe('Blueprints', function () {
setupTestHooks(this);

describe('ember generate', function () {
it('generates config/manifest.js file', function () {
it('generates files', function () {
let args = ['ember-web-app', 'foo'];

return emberNew().then(() =>
emberGenerateDestroy(args, (file) => {
emberGenerate(args, (file) => {
expect(file('config/manifest.js'))
.to.contain('name: "my-app"')
.to.contain('short_name: "my-app"')
.to.contain('display: "standalone"');
})
);
});

it('adds manifest link & browserconfig meta into app/index.html file', function () {
let args = ['ember-web-app', 'foo'];

return emberNew().then(() =>
emberGenerate(args, (file) => {
expect(file('app/index.html'))
.to.contain(
'<link rel="manifest" src="{{rootURL}}manifest.webmanifest">'
'<link rel="manifest" href="{{rootURL}}manifest.webmanifest">'
)
.to.contain(
'<meta name="msapplication-config" content="{{rootURL}}browserconfig.xml">'
);

expect(file('ember-cli-build.js'))
.to.contain(`const { treeForManifest } = require('ember-web-app');`)
.to.contain(`return app.toTree([treeForManifest(app)]${EOL});`);
}).then(() => emberDestroy(args))
);
});
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"release": "release-it",
"changelog": "lerna-changelog",
"fast-test": "SKIP_ACCEPTANCE=true yarn node-test",
"node-test": "nyc --reporter=lcov mocha --recursive node-tests",
"node-test": "nyc --reporter=lcov mocha --recursive node-tests/**/*-test.js",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint . --cache",
Expand All @@ -47,6 +47,7 @@
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.4.2",
"@embroider/test-setup": "^0.43.5",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"babel-eslint": "^10.1.0",
Expand Down Expand Up @@ -117,4 +118,4 @@
"node": "12.22.1",
"yarn": "1.22.10"
}
}
}
9 changes: 5 additions & 4 deletions tests/dummy/app/templates/docs/advanced/fingerprinting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ The following example prepends with a custom domain and adds fingerprint checksu
```javascript
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const broccoliAssetRevDefaults = require('broccoli-asset-rev/lib/default-options');
const { treeForManifest } = require('ember-web-app');
const { extensions } = require('broccoli-asset-rev/lib/default-options');

module.exports = function(defaults) {
module.exports = function (defaults) {
let options = {
fingerprint: {
extensions: broccoliAssetRevDefaults.extensions.concat(['webmanifest']),
extensions: [...extensions, 'webmanifest'],
prepend: 'https://www.example.com/',
},
};

let app = new EmberApp(defaults, options);

return app.toTree();
return app.toTree([treeForManifest(app)]);
};
```

Expand Down
10 changes: 6 additions & 4 deletions tests/dummy/app/templates/docs/advanced/generating-icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ If your `config/manifest.js` looks like this and needs a `192px` and a `512px` i
```javascript
'use strict';

module.exports = function() {
module.exports = function () {
return {
icons: [
{
src: '/assets/icons/appicon-32.png',
sizes: '32x32',
targets: ['favicon'],
},
...[192, 280, 512].map(size => ({
...[192, 280, 512].map((size) => ({
src: `/assets/icons/appicon-${size}.png`,
sizes: `${size}x${size}`,
})),
Expand All @@ -28,8 +28,10 @@ You can start with a base `brand-icon.svg` image and automatically build the `19

```javascript
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { treeForManifest } = require('ember-web-app');

module.exports = function(defaults) {
module.exports = function (defaults) {
let options = {
'ember-cli-image-transformer': {
images: [
Expand All @@ -46,6 +48,6 @@ module.exports = function(defaults) {

let app = new EmberApp(defaults, options);

return app.toTree();
return app.toTree([treeForManifest(app)]);
};
```
Loading

0 comments on commit c62cf1a

Please sign in to comment.