Skip to content

Commit

Permalink
Merge pull request #18 from trentmwillis/no-manifest
Browse files Browse the repository at this point in the history
Properly handle noManifest option
  • Loading branch information
trentmwillis authored Aug 30, 2016
2 parents 9fc77a6 + e6d24c3 commit 79438ef
Show file tree
Hide file tree
Showing 29 changed files with 253 additions and 7 deletions.
26 changes: 25 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
/* jshint node: true */
'use strict';

var Funnel = require('broccoli-funnel');

module.exports = {
name: 'ember-asset-loader'
name: 'ember-asset-loader',

/**
* If the app has specified `noManifest` to be generated, then we don't
* include the shim for the manifest and the service initializer.
*
* @override
*/
treeForApp: function() {
var tree = this._super.treeForApp.apply(this, arguments);
var app = this.app;

if (app && app.options && app.options.assetLoader && app.options.assetLoader.noManifest) {
tree = new Funnel(tree, {
exclude: [
'asset-manifest.js',
'instance-initializers/load-asset-manifest.js'
]
});
}

return tree;
}
};
12 changes: 6 additions & 6 deletions lib/manifest-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ var ManifestGenerator = Addon.extend({
postprocessTree: function(type, tree) {
if (type !== 'all') { return tree; }

var options = this.app && this.app.options && this.app.options;
var assetLoaderOptions = options.assetLoader;

var generateAssetManifest = require('./generate-asset-manifest'); // eslint-disable-line global-require
var treeWithManifest = generateAssetManifest(tree, this.manifestOptions);
var options = this.app && this.app.options;
var assetLoaderOptions = options && options.assetLoader;

if (assetLoaderOptions && assetLoaderOptions.noManifest) {
return treeWithManifest;
return tree;
}

var generateAssetManifest = require('./generate-asset-manifest'); // eslint-disable-line global-require
var treeWithManifest = generateAssetManifest(tree, this.manifestOptions);

var indexName = options.outputPaths.app.html;
var insertAssetManifest = require('./insert-asset-manifest'); // eslint-disable-line global-require
var treeWithInsertedManifest = insertAssetManifest(treeWithManifest, { indexName: indexName });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"shared"
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
empty on purpose
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty on purpose */
26 changes: 26 additions & 0 deletions node-tests/fixtures/generator-test/extra.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="dummy/config/environment" content="%7B%22modulePrefix%22%3A%22dummy%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22ember-asset-loader%22%2C%22version%22%3A%22v0.1.1%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" />

<link rel="stylesheet" href="/assets/vendor.css">
<link rel="stylesheet" href="/assets/dummy.css">

<meta name="dummy/asset-manifest" content="" />
</head>
<body>


<script src="/assets/vendor.js"></script>
<script src="/assets/dummy.js"></script>


</body>
</html>
26 changes: 26 additions & 0 deletions node-tests/fixtures/generator-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="dummy/config/environment" content="%7B%22modulePrefix%22%3A%22dummy%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22ember-asset-loader%22%2C%22version%22%3A%22v0.1.1%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" />

<link rel="stylesheet" href="/assets/vendor.css">
<link rel="stylesheet" href="/assets/dummy.css">

<meta name="dummy/asset-manifest" content="" />
</head>
<body>


<script src="/assets/vendor.js"></script>
<script src="/assets/dummy.js"></script>


</body>
</html>
40 changes: 40 additions & 0 deletions node-tests/fixtures/generator-test/tests/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="dummy/config/environment" content="%7B%22modulePrefix%22%3A%22dummy%22%2C%22environment%22%3A%22test%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22none%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%7D%2C%22APP%22%3A%7B%22LOG_ACTIVE_GENERATION%22%3Afalse%2C%22LOG_VIEW_LOOKUPS%22%3Afalse%2C%22rootElement%22%3A%22%23ember-testing%22%2C%22name%22%3A%22ember-asset-loader%22%2C%22version%22%3A%22v0.1.1%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" />


<link rel="stylesheet" href="/assets/vendor.css">
<link rel="stylesheet" href="/assets/dummy.css">
<link rel="stylesheet" href="/assets/test-support.css">

<meta name="dummy/asset-manifest" content="" />

</head>
<body>

<div id="qunit"></div>
<div id="qunit-fixture"></div>

<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>


<script src="/testem.js" integrity=""></script>
<script src="/assets/vendor.js"></script>
<script src="/assets/test-support.js"></script>
<script src="/assets/dummy.js"></script>
<script src="/assets/tests.js"></script>


<script>Ember.assert('The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js".', EmberENV.TESTS_FILE_LOADED);</script>
</body>
</html>
106 changes: 106 additions & 0 deletions node-tests/manifest-generator-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
var path = require('path');
var assert = require('assert');
var walk = require('walk-sync');
var broccoli = require('broccoli');
var fs = require('fs-extra');

var ManifestGenerator = require('../lib/manifest-generator');
var metaHandler = require('../lib/meta-handler');

describe('manifest-generator', function() {
function createGenerator(options, outputPaths) {
var Addon = ManifestGenerator.extend({
name: 'test',
root: process.cwd(),
app: {
options: {
assetLoader: options,
outputPaths: outputPaths
}
}
});

return new Addon();
}

describe('contentFor', function() {
it('returns a meta tag with a placeholder for head-footer', function() {
var generator = createGenerator();
var result = generator.contentFor('head-footer', { modulePrefix: 'dummy' });
assert.equal(result, '<meta name="dummy/asset-manifest" content="%GENERATED_ASSET_MANIFEST%" />');
});

it('returns nothing when using the noManifest option', function() {
var generator = createGenerator({
noManifest: true
});
var result = generator.contentFor('head-footer', { modulePrefix: 'dummy' });
assert.equal(result, undefined);
});

it('returns nothing when type is not head-footer', function() {
var generator = createGenerator();
var result = generator.contentFor('head', { modulePrefix: 'dummy' });
assert.equal(result, undefined);
});
});

describe('postprocessTree', function() {
var fixturePath = path.join(__dirname, 'fixtures');
var inputTree = path.join(fixturePath, 'insertion-test');

it('returns the input tree if not of type all', function() {
var generator = createGenerator();
var processedTree = generator.postprocessTree('js', inputTree);

assert.strictEqual(processedTree, inputTree);
});

it('returns the input tree when using the noManifest option', function() {
var generator = createGenerator({
noManifest: true
});
var processedTree = generator.postprocessTree('all', inputTree);

assert.strictEqual(processedTree, inputTree);
});

function verifyInsertedManifest(indexPath) {
var fixturePath = path.join(__dirname, 'fixtures');
var inputTree = path.join(fixturePath, 'generator-test');

var generator = createGenerator(undefined, {
app: {
html: indexPath
}
});
var processedTree = generator.postprocessTree('all', inputTree);

var builder = new broccoli.Builder(processedTree);
return builder.build().then(function(results) {
var output = results.directory;
var outputFiles = walk(output);
var inputFiles = walk(inputTree);

assert.notEqual(outputFiles.indexOf('asset-manifest.json'), -1, 'the output tree contains an asset manifest');
assert.equal(inputFiles.indexOf('asset-manifest.json'), -1, 'the input tree does not contain an asset manifest');

var manifest = fs.readJsonSync(path.join(output, 'asset-manifest.json'));
var escapedManifest = metaHandler.escaper(manifest);
var indexFile = fs.readFileSync(path.join(output, indexPath));

assert.notEqual(indexFile.indexOf(escapedManifest), -1, 'index contains the escaped manifest');

builder.cleanup();
});
}

it('generates an asset manifest, merges it into the given tree, and inserts it into index.html', function() {
return verifyInsertedManifest('index.html');
});

it('inserts the asset manifest into a custom index path', function() {
return verifyInsertedManifest('extra.html');
});
});
})

0 comments on commit 79438ef

Please sign in to comment.