UNPKG

3.1 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { json } from '@angular-devkit/core';
9import { BuilderInfo, BuilderInput, BuilderOutput, Target } from './api';
10import { JobDescription, JobHandler } from './jobs';
11/**
12 * BuilderSymbol used for knowing if a function was created using createBuilder(). This is a
13 * property set on the function that should be `true`.
14 * Using Symbol.for() as it's a global registry that's the same for all installations of
15 * Architect (if some libraries depends directly on architect instead of sharing the files).
16 */
17export declare const BuilderSymbol: unique symbol;
18/**
19 * BuilderVersionSymbol used for knowing which version of the library createBuilder() came from.
20 * This is to make sure we don't try to use an incompatible builder.
21 * Using Symbol.for() as it's a global registry that's the same for all installations of
22 * Architect (if some libraries depends directly on architect instead of sharing the files).
23 */
24export declare const BuilderVersionSymbol: unique symbol;
25/**
26 * A Specialization of the JobHandler type. This exposes BuilderDescription as the job description
27 * type.
28 */
29export declare type BuilderJobHandler<A extends json.JsonObject = json.JsonObject, I extends BuilderInput = BuilderInput, O extends BuilderOutput = BuilderOutput> = JobHandler<A, I, O> & {
30 jobDescription: BuilderDescription;
31};
32/**
33 * A Builder description, which is used internally. Adds the builder info which is the
34 * metadata attached to a builder in Architect.
35 */
36export interface BuilderDescription extends JobDescription {
37 info: BuilderInfo;
38}
39/**
40 * A Builder instance. Use createBuilder() to create one of these.
41 */
42export interface Builder<OptionT extends json.JsonObject = json.JsonObject> {
43 handler: JobHandler<json.JsonObject, BuilderInput, BuilderOutput>;
44 [BuilderSymbol]: true;
45 [BuilderVersionSymbol]: string;
46}
47export interface ArchitectHost<BuilderInfoT extends BuilderInfo = BuilderInfo> {
48 /**
49 * Get the builder name for a target.
50 * @param target The target to inspect.
51 */
52 getBuilderNameForTarget(target: Target): Promise<string | null>;
53 /**
54 * Resolve a builder. This needs to return a string which will be used in a dynamic `import()`
55 * clause. This should throw if no builder can be found. The dynamic import will throw if
56 * it is unsupported.
57 * @param builderName The name of the builder to be used.
58 * @returns All the info needed for the builder itself.
59 */
60 resolveBuilder(builderName: string): Promise<BuilderInfoT | null>;
61 loadBuilder(info: BuilderInfoT): Promise<Builder | null>;
62 getCurrentDirectory(): Promise<string>;
63 getWorkspaceRoot(): Promise<string>;
64 getOptionsForTarget(target: Target): Promise<json.JsonObject | null>;
65 getProjectMetadata(projectName: string): Promise<json.JsonObject | null>;
66 getProjectMetadata(target: Target): Promise<json.JsonObject | null>;
67}