Skip to content

Commit

Permalink
feat(@angular/cli): ng doc uses angular core version by default
Browse files Browse the repository at this point in the history
Follow-up to angular#14788 that allowed `ng doc --version 6`.
This commit enhances the doc command to use the current Angular version of the project by default, if no version is provided explicitely.

Fixes angular#12365
  • Loading branch information
cexbrayat committed Jun 27, 2019
1 parent 277d4ab commit e918ec8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/angular/cli/commands/doc-impl.ts
Expand Up @@ -26,14 +26,22 @@ export class DocCommand extends Command<DocCommandSchema> {
// version can either be a string containing "next"
if (options.version == 'next') {
domain = 'next.angular.io';
// or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
// or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
} else if (!isNaN(+options.version) && ![0, 1, 3].includes(+options.version)) {
domain = `v${options.version}.angular.io`;
} else {
this.logger.error('Version should either be a number (2, 4, 5, 6...) or "next"');

return 0;
}
} else {
// we try to get the current Angular version of the project
// and use it if we can find it
try {
/* tslint:disable-next-line:no-implicit-dependencies */
const currentNgVersion = require('@angular/core').VERSION.major;
domain = `v${currentNgVersion}.angular.io`;
} catch (e) {}
}

let searchUrl = `https://${domain}/api?query=${options.keyword}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/doc.json
Expand Up @@ -36,7 +36,7 @@
"enum": [2, "next"]
}
],
"description": "Contains the version of Angular to use for the documentation."
"description": "Contains the version of Angular to use for the documentation. If not provided, the command uses your current Angular core version."
}
},
"required": [
Expand Down

0 comments on commit e918ec8

Please sign in to comment.