UNPKG

2.1 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 });
10const command_1 = require("../models/command");
11const open = require('open');
12class 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 // version can either be a string containing "next"
21 if (options.version == 'next') {
22 domain = 'next.angular.io';
23 // or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
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 // we try to get the current Angular version of the project
35 // and use it if we can find it
36 try {
37 /* tslint:disable-next-line:no-implicit-dependencies */
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 // We should wrap `open` in a new Promise because `open` is already resolved
48 await new Promise(() => {
49 open(searchUrl, {
50 wait: false,
51 });
52 });
53 }
54}
55exports.DocCommand = DocCommand;