This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
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
0 parents
commit 3dc5b23
Showing
11 changed files
with
587 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
.DS_Store | ||
.vscode | ||
**/*.log | ||
dist | ||
tests | ||
tmp |
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,10 @@ | ||
node_modules | ||
test | ||
tests | ||
tmp | ||
testem.json | ||
tsconfig.* | ||
.travis.yml | ||
.gitignore | ||
.DS_Store | ||
*.log |
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,9 @@ | ||
The Ember team and community are committed to everyone having a safe and inclusive experience. | ||
|
||
**Our Community Guidelines / Code of Conduct can be found here**: | ||
|
||
http://emberjs.com/guidelines/ | ||
|
||
For a history of updates, see the page history here: | ||
|
||
https://github.com/emberjs/website/commits/master/source/guidelines.html.erb |
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,19 @@ | ||
Copyright (c) 2017 Dan Gebhardt, Tom Dale, and contributors. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,10 @@ | ||
# glimmer-application-pipeline [![Build Status](https://secure.travis-ci.org/glimmerjs/glimmer-application-pipeline.svg?branch=master)](http://travis-ci.org/glimmerjs/glimmer-application-pipeline) | ||
|
||
## Acknowledgements | ||
|
||
Thanks to [Monegraph](http://monegraph.com) for funding the initial development | ||
of this library. | ||
|
||
## License | ||
|
||
MIT License. |
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,24 @@ | ||
module.exports = function(config) { | ||
let moduleConfig = config.moduleConfiguration; | ||
|
||
let collectionMap = {}; | ||
let collectionPaths = []; | ||
let collections = moduleConfig.collections; | ||
let collectionNames = Object.keys(collections); | ||
collectionNames.forEach(function(collectionName) { | ||
var collection = collections[collectionName]; | ||
var fullPath = collectionName; | ||
if (collection.group) { | ||
fullPath = collection.group + '/' + fullPath; | ||
} | ||
collectionPaths.push(fullPath); | ||
collectionMap[fullPath] = collectionName; | ||
}); | ||
|
||
moduleConfig.collectionMap = collectionMap; | ||
moduleConfig.collectionPaths = collectionPaths; | ||
|
||
// console.log('moduleConfig', moduleConfig); | ||
|
||
return moduleConfig; | ||
}; |
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,272 @@ | ||
"use strict"; | ||
|
||
var defaultsDeep = require('ember-cli-lodash-subset').defaultsDeep; | ||
var EmberApp = require('ember-cli/lib/broccoli/ember-app'); | ||
var ConfigLoader = require('broccoli-config-loader'); | ||
var ConfigReplace = require('broccoli-config-replace'); | ||
var Funnel = require('broccoli-funnel'); | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var rimraf = require('rimraf'); | ||
var typescript = require('broccoli-typescript-compiler'); | ||
var concat = require('broccoli-concat'); | ||
var merge = require('broccoli-merge-trees'); | ||
var stew = require('broccoli-stew'); | ||
var compileSass = require('broccoli-sass'); | ||
var replace = require('broccoli-string-replace'); | ||
var mv = stew.mv; | ||
var find = stew.find; | ||
var map = stew.map; | ||
var babel = require('broccoli-babel-transpiler'); | ||
var assetRev = require('broccoli-asset-rev'); | ||
var uglify = require('broccoli-uglify-sourcemap'); | ||
|
||
var RollupWithDependencies = require('./rollup-with-dependencies'); | ||
var GlimmerTemplatePrecompiler = require('./glimmer-template-precompiler'); | ||
const ModuleMapCreator = require('./module-map-creator'); | ||
|
||
var DEFAULT_CONFIG = { | ||
configPath: './config/environment', | ||
trees: { | ||
app: 'src', | ||
styles: 'src/ui/styles' | ||
}, | ||
jshintrc: { | ||
tests: 'tests', | ||
app: 'src' | ||
} | ||
}; | ||
|
||
module.exports = GlimmerApp; | ||
|
||
/** | ||
* GlimmerApp provides an interface to a package (app, engine, or addon) | ||
* compatible with the module unification layout. | ||
* | ||
* @class GlimmerApp | ||
* @extends EmberApp | ||
* @constructor | ||
* @param {Object} [defaults] | ||
* @param {Object} [options={}] Configuration options | ||
*/ | ||
function GlimmerApp(defaults, options) { | ||
if (arguments.length === 0) { | ||
options = {}; | ||
} else if (arguments.length === 1) { | ||
options = defaults; | ||
} else { | ||
defaultsDeep(options, defaults); | ||
} | ||
|
||
this.appConstructor(defaultsDeep(options, DEFAULT_CONFIG)); | ||
} | ||
|
||
GlimmerApp.__proto__ = EmberApp; | ||
|
||
GlimmerApp.prototype = Object.create(EmberApp.prototype); | ||
GlimmerApp.prototype.constructor = GlimmerApp; | ||
GlimmerApp.prototype.appConstructor = EmberApp.prototype.constructor; | ||
|
||
GlimmerApp.prototype.toTree = function(options) { | ||
var projectDir = process.cwd(); | ||
var projectFolder = this.projectFolder = (options && options.projectFolder || 'src'); | ||
var app = projectDir + '/' + projectFolder; | ||
|
||
console.log('Building app tree:', app); | ||
|
||
if (process.env.EMBER_ENV !== 'production') { | ||
rimraf.sync('dist'); | ||
} | ||
|
||
var tsOptions = { | ||
tsconfig: { | ||
compilerOptions: { | ||
target: "es5", | ||
module: "es2015", | ||
inlineSourceMap: true, | ||
inlineSources: true, | ||
moduleResolution: "node", | ||
rootDir: '.', | ||
mapRoot : '/' | ||
} | ||
} | ||
}; | ||
|
||
// Select all app src, except config file that needs to be rewritten | ||
var tsTree = find(app, { | ||
include: ['**/*.ts'], | ||
exclude: ['**/*.d.ts', 'config/**/*.ts'] | ||
}); | ||
|
||
var resolvableTree = find(app, { | ||
include: ['**/*.ts', '**/*.hbs'], | ||
exclude: ['**/*.d.ts', 'config/**/*.ts'] | ||
}); | ||
|
||
var configEnvironment = find(app, { | ||
include: ['config/environment.ts'] | ||
}); | ||
|
||
var moduleMap = this.buildModuleMap(resolvableTree, configEnvironment); | ||
|
||
configEnvironment = this.rewriteConfigEnvironment(configEnvironment); | ||
|
||
tsTree = merge([ | ||
tsTree, | ||
moduleMap, | ||
configEnvironment | ||
]); | ||
|
||
var jsTree = typescript(tsTree, tsOptions); | ||
|
||
var hbsTree = find([ app ], { | ||
include: [ | ||
'**/*.hbs' | ||
] | ||
}); | ||
|
||
hbsTree = new GlimmerTemplatePrecompiler(hbsTree, { | ||
rootName: this.project.pkg.name | ||
}); | ||
|
||
jsTree = merge([jsTree, | ||
hbsTree]); | ||
|
||
jsTree = new RollupWithDependencies(jsTree, { | ||
inputFiles: ['**/*.js'], | ||
rollup: { | ||
onwarn(message) { | ||
// Suppress known error message caused by TypeScript compiled code with Rollup | ||
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined | ||
if (/The \`this\` keyword is equivalent to \`undefined\` at the top level of an ES module, and has been rewritten/.test(message)) { | ||
return; | ||
} | ||
console.error(message); | ||
}, | ||
entry: 'index.js', | ||
dest: 'app.js', | ||
sourceMap: 'inline' | ||
} | ||
}); | ||
|
||
if (process.env.EMBER_ENV === 'production') { | ||
jsTree = uglify(jsTree, { | ||
compress: { | ||
screw_ie8: true, | ||
}, | ||
sourceMapConfig: { | ||
enabled: false | ||
} | ||
}); | ||
} | ||
|
||
var htmlTree = this.index(); | ||
|
||
var cssTree = compileSass([app + '/ui/styles'], | ||
'app.scss', 'app.css'); | ||
|
||
var appTree = merge([ | ||
jsTree, | ||
htmlTree, | ||
cssTree, | ||
'public/' | ||
]); | ||
|
||
if (process.env.EMBER_ENV === 'production') { | ||
var extensions = ['js']; | ||
var replaceExtensions = ['html', 'js']; | ||
|
||
if (!options.preventCssFingerPrinting) { | ||
extensions.push('css'); | ||
replaceExtensions.push('css'); | ||
} | ||
appTree = assetRev(appTree, { | ||
extensions: extensions, | ||
replaceExtensions: replaceExtensions | ||
}); | ||
|
||
if (!options.disableCache) { | ||
var manifestTree = appcache(appTree, { | ||
cache: ['/'], | ||
network: ['*'], | ||
treeCacheEntryPathPrefix: options && options.prefix || null | ||
}); | ||
|
||
appTree = merge([appTree, manifestTree]); | ||
} | ||
} | ||
|
||
return appTree; | ||
} | ||
|
||
GlimmerApp.prototype._configPath = function() { | ||
return path.join(this.name, 'config', 'environments', this.env + '.json'); | ||
} | ||
|
||
GlimmerApp.prototype.rewriteConfigEnvironment = function(src) { | ||
return new ConfigReplace(src, this._configTree(), { | ||
configPath: this._configPath(), | ||
files: [ 'config/environment.ts' ], | ||
patterns: this._configReplacePatterns() | ||
}); | ||
} | ||
|
||
GlimmerApp.prototype.buildModuleMap = function(src, config) { | ||
return new ModuleMapCreator(src, this._configTree(), { | ||
configPath: this._configPath() | ||
}); | ||
} | ||
|
||
GlimmerApp.prototype.index = function() { | ||
var htmlName = this.options.outputPaths.app.html; | ||
var files = [ | ||
'index.html' | ||
]; | ||
|
||
var index = new Funnel(this.trees.app + '/ui', { | ||
files: files, | ||
getDestinationPath: function(relativePath) { | ||
if (relativePath === 'index.html') { | ||
relativePath = htmlName; | ||
} | ||
return relativePath; | ||
}, | ||
annotation: 'Funnel: index.html' | ||
}); | ||
|
||
return new ConfigReplace(index, this._configTree(), { | ||
configPath: path.join(this.name, 'config', 'environments', this.env + '.json'), | ||
files: [ htmlName ], | ||
patterns: this._configReplacePatterns() | ||
}); | ||
}; | ||
|
||
GlimmerApp.prototype._configTree = function() { | ||
if (this._cachedConfigTree) { | ||
return this._cachedConfigTree; | ||
} | ||
|
||
var configPath = this.project.configPath(); | ||
var configTree = new ConfigLoader(path.dirname(configPath), { | ||
env: this.env, | ||
tests: this.tests, | ||
project: this.project | ||
}); | ||
|
||
this._cachedConfigTree = new Funnel(configTree, { | ||
srcDir: '/', | ||
destDir: this.name + '/config', | ||
annotation: 'Funnel (config)' | ||
}); | ||
|
||
return this._cachedConfigTree; | ||
} | ||
|
||
function getNpmDependencies(projectPath) { | ||
return JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json'))).dependencies; | ||
} | ||
|
||
function getBowerDependencies(projectPath) { | ||
return JSON.parse(fs.readFileSync(path.join(projectPath, 'bower.json'))).dependencies; | ||
} |
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,38 @@ | ||
var Filter = require('broccoli-persistent-filter'); | ||
var compiler = require('@glimmer/compiler'); | ||
|
||
GlimmerTemplatePrecompiler.prototype = Object.create(Filter.prototype); | ||
GlimmerTemplatePrecompiler.prototype.constructor = GlimmerTemplatePrecompiler; | ||
|
||
function GlimmerTemplatePrecompiler(inputNode, options) { | ||
this.options = options || {}; | ||
Filter.call(this, inputNode, { | ||
annotation: options.annotation | ||
}); | ||
} | ||
|
||
GlimmerTemplatePrecompiler.prototype.extensions = ['hbs']; | ||
GlimmerTemplatePrecompiler.prototype.targetExtension = 'js'; | ||
|
||
function getTemplateSpecifier(rootName, relativePath) { | ||
let path = relativePath.split('/'); | ||
|
||
// TODO - should use module map config to be rigorous | ||
if (path[path.length - 1] === 'template.hbs') { | ||
path.pop(); | ||
} | ||
if (path[0] === 'ui') { | ||
path.shift(); | ||
} | ||
|
||
return 'template:/' + rootName + '/' + path.join('/'); | ||
} | ||
|
||
GlimmerTemplatePrecompiler.prototype.processString = function(content, relativePath) { | ||
console.log('GlimmerTemplatePrecompiler.processString', relativePath, this.options); | ||
|
||
let specifier = getTemplateSpecifier(this.options.rootName, relativePath); | ||
return 'export default ' + compiler.precompile(content, { meta: { specifier } }) + ';'; | ||
}; | ||
|
||
module.exports = GlimmerTemplatePrecompiler; |
Oops, something went wrong.