Skip to content

Commit

Permalink
fix(build): re-add support for sourceDir
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jul 19, 2016
1 parent 18318a2 commit 0a851d6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/ng2/files/__path__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Promise.all([
);
});

let testContext: any = require.context('../src', true, /\.spec\.ts/);
let testContext: any = require.context('./', true, /\.spec\.ts/);
function requireAll(requireContext: any) {
return requireContext.keys().map(requireContext);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/ng2/files/__path__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"baseUrl":"./src",
"baseUrl":"./",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Expand Down
15 changes: 9 additions & 6 deletions addon/ng2/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import * as webpack from 'webpack';
import {LoaderConfig, PathsPlugin} from '../utilities/ts-path-mappings-webpack-plugin';
import { CliConfig } from './config';

const path = require('path');
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

export function getWebpackCommonConfig(projectRoot: string) {
const sourceDir = CliConfig.fromProject().defaults.sourceDir;

const awesomeTypescriptLoaderConfig: LoaderConfig | any = {
useWebpackText: true,
useForkChecker: true,
tsconfig: path.resolve(projectRoot, './src/tsconfig.json')
tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`)
}

return {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.ts', '.js'],
root: path.resolve(projectRoot, './src'),
root: path.resolve(projectRoot, `./${sourceDir}`),
moduleDirectories: ['node_modules'],
plugins: [
new PathsPlugin(awesomeTypescriptLoaderConfig);
]
},
context: path.resolve(__dirname, './'),
entry: {
main: [path.resolve(projectRoot, './src/main.ts')],
vendor: path.resolve(projectRoot, './src/vendor.ts'),
polyfills: path.resolve(projectRoot, './src/polyfills.ts')
main: [path.resolve(projectRoot, `./${sourceDir}/main.ts`)],
vendor: path.resolve(projectRoot, `./${sourceDir}/vendor.ts`),
polyfills: path.resolve(projectRoot, `./${sourceDir}/polyfills.ts`)
},
output: {
path: path.resolve(projectRoot, './dist'),
Expand Down Expand Up @@ -70,7 +73,7 @@ export function getWebpackCommonConfig(projectRoot: string) {
plugins: [
new ForkCheckerPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(projectRoot, 'src/index.html'),
template: path.resolve(projectRoot, `./${sourceDir}/index.html`),
chunksSortMode: 'dependency'
}),
new webpack.optimize.CommonsChunkPlugin({
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/models/webpack-build-development.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CliConfig } from './config';
const path = require('path')

export const getWebpackDevConfigPartial = function(projectRoot: string) {
Expand All @@ -13,7 +14,7 @@ export const getWebpackDevConfigPartial = function(projectRoot: string) {
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: path.resolve(projectRoot, './src')
resourcePath: path.resolve(projectRoot, `./${CliConfig.fromProject().defaults.sourceDir}`)
},
node: {
global: 'window',
Expand Down
11 changes: 7 additions & 4 deletions addon/ng2/models/webpack-build-mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import * as path from 'path';
import * as OfflinePlugin from 'offline-plugin';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import { PrerenderWebpackPlugin } from '../utilities/prerender-webpack-plugin.ts';
import { CliConfig } from './config';

export const getWebpackMobileConfigPartial = function (projectRoot: string) {
const sourceDir = CliConfig.fromProject().defaults.sourceDir;

return {
plugins: [
new CopyWebpackPlugin([
{from: path.resolve(projectRoot, './src/icons'), to: path.resolve(projectRoot, './dist/icons')},
{from: path.resolve(projectRoot, './src/manifest.webapp'), to: path.resolve(projectRoot, './dist')}
{from: path.resolve(projectRoot, `./${sourceDir}/icons`), to: path.resolve(projectRoot, './dist/icons')},
{from: path.resolve(projectRoot, `./${sourceDir}/manifest.webapp`), to: path.resolve(projectRoot, './dist')}
]),
new PrerenderWebpackPlugin({
templatePath: 'index.html',
configPath: path.resolve(projectRoot, './src/main-app-shell.ts'),
appPath: path.resolve(projectRoot, './src')
configPath: path.resolve(projectRoot, `./${sourceDir}/main-app-shell.ts`),
appPath: path.resolve(projectRoot, `./${sourceDir}`)
})
]
}
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/models/webpack-build-production.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as webpack from 'webpack';
import { CliConfig } from './config';

const path = require('path');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
Expand Down Expand Up @@ -36,7 +37,7 @@ export const getWebpackProdConfigPartial = function(projectRoot: string) {
tslint: {
emitErrors: true,
failOnHint: true,
resourcePath: path.resolve(projectRoot, './src')
resourcePath: path.resolve(projectRoot, `./${CliConfig.fromProject().defaults.sourceDir}`)
},
htmlLoader: {
minimize: true,
Expand Down
13 changes: 8 additions & 5 deletions addon/ng2/models/webpack-build-test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as webpack from 'webpack';
import { CliConfig } from './config';

const path = require('path');

export const getWebpackTestConfig = function(projectRoot: string) {
const sourceDir = CliConfig.fromProject().defaults.sourceDir;

return {
devtool: 'inline-source-map',
context: path.resolve(__dirname, './'),
resolve: {
extensions: ['', '.ts', '.js'],
root: path.resolve(projectRoot, './src')
root: path.resolve(projectRoot, `./${sourceDir}`)
},
entry: {
test: path.resolve(projectRoot, './src/test.ts')
test: path.resolve(projectRoot, `./${sourceDir}/test.ts`)
},
output: {
path: './dist.test',
Expand Down Expand Up @@ -43,7 +46,7 @@ export const getWebpackTestConfig = function(projectRoot: string) {
loader: 'awesome-typescript-loader',
query: {
useWebpackText: true,
tsconfig: path.resolve(projectRoot, './src/tsconfig.json'),
tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`),
module: "commonjs",
target: "es5",
useForkChecker: true,
Expand All @@ -62,7 +65,7 @@ export const getWebpackTestConfig = function(projectRoot: string) {
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
{ test: /\.html$/, loader: 'raw-loader', exclude: [path.resolve(projectRoot, 'src/index.html')] }
{ test: /\.html$/, loader: 'raw-loader', exclude: [path.resolve(projectRoot, `./${sourceDir}/index.html`)] }
],
postLoaders: [
{
Expand All @@ -77,7 +80,7 @@ export const getWebpackTestConfig = function(projectRoot: string) {
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
resourcePath: `./${sourceDir}`
},
node: {
global: 'window',
Expand Down
3 changes: 2 additions & 1 deletion addon/ng2/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {webpackDevServerOutputOptions} from '../models/';
import {NgCliWebpackConfig} from '../models/webpack-config';
import {ServeTaskOptions} from '../commands/serve';
import { CliConfig } from '../models/config';

const path = require('path');
const chalk = require('chalk');
Expand Down Expand Up @@ -32,7 +33,7 @@ module.exports = Task.extend({
}));

const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = {
contentBase: path.resolve(this.project.root, './src'),
contentBase: path.resolve(this.project.root, `./${CliConfig.fromProject().defaults.sourceDir}`),
historyApiFallback: true,
stats: webpackDevServerOutputOptions,
inline: true,
Expand Down
10 changes: 5 additions & 5 deletions addon/ng2/tasks/test.js → addon/ng2/tasks/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* jshint node: true */
'use strict';
import { CliConfig } from '../models/config';

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
Expand All @@ -13,8 +12,9 @@ function requireDependency(root, moduleName) {
return require(path.join(root, 'node_modules', moduleName, main));
}

module.exports = Task.extend({
module.exports = Task.extend({
run: function (options) {
const sourceDir = CliConfig.fromProject().defaults.sourceDir;
var projectRoot = this.project.root;
return new Promise((resolve) => {

Expand All @@ -35,8 +35,8 @@ module.exports = Task.extend({
// Add those details here.

// Single test entry file. Will run the test.ts bundle and track it.
options.files = [{ pattern: './src/test.ts', watched: false }];
options.preprocessors = { './src/test.ts': ['webpack','sourcemap'] };
options.files = [{ pattern: `./${sourceDir}/test.ts`, watched: false }];
options.preprocessors = { `./${sourceDir}/test.ts`: ['webpack','sourcemap'] };
options.webpack = webpackTestConfig(projectRoot);
options.webpackMiddleware = {
noInfo: true, // Hide webpack output because its noisy.
Expand Down

0 comments on commit 0a851d6

Please sign in to comment.