-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Trent Willis
committed
Jul 29, 2016
1 parent
46455f1
commit 8843321
Showing
4 changed files
with
95 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,6 @@ | ||
/* jshint node: true */ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var fs = require('fs-extra'); | ||
|
||
module.exports = { | ||
name: 'ember-asset-loader', | ||
|
||
/** | ||
* Insert a meta tag to hold the manifest in the DOM. We won't insert the | ||
* manifest until after postprocessing so the content is a placeholder value. | ||
*/ | ||
contentFor: function(type, config) { | ||
var options = this.app && this.app.options && this.app.options.assetLoader; | ||
if (type === 'head-footer' && !(options && options.noManifest)) { | ||
var metaName = config.modulePrefix + '/asset-manifest'; | ||
return '<meta name="' + metaName + '" content="%GENERATED_ASSET_MANIFEST%" />'; | ||
} | ||
}, | ||
|
||
/** | ||
* Replace the manifest placeholder with an escaped version of the manifest. | ||
* We do this in both the app's index and test's index. | ||
*/ | ||
postBuild: function(result) { | ||
var options = this.app && this.app.options && this.app.options.assetLoader; | ||
if (options && options.noManifest) { | ||
return; | ||
} | ||
|
||
var manifestFile = path.join(result.directory, 'asset-manifest.json'); | ||
var manifest; | ||
|
||
try { | ||
manifest = fs.readJsonSync(manifestFile); | ||
} catch (error) { | ||
console.warn('\n\nWarning: Unable to read asset-manifest.json from build with error: ' + error) | ||
console.warn('Warning: Proceeding without generated manifest; you will need to manually provide a manifest to the Asset Loader Service to load bundles at runtime. If this was intentional you can turn this message off via the `noManifest` flag.\n\n'); | ||
manifest = { bundles: {} }; | ||
} | ||
|
||
var escapedManifest = escape(JSON.stringify(manifest)); | ||
|
||
var indexFilePath = path.join(result.directory, 'index.html'); | ||
this.replaceAssetManifestPlaceholder(indexFilePath, escapedManifest); | ||
|
||
var testsIndexFilePath = path.join(result.directory, 'tests/index.html') | ||
this.replaceAssetManifestPlaceholder(testsIndexFilePath, escapedManifest); | ||
}, | ||
|
||
replaceAssetManifestPlaceholder: function(filePath, manifest) { | ||
var resolvedFile = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
fs.outputFileSync(filePath, resolvedFile.replace(/%GENERATED_ASSET_MANIFEST%/, manifest)); | ||
} | ||
name: 'ember-asset-loader' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var path = require('path'); | ||
var fs = require('fs-extra'); | ||
var Addon = require('ember-cli/lib/models/addon'); | ||
|
||
var ManifestGenerator = Addon.extend({ | ||
/** | ||
* Insert a meta tag to hold the manifest in the DOM. We won't insert the | ||
* manifest until after postprocessing so the content is a placeholder value. | ||
*/ | ||
contentFor: function(type, config) { | ||
var options = this.app && this.app.options && this.app.options.assetLoader; | ||
if (type === 'head-footer' && !(options && options.noManifest)) { | ||
var metaName = config.modulePrefix + '/asset-manifest'; | ||
return '<meta name="' + metaName + '" content="%GENERATED_ASSET_MANIFEST%" />'; | ||
} | ||
}, | ||
|
||
postprocessTree: function(type, tree) { | ||
if (type === 'all') { | ||
var generateAssetManifest = require('./generate-asset-manifest'); // eslint-disable-line global-require | ||
return generateAssetManifest(tree, this.manifestOptions); | ||
} | ||
|
||
return tree; | ||
}, | ||
|
||
/** | ||
* Replace the manifest placeholder with an escaped version of the manifest. | ||
* We do this in both the app's index and test's index. | ||
*/ | ||
postBuild: function(result) { | ||
var options = this.app && this.app.options && this.app.options.assetLoader; | ||
if (options && options.noManifest) { | ||
return; | ||
} | ||
|
||
var manifestFile = path.join(result.directory, 'asset-manifest.json'); | ||
var manifest; | ||
|
||
try { | ||
manifest = fs.readJsonSync(manifestFile); | ||
} catch (error) { | ||
console.warn('\n\nWarning: Unable to read asset-manifest.json from build with error: ' + error) | ||
console.warn('Warning: Proceeding without generated manifest; you will need to manually provide a manifest to the Asset Loader Service to load bundles at runtime. If this was intentional you can turn this message off via the `noManifest` flag.\n\n'); | ||
manifest = { bundles: {} }; | ||
} | ||
|
||
var escapedManifest = escape(JSON.stringify(manifest)); | ||
|
||
var indexFilePath = path.join(result.directory, 'index.html'); | ||
this.replaceAssetManifestPlaceholder(indexFilePath, escapedManifest); | ||
|
||
var testsIndexFilePath = path.join(result.directory, 'tests/index.html') | ||
this.replaceAssetManifestPlaceholder(testsIndexFilePath, escapedManifest); | ||
}, | ||
|
||
replaceAssetManifestPlaceholder: function(filePath, manifest) { | ||
var resolvedFile = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
fs.outputFileSync(filePath, resolvedFile.replace(/%GENERATED_ASSET_MANIFEST%/, manifest)); | ||
} | ||
}); | ||
|
||
module.exports = ManifestGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
name: 'test-generator-plugin', | ||
var ManifestGenerator = require('../../../../lib/manifest-generator'); | ||
|
||
postprocessTree: function(type, tree) { | ||
if (type === 'all') { | ||
var generateAssetManifest = require('../../../../lib/generate-asset-manifest'); | ||
return generateAssetManifest(tree, { | ||
bundlesLocation: 'test-dist', | ||
supportedTypes: [ 'js', 'css' ] | ||
}); | ||
} | ||
module.exports = ManifestGenerator.extend({ | ||
name: 'test-generator-plugin', | ||
|
||
return tree; | ||
manifestOptions: { | ||
bundlesLocation: 'test-dist', | ||
supportedTypes: [ 'js', 'css' ] | ||
} | ||
}; | ||
}); |