diff --git a/docs/documentation/config.md b/docs/documentation/config.md index 88ce5e000df0..bc4d49f32612 100644 --- a/docs/documentation/config.md +++ b/docs/documentation/config.md @@ -12,7 +12,7 @@ If both the `[key]` and `[value]` are provided it will set the value.
global

- --global (alias: -g) + --global (alias: -g)

Get/set the value in the global configuration (in your home directory). diff --git a/docs/documentation/doc.md b/docs/documentation/doc.md index ab3ca31752eb..33fcd402f69c 100644 --- a/docs/documentation/doc.md +++ b/docs/documentation/doc.md @@ -9,7 +9,7 @@

search

- --search (alias: -s) + --search (alias: -s)

Search whole angular.io instead of just api. diff --git a/docs/documentation/eject.md b/docs/documentation/eject.md new file mode 100644 index 000000000000..3e2ff0055fe4 --- /dev/null +++ b/docs/documentation/eject.md @@ -0,0 +1,9 @@ + + +# ng eject + +## Overview +Temporarily disabled. Ejects your app and output the proper webpack configuration and scripts. + +## Options +None. diff --git a/docs/documentation/generate.md b/docs/documentation/generate.md index 2470159a029d..ca7cb81c79b6 100644 --- a/docs/documentation/generate.md +++ b/docs/documentation/generate.md @@ -20,7 +20,7 @@

dry-run

- --dry-run (alias: -d) + --dry-run (alias: -d)

Run through without making any changes. @@ -29,7 +29,7 @@

force

- --force (alias: -f) + --force (alias: -f)

Forces overwriting of files. diff --git a/docs/documentation/generate/app-shell.md b/docs/documentation/generate/app-shell.md new file mode 100644 index 000000000000..42308267e804 --- /dev/null +++ b/docs/documentation/generate/app-shell.md @@ -0,0 +1,170 @@ + + +# ng generate app-shell + +## Overview +Create an app shell. + +## Options +

+ dry-run +

+ --dry-run (alias: -d) +

+

+ Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ client-project +

+ --client-project +

+

+ Name of related client app. +

+
+
+ universal-project +

+ --universal-project +

+

+ Name of related universal app. +

+
+
+ route +

+ --route +

+

+ Route path used to produce the app shell. +

+
+
+ name +

+ --name +

+

+ Name of the universal app +

+
+
+ app-id +

+ --app-id +

+

+ The appId to use withServerTransition. +

+
+
+ out-dir +

+ --out-dir +

+

+ The output directory for build results. +

+
+
+ root +

+ --root +

+

+ The root directory of the app. +

+
+
+ index +

+ --index +

+

+ Name of the index file +

+
+
+ main +

+ --main +

+

+ The name of the main entry-point file. +

+
+
+ test +

+ --test +

+

+ The name of the test entry-point file. +

+
+
+ tsconfig-file-name +

+ --tsconfig-file-name +

+

+ The name of the TypeScript configuration file. +

+
+
+ test-tsconfig-file-name +

+ --test-tsconfig-file-name +

+

+ The name of the TypeScript configuration file for tests. +

+
+
+ app-dir +

+ --app-dir +

+

+ The name of the application directory. +

+
+
+ root-module-file-name +

+ --root-module-file-name +

+

+ The name of the root module file +

+
+
+ root-module-class-name +

+ --root-module-class-name +

+

+ The name of the root module class. +

+
+
+ source-dir +

+ --source-dir (alias: -D) +

+

+ The path of the source directory. +

+
diff --git a/docs/documentation/generate/application.md b/docs/documentation/generate/application.md new file mode 100644 index 000000000000..439d24693cf2 --- /dev/null +++ b/docs/documentation/generate/application.md @@ -0,0 +1,98 @@ + + +# ng generate application + +## Overview +Create an Angular application. + +## Options +
+ dry-run +

+ --dry-run (alias: -d) +

+

+ Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ inline-style +

+ --inline-style (alias: -s) +

+

+ Specifies if the style will be in the ts file. +

+
+
+ inline-template +

+ --inline-template (alias: -t) +

+

+ Specifies if the template will be in the ts file. +

+
+
+ view-encapsulation +

+ --view-encapsulation +

+

+ Specifies the view encapsulation strategy. +

+
+
+ routing +

+ --routing +

+

+ Generates a routing module. +

+
+
+ prefix +

