-
Notifications
You must be signed in to change notification settings - Fork 3
/
espower-typescript.js
43 lines (35 loc) · 1.18 KB
/
espower-typescript.js
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
var fs = require('fs');
var path = require('path');
var ts = require('typescript');
var pattern = 'test/**/*.@(ts|tsx)';
var cwd = process.cwd();
var packageData = require(path.join(cwd, 'package.json'));
if (packageData &&
typeof packageData.directories === 'object' &&
typeof packageData.directories.test === 'string') {
var testDir = packageData.directories.test;
pattern = testDir + ((testDir.lastIndexOf('/', 0) === 0) ? '' : '/') + '**/*.@(ts|tsx)';
}
var tsconfigPath = ts.findConfigFile(cwd, fs.existsSync, 'tsconfig.test.json');
var tsconfigBasepath = null;
var compilerOptions = null;
if (tsconfigPath) {
compilerOptions = parseTsConfig(tsconfigPath);
tsconfigBasepath = path.dirname(tsconfigPath);
}
require('espower-typescript')({
cwd: cwd,
pattern: pattern,
compilerOptions: compilerOptions,
basepath: tsconfigBasepath
});
function parseTsConfig(tsconfigPath) {
var parsed = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, 'utf8'));
if (parsed.error) {
throw new Error(parsed.error.messageText);
}
if (!parsed.config || !parsed.config.compilerOptions) {
return null;
}
return parsed.config.compilerOptions;
}