Skip to content

fix(build): re-add support for sourceDir #1378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 7 additions & 6 deletions addon/ng2/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
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) {
export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
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')],
polyfills: path.resolve(projectRoot, './src/polyfills.ts')
main: [path.resolve(projectRoot, `./${sourceDir}/main.ts`)],
polyfills: path.resolve(projectRoot, `./${sourceDir}/polyfills.ts`)
},
output: {
path: path.resolve(projectRoot, './dist'),
Expand Down Expand Up @@ -69,7 +70,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
5 changes: 3 additions & 2 deletions addon/ng2/models/webpack-build-development.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CliConfig } from './config';
const path = require('path')

export const getWebpackDevConfigPartial = function(projectRoot: string) {
export const getWebpackDevConfigPartial = function(projectRoot: string, sourceDir: string) {
return {
debug: true,
devtool: 'cheap-module-source-map',
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, `./${sourceDir}`)
},
node: {
global: 'window',
Expand Down
11 changes: 6 additions & 5 deletions addon/ng2/models/webpack-build-mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ 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) {
export const getWebpackMobileConfigPartial = function (projectRoot: string, sourceDir: string) {
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
5 changes: 3 additions & 2 deletions addon/ng2/models/webpack-build-production.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as webpack from 'webpack';
import { CliConfig } from './config';

const path = require('path');
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const WebpackMd5Hash = require('webpack-md5-hash');
const CompressionPlugin = require("compression-webpack-plugin");

export const getWebpackProdConfigPartial = function(projectRoot: string) {
export const getWebpackProdConfigPartial = function(projectRoot: string, sourceDir: string) {
return {
debug: false,
devtool: 'source-map',
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, `./${sourceDir}`)
},
htmlLoader: {
minimize: true,
Expand Down
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
12 changes: 7 additions & 5 deletions addon/ng2/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export class NgCliWebpackConfig {
private webpackMobileProdConfigPartial: any;

constructor(public ngCliProject: any, public environment: string) {
this.webpackBaseConfig = getWebpackCommonConfig(this.ngCliProject.root);
this.webpackDevConfigPartial = getWebpackDevConfigPartial(this.ngCliProject.root);
this.webpackProdConfigPartial = getWebpackProdConfigPartial(this.ngCliProject.root);
const sourceDir = CliConfig.fromProject().defaults.sourceDir;

this.webpackBaseConfig = getWebpackCommonConfig(this.ngCliProject.root, sourceDir);
this.webpackDevConfigPartial = getWebpackDevConfigPartial(this.ngCliProject.root, sourceDir);
this.webpackProdConfigPartial = getWebpackProdConfigPartial(this.ngCliProject.root, sourceDir);

if (CliConfig.fromProject().apps[0].mobile){
this.webpackMobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root);
this.webpackMobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root);
this.webpackMobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, sourceDir);
this.webpackMobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root, sourceDir);
this.webpackBaseConfig = webpackMerge(this.webpackBaseConfig, this.webpackMobileConfigPartial);
this.webpackProdConfigPartial = webpackMerge(this.webpackProdConfigPartial, this.webpackMobileProdConfigPartial);
}
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
31 changes: 14 additions & 17 deletions addon/ng2/tasks/test.js → addon/ng2/tasks/test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/* jshint node: true */
'use strict';

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var path = require('path');
var webpackTestConfig = require('../models/webpack-build-test').getWebpackTestConfig;
const Promise = require('ember-cli/lib/ext/promise');
const Task = require('ember-cli/lib/models/task');
const path = require('path');
const webpackTestConfig = require('../models/webpack-build-test').getWebpackTestConfig;

// require dependencies within the target project
function requireDependency(root, moduleName) {
var packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json'));
var main = path.normalize(packageJson.main);
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({
module.exports = Task.extend({
run: function (options) {
var projectRoot = this.project.root;
const projectRoot = this.project.root;
return new Promise((resolve) => {

var karma = requireDependency(projectRoot, 'karma');
var karmaConfig = path.join(projectRoot, this.project.ngConfig.test.karma.config);
const karma = requireDependency(projectRoot, 'karma');
const karmaConfig = path.join(projectRoot, this.project.ngConfig.test.karma.config);
const testFile = `./${this.project.ngConfig.defaults.sourceDir}/test.ts`;

options.plugins = [
require('karma-webpack'),
Expand All @@ -35,8 +32,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: testFile, watched: false }];
options.preprocessors = { [testFile]: ['webpack','sourcemap'] };
options.webpack = webpackTestConfig(projectRoot);
options.webpackMiddleware = {
noInfo: true, // Hide webpack output because its noisy.
Expand All @@ -60,7 +57,7 @@ module.exports = Task.extend({
options.configFile = karmaConfig;

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