+ --prefix (alias: -p) +

+

+ The prefix to apply to generated selectors. +

+
+
+ style +

+ --style +

+

+ The file extension to be used for style files. +

+
+
+ skip-tests +

+ --skip-tests (alias: -S) +

+

+ Skip creating spec files. +

+
+
+ skip-package-json +

+ --skip-package-json +

+

+ Do not add dependencies to package.json. +

+
diff --git a/docs/documentation/generate/class.md b/docs/documentation/generate/class.md index e1ccd6f5c1b0..4804318f7eff 100644 --- a/docs/documentation/generate/class.md +++ b/docs/documentation/generate/class.md @@ -7,15 +7,32 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ project +

+ --project +

+

+ The name of the project.

-
spec

@@ -25,3 +42,12 @@ Specifies if a spec file is generated.

+
+ type +

+ --type +

+

+ Specifies the type of class. +

+
diff --git a/docs/documentation/generate/component.md b/docs/documentation/generate/component.md index 37b31a077b67..95335f9c792e 100644 --- a/docs/documentation/generate/component.md +++ b/docs/documentation/generate/component.md @@ -7,95 +7,86 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes.

-
- change-detection + force

- --change-detection (aliases: -c) + --force (alias: -f)

- Specifies the change detection strategy. + Forces overwriting of files.

-
- flat + project

- --flat default value: false + --project

- Flag to indicate if a dir is created. + The name of the project.

-
- export + inline-style

- --export default value: false + --inline-style (alias: -s)

- Specifies if declaring module exports the component. + Specifies if the style will be in the ts file.

-
- inline-style + inline-template

- --inline-style (aliases: -s) default value: false + --inline-template (alias: -t)

- Specifies if the style will be in the ts file. + Specifies if the template will be in the ts file.

-
- inline-template + view-encapsulation

- --inline-template (aliases: -t) default value: false + --view-encapsulation (alias: -v)

- Specifies if the template will be in the ts file. + Specifies the view encapsulation strategy.

-
- module + change-detection

- --module (aliases: -m) + --change-detection (alias: -c)

- Allows specification of the declaring module's file name (e.g `app.module.ts`). + Specifies the change detection strategy.

-
prefix

- --prefix + --prefix (alias: -p)

- Specifies whether to use the prefix. + The prefix to apply to generated selectors.

-
- skip-import + styleext

- --skip-import default value: false + --styleext

- Allows for skipping the module import. + The file extension to be used for style files.

-
spec

@@ -105,13 +96,48 @@ Specifies if a spec file is generated.

-
- view-encapsulation + flat

- --view-encapsulation (aliases: -v) + --flat

- Specifies the view encapsulation strategy. + Flag to indicate if a dir is created. +

+
+
+ skip-import +

+ --skip-import +

+

+ Flag to skip the module import. +

+
+
+ selector +

+ --selector +

+

+ The selector to use for the component. +

+
+
+ module +

+ --module (alias: -m) +

+

+ Allows specification of the declaring module. +

+
+
+ export +

+ --export +

+

+ Specifies if declaring module exports the component.

diff --git a/docs/documentation/generate/directive.md b/docs/documentation/generate/directive.md index 9ed8f37046c7..aa1653ebf9cc 100644 --- a/docs/documentation/generate/directive.md +++ b/docs/documentation/generate/directive.md @@ -7,71 +7,92 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes.

-
- export + force

- --export default value: false + --force (alias: -f)

- Specifies if declaring module exports the component. + Forces overwriting of files.

-
- flat + project

- --flat + --project

- Flag to indicate if a dir is created. + The name of the project.

-
- module + prefix

- --module (aliases: -m) + --prefix (alias: -p)

- Allows specification of the declaring module. + The prefix to apply to generated selectors.

-
- prefix + spec

- --prefix + --spec

- Specifies whether to use the prefix. + Specifies if a spec file is generated.

-
skip-import

--skip-import

- Allows for skipping the module import. + Flag to skip the module import.

-
- spec + selector

- --spec + --selector

- Specifies if a spec file is generated. + The selector to use for the directive. +

+
+
+ flat +

+ --flat +

+

+ Flag to indicate if a dir is created. +

+
+
+ module +

+ --module (alias: -m) +

+

+ Allows specification of the declaring module. +

+
+
+ export +

+ --export +

+

+ Specifies if declaring module exports the directive.

