forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschematics.ts
More file actions
54 lines (45 loc) · 1.55 KB
/
Copy pathschematics.ts
File metadata and controls
54 lines (45 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
49
50
51
52
53
54
// tslint:disable:no-global-tslint-disable no-any file-header
import { schema } from '@angular-devkit/core';
import {
Collection,
Engine,
Schematic,
SchematicEngine,
formats,
} from '@angular-devkit/schematics';
import {
FileSystemCollectionDesc,
FileSystemSchematicDesc,
NodeModulesEngineHost,
validateOptionsWithSchema,
} from '@angular-devkit/schematics/tools';
export class UnknownCollectionError extends Error {
constructor(collectionName: string) {
super(`Invalid collection (${collectionName}).`);
}
}
const engineHost = new NodeModulesEngineHost();
const engine: Engine<FileSystemCollectionDesc, FileSystemSchematicDesc>
= new SchematicEngine(engineHost);
// Add support for schemaJson.
const registry = new schema.CoreSchemaRegistry(formats.standardFormats);
engineHost.registerOptionsTransform(validateOptionsWithSchema(registry));
export function getEngineHost() {
return engineHost;
}
export function getEngine(): Engine<FileSystemCollectionDesc, FileSystemSchematicDesc> {
return engine;
}
export function getCollection(collectionName: string): Collection<any, any> {
const engine = getEngine();
const collection = engine.createCollection(collectionName);
if (collection === null) {
throw new UnknownCollectionError(collectionName);
}
return collection;
}
export function getSchematic(collection: Collection<any, any>,
schematicName: string,
allowPrivate?: boolean): Schematic<any, any> {
return collection.createSchematic(schematicName, allowPrivate);
}