Repository navigation
fix(docs-infra): convert hard-coded cli-builder examples into proper mini-app
#34362
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
Closed
sonukapoor
wants to merge
1
commit into
angular:master
from
sonukapoor:extract-hardcoded-from-cli-builder-into-files
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,48 @@ | ||
| // #docregion | ||
| import { Architect } from '@angular-devkit/architect'; | ||
| import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
| import { logging, schema } from '@angular-devkit/core'; | ||
|
|
||
| describe('Command Runner Builder', () => { | ||
| let architect: Architect; | ||
| let architectHost: TestingArchitectHost; | ||
|
|
||
| beforeEach(async () => { | ||
| const registry = new schema.CoreSchemaRegistry(); | ||
| registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
|
|
||
| // TestingArchitectHost() takes workspace and current directories. | ||
| // Since we don't use those, both are the same in this case. | ||
| architectHost = new TestingArchitectHost(__dirname, __dirname); | ||
| architect = new Architect(architectHost, registry); | ||
|
|
||
| // This will either take a Node package name, or a path to the directory | ||
| // for the package.json file. | ||
| await architectHost.addBuilderFromPackage('..'); | ||
| }); | ||
|
|
||
| it('can run node', async () => { | ||
| // Create a logger that keeps an array of all messages that were logged. | ||
| const logger = new logging.Logger(''); | ||
| const logs = []; | ||
| logger.subscribe(ev => logs.push(ev.message)); | ||
|
|
||
| // A "run" can have multiple outputs, and contains progress information. | ||
| const run = await architect.scheduleBuilder('@example/command-runner:command', { | ||
| command: 'node', | ||
| args: ['--print', '\'foo\''], | ||
| }, { logger }); // We pass the logger for checking later. | ||
|
|
||
| // The "result" member (of type BuilderOutput) is the next output. | ||
| const output = await run.result; | ||
|
|
||
| // Stop the builder from running. This stops Architect from keeping | ||
| // the builder-associated states in memory, since builders keep waiting | ||
| // to be scheduled. | ||
| await run.stop(); | ||
|
|
||
| // Expect that foo was logged | ||
| expect(logs).toContain('foo'); | ||
| }); | ||
| }); | ||
| // #enddocregion |
This file contains hidden or 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,46 @@ | ||
| // #docplaster | ||
| // #docregion builder, builder-skeleton, handling-output, progress-reporting | ||
| import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect'; | ||
| import { JsonObject } from '@angular-devkit/core'; | ||
| // #enddocregion builder-skeleton | ||
| import * as childProcess from 'child_process'; | ||
| // #docregion builder-skeleton | ||
|
|
||
| interface Options extends JsonObject { | ||
| command: string; | ||
| args: string[]; | ||
| } | ||
|
|
||
| export default createBuilder(commandBuilder); | ||
|
|
||
| function commandBuilder( | ||
| options: Options, | ||
| context: BuilderContext, | ||
| ): Promise<BuilderOutput> { | ||
| // #enddocregion builder, builder-skeleton, handling-output | ||
| // #docregion report-status | ||
| context.reportStatus(`Executing "${options.command}"...`); | ||
| // #docregion builder, handling-output | ||
| const child = childProcess.spawn(options.command, options.args); | ||
| // #enddocregion builder, report-status | ||
|
|
||
| child.stdout.on('data', data => { | ||
| context.logger.info(data.toString()); | ||
| }); | ||
| child.stderr.on('data', data => { | ||
| context.logger.error(data.toString()); | ||
| }); | ||
|
|
||
| // #docregion builder | ||
| return new Promise(resolve => { | ||
| // #enddocregion builder, handling-output | ||
| context.reportStatus(`Done.`); | ||
| // #docregion builder, handling-output | ||
| child.on('close', code => { | ||
| resolve({ success: code === 0 }); | ||
| }); | ||
| }); | ||
| // #docregion builder-skeleton | ||
| } | ||
|
|
||
| // #enddocregion builder, builder-skeleton, handling-output, progress-reporting |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.