diff --git a/docs/documentation/generate/enum.md b/docs/documentation/generate/enum.md index c7b4b66ff19f..b5614375d60b 100644 --- a/docs/documentation/generate/enum.md +++ b/docs/documentation/generate/enum.md @@ -7,11 +7,29 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ project +

+ --project +

+

+ The name of the project.

diff --git a/docs/documentation/generate/guard.md b/docs/documentation/generate/guard.md index 3435dd172f66..ea2e17aec000 100644 --- a/docs/documentation/generate/guard.md +++ b/docs/documentation/generate/guard.md @@ -5,41 +5,56 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ spec +

+ --spec +

+

+ Specifies if a spec file is generated.

-
flat

--flat

- Indicate if a dir is created. + Flag to indicate if a dir is created.

-
module

- --module (aliases: -m) + --module (alias: -m)

- Specifies where the guard should be provided. + Allows specification of the declaring module.

-
- spec + project

- --spec + --project

- Specifies if a spec file is generated. + The name of the project.

diff --git a/docs/documentation/generate/interface.md b/docs/documentation/generate/interface.md index 8aa09de4ca76..c769635e12b0 100644 --- a/docs/documentation/generate/interface.md +++ b/docs/documentation/generate/interface.md @@ -7,18 +7,38 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files.

-
- type + project +

+ --project +

+

+ The name of the project. +

+
+
+ prefix +

+ --prefix +

- Optional String to specify the type of interface. + Specifies the prefix to use.

diff --git a/docs/documentation/generate/library.md b/docs/documentation/generate/library.md new file mode 100644 index 000000000000..7407d90da8e3 --- /dev/null +++ b/docs/documentation/generate/library.md @@ -0,0 +1,62 @@ + + +# ng generate library + +## Overview +Generate a library project for Angular. + +## Options +
+ dry-run +

+ --dry-run (alias: -d) +

+

+ Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ entry-file +

+ --entry-file +

+

+ The path to create the library's public API file. +

+
+
+ prefix +

+ --prefix (alias: -p) +

+

+ The prefix to apply to generated selectors. +

+
+
+ skip-package-json +

+ --skip-package-json +

+

+ Do not add dependencies to package.json. +

+
+
+ skip-ts-config +

+ --skip-ts-config +

+

+ Do not update tsconfig.json for development experience. +

+
diff --git a/docs/documentation/generate/module.md b/docs/documentation/generate/module.md index 55559f122406..090a04366098 100644 --- a/docs/documentation/generate/module.md +++ b/docs/documentation/generate/module.md @@ -7,35 +7,50 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes.

-
- flat + force

- --flat + --force (alias: -f)

- Flag to indicate if a dir is created. + Forces overwriting of files.

-
- module + project

- --module (aliases: -m) + --project

- Specifies where the module should be imported. + The name of the project. +

+
+
+ routing +

+ --routing +

+

+ Generates a routing module. +

+
+
+ routing-scope +

+ --routing-scope +

+

+ The scope for the generated routing.

-
spec

@@ -45,15 +60,21 @@ Specifies if a spec file is generated.

-
- routing + flat

- --routing + --flat +

+

+ Flag to indicate if a dir is created.

+
+
+ module

- Specifies if a routing module file should be generated. + --module (alias: -m) +

+

+ Allows specification of the declaring module.

- - diff --git a/docs/documentation/generate/pipe.md b/docs/documentation/generate/pipe.md index b8ee09497f3a..e5384f787a19 100644 --- a/docs/documentation/generate/pipe.md +++ b/docs/documentation/generate/pipe.md @@ -7,25 +7,32 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes.

-
- export + force

- --export + --force (alias: -f)

- Specifies if declaring module exports the pipe. + Forces overwriting of files. +

+
+
+ project +

+ --project +

+

+ The name of the project.

-
flat

@@ -35,17 +42,15 @@ Flag to indicate if a dir is created.

-
- module + spec

- --module (aliases: -m) + --spec

- Allows specification of the declaring module. + Specifies if a spec file is generated.

-
skip-import

@@ -55,13 +60,21 @@ Allows for skipping the module import.

-
- spec + module

- --spec + --module (alias: -m)

- Specifies if a spec file is generated. + Allows specification of the declaring module. +

+
+
+ export +

+ --export +

+

+ Specifies if declaring module exports the pipe.

