UNPKG

1.78 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const guards_1 = require("../guards");
4const color_1 = require("../lib/color");
5const command_1 = require("../lib/command");
6const open_1 = require("../lib/open");
7const serve_1 = require("../lib/serve");
8const http_1 = require("../lib/utils/http");
9class DocsCommand extends command_1.Command {
10 async getMetadata() {
11 return {
12 name: 'docs',
13 type: 'global',
14 summary: 'Open the Ionic documentation website',
15 options: [
16 {
17 name: 'browser',
18 summary: `Specifies the browser to use (${serve_1.BROWSERS.map(b => color_1.input(b)).join(', ')})`,
19 aliases: ['w'],
20 groups: ["advanced" /* ADVANCED */],
21 },
22 ],
23 };
24 }
25 async run(inputs, options) {
26 const browser = options['browser'] ? String(options['browser']) : undefined;
27 const homepage = 'https://ion.link/docs';
28 const url = this.project ? await this.project.getDocsUrl() : homepage;
29 try {
30 const { req } = await http_1.createRequest('HEAD', url, this.env.config.getHTTPConfig());
31 await req;
32 }
33 catch (e) {
34 if (guards_1.isSuperAgentError(e) && e.response.status === 404) {
35 this.env.log.warn(`Docs not found for your specific version of Ionic. Directing you to docs homepage.`);
36 await open_1.openUrl(homepage, { app: browser });
37 return;
38 }
39 throw e;
40 }
41 await open_1.openUrl(url, { app: browser });
42 this.env.log.ok('Launched Ionic docs in your browser!');
43 }
44}
45exports.DocsCommand = DocsCommand;