Skip to content

Commit 0136a8e

Browse files
committed
rearranged code into appropriate task/command/models folders
1 parent dbfaf76 commit 0136a8e

File tree

6 files changed

+72
-47
lines changed

6 files changed

+72
-47
lines changed

addon/ng2/blueprints/ng2/files/__path__/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@
2626
</head>
2727
<body>
2828
<<%= htmlComponentName %>-app>Loading...</<%= htmlComponentName %>-app>
29-
3029
</body>
3130
</html>

addon/ng2/commands/build.ts

+3-46
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@ const win = require('ember-cli/lib/utilities/windows-admin');
44
// const Build = require('../tasks/build');
55
// const BuildWatch = require('../tasks/build-watch');
66

7-
// Webpack Configuration
8-
const webpack = require('webpack');
9-
const webpackConfig = require('../tasks/webpack-build-config');
10-
const webpackCompiler = webpack(webpackConfig);
11-
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
12-
const webpackOutputOptions = {
13-
colors: true,
14-
chunks: true,
15-
modules: false,
16-
reasons: false,
17-
chunkModules: false
18-
}
19-
20-
let lastHash = null;
21-
22-
webpackCompiler.apply(new ProgressPlugin({
23-
profile: true
24-
}));
25-
7+
const Build = require('../tasks/build-webpack');
268

279
module.exports = Command.extend({
2810
name: 'build',
@@ -38,34 +20,9 @@ module.exports = Command.extend({
3820
],
3921

4022
run: function(commandOptions) {
41-
return new Promise((resolve, reject) => {
42-
webpackCompiler.run((err, stats) => {
43-
// Don't keep cache
44-
// TODO: Make conditional if using --watch
45-
webpackCompiler.purgeInputFileSystem();
46-
47-
if(err) {
48-
lastHash = null;
49-
console.error(err.stack || err);
50-
if(err.details) console.error(err.details);
51-
reject(err.details);
52-
}
53-
54-
if(stats.hash !== lastHash) {
55-
lastHash = stats.hash;
56-
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
57-
}
58-
resolve();
59-
});
60-
});
61-
},
23+
let buildTask = new Build({options: commandOptions});
6224

63-
taskFor: function(options) {
64-
if (options.watch) {
65-
return BuildWatch;
66-
} else {
67-
return Build;
68-
}
25+
return buildTask.run();
6926
}
7027
});
7128

addon/ng2/tasks/webpack-build-config.ts renamed to addon/ng2/models/webpack-build-config.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const webpack = require('webpack');
22
const HtmlWebpackPlugin = require('html-webpack-plugin');
33
const path = require('path');
4+
const ClosureCompilerPlugin = require('webpack-closure-compiler');
45

56

67
// Resolve to the generated applications
@@ -30,6 +31,14 @@ module.exports = {
3031
{
3132
test: /\.ts$/,
3233
loaders: [
34+
{
35+
loader: 'babel-loader',
36+
query: {
37+
presets: [
38+
'babel-preset-es2015-webpack'
39+
].map(require.resolve)
40+
}
41+
}
3342
{
3443
loader: 'awesome-typescript-loader',
3544
query: {
@@ -76,6 +85,14 @@ module.exports = {
7685
test: /\.js$/,
7786
jsfile: true
7887
})
88+
new ClosureCompilerPlugin({
89+
compiler: {
90+
language_in: 'ECMASCRIPT5',
91+
language_out: 'ECMASCRIPT5',
92+
compilation_level: 'SIMPLE'
93+
},
94+
concurrency: 3,
95+
})
7996
],
8097

8198
// ts: {

addon/ng2/tasks/build-webpack-watch.ts

Whitespace-only changes.

addon/ng2/tasks/build-webpack.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const Task = require('ember-cli/lib/models/task');
2+
3+
// Webpack Configuration
4+
const webpack = require('webpack');
5+
const webpackConfig = require('../models/webpack-build-config');
6+
const webpackCompiler = webpack(webpackConfig);
7+
const webpackOutputOptions = {
8+
colors: true,
9+
chunks: true,
10+
modules: false,
11+
reasons: false,
12+
chunkModules: false
13+
}
14+
15+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
16+
webpackCompiler.apply(new ProgressPlugin({
17+
profile: true
18+
}));
19+
20+
21+
let lastHash = null;
22+
23+
module.exports = Task.extend({
24+
// Options: String outputPath
25+
run: function() {
26+
let commandOptions = this.options;
27+
28+
return new Promise((resolve, reject) => {
29+
webpackCompiler.run((err, stats) => {
30+
// Don't keep cache
31+
// TODO: Make conditional if using --watch
32+
webpackCompiler.purgeInputFileSystem();
33+
34+
if(err) {
35+
lastHash = null;
36+
console.error(err.stack || err);
37+
if(err.details) console.error(err.details);
38+
reject(err.details);
39+
}
40+
41+
if(stats.hash !== lastHash) {
42+
lastHash = stats.hash;
43+
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
44+
}
45+
resolve();
46+
});
47+
});
48+
}
49+
});

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"dependencies": {
3333
"angular2-template-loader": "^0.2.0",
3434
"awesome-typescript-loader": "^0.19.0",
35+
"babel-core": "^6.9.1",
36+
"babel-loader": "^6.2.4",
37+
"babel-preset-es2015-webpack": "^6.4.1",
3538
"broccoli": "^1.0.0-beta.7",
3639
"broccoli-caching-writer": "^2.2.1",
3740
"broccoli-concat": "^2.2.0",

0 commit comments

Comments
 (0)