diff --git a/docs/documentation/generate/service.md b/docs/documentation/generate/service.md index eb94f5c5b9bc..e4008eb0fc20 100644 --- a/docs/documentation/generate/service.md +++ b/docs/documentation/generate/service.md @@ -7,35 +7,41 @@ ## Options
- app + dry-run

- --app (aliases: -a) default value: 1st app + --dry-run (alias: -d)

- Specifies app name to use. + Run through without making any changes.

-
- flat + force

- --flat + --force (alias: -f)

- Flag to indicate if a dir is created. + Forces overwriting of files.

-
- module + project

- --module (aliases: -m) + --project

- Specifies where the service should be provided. + The name of the project. +

+
+
+ flat +

+ --flat +

+

+ Flag to indicate if a dir is created.

-
spec

diff --git a/docs/documentation/generate/universal.md b/docs/documentation/generate/universal.md new file mode 100644 index 000000000000..945eaa3c2c0c --- /dev/null +++ b/docs/documentation/generate/universal.md @@ -0,0 +1,116 @@ + + +# ng generate universal + +## Overview +Create an Angular universal app. + +## Options +

+ dry-run +

+ --dry-run (alias: -d) +

+

+ Run through without making any changes. +

+
+
+ force +

+ --force (alias: -f) +

+

+ Forces overwriting of files. +

+
+
+ client-project +

+ --client-project +

+

+ Name of related client app. +

+
+
+ app-id +

+ --app-id +

+

+ The appId to use withServerTransition. +

+
+
+ main +

+ --main +

+

+ The name of the main entry-point file. +

+
+
+ test +

+ --test +

+

+ The name of the test entry-point file. +

+
+
+ tsconfig-file-name +

+ --tsconfig-file-name +

+

+ The name of the TypeScript configuration file. +

+
+
+ test-tsconfig-file-name +

+ --test-tsconfig-file-name +

+

+ The name of the TypeScript configuration file for tests. +

+
+
+ app-dir +

+ --app-dir +

+

+ The name of the application directory. +

+
+
+ root-module-file-name +

+ --root-module-file-name +

+

+ The name of the root module file +

+
+
+ root-module-class-name +

+ --root-module-class-name +

+

+ The name of the root module class. +

+
+
+ skip-install +

+ --skip-install +

+

+ Skip installing dependency packages. +

+
diff --git a/docs/documentation/new.md b/docs/documentation/new.md index a20f204f34d1..4e7ebd260918 100644 --- a/docs/documentation/new.md +++ b/docs/documentation/new.md @@ -11,7 +11,7 @@ Default applications are created in a directory of the same name, with an initia
dry-run

- --dry-run (alias: -d) + --dry-run (alias: -d)

Run through without making any changes. @@ -20,7 +20,7 @@ Default applications are created in a directory of the same name, with an initia

force

- --force (alias: -f) + --force (alias: -f)

Forces overwriting of files. @@ -29,7 +29,7 @@ Default applications are created in a directory of the same name, with an initia

verbose

- --verbose (alias: -v) + --verbose (alias: -v)

Adds more details to output logging. @@ -38,7 +38,7 @@ Default applications are created in a directory of the same name, with an initia

collection

- --collection (alias: -c) + --collection (alias: -c)

Schematics collection to use. @@ -47,7 +47,7 @@ Default applications are created in a directory of the same name, with an initia

inline-style

- --inline-style (alias: -s) + --inline-style (alias: -s)

Specifies if the style will be in the ts file. @@ -56,7 +56,7 @@ Default applications are created in a directory of the same name, with an initia

inline-template

- --inline-template (alias: -t) + --inline-template (alias: -t)

Specifies if the template will be in the ts file. @@ -65,7 +65,7 @@ Default applications are created in a directory of the same name, with an initia

view-encapsulation

- --view-encapsulation + --view-encapsulation

Specifies the view encapsulation strategy. @@ -74,7 +74,7 @@ Default applications are created in a directory of the same name, with an initia

routing

- --routing + --routing

Generates a routing module. @@ -83,7 +83,7 @@ Default applications are created in a directory of the same name, with an initia

prefix

- --prefix (alias: -p) + --prefix (alias: -p)

The prefix to apply to generated selectors. @@ -92,7 +92,7 @@ Default applications are created in a directory of the same name, with an initia

style

- --style + --style

The file extension to be used for style files. @@ -101,7 +101,7 @@ Default applications are created in a directory of the same name, with an initia

