Skip to content

Commit d52fb7f

Browse files
authored
Feature/new root directory syntax (#1)
* added project args to config * Refactored configs to a single class and instance for env and path reasons * Updated the ng serve command to respect the new class instance 🔥
1 parent 6f77db5 commit d52fb7f

14 files changed

+445
-423
lines changed

addon/ng2/blueprints/ng2/files/__path__/test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ require('zone.js/dist/sync-test');
1515
// RxJS
1616
require('rxjs/Rx');
1717

18-
var testing = require('@angular/core/testing');
19-
var browser = require('@angular/platform-browser-dynamic/testing');
18+
let testing: any = require('@angular/core/testing');
19+
let browser: any = require('@angular/platform-browser-dynamic/testing');
2020

2121
testing.setBaseTestProviders(
2222
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
2323
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
2424
);
2525

26-
var testContext = require.context('../src', true, /\.spec\.ts/);
26+
let testContext: any = require.context('../src', true, /\.spec\.ts/);
2727

2828
/*
2929
* get all the files, for each file, call the context function
3030
* that will require the file and load it up here. Context will
3131
* loop and require those spec files here
3232
*/
33-
function requireAll(requireContext) {
33+
function requireAll(requireContext: any) {
3434
return requireContext.keys().map(requireContext);
3535
}
3636

addon/ng2/commands/build.ts

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

7-
const WebpackBuild = require('../tasks/build-webpack');
8-
const WebpackBuildWatch = require('../tasks/build-webpack-watch');
7+
var WebpackBuild = require('../tasks/build-webpack');
8+
var WebpackBuildWatch = require('../tasks/build-webpack-watch');
99

1010
interface BuildOptions {
1111
environment?: string;
@@ -31,11 +31,22 @@ module.exports = Command.extend({
3131
{ name: 'm2', type: Boolean, default: false}
3232
],
3333

34-
run: function(commandOptions: BuildOptions) {
35-
36-
let buildTask = commandOptions.watch ?
37-
new WebpackBuildWatch() :
38-
new WebpackBuild();
34+
run: function (commandOptions: BuildOptions) {
35+
var project = this.project;
36+
var ui = this.ui;
37+
var buildTask = commandOptions.watch ?
38+
new WebpackBuildWatch({
39+
cliProject: project,
40+
ui: ui,
41+
outputPath: commandOptions.outputPath,
42+
environment: commandOptions.environment
43+
}) :
44+
new WebpackBuild({
45+
cliProject: project,
46+
ui: ui,
47+
outputPath: commandOptions.outputPath,
48+
environment: commandOptions.environment
49+
});
3950

4051
console.log(buildTask);
4152

addon/ng2/commands/serve.ts

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ module.exports = Command.extend({
7474
}
7575

7676
const ServeWebpackTask = (require('../tasks/serve-webpack.ts'))
77-
// var ServeTask = require('../tasks/serve');
7877

7978
var serve = new ServeWebpackTask({
8079
ui: this.ui,

addon/ng2/models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export * from './webpack-build-test';
33
export * from './webpack-build-production';
44
export * from './webpack-build-development';
55
export * from './webpack-build-utils';
6+
export {getWebpackMaterialConfig, getWebpackMaterialE2EConfig} from './webpack-build-material2.ts';
67

78
export * from './webpack-karma-config';
+82-81
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,93 @@
11
import * as webpack from 'webpack';
2-
import {ngAppResolve} from './webpack-build-utils';
32

43
const path = require('path');
54
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
65
const CopyWebpackPlugin = require('copy-webpack-plugin');
76
const HtmlWebpackPlugin = require('html-webpack-plugin');
87
const DebugWebpackPlugin = require('debug-webpack-plugin');
98

10-
export const webpackCommonConfig = {
11-
devtool: 'inline-source-map',
12-
resolve: {
13-
extensions: ['', '.ts', '.js'],
14-
root: ngAppResolve('./src')
15-
},
16-
context: path.resolve(__dirname, './'),
17-
entry: {
18-
main: [ngAppResolve('./src/main.ts')],
19-
vendor: ngAppResolve('./src/vendor.ts'),
20-
polyfills: ngAppResolve('./src/polyfills.ts')
21-
},
22-
output: {
23-
path: ngAppResolve('./dist'),
24-
filename: '[name].bundle.js'
25-
},
26-
module: {
27-
preLoaders: [
28-
{
29-
test: /\.js$/,
30-
loader: 'source-map-loader',
31-
exclude: [
32-
ngAppResolve('node_modules/rxjs'),
33-
ngAppResolve('node_modules/@angular'),
34-
]
35-
}
36-
],
37-
loaders: [
38-
{
39-
test: /\.ts$/,
40-
loaders: [
41-
{
42-
loader: 'awesome-typescript-loader',
43-
query: {
44-
useWebpackText: true,
45-
tsconfig: ngAppResolve('./src/tsconfig.json'),
46-
// resolveGlobs: false,
47-
module: "es2015",
48-
target: "es5",
49-
lib: ['es6', 'dom'],
50-
useForkChecker: true
9+
export const getWebpackCommonConfig = function(projectRoot: string) {
10+
return {
11+
devtool: 'inline-source-map',
12+
resolve: {
13+
extensions: ['', '.ts', '.js'],
14+
root: path.resolve(projectRoot, './src')
15+
},
16+
context: path.resolve(__dirname, './'),
17+
entry: {
18+
main: [path.resolve(projectRoot, './src/main.ts')],
19+
vendor: path.resolve(projectRoot, './src/vendor.ts'),
20+
polyfills: path.resolve(projectRoot, './src/polyfills.ts')
21+
},
22+
output: {
23+
path: path.resolve(projectRoot, './dist'),
24+
filename: '[name].bundle.js'
25+
},
26+
module: {
27+
preLoaders: [
28+
{
29+
test: /\.js$/,
30+
loader: 'source-map-loader',
31+
exclude: [
32+
path.resolve(projectRoot, 'node_modules/rxjs'),
33+
path.resolve(projectRoot, 'node_modules/@angular'),
34+
]
35+
}
36+
],
37+
loaders: [
38+
{
39+
test: /\.ts$/,
40+
loaders: [
41+
{
42+
loader: 'awesome-typescript-loader',
43+
query: {
44+
useWebpackText: true,
45+
tsconfig: path.resolve(projectRoot, './src/tsconfig.json'),
46+
// resolveGlobs: false,
47+
module: "es2015",
48+
target: "es5",
49+
lib: ['es6', 'dom'],
50+
useForkChecker: true
51+
}
52+
},
53+
{
54+
loader: 'angular2-template-loader'
5155
}
52-
},
53-
{
54-
loader: 'angular2-template-loader'
55-
}
56-
],
57-
exclude: [/\.(spec|e2e)\.ts$/]
58-
},
59-
{ test: /\.json$/, loader: 'json-loader'},
60-
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
61-
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
62-
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
63-
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
64-
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
65-
{ test: /\.html$/, loader: 'raw-loader' }
66-
]
67-
},
68-
plugins: [
69-
new ForkCheckerPlugin(),
70-
new HtmlWebpackPlugin({
71-
template: ngAppResolve('src/index.html'),
72-
chunksSortMode: 'dependency'
73-
}),
74-
new webpack.optimize.CommonsChunkPlugin({
75-
name: ['polyfills', 'vendor'].reverse()
76-
}),
77-
new webpack.optimize.CommonsChunkPlugin({
78-
minChunks: Infinity,
79-
name: 'inline',
80-
filename: 'inline.js',
81-
sourceMapFilename: 'inline.map'
82-
}),
83-
new CopyWebpackPlugin([{from: ngAppResolve('./public'), to: ngAppResolve('./dist/public')}])
84-
],
85-
node: {
86-
global: 'window',
87-
crypto: 'empty',
88-
module: false,
89-
clearImmediate: false,
90-
setImmediate: false
56+
],
57+
exclude: [/\.(spec|e2e)\.ts$/]
58+
},
59+
{ test: /\.json$/, loader: 'json-loader'},
60+
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
61+
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
62+
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
63+
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
64+
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
65+
{ test: /\.html$/, loader: 'raw-loader' }
66+
]
67+
},
68+
plugins: [
69+
new ForkCheckerPlugin(),
70+
new HtmlWebpackPlugin({
71+
template: path.resolve(projectRoot, 'src/index.html'),
72+
chunksSortMode: 'dependency'
73+
}),
74+
new webpack.optimize.CommonsChunkPlugin({
75+
name: ['polyfills', 'vendor'].reverse()
76+
}),
77+
new webpack.optimize.CommonsChunkPlugin({
78+
minChunks: Infinity,
79+
name: 'inline',
80+
filename: 'inline.js',
81+
sourceMapFilename: 'inline.map'
82+
}),
83+
new CopyWebpackPlugin([{from: path.resolve(projectRoot, './public'), to: path.resolve(projectRoot, './dist/public')}])
84+
],
85+
node: {
86+
global: 'window',
87+
crypto: 'empty',
88+
module: false,
89+
clearImmediate: false,
90+
setImmediate: false
91+
}
9192
}
9293
};
+25-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import { webpackCommonConfig } from '../models';
2-
import { webpackMaterialConfig, webpackMaterialE2EConfig } from './webpack-build-material2';
3-
import { ngAppResolve } from './webpack-build-utils';
1+
const path = require('path')
42

5-
const webpackMerge = require('webpack-merge');
6-
7-
const devConfigPartial = {
8-
debug: true,
9-
devtool: 'cheap-module-source-map',
10-
output: {
11-
path: ngAppResolve('./dist'),
12-
filename: '[name].bundle.js',
13-
sourceMapFilename: '[name].map',
14-
chunkFilename: '[id].chunk.js'
15-
},
16-
tslint: {
17-
emitErrors: false,
18-
failOnHint: false,
19-
resourcePath: ngAppResolve('./src')
20-
},
21-
node: {
22-
global: 'window',
23-
crypto: 'empty',
24-
process: true,
25-
module: false,
26-
clearImmediate: false,
27-
setImmediate: false
28-
}
3+
export const getWebpackDevConfigPartial = function(projectRoot: string) {
4+
return {
5+
debug: true,
6+
devtool: 'cheap-module-source-map',
7+
output: {
8+
path: path.resolve(projectRoot, './dist'),
9+
filename: '[name].bundle.js',
10+
sourceMapFilename: '[name].map',
11+
chunkFilename: '[id].chunk.js'
12+
},
13+
tslint: {
14+
emitErrors: false,
15+
failOnHint: false,
16+
resourcePath: path.resolve(projectRoot, './src')
17+
},
18+
node: {
19+
global: 'window',
20+
crypto: 'empty',
21+
process: true,
22+
module: false,
23+
clearImmediate: false,
24+
setImmediate: false
25+
}
26+
};
2927
}
30-
31-
export const webpackDevConfig = webpackMerge(webpackCommonConfig, devConfigPartial);
32-
33-
export const webpackDevMaterialConfig = webpackMerge(webpackMaterialConfig, devConfigPartial);
34-
35-
export const webpackDevMaterialE2EConfig = webpackMerge(webpackMaterialE2EConfig, devConfigPartial);

0 commit comments

Comments
 (0)