Permalink
Browse files

Refactored Brocfile, started Implemenation for rootURL, moved index.h…

…tml into app/
  • Loading branch information...
MajorBreakfast committed Mar 30, 2014
1 parent 78ac29d commit 404091401400478ef55088888b8ec383e02a17d6
View
@@ -1,127 +1,147 @@
/* global require, module */
var uglifyJavaScript = require('broccoli-uglify-js');
var replace = require('broccoli-replace');
var compileES6 = require('broccoli-es6-concatenator');
var p = require('ember-cli/lib/preprocessors');
var pickFiles = require('broccoli-static-compiler');
var env = require('broccoli-env').getEnv();
var p = require('ember-cli/lib/preprocessors');
var preprocessCss = p.preprocessCss;
var preprocessTemplates = p.preprocessTemplates;
var preprocessJs = p.preprocessJs;
module.exports = function (broccoli) {
var app = 'app';
var tests = 'tests';
var publicFiles = 'public';
var vendor = 'vendor';
var config = 'config';
var styles;
var qunit;
var testsIndex;
app = pickFiles(app, {
srcDir: '/',
destDir: '<%= modulePrefix %>/'
});
app = preprocessTemplates(app);
var prefix = '<%= modulePrefix %>';
var rootURL = '/';
config = pickFiles(config, {
// index.html
var indexHTML = pickFiles('app', {
srcDir: '/',
files: [
'environment.*',
'environments/' + env + '.*'
],
destDir: '<%= modulePrefix %>/config'
files: ['index.html'],
destDir: '/'
});
indexHTML = replace(indexHTML, {
files: ['index.html'],
patterns: [{ match: /\{\{rootURL\}\}/g, replacement: rootURL}]
});
testsIndex = pickFiles(tests, {
var testsIndexHTML = pickFiles('tests', {
srcDir: '/',
files: ['index.html'],
destDir: '/tests'
});
tests = pickFiles(tests, {
testsIndexHTML = replace(testsIndexHTML, {
files: ['tests/index.html'],
patterns: [{ match: /\{\{rootURL\}\}/g, replacement: rootURL}]

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

good for now, but we should prefer a better templating solution re: handlebars/mustache

@stefanpenner

stefanpenner Mar 30, 2014

Contributor

good for now, but we should prefer a better templating solution re: handlebars/mustache

This comment has been minimized.

Show comment
Hide comment
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

I agree. Should I maybe switch to the @@rootURL syntax that is the default?

@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

I agree. Should I maybe switch to the @@rootURL syntax that is the default?

This comment has been minimized.

Show comment
Hide comment
@joefiorini

joefiorini Mar 30, 2014

Contributor

I have lodash in just for its template support. I'd prefer to use something with <% %> syntax just to alleviate any confusion between app templates & configuration templates.

@joefiorini

joefiorini Mar 30, 2014

Contributor

I have lodash in just for its template support. I'd prefer to use something with <% %> syntax just to alleviate any confusion between app templates & configuration templates.

});

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

much extra whitespace

@stefanpenner

stefanpenner Mar 30, 2014

Contributor

much extra whitespace

This comment has been minimized.

Show comment
Hide comment
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

You found it :)

@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

You found it :)

// sourceTrees, appAndDependencies for CSS and JavaScript
var app = pickFiles('app', {
srcDir: '/',
destDir: '<%= modulePrefix %>/tests'
destDir: prefix
});
qunit = pickFiles(vendor, {
srcDir: '/qunit/qunit',
files: ['qunit.css'],
destDir: '/assets/'
app = preprocessTemplates(app);
var config = pickFiles('config', {
srcDir: '/',
files: [
'environment.*',
'environments/' + env + '.*'
],
destDir: prefix + '/config'
});
tests = preprocessTemplates(tests);
var sourceTrees = [app, config, 'vendor'].concat(broccoli.bowerTrees());
var sourceTrees = [
app,
config,
vendor
];
if (env !== 'production') {
var tests = pickFiles('tests', {
srcDir: '/',
destDir: prefix + '/tests'
});
tests = preprocessTemplates(tests);
sourceTrees.push(tests);
}
var appAndDependencies = new broccoli.MergedTree(sourceTrees);
// JavaScript
var legacyFilesToAppend = [
'<%= modulePrefix %>/config/environment.js',
'<%= modulePrefix %>/config/environments/' + env + '.js',
prefix + '/config/environment.js',
prefix + '/config/environments/' + env + '.js',
'jquery.js',
'handlebars.js',
'ember.js',
'ic-ajax/main.js',
'ember-data.js',
'ember-resolver.js'
'ember-resolver.js',
'ember-shim.js'
];
if (env !== 'production') {
legacyFilesToAppend.push(
'ember-shim.js',
'qunit/qunit/qunit.js',
'qunit-shim.js',
'ember-qunit/dist/named-amd/main.js'
);
sourceTrees.push(tests);
}
sourceTrees = sourceTrees.concat(broccoli.bowerTrees());
var appAndDependencies = new broccoli.MergedTree(sourceTrees);
var applicationJs = preprocessJs(appAndDependencies, '/', prefix);
appAndDependencies = preprocessJs(appAndDependencies, '/', '<%= modulePrefix %>');
var applicationJs = compileES6(appAndDependencies, {
applicationJs = compileES6(applicationJs, {
loaderFile: 'loader/loader.js',
ignoredModules: [
'ember/resolver',
'ember-qunit'
],
inputFiles: [
'<%= modulePrefix %>/**/*.js'
prefix + '/**/*.js'
],
legacyFilesToAppend: legacyFilesToAppend,
wrapInEval: env !== 'production',
outputFile: '/assets/app.js'
});
styles = preprocessCss(sourceTrees, '<%= modulePrefix %>/styles', '/assets');
if (env === 'production') {
applicationJs = uglifyJavaScript(applicationJs, {
mangle: false,
compress: false
});
}
var outputTrees = [
applicationJs,
publicFiles,
styles
];
// Styles
styles = preprocessCss(sourceTrees, prefix + '/styles', '/assets');
qunitStyles = pickFiles('vendor', {
srcDir: '/qunit/qunit',
files: ['qunit.css'],
destDir: '/assets/'
});
// Ouput
var outputTrees = [indexHTML, applicationJs, 'public', styles];
if (env !== 'production') {
outputTrees.push(qunit, testsIndex);
outputTrees.push(qunitStyles, testsIndexHTML);
}
return outputTrees;
};
@@ -7,6 +7,10 @@
<meta name='description' content=''>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script> // Sets base tag in order to support history location properly
document.write('<base href="' + document.location.origin + '{{rootURL}}" />');

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

can we avoid the document.write and instead just setup the base href via templating?

@stefanpenner

stefanpenner Mar 30, 2014

Contributor

can we avoid the document.write and instead just setup the base href via templating?

This comment has been minimized.

Show comment
Hide comment
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

We don't know document.location.origin at build time. Let's try how this solution performs first. It has two advantages:

  • Portablity: The user can host the generated dist version on any domain. It doesn't matter if it's http://localhost:4200, http://192.168.0.1 or https://example.com. It always set the right thing. The spec says the base tag's href should be an absolute URL. Only firefox supports a relative URL.
  • We can use relative paths everywhere else in the app. No more /assets/image.png! Finally we can use assets/image.png without / at the beginning.
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

We don't know document.location.origin at build time. Let's try how this solution performs first. It has two advantages:

  • Portablity: The user can host the generated dist version on any domain. It doesn't matter if it's http://localhost:4200, http://192.168.0.1 or https://example.com. It always set the right thing. The spec says the base tag's href should be an absolute URL. Only firefox supports a relative URL.
  • We can use relative paths everywhere else in the app. No more /assets/image.png! Finally we can use assets/image.png without / at the beginning.
</script>
<link rel='stylesheet' href='/assets/app.css'>
<script src='/assets/app.js'></script>
</head>
View
@@ -28,6 +28,7 @@
"broccoli-static-compiler": "0.1.2",
"broccoli-template": "0.1.0",
"broccoli-uglify-js": "0.1.1",
"broccoli-env": "0.0.1"
"broccoli-env": "0.0.1",
"broccoli-replace": "^0.1.5"
}
}
No changes.
@@ -7,6 +7,10 @@
<meta name='description' content=''>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script> // Sets base tag in order to support history location properly
document.write('<base href="' + document.location.origin + '{{rootURL}}" />');
</script>
<link rel='stylesheet' href='/assets/app.css'>
<link rel="stylesheet" href='/assets/qunit.css'>

5 comments on commit 4040914

@abuiles

This comment has been minimized.

Show comment
Hide comment
@abuiles

abuiles Mar 30, 2014

Member

@MajorBreakfast something worth for the CHANGELOG?

Member

abuiles replied Mar 30, 2014

@MajorBreakfast something worth for the CHANGELOG?

@MajorBreakfast

This comment has been minimized.

Show comment
Hide comment
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Contributor

You're right. This issue gives detailed information on what the current status is: #172

Contributor

MajorBreakfast replied Mar 30, 2014

You're right. This issue gives detailed information on what the current status is: #172

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

@MajorBreakfast in general i would prefer to have these code-reviews in PR's not on a commit on master.

Contributor

stefanpenner replied Mar 30, 2014

@MajorBreakfast in general i would prefer to have these code-reviews in PR's not on a commit on master.

@joefiorini

This comment has been minimized.

Show comment
Hide comment
@joefiorini

joefiorini Mar 30, 2014

Contributor

I realize we're not 1.0 yet, but how careful should we be when moving files around in the blueprint? We'll need to communicate to users when to rerun ember init in their apps to upgrade, and what files they can safely remove. Or should we remove them in init automatically? @MajorBreakfast @stefanpenner

Contributor

joefiorini replied Mar 30, 2014

I realize we're not 1.0 yet, but how careful should we be when moving files around in the blueprint? We'll need to communicate to users when to rerun ember init in their apps to upgrade, and what files they can safely remove. Or should we remove them in init automatically? @MajorBreakfast @stefanpenner

@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

@joefiorini I don't think we can remove, but likely a good change-log is appropriate.

We should not move any files around in blueprint without a PR and some discussion.

Contributor

stefanpenner replied Mar 30, 2014

@joefiorini I don't think we can remove, but likely a good change-log is appropriate.

We should not move any files around in blueprint without a PR and some discussion.

Please sign in to comment.