skip-tests

- --skip-tests (alias: -S) + --skip-tests (alias: -S)

Skip creating spec files. @@ -110,7 +110,7 @@ Default applications are created in a directory of the same name, with an initia

skip-package-json

- --skip-package-json + --skip-package-json

Do not add dependencies to package.json. diff --git a/docs/documentation/run.md b/docs/documentation/run.md index 4c58f7308b2d..c7de54d15085 100644 --- a/docs/documentation/run.md +++ b/docs/documentation/run.md @@ -9,7 +9,7 @@ Runs Architect targets.

configuration

- --configuration (alias: -c) + --configuration (alias: -c)

Specify the configuration to use. diff --git a/docs/documentation/update.md b/docs/documentation/update.md index 9fca82dff015..38b39baaac58 100644 --- a/docs/documentation/update.md +++ b/docs/documentation/update.md @@ -9,7 +9,7 @@

dry-run

- --dry-run (alias: -d) + --dry-run (alias: -d)

Run through without making any changes. @@ -18,7 +18,7 @@

force

- --force + --force

If false, will error out if installed packages are incompatible with the update. @@ -27,7 +27,7 @@

all

- --all + --all

Whether to update all packages in package.json. @@ -36,7 +36,7 @@

next

- --next + --next

Use the largest version, including beta and RCs. @@ -45,7 +45,7 @@

migrate-only

- --migrate-only + --migrate-only

Only perform a migration, does not update the installed version. @@ -54,7 +54,7 @@

from

- --from + --from

Version from which to migrate from. Only available with a single package being updated, and only on migration only. @@ -63,7 +63,7 @@

to

- --to + --to

Version up to which to apply migrations. Only available with a single package being updated, and only on migrations only. Requires from to be specified. Default to the installed version detected. @@ -72,7 +72,7 @@

registry

- --registry + --registry

The NPM registry to use. diff --git a/docs/documentation/xi18n.md b/docs/documentation/xi18n.md index f05b946ae567..6ba9d6536571 100644 --- a/docs/documentation/xi18n.md +++ b/docs/documentation/xi18n.md @@ -9,7 +9,7 @@

configuration

- --configuration (alias: -c) + --configuration (alias: -c)

Specify the configuration to use. @@ -18,7 +18,7 @@

browser-target

- --browser-target + --browser-target

Target to extract from. @@ -27,7 +27,7 @@

i18n-format

- --i18n-format + --i18n-format

Output format for the generated file. @@ -36,7 +36,7 @@

i18n-locale

- --i18n-locale + --i18n-locale

Specifies the source language of the application. @@ -45,7 +45,7 @@

output-path

- --output-path + --output-path

Path where output will be placed. @@ -54,7 +54,7 @@

out-file

- --out-file + --out-file

