1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { logging } from '@angular-devkit/core';
|
9 | import { Observable } from 'rxjs';
|
10 | import { Url } from 'url';
|
11 | import { FileEntry, MergeStrategy, Tree } from '../tree/interface';
|
12 | import { Workflow } from '../workflow/interface';
|
13 | export interface TaskConfiguration<T = {}> {
|
14 | name: string;
|
15 | dependencies?: Array<TaskId>;
|
16 | options?: T;
|
17 | }
|
18 | export interface TaskConfigurationGenerator<T = {}> {
|
19 | toConfiguration(): TaskConfiguration<T>;
|
20 | }
|
21 | export type TaskExecutor<T = {}> = (options: T | undefined, context: SchematicContext) => Promise<void> | Observable<void>;
|
22 | export interface TaskExecutorFactory<T> {
|
23 | readonly name: string;
|
24 | create(options?: T): Promise<TaskExecutor> | Observable<TaskExecutor>;
|
25 | }
|
26 | export interface TaskId {
|
27 | readonly id: number;
|
28 | }
|
29 | export interface TaskInfo {
|
30 | readonly id: number;
|
31 | readonly priority: number;
|
32 | readonly configuration: TaskConfiguration;
|
33 | readonly context: SchematicContext;
|
34 | }
|
35 | export interface ExecutionOptions {
|
36 | scope: string;
|
37 | interactive: boolean;
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export type CollectionDescription<CollectionMetadataT extends object> = CollectionMetadataT & {
|
45 | readonly name: string;
|
46 | readonly extends?: string[];
|
47 | };
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export type SchematicDescription<CollectionMetadataT extends object, SchematicMetadataT extends object> = SchematicMetadataT & {
|
54 | readonly collection: CollectionDescription<CollectionMetadataT>;
|
55 | readonly name: string;
|
56 | readonly private?: boolean;
|
57 | readonly hidden?: boolean;
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export interface EngineHost<CollectionMetadataT extends object, SchematicMetadataT extends object> {
|
65 | createCollectionDescription(name: string, requester?: CollectionDescription<CollectionMetadataT>): CollectionDescription<CollectionMetadataT>;
|
66 | listSchematicNames(collection: CollectionDescription<CollectionMetadataT>, includeHidden?: boolean): string[];
|
67 | createSchematicDescription(name: string, collection: CollectionDescription<CollectionMetadataT>): SchematicDescription<CollectionMetadataT, SchematicMetadataT> | null;
|
68 | getSchematicRuleFactory<OptionT extends object>(schematic: SchematicDescription<CollectionMetadataT, SchematicMetadataT>, collection: CollectionDescription<CollectionMetadataT>): RuleFactory<OptionT>;
|
69 | createSourceFromUrl(url: Url, context: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): Source | null;
|
70 | transformOptions<OptionT extends object, ResultT extends object>(schematic: SchematicDescription<CollectionMetadataT, SchematicMetadataT>, options: OptionT, context?: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): Observable<ResultT>;
|
71 | transformContext(context: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): TypedSchematicContext<CollectionMetadataT, SchematicMetadataT> | void;
|
72 | createTaskExecutor(name: string): Observable<TaskExecutor>;
|
73 | hasTaskExecutor(name: string): boolean;
|
74 | readonly defaultMergeStrategy?: MergeStrategy;
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export interface Engine<CollectionMetadataT extends object, SchematicMetadataT extends object> {
|
87 | createCollection(name: string, requester?: Collection<CollectionMetadataT, SchematicMetadataT>): Collection<CollectionMetadataT, SchematicMetadataT>;
|
88 | createContext(schematic: Schematic<CollectionMetadataT, SchematicMetadataT>, parent?: Partial<TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>>, executionOptions?: Partial<ExecutionOptions>): TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>;
|
89 | createSchematic(name: string, collection: Collection<CollectionMetadataT, SchematicMetadataT>): Schematic<CollectionMetadataT, SchematicMetadataT>;
|
90 | createSourceFromUrl(url: Url, context: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): Source;
|
91 | transformOptions<OptionT extends object, ResultT extends object>(schematic: Schematic<CollectionMetadataT, SchematicMetadataT>, options: OptionT, context?: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): Observable<ResultT>;
|
92 | executePostTasks(): Observable<void>;
|
93 | readonly defaultMergeStrategy: MergeStrategy;
|
94 | readonly workflow: Workflow | null;
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export interface Collection<CollectionMetadataT extends object, SchematicMetadataT extends object> {
|
101 | readonly description: CollectionDescription<CollectionMetadataT>;
|
102 | readonly baseDescriptions?: Array<CollectionDescription<CollectionMetadataT>>;
|
103 | createSchematic(name: string, allowPrivate?: boolean): Schematic<CollectionMetadataT, SchematicMetadataT>;
|
104 | listSchematicNames(includeHidden?: boolean): string[];
|
105 | }
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export interface Schematic<CollectionMetadataT extends object, SchematicMetadataT extends object> {
|
111 | readonly description: SchematicDescription<CollectionMetadataT, SchematicMetadataT>;
|
112 | readonly collection: Collection<CollectionMetadataT, SchematicMetadataT>;
|
113 | call<OptionT extends object>(options: OptionT, host: Observable<Tree>, parentContext?: Partial<TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>>, executionOptions?: Partial<ExecutionOptions>): Observable<Tree>;
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | export interface TypedSchematicContext<CollectionMetadataT extends object, SchematicMetadataT extends object> {
|
120 | readonly debug: boolean;
|
121 | readonly engine: Engine<CollectionMetadataT, SchematicMetadataT>;
|
122 | readonly logger: logging.LoggerApi;
|
123 | readonly schematic: Schematic<CollectionMetadataT, SchematicMetadataT>;
|
124 | readonly strategy: MergeStrategy;
|
125 | readonly interactive: boolean;
|
126 | addTask<T extends object>(task: TaskConfigurationGenerator<T>, dependencies?: Array<TaskId>): TaskId;
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | export type SchematicContext = TypedSchematicContext<{}, {}>;
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | export type RuleFactory<T extends object> = (options: T) => Rule;
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | export type FileOperator = (entry: FileEntry) => FileEntry | null;
|
143 | export type AsyncFileOperator = (tree: FileEntry) => Observable<FileEntry | null>;
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | export type Source = (context: SchematicContext) => Tree | Observable<Tree>;
|
154 | export type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void | Rule> | void;
|