forked from Adornis/typescript-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-utils.js
65 lines (53 loc) · 1.77 KB
/
file-utils.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const colors = Npm.require('colors');
export function isBare(inputFile) {
const fileOptions = inputFile.getFileOptions();
return fileOptions && fileOptions.bare;
}
// Gets root app tsconfig.
export function isMainConfig(inputFile) {
if (! isWeb(inputFile)) return false;
const filePath = inputFile.getPathInPackage();
return /^tsconfig\.json$/.test(filePath);
}
export function isConfig(inputFile) {
const filePath = inputFile.getPathInPackage();
return /tsconfig\.json$/.test(filePath);
}
// Gets server tsconfig.
export function isServerConfig(inputFile) {
if (isWeb(inputFile)) return false;
const filePath = inputFile.getPathInPackage();
return /^server\/tsconfig\.json$/.test(filePath);
}
// Checks if it's .d.ts-file.
export function isDeclaration(inputFile) {
return TypeScript.isDeclarationFile(inputFile.getBasename());
}
export function isWeb(inputFile) {
const arch = inputFile.getArch();
return /^web/.test(arch);
}
// Gets path with package prefix if any.
export function getExtendedPath(inputFile) {
let packageName = inputFile.getPackageName();
packageName = packageName ?
(packageName.replace(':', '_') + '/') : '';
const inputFilePath = inputFile.getPathInPackage();
return packageName + inputFilePath;
}
export function getES6ModuleName(inputFile) {
const extended = getExtendedPath(inputFile);
return TypeScript.removeTsExt(extended);
}
export const WarnMixin = {
warn(error) {
console.log(`${error.sourcePath} (${error.line}, ${error.column}): ${error.message}`);
},
logError(error) {
console.log(colors.red(
`${error.sourcePath} (${error.line}, ${error.column}): ${error.message}`));
}
}
export function extendFiles(inputFiles, fileMixin) {
inputFiles.forEach(inputFile => _.defaults(inputFile, fileMixin));
}