/
index.ts
101 lines (95 loc) · 2.59 KB
/
index.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import {
Tree,
SchematicContext,
Rule,
branchAndMerge,
mergeWith,
apply,
url,
template,
move
} from '@angular-devkit/schematics';
import {
updateTsConfig,
IHelperSchema,
IHelperConfig,
getDefaultTemplateOptions,
XplatHelpers
} from '@nstudio/xplat';
export const config: IHelperConfig = {
addHelperFiles,
additionalSupport: imports
};
function addHelperFiles(options: IHelperSchema): Rule {
// executed from 'helpers' directory so ensure _files are loaded relative
const xplatFolderName = XplatHelpers.getXplatFoldername('nativescript');
return branchAndMerge(
mergeWith(
apply(url(`./imports/_files`), [
template({
...(options as any),
...getDefaultTemplateOptions()
}),
move(`xplat/${xplatFolderName}/utils`)
])
)
);
}
function imports(helperChains: Array<any>, options: IHelperSchema) {
return (tree: Tree, context: SchematicContext) => {
const xplatFolderName = XplatHelpers.getXplatFoldername('nativescript');
let pathRef = `xplat/${xplatFolderName}/utils/@nativescript/*`;
// update root tsconfig
helperChains.push(
updateTsConfig(tree, (tsConfig: any) => {
const updates: any = {};
updates[`@nativescript/*`] = [pathRef];
if (tsConfig) {
if (!tsConfig.compilerOptions) {
tsConfig.compilerOptions = {};
}
tsConfig.compilerOptions.paths = {
...(tsConfig.compilerOptions.paths || {}),
...updates
};
}
})
);
// update all {N} app tsconfig's
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
pathRef = `../../${pathRef}`;
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (
dir.indexOf('nativescript-') === 0 ||
dir.indexOf('-nativescript') === 0
) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
helperChains.push(
updateTsConfig(
tree,
(tsConfig: any) => {
const updates: any = {};
updates[`@nativescript/*`] = [pathRef];
if (tsConfig) {
if (!tsConfig.compilerOptions) {
tsConfig.compilerOptions = {};
}
tsConfig.compilerOptions.paths = {
...(tsConfig.compilerOptions.paths || {}),
...updates
};
}
},
null,
`${appDir}/`
)
);
}
}
return tree;
};
}