Created
November 17, 2018 12:22
-
-
Save rajasegar/4550efdab38a3642c832e9b00710a545 to your computer and use it in GitHub Desktop.
Ember Build multiple app trees
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
/* jshint node : true */ | |
module.exports = [{ | |
name: 'contacts', | |
packages: ['contacts'], | |
handledRoutesPatterns: ['/contact'], | |
routeNames: ['^contact'] | |
}]; |
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
let bootAppTree = app.toTree(compilationAssets); | |
// packages subsequent calls to EmberApp() constructor must come after the main app.toTree | |
// in order for the addons to run postprocessTree correctly | |
let packagesApplications = packageNames.map(function(packageName) { | |
console.log(packageName); | |
// packages export their own js file and are intended to distribute the code-base. | |
let packageConfig = { | |
// Instructions: Add your custom config for packages here | |
name: packageName, | |
tests: false, | |
// Instructions: Add your custom shared config for packages and the boot app | |
hinting: false, | |
fingerprint: { | |
// Disabling here since we do it at the end for *all* the assets | |
enabled: false | |
}, | |
outputPaths: { | |
app: { | |
js: `/assets/${ packageName }.js` | |
} | |
}, | |
'ember-cli-babel': { | |
includePolyfill: true | |
}, | |
sassOptions: { | |
sourceComments: true, | |
includePaths: [ | |
'bower_components/bootstrap-sass-official/assets/stylesheets' | |
] | |
}, | |
trees: { | |
app: mergeTrees([ | |
// The index.html is required, so we funnel it here, but return it unmodified | |
// below (see package.index) to avoid running ConfigReplace | |
new Funnel('app', { files: ['index.html'] }), | |
new Funnel(`packages/${ packageName}`) | |
]), | |
styles: new Funnel(`packages/${ packageName }/styles`), | |
templates: new Funnel(`packages/${ packageName }/templates`) | |
}, | |
vendorFiles: { | |
// Avoids serving the same dependency twice. List extracted from ember-cli/lib/broccoli/ember-app.js#_initVendorFiles | |
'jquery.js': null, | |
'handlebars.js': null, | |
'ember.js': null, | |
'loader.js': null, | |
// We need to leave this as is. | |
// 'ember-testing.js': null, | |
'app-shims.js': null, | |
'ember-resolver.js': null, | |
'ember-data': null, // do this for boot as well if you don't use ember-data | |
'ember-cli-app-version': null, | |
'vendor-suffix': null, | |
'ember-load-initializers.js': null, | |
'ember-debug-handlers-polyfill': null, | |
'ember-cli-deprecation-workflow': null, | |
'ic-ajax': null | |
} | |
}; | |
let engine = new EmberApp(defaults, packageConfig); | |
// Prevent packages from creating their own Ember Application | |
engine.contentFor = function(config, match, type) { | |
if (type === 'app-boot' || type === 'app-config') { | |
return ''; | |
} else { | |
return EmberApp.prototype.contentFor.call(this, config, match, type); | |
} | |
}; | |
engine.index = function () { | |
let htmlName = this.options.outputPaths.app.html; | |
let files = ['index.html']; | |
let index = new Funnel(this.trees.app, { | |
files, | |
getDestinationPath(relativePath) { | |
if (relativePath === 'index.html') { | |
relativePath = htmlName; | |
} | |
return relativePath; | |
}, | |
annotation: 'Funnel: index.html' | |
}); | |
return index; | |
}; | |
// Only boot includes addon's code | |
engine.addonTreesFor = function(type) { | |
if (type === 'app') { | |
return []; | |
} else { | |
return EmberApp.prototype.addonTreesFor.call(this, type); | |
} | |
}; | |
return engine; | |
}); | |
let movedenginesApplicationTrees = packagesApplications.map(function(engine) { | |
let packageTree = engine.toTree(); | |
return new Funnel(packageTree); | |
}); | |
let allTrees = mergeTrees(movedenginesApplicationTrees.concat([bootAppTree/* , publicVendorFiles*/]), { overwrite: true }); | |
if (ENV === 'production') { | |
allTrees = new AssetRev(allTrees); | |
} | |
return allTrees; |
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
/* jshint node:true*/ | |
let fs = require('fs'), | |
path = require('path'); | |
function getDirectories(srcpath) { | |
return fs.readdirSync(srcpath).filter(function (file) { | |
return fs.statSync(path.join(srcpath, file)).isDirectory(); | |
}); | |
} | |
module.exports = getDirectories('packages'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment