Skip to content

Commit

Permalink
fix(build): re-add support for sourceDir (angular#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and johannes.werner committed Aug 15, 2016
1 parent 83c86c2 commit 89f521e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
13 changes: 7 additions & 6 deletions addon/ng2/models/webpack-build-test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as webpack from 'webpack';
import { CliConfig } from './config';

const path = require('path');

export const getWebpackTestConfig = function(projectRoot: string) {
export const getWebpackTestConfig = function(projectRoot: string, sourceDir: string) {
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 +44,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 +63,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 +78,7 @@ export const getWebpackTestConfig = function(projectRoot: string) {
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
resourcePath: `./${sourceDir}`
},
node: {
global: 'window',
Expand Down
Empty file removed addon/ng2/tasks/test.js
Empty file.
33 changes: 0 additions & 33 deletions addon/ng2/tasks/test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +0,0 @@
import * as Promise from 'ember-cli/lib/ext/promise';
import * as Task from 'ember-cli/lib/models/task';
import * as path from 'path';
import { getWebpackTestConfig } from '../models/webpack-build-test';

// require dependencies within the target project
function requireDependency(root, moduleName) {
const packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json'));
const main = path.normalize(packageJson.main);
return require(path.join(root, 'node_modules', moduleName, main));
}

module.exports = Task.extend({
run: function (options) {
const projectRoot = this.project.root;
return new Promise((resolve) => {
const karma = requireDependency(projectRoot, 'karma');
const karmaConfig = path.join(projectRoot, this.project.ngConfig.test.karma.config);

// Convert browsers from a string to an array
if (options.browsers) {
options.browsers = options.browsers.split(',');
}

// Assign additional karmaConfig options to the local ngapp config
options.configFile = karmaConfig;

// :shipit:
const karmaServer = new karma.Server(options, resolve);
karmaServer.start();
});
}
});

0 comments on commit 89f521e

Please sign in to comment.