1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const command_1 = require("../models/command");
|
11 | const open = require('open');
|
12 | class DocCommand extends command_1.Command {
|
13 | async run(options) {
|
14 | if (!options.keyword) {
|
15 | this.logger.error('You should specify a keyword, for instance, `ng doc ActivatedRoute`.');
|
16 | return 0;
|
17 | }
|
18 | let domain = 'angular.io';
|
19 | if (options.version) {
|
20 |
|
21 | if (options.version == 'next') {
|
22 | domain = 'next.angular.io';
|
23 |
|
24 | }
|
25 | else if (!isNaN(+options.version) && ![0, 1, 3].includes(+options.version)) {
|
26 | domain = `v${options.version}.angular.io`;
|
27 | }
|
28 | else {
|
29 | this.logger.error('Version should either be a number (2, 4, 5, 6...) or "next"');
|
30 | return 0;
|
31 | }
|
32 | }
|
33 | else {
|
34 |
|
35 |
|
36 | try {
|
37 |
|
38 | const currentNgVersion = require('@angular/core').VERSION.major;
|
39 | domain = `v${currentNgVersion}.angular.io`;
|
40 | }
|
41 | catch (e) { }
|
42 | }
|
43 | let searchUrl = `https://${domain}/api?query=${options.keyword}`;
|
44 | if (options.search) {
|
45 | searchUrl = `https://${domain}/docs?search=${options.keyword}`;
|
46 | }
|
47 |
|
48 | await new Promise(() => {
|
49 | open(searchUrl, {
|
50 | wait: false,
|
51 | });
|
52 | });
|
53 | }
|
54 | }
|
55 | exports.DocCommand = DocCommand;
|