-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
2,315 additions
and
252 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, tap } 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.progress(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; | ||
|
||
return from(allRuns).pipe( | ||
tap(() => context.progress(0, allRuns.length)), | ||
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.progress(++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), | ||
}); | ||
} | ||
}), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @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.progress(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.progress(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.progress(i++, allRuns.length); | ||
if (output === null || stop !== null) { | ||
return stop || { success: false }; | ||
} else if (output.success === false) { | ||
return stop = output; | ||
} else { | ||
return output; | ||
} | ||
}), | ||
last(), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
})); |
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
packages/angular_devkit/architect/builders/operator-schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.