Skip to content

New Architect API #13463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions etc/api/angular_devkit/core/src/_golden-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface AdditionalPropertiesValidatorError extends SchemaValidatorError
};
}

export declare function addUndefinedDefaults(value: JsonValue, _pointer: JsonPointer, schema?: JsonObject): JsonValue;
export declare function addUndefinedDefaults(value: JsonValue, _pointer: JsonPointer, schema?: JsonSchema): JsonValue;

export declare class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
protected _aliases: Map<Path, Path>;
Expand Down Expand Up @@ -989,7 +989,7 @@ export declare class UnsupportedPlatformException extends BaseException {

export declare type UriHandler = (uri: string) => Observable<JsonObject> | Promise<JsonObject> | null | undefined;

export declare function visitJson<ContextT>(json: JsonValue, visitor: JsonVisitor, schema?: JsonObject, refResolver?: ReferenceResolver<ContextT>, context?: ContextT): Observable<JsonValue>;
export declare function visitJson<ContextT>(json: JsonValue, visitor: JsonVisitor, schema?: JsonSchema, refResolver?: ReferenceResolver<ContextT>, context?: ContextT): Observable<JsonValue>;

export declare function visitJsonSchema(schema: JsonSchema, visitor: JsonSchemaVisitor): void;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
]
},
"dependencies": {
"@types/progress": "^2.0.3",
"glob": "^7.0.3",
"node-fetch": "^2.2.0",
"puppeteer": "1.12.2",
Expand Down
10 changes: 0 additions & 10 deletions packages/_/builders/builders.json

This file was deleted.

12 changes: 0 additions & 12 deletions packages/_/builders/package.json

This file was deleted.

20 changes: 0 additions & 20 deletions packages/_/builders/src/true.ts

This file was deleted.

46 changes: 46 additions & 0 deletions packages/angular_devkit/architect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,52 @@ licenses(["notice"]) # MIT

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
load("//tools:ts_json_schema.bzl", "ts_json_schema")

package(default_visibility = ["//visibility:public"])

ts_json_schema(
name = "builder_input_schema",
src = "src/input-schema.json",
)
ts_json_schema(
name = "builder_output_schema",
src = "src/output-schema.json",
)
ts_json_schema(
name = "builder_builders_schema",
src = "src/builders-schema.json",
)
ts_json_schema(
name = "progress_schema",
src = "src/progress-schema.json",
)

ts_library(
name = "node",
srcs = glob(
include = ["node/**/*.ts"],
exclude = [
"**/*_spec.ts",
"**/*_spec_large.ts",
],
),
module_name = "@angular-devkit/architect/node",
module_root = "node/index.d.ts",
# strict_checks = False,
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/core:node",
"@rxjs",
"@rxjs//operators",
"@npm//@types/node",
":architect",
":builder_builders_schema",
":builder_input_schema",
":builder_output_schema",
],
)

