123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const tslib_1 = require("tslib");
- const chalk_1 = require("chalk");
- const command_1 = require("@ionic/cli-utils/lib/command");
- const serve_1 = require("@ionic/cli-utils/lib/serve");
- let DocsCommand = class DocsCommand extends command_1.Command {
- run(inputs, options) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { isSuperAgentError } = yield Promise.resolve().then(() => require('@ionic/cli-utils/guards'));
- const { createRequest } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/http'));
- const browser = options['browser'] ? String(options['browser']) : undefined;
- const opn = yield Promise.resolve().then(() => require('opn'));
- const docsHomepage = 'https://ionicframework.com/docs';
- let url = docsHomepage;
- const project = this.env.project.directory ? yield this.env.project.load() : undefined;
- if (project) {
- if (project.type === 'ionic1') {
- url = 'https://ionicframework.com/docs/v1/';
- }
- else if (project.type === 'ionic-angular') {
- url = 'https://ionicframework.com/docs/api'; // TODO: can know framework version, HEAD request, etc
- }
- }
- try {
- const { req } = yield createRequest(this.env.config, 'head', url);
- yield req;
- }
- catch (e) {
- if (isSuperAgentError(e)) {
- if (e.response.status === 404) {
- this.env.log.warn(`Docs not found for your specific version of Ionic. Directing you to latest docs.`);
- opn(`${docsHomepage}/api`, { wait: false });
- return;
- }
- }
- throw e;
- }
- yield opn(url, { app: browser, wait: false });
- this.env.log.ok('Launched Ionic docs in your browser!');
- });
- }
- };
- DocsCommand = tslib_1.__decorate([
- command_1.CommandMetadata({
- name: 'docs',
- type: 'global',
- description: 'Open the Ionic documentation website',
- options: [
- {
- name: 'browser',
- description: `Specifies the browser to use (${serve_1.BROWSERS.map(b => chalk_1.default.green(b)).join(', ')})`,
- aliases: ['w'],
- advanced: true,
- },
- ],
- })
- ], DocsCommand);
- exports.DocsCommand = DocsCommand;
|