79e99040
ABNER SILVA DE OLIVEIRA
versão inicial co...
|
1
2
|
/* global __dirname */
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
3
4
|
var argv = require("yargs").argv;
var path = require("path");
|
79e99040
ABNER SILVA DE OLIVEIRA
versão inicial co...
|
5
|
var glob = require("glob");
|
50a53289
ABNER SILVA DE OLIVEIRA
adicionado arquiv...
|
6
|
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
7
8
|
var WebpackOnBuildPlugin = require('on-build-webpack');
|
50a53289
ABNER SILVA DE OLIVEIRA
adicionado arquiv...
|
9
|
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
10
11
12
|
var extension = ".js";
if (argv.production) {
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
13
|
extension = ".min.js"
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
14
15
|
}
|
78b1f609
Ábner Oliveira
changes to make c...
|
16
|
var testFiles = glob.sync("./src/**/**/*.[sS]pec.ts");
|
69b2897c
ABNER SILVA DE OLIVEIRA
npm test now run ...
|
17
|
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
18
|
var uglifyLoaderConfig = {
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
19
20
21
22
|
// I want to uglify with mangling only app files, not thirdparty libs
test: /\.js$/,
exclude: /.spec.js/, // excluding .spec files
loader: "uglify"
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
23
24
|
};
|
78b1f609
Ábner Oliveira
changes to make c...
|
25
|
var testingFiles = glob.sync("./src/app/**/**/*.[sS]pec.ts");
|
79e99040
ABNER SILVA DE OLIVEIRA
versão inicial co...
|
26
|
|
78b1f609
Ábner Oliveira
changes to make c...
|
27
28
29
|
var entries = {
noosfero: './src/app/index.ts',
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
30
|
'noosfero-specs': testFiles, // './src/specs.ts',
|
78b1f609
Ábner Oliveira
changes to make c...
|
31
32
33
|
'vendor.bundle': ['core-js', 'reflect-metadata', 'ng-forward', 'ng-forward/cjs/testing/test-component-builder']
};
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
34
|
var webpackConfig = {
|
78b1f609
Ábner Oliveira
changes to make c...
|
35
|
entry: entries,
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
36
|
|
78b1f609
Ábner Oliveira
changes to make c...
|
37
|
plugins: [new CommonsChunkPlugin("commons", "commons.js")],
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
38
|
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
39
40
41
42
|
output: {
path: path.join(__dirname, "src"),
filename: "[name]" + extension,
},
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
43
44
45
46
47
48
49
50
51
52
53
54
55
|
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
// Source maps support (or 'inline-source-map' also works)
devtool: 'source-map',
module: {
loaders: [{
test: /\.css$/,
loader: "style!css"
}, {
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
56
57
58
59
60
61
62
63
64
65
66
67
|
test: /\.scss$/,
loaders: ["style", "css?sourceMap", "sass?sourceMap"]
}, {
test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
loader: 'url-loader?limit=100000'
}, {
test: /\.tsx?$/,
loader: 'ts-loader'
}, {
test: /\.ts?$/,
loader: "tslint"
}]
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
68
|
}
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
69
70
71
|
};
if (argv.production) {
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
72
73
74
|
webpackConfig.module.loaders.push(uglifyLoaderConfig);
}
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
75
76
77
|
// if webpack executed with --test argument, this code bellow will add a post-compilation
// code which will run the Tests + Coverage (npm run coverage)
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
78
79
80
81
|
var testProcess = null;
var child_process = require("child_process");
var count = 0;
var stdinPatched = false;
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
82
83
|
|
babe9d57
ABNER SILVA DE OLIVEIRA
testing scripts a...
|
84
|
if (argv.test) {
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
85
86
|
function spawnChildProcessTest() {
if (!testProcess) {
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
87
88
89
90
91
92
|
testProcess = child_process.spawn("npm", ["run", "coverage"], {
stdio: 'inherit'
});
testProcess.on('exit', function() {
testProcess = null
});
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
93
94
95
|
}
}
// configure the webPackOnBuildPlugin with our post-compilation function as argument
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
96
|
var onBuildPluginConfigured = new WebpackOnBuildPlugin(function(stats) {
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
97
98
99
100
|
// here we are patching the stdin to allow trigger tests when pressing 'Enter'
// on terminal
if (!stdinPatched) {
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
101
|
process.stdin.on('data', function(info) {
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
102
103
104
105
106
107
|
if (info == '\n') {
spawnChildProcessTest();
}
});
stdinPatched = true;
}
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
108
|
|
232ead7e
ABNER SILVA DE OLIVEIRA
merge and small i...
|
109
110
111
112
113
114
115
116
117
118
119
|
// webpack in watch mode call this twice for just one compilation
// so, here we are checking if the process is still running before trigger another test execution
if (testProcess == null) {
console.log("Starting tests execution...");
spawnChildProcessTest();
} else {
console.log("Test still running... Sorry webpack!! :)");
}
});
webpackConfig.plugins.push(onBuildPluginConfigured);
|
d81889c2
ABNER SILVA DE OLIVEIRA
first typescript ...
|
120
121
|
}
|
d1dd6539
ABNER SILVA DE OLIVEIRA
Fix the dist build
|
122
|
module.exports = webpackConfig;
|