Skip to content

Instantly share code, notes, and snippets.

@billpull
Last active November 16, 2015 16:46
Show Gist options
  • Save billpull/f7a07402d78c9c30eb6c to your computer and use it in GitHub Desktop.
Save billpull/f7a07402d78c9c30eb6c to your computer and use it in GitHub Desktop.
Ember Build Script for Separating Pods
/* global require, module */
var stew = require('broccoli-stew');
var concat = require('broccoli-concat');
var Funnel = require('broccoli-funnel');
var replace = require('broccoli-string-replace');
var mergeTrees = require('broccoli-merge-trees');
var esTranspiler = require('broccoli-babel-transpiler');
var HtmlbarsCompiler = require('ember-cli-htmlbars');
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
storeConfigInMeta: false,
sassOptions: {
includePaths: [
'bower_components/bourbon/app/assets/stylesheets/',
'bower_components/neat/app/assets/stylesheets/',
'bower_components/bitters/app/assets/stylesheets/'
]
}
});
var additionalTrees = [];
var appTree = app.appAndDependencies();
if (EmberApp.env() !== "production") {
var jQuery = stew.find(appTree, "bower_components/jquery/dist/jquery.min.js");
jQuery = stew.mv(jQuery, "bower_components/jquery/dist/jquery.min.js", "assets/jquery.js");
additionalTrees.push(jQuery);
}
function extractModule(fileName, moduleName) {
var module = stew.find(appTree, 'mobile-web/'+ fileName + '.js');
moduleName = "mobile-web/" + moduleName;
module = esTranspiler(module, {
modules: "amdStrict",
moduleIds: true,
moduleId: moduleName
});
module = stew.mv(module, 'mobile-web/'+ fileName + '.js', 'assets/'+ fileName + '.js');
stew.rm(appTree, 'mobile-web/'+ fileName + '.js');
additionalTrees.push(module);
}
function extractPod(podPath) {
var srcPodPath = 'app/pods/' + podPath;
var moduleRoot = 'mobile-web/pods/' + podPath;
var outputPath = 'assets/' + podPath + '/';
var jsFunnel = new Funnel(srcPodPath, {
include: ['**/*.js'],
destDir: outputPath
});
var templateFunnel = new Funnel(srcPodPath, {
include: ['**/*.hbs'],
destDir: outputPath
});
templateFunnel = new HtmlbarsCompiler(templateFunnel, {
isHTMLBars: true,
templateCompiler: require('./bower_components/ember/ember-template-compiler')
});
var podTree = mergeTrees([jsFunnel, templateFunnel]);
podTree = esTranspiler(podTree, {
modules: "amdStrict",
moduleIds: true,
sourceMaps: true
});
podTree = concat(podTree, {
inputFiles: ['**/*.js'],
outputFile: '/' + outputPath + 'index.js'
});
podTree = replace(podTree, {
files: ['**/*.js'],
pattern: {
match: /assets/g,
replacement: 'mobile-web/pods'
}
});
stew.rm(appTree, moduleRoot + '/*.js', moduleRoot + '/*.hbs');
additionalTrees.push(podTree);
}
extractModule('router', 'router');
extractModule('secure-router', 'router');
extractPod('secure/login');
return app.toTree(additionalTrees);
};
desired output
assets/
└── pods/
└── secure/
└── login
└── index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment