-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: now use Handlebars for building the index.html. (#712)
- Loading branch information
Showing
7 changed files
with
108 additions
and
104 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
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const BroccoliCacheWriter = require('broccoli-caching-writer'); | ||
const Handlebars = require('handlebars'); | ||
|
||
|
||
class HandlebarReplace extends BroccoliCacheWriter { | ||
constructor(inputTree, context, options) { | ||
super([inputTree], options); | ||
if (options && options.helpers) { | ||
Object.keys(options.helpers).forEach((helperName) => { | ||
Handlebars.registerHelper(helperName, function() { | ||
const result = options.helpers[helperName].apply(null, arguments); | ||
return new Handlebars.SafeString(result); | ||
}); | ||
}) | ||
} | ||
this._context = context; | ||
} | ||
|
||
build() { | ||
this.listFiles().forEach((filePath) => { | ||
const destPath = filePath.replace(this.inputPaths[0], this.outputPath); | ||
const content = fs.readFileSync(filePath, 'utf-8'); | ||
const template = Handlebars.compile(content); | ||
|
||
if (!fs.existsSync(path.dirname(destPath))) { | ||
fs.mkdirsSync(path.dirname(destPath)); | ||
} | ||
fs.writeFileSync(destPath, template(this._context), 'utf-8'); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = HandlebarReplace; |
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,28 @@ | ||
'use strict'; | ||
// Load the environment file defined by the EMBER_ENV environment variable. | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const ts = require('typescript'); | ||
|
||
|
||
// Export the content of the transpiled file. | ||
module.exports = function loadEnvironment(project, environment) { | ||
let env = environment || process.env['EMBER_ENV'] || 'dev'; | ||
switch (env) { | ||
case 'production': env = 'prod'; break; | ||
case 'development': env = 'dev'; break; | ||
} | ||
|
||
// Load the content of the environment file. | ||
const filePath = path.join(project.root, `config/environment.${env}.ts`); | ||
const source = fs.readFileSync(filePath, 'utf-8'); | ||
const result = ts.transpile(source, { | ||
target: ts.ScriptTarget.ES5, | ||
module: ts.ModuleKind.CommonJs | ||
}); | ||
|
||
const Module = module.constructor; | ||
const m = new Module(); | ||
m._compile(result, filePath); | ||
return m.exports.environment; | ||
}; |
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