Name of the file to output. diff --git a/packages/@angular/cli/commands/getset.ts b/packages/@angular/cli/commands/getset.ts index 4baeb91b8923..85b674bd7cd8 100644 --- a/packages/@angular/cli/commands/getset.ts +++ b/packages/@angular/cli/commands/getset.ts @@ -10,6 +10,7 @@ export default class GetSetCommand extends Command { public readonly description = 'Deprecated in favor of config command.'; public readonly arguments: string[] = []; public readonly options: Option[] = []; + public readonly hidden = true; public async run(_options: Options) { this.logger.warn('get/set have been deprecated in favor of the config command.'); diff --git a/tools/publish/src/generate-docs.ts b/tools/publish/src/generate-docs.ts index 2e6b16d038de..ecaf0b7b070a 100644 --- a/tools/publish/src/generate-docs.ts +++ b/tools/publish/src/generate-docs.ts @@ -1,11 +1,20 @@ import * as fs from 'fs'; import * as path from 'path'; -import { logging, tags } from '@angular-devkit/core'; +import { logging, schema, strings, tags } from '@angular-devkit/core'; +import { formats } from '@angular-devkit/schematics'; +import { + NodeModulesEngineHost, + validateOptionsWithSchema +} from '@angular-devkit/schematics/tools'; export default async function () { const commandsPath = __dirname + '/../../../packages/@angular/cli/commands'; const commandFiles = fs.readdirSync(commandsPath); + const engineHost = new NodeModulesEngineHost(); + const registry = new schema.CoreSchemaRegistry(formats.standardFormats); + engineHost.registerOptionsTransform(validateOptionsWithSchema(registry)); + for (const commandFile of commandFiles) { const commandConstructor = require(path.join(commandsPath, commandFile)).default; const command = new commandConstructor( @@ -17,70 +26,121 @@ export default async function () { continue; } - try { - await command.initialize({}); - } catch (e) { - console.log(`initialize failed [${commandFile}]: ` + e.toString()); - } + generateDoc(command, commandFile); - let optionText; - if (!command.options) { - optionText = ''; - } else { - optionText = (command.options as any[]) - .filter(option => !option.hidden) - .map(option => { - let defaultText = ''; - if (option.default) { - defaultText = `default value: ${option.default}`; - } - let aliasText = ''; - if (option.aliases && option.aliases.length > 0) { - aliasText = (option.aliases as string[]) - .map(alias => '' + (alias.length === 1 ? '-' : '--') + alias + '') - .join(','); - aliasText = ` (alias: ${aliasText})`; - } - - return tags.stripIndent` -

- ${option.name} -

- --${option.name}${aliasText} ${defaultText} -

-

- ${option.description} -

-
- `; - }).join('\n'); + if (command.name === 'generate') { + const collection = engineHost.createCollectionDescription('@schematics/angular'); + + for (const schematicName in collection.schematics) { + const schematic = collection.schematics[schematicName]; + if (schematic.hidden || schematic.private) { + continue; + } + const generateCommand = new commandConstructor( + { project: { root: path.join(__dirname, '../fake_root/') } }, + new logging.NullLogger(), + ); + generateDoc( + generateCommand, + commandFile, + { _: [`${collection.name}:${schematicName}`] }, + { + name: strings.dasherize(schematicName), + namePrefix: 'generate ', + description: schematic.description, + path: 'generate' + }, + ); + } } + } +} - const docFile = path.join( - __dirname, - '../../../docs/documentation/', - path.basename(commandFile, '.ts') + '.md'); +interface DocInfo { + name: string; + namePrefix: string; + description: string; + path: string; +} +async function generateDoc( + command: any, + commandFile: string, + options: any = {}, + info?: Partial, +) { + const docInfo = { + name: command.name, + namePrefix: '', + description: command.description, + path: '', + ...info, + }; - let docText; - if (fs.existsSync(docFile)) { - docText = fs.readFileSync(docFile, 'utf8'); - docText = docText.slice(0, docText.indexOf('## Options') + 10); - } else { - // tslint:disable:max-line-length - docText = tags.stripIndent` - + try { + await command.initialize(options); + } catch (e) { + console.log(`initialize failed [${commandFile}]: ` + e); + } - # ng ${command.name} + let optionText; + if (!command.options) { + optionText = ''; + } else { + optionText = (command.options as any[]) + .filter(option => !option.hidden) + .map(option => { + let defaultText = ''; + if (option.default) { + defaultText = ` default value: ${option.default}`; + } + let aliasText = ''; + if (option.aliases && option.aliases.length > 0) { + aliasText = (option.aliases as string[]) + .map(alias => '' + (alias.length === 1 ? '-' : '--') + alias + '') + .join(','); + aliasText = ` (alias: ${aliasText})`; + } - ## Overview - ${command.description} + return tags.stripIndent` +
+ ${option.name} +

+ --${option.name}${aliasText}${defaultText} +

+

+ ${option.description} +

+
+ `; + }).join('\n'); + } - ## Options - `; - // tslint:enable:max-line-length - } + const docFile = path.join( + __dirname, + '../../../docs/documentation/', + docInfo.path, + strings.dasherize(docInfo.name) + '.md', + ); + + let docText; + if (fs.existsSync(docFile)) { + docText = fs.readFileSync(docFile, 'utf8'); + docText = docText.slice(0, docText.indexOf('## Options') + 10); + } else { + // tslint:disable:max-line-length + docText = tags.stripIndent` + - const finalText = docText + '\n' + (optionText ? optionText : 'None.') + '\n'; - fs.writeFileSync(docFile, finalText); + # ng ${docInfo.namePrefix}${docInfo.name} + + ## Overview + ${docInfo.description} + + ## Options + `; + // tslint:enable:max-line-length } + + const finalText = docText + '\n' + (optionText ? optionText : 'None.') + '\n'; + fs.writeFileSync(docFile, finalText); }