1.The following values can be returned by BuilderOutput:
error: It is an error message to send to the application. it is an optional value.
info: this function returns a [key, value] pair and it is optional.
success: It is required and can return a true/false value.
target: It can return a configuration project and target this is optional.
Index.ts
export default createBuilder(
async (options: Options, context: BuilderContext): Promise => {
context.reportStatus(`Executing "${options.command}"...`);
const configuration = options.configuration ? options.configuration : 'production';
const build = await context.scheduleTarget({
target: 'build',
project: context.target !== undefined ? context.target.project : '',
configuration
});
const test = await context.scheduleTarget({
target: 'test',
project: context.target !== undefined ? context.target.project : ''
});
let buildResult = await build.result && await test.result;
return { success: buildResult.success };
});
2.To test the builder locally, use the npm run build command.
3.To link the package locally, use the npm link command.
4.Using the CLI, create a new Angular application.
5.Run npm link @example/command-runner we may modify the package name to fit the one mentioned in the builder's package. JSON is a type of data.
6.In angular.json, add the following configuration.
"[our-command]": {
"builder": "@example/command-runner:command",
"options": {
"command": "[our-command]",
"args": [
"src/main.ts"
]
}
}
7.To test the builder, type ng run [project-name]: [our-command] or ng deploy if our command is for deploying. This will be available after the release of Angular CLI 8.3.0.
We can also use it across multiple applications by publishing it on npm.