Skip to content

Commit

Permalink
Refactored Brocfile, started Implemenation for rootURL, moved index.h…
Browse files Browse the repository at this point in the history
…tml into app/
  • Loading branch information
MajorBreakfast committed Mar 30, 2014
1 parent 78ac29d commit 4040914
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 56 deletions.
130 changes: 75 additions & 55 deletions blueprint/Brocfile.js
@@ -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.

Copy link
@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.

Copy link
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Author Contributor

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

This comment has been minimized.

Copy link
@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.

Copy link
@stefanpenner

stefanpenner Mar 30, 2014

Contributor

much extra whitespace

This comment has been minimized.

Copy link
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Author 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;
};
4 changes: 4 additions & 0 deletions blueprint/public/index.html → blueprint/app/index.html
Expand Up @@ -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.

Copy link
@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.

Copy link
@MajorBreakfast

MajorBreakfast Mar 30, 2014

Author 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>
Expand Down
3 changes: 2 additions & 1 deletion blueprint/package.json
Expand Up @@ -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"
}
}
Empty file added blueprint/public/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions blueprint/tests/index.html
Expand Up @@ -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'>

Expand Down

5 comments on commit 4040914

@abuiles
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MajorBreakfast something worth for the CHANGELOG?

@MajorBreakfast
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@stefanpenner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@joefiorini
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.