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