1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const guards_1 = require("../guards");
|
4 | const color_1 = require("../lib/color");
|
5 | const command_1 = require("../lib/command");
|
6 | const open_1 = require("../lib/open");
|
7 | const serve_1 = require("../lib/serve");
|
8 | const http_1 = require("../lib/utils/http");
|
9 | class 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" ],
|
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 | }
|
45 | exports.DocsCommand = DocsCommand;
|