UNPKG

2.13 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google Inc. All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.DocCommand = void 0;
11const command_1 = require("../models/command");
12const open = require('open');
13class 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 // version can either be a string containing "next"
22 if (options.version == 'next') {
23 domain = 'next.angular.io';
24 // or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
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 // we try to get the current Angular version of the project
36 // and use it if we can find it
37 try {
38 /* tslint:disable-next-line:no-implicit-dependencies */
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 // We should wrap `open` in a new Promise because `open` is already resolved
49 await new Promise(() => {
50 open(searchUrl, {
51 wait: false,
52 });
53 });
54 }
55}
56exports.DocCommand = DocCommand;