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