ts_library(
name = "architect",
srcs = glob(
Expand All @@ -29,6 +72,9 @@ ts_library(
"@rxjs",
"@rxjs//operators",
"@npm//@types/node",
":builder_input_schema",
":builder_output_schema",
":progress_schema",
],
)

Expand Down
59 changes: 59 additions & 0 deletions packages/angular_devkit/architect/builders/all-of.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { json } from '@angular-devkit/core';
import { EMPTY, from, of } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
import { BuilderOutput, BuilderRun, createBuilder } from '../src/index2';
import { Schema as OperatorSchema } from './operator-schema';

export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
const allRuns: Promise<[number, BuilderRun]>[] = [];

context.reportProgress(0,
(options.targets ? options.targets.length : 0)
+ (options.builders ? options.builders.length : 0),
);

if (options.targets) {
allRuns.push(...options.targets.map(({ target: targetStr, overrides }, i) => {
const [project, target, configuration] = targetStr.split(/:/g, 3);

return context.scheduleTarget({ project, target, configuration }, overrides || {})
.then(run => [i, run] as [number, BuilderRun]);
}));
}

if (options.builders) {
allRuns.push(...options.builders.map(({ builder, options }, i) => {
return context.scheduleBuilder(builder, options || {})
.then(run => [i, run] as [number, BuilderRun]);
}));
}

const allResults: (BuilderOutput | null)[] = allRuns.map(() => null);
let n = 0;
context.reportProgress(n++, allRuns.length);

return from(allRuns).pipe(
mergeMap(runPromise => from(runPromise)),
mergeMap(([i, run]: [number, BuilderRun]) => run.output.pipe(map(output => [i, output]))),
mergeMap<[number, BuilderOutput], BuilderOutput>(([i, output]) => {
allResults[i] = output;
context.reportProgress(n++, allRuns.length);

if (allResults.some(x => x === null)) {
// Some builders aren't done running yet.
return EMPTY;
} else {
return of({
success: allResults.every(x => x ? x.success : false),
});
}
}),
);
});
25 changes: 25 additions & 0 deletions packages/angular_devkit/architect/builders/builders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "../src/builders-schema.json",
"builders": {
"true": {
"implementation": "./true",
"schema": "./noop-schema.json",
"description": "Always succeed."
},
"false": {
"implementation": "./false",
"schema": "./noop-schema.json",
"description": "Always fails."
},
"allOf": {
"implementation": "./all-of",
"schema": "./operator-schema.json",
"description": "A builder that executes many builders in parallel, and succeed if both succeeds."
},
"concat": {
"implementation": "./concat",
"schema": "./operator-schema.json",
"description": "A builder that executes many builders one after the other, and stops when one fail. It will succeed if all builders succeeds (and return the last output)"
}
}
}
56 changes: 56 additions & 0 deletions packages/angular_devkit/architect/builders/concat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { json } from '@angular-devkit/core';
import { from, of } from 'rxjs';
import { concatMap, first, last, map, switchMap } from 'rxjs/operators';
import { BuilderOutput, BuilderRun, createBuilder } from '../src/index2';
import { Schema as OperatorSchema } from './operator-schema';

export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
const allRuns: (() => Promise<BuilderRun>)[] = [];

context.reportProgress(0,
(options.targets ? options.targets.length : 0)
+ (options.builders ? options.builders.length : 0),
);

if (options.targets) {
allRuns.push(...options.targets.map(({ target: targetStr, overrides }) => {
const [project, target, configuration] = targetStr.split(/:/g, 3);

return () => context.scheduleTarget({ project, target, configuration }, overrides || {});
}));
}

if (options.builders) {
allRuns.push(...options.builders.map(({ builder, options }) => {
return () => context.scheduleBuilder(builder, options || {});
}));
}

let stop: BuilderOutput | null = null;
let i = 0;
context.reportProgress(i++, allRuns.length);

return from(allRuns).pipe(
concatMap(fn => stop ? of(null) : from(fn()).pipe(
switchMap(run => run === null ? of(null) : run.output.pipe(first())),
)),
map(output => {
context.reportProgress(i++, allRuns.length);
if (output === null || stop !== null) {
return stop || { success: false };
} else if (output.success === false) {
return stop = output;
} else {
return output;
}
}),
last(),
);
});
14 changes: 14 additions & 0 deletions packages/angular_devkit/architect/builders/false.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { of } from 'rxjs';
import { createBuilder } from '../src/index2';

export default createBuilder(() => of({
success: false,
error: 'False builder always errors.',
}));
45 changes: 45 additions & 0 deletions packages/angular_devkit/architect/builders/operator-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "http://json-schema.org/schema",
"description": "All input types of builders that perform operations on one or multiple sub-builders.",
"type": "object",
"properties": {
"builders": {
"type": "array",
"items": {
"type": "object",
"properties": {
"builder": {
"type": "string",
"pattern": ".*:.*"
},
"options": {
"type": "object"
}
},
"required": [
"builder"
]
},
"minItems": 1
},
"targets": {
"type": "array",
"items": {
"type": "object",
"properties": {
"target": {
"type": "string",
"pattern": ".*:.*"
},
"overrides": {
"type": "object"
}
},
"required": [
"target"
]
},
"minItems": 1
}
}
}
11 changes: 11 additions & 0 deletions packages/angular_devkit/architect/builders/true.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { of } from 'rxjs';
import { createBuilder } from '../src/index2';

export default createBuilder(() => of({ success: true }));
8 changes: 8 additions & 0 deletions packages/angular_devkit/architect/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export * from './node-modules-architect-host';
Loading