Skip to content

Add documented public api #12499

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
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions packages/angular/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ with NPM 5.5.1 or higher.
* [Updating Angular CLI](#updating-angular-cli)
* [Development Hints for working on Angular CLI](#development-hints-for-working-on-angular-cli)
* [Documentation](#documentation)
* [Programmatic usage](#programmatic-usage)
* [License](#license)

## Installation
Expand Down Expand Up @@ -252,6 +253,18 @@ In addition to this one, another, more elaborated way to capture a CPU profile u

The documentation for the Angular CLI is located in this repo's [wiki](https://github.com/angular/angular-cli/wiki).

## Programmatic usage

You can also use angular cli programmatically. Here is an example on how to run `ng test --watch false` from inside your nodejs application:

```js
import cli from '@angular/cli';

const returnCode = await cli({ args: ['test', '--watch', 'false'] });
```

Types for typescript are included.

## License

MIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ import { runCommand } from '../../models/command-runner';
import { getWorkspaceRaw } from '../../utilities/config';
import { getWorkspaceDetails } from '../../utilities/project';

export interface CliOptions {
testing?: boolean;
/**
* The cli arguments to provide to the command (without the `ng`)
*/
args: string[];
}

export default async function(options: { testing?: boolean, cliArgs: string[] }) {
/**
* Run an arbitrary `ng` command.
*
* @example
* const returnCode = await cli({ args: ['test', '--watch', 'false' ] } );
*
* @param options The cli options, including the arguments use to run
* @returns {Promise<number>} A promise that resolves to the exit code of the ng command.
*/
export default async function(options: CliOptions): Promise<number> {
const logger = new logging.IndentLogger('cling');
let loggingSubscription;
if (!options.testing) {
Expand All @@ -34,7 +50,7 @@ export default async function(options: { testing?: boolean, cliArgs: string[] })
}

try {
const maybeExitCode = await runCommand(options.cliArgs, logger, projectDetails);
const maybeExitCode = await runCommand(options.args, logger, projectDetails);
if (typeof maybeExitCode === 'number') {
console.assert(Number.isInteger(maybeExitCode));

Expand Down
4 changes: 2 additions & 2 deletions packages/angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ try {
// library from a package.json. Instead, include it from a relative
// path to this script file (which is likely a globally installed
// npm package). Most common cause for hitting this is `ng new`
cli = require('./cli');
cli = require('./cli/main');
}

if ('default' in cli) {
Expand All @@ -144,7 +144,7 @@ try {
}

cli({
cliArgs: process.argv.slice(2),
args: process.argv.slice(2),
inputStream: standardInput,
outputStream: process.stdout,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@angular/cli",
"version": "0.0.0",
"description": "CLI tool for Angular",
"main": "lib/cli/index.js",
"main": "lib/cli/main.js",
"trackingCode": "UA-8594346-19",
"bin": {
"ng": "./bin/ng"
Expand Down
4 changes: 2 additions & 2 deletions scripts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
// tslint:disable:no-implicit-dependencies
import { logging } from '@angular-devkit/core';
import cli from '@angular/cli/lib/cli';
import cli from '@angular/cli';
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
Expand All @@ -20,7 +20,7 @@ export interface CreateOptions {

async function _ng(command: string, ...args: string[]) {
const exitCode = await cli({
cliArgs: [command, ...args],
args: [command, ...args],
});

if (exitCode !== 0) {
Expand Down