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