Skip to content

Commit 3e95474

Browse files
cexbrayatvikerman
authored andcommitted
feat(@angular/cli): ng doc uses angular core version by default
Follow-up to #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 #12365
1 parent 46ade49 commit 3e95474

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/angular/cli/commands/doc-impl.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ export class DocCommand extends Command<DocCommandSchema> {
2626
// version can either be a string containing "next"
2727
if (options.version == 'next') {
2828
domain = 'next.angular.io';
29-
// or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
29+
// or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
3030
} else if (!isNaN(+options.version) && ![0, 1, 3].includes(+options.version)) {
3131
domain = `v${options.version}.angular.io`;
3232
} else {
3333
this.logger.error('Version should either be a number (2, 4, 5, 6...) or "next"');
3434

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

3947
let searchUrl = `https://${domain}/api?query=${options.keyword}`;

packages/angular/cli/commands/doc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"enum": [2, "next"]
3737
}
3838
],
39-
"description": "Contains the version of Angular to use for the documentation."
39+
"description": "Contains the version of Angular to use for the documentation. If not provided, the command uses your current Angular core version."
4040
}
4141
},
4242
"required": [

0 commit comments

Comments
 (0)