-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.js
More file actions
48 lines (38 loc) · 1.55 KB
/
helpers.js
File metadata and controls
48 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var path = require('path');
function isWebpackDevServer() {
return process.argv[1] && !!(/webpack-dev-server/.exec(process.argv[1]));
}
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}
function createTsConfigPathAliases(tsConfig) {
var alias = {};
var baseUrl = tsConfig.compilerOptions.baseUrl;
var tsPaths = tsConfig.compilerOptions.paths;
for (var prop in tsPaths) {
let relativePath = tsPaths[prop][0];
const wildcardEnding = '/*';
// Trim wildcards (we don't need them for webpack aliases - it works as wildcard by default)
if (prop.endsWith(wildcardEnding) && relativePath.endsWith(wildcardEnding)) {
prop = prop.substring(0, prop.length - wildcardEnding.length);
relativePath = relativePath.substring(0, relativePath.length - wildcardEnding.length);
}
alias[prop] = root(baseUrl, relativePath);
//console.log('ALIAS: ' + prop + '=' + alias[prop]);
}
return alias;
}
function isTestWatch() {
return process.env.npm_lifecycle_script.indexOf('--auto-watch') !== -1;
}
function isTestCoverageEnabled() {
// skip coverage in watch mode
// See http://stackoverflow.com/questions/39131809/karma-webpack-sourcemaps-not-working
return !isTestWatch();
}
exports.isWebpackDevServer = isWebpackDevServer;
exports.root = root;
exports.createTsConfigPathAliases = createTsConfigPathAliases;
exports.isTestWatch = isTestWatch;
exports.isTestCoverageEnabled = isTestCoverageEnabled;