-
Notifications
You must be signed in to change notification settings - Fork 571
/
build-meta-config.ts
54 lines (45 loc) · 1.49 KB
/
build-meta-config.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
import { strings } from '@angular-devkit/core';
import {
SchematicContext,
Tree,
SchematicsException,
url,
apply,
applyTemplates,
Rule,
move,
mergeWith,
} from '@angular-devkit/schematics';
import { parseName } from '@schematics/angular/utility/parse-name';
import { findModuleFromOptions } from '@schematics/angular/utility/find-module';
import { buildDefaultPath, getProject } from '@schematics/angular/utility/project';
import { dirname, normalize } from '@angular-devkit/core';
export function buildMetaConfig(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
if (!_options.project) {
throw new SchematicsException('Option (project) is required.');
}
const project = getProject(tree, _options.project);
if (_options.path === undefined) {
_options.path = buildDefaultPath(project);
}
_options.module = findModuleFromOptions(tree, _options);
const parsedPath = parseName(dirname(normalize(_options.module)), 'not applicable');
_options.metaname = parsedPath.name;
_options.metapath = parsedPath.path;
const metaConfigExists = tree.exists('/src/app/app-chart-config.ts');
if (metaConfigExists) {
return tree;
}
const templateSource = apply(url('./files'), [
applyTemplates({
...strings,
'if-flat': (s: string) => _options.flat ? '' : s,
..._options,
}),
move(parsedPath.path),
]);
return mergeWith(templateSource);
// return undefined;
};
}