UNPKG

6.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.LabCommand = exports.ServeCommand = void 0;
4const utils_process_1 = require("@ionic/utils-process");
5const lodash = require("lodash");
6const color_1 = require("../lib/color");
7const command_1 = require("../lib/command");
8const errors_1 = require("../lib/errors");
9const executor_1 = require("../lib/executor");
10const serve_1 = require("../lib/serve");
11class ServeCommand extends command_1.Command {
12 async getMetadata() {
13 const groups = [];
14 let options = [
15 ...serve_1.COMMON_SERVE_COMMAND_OPTIONS,
16 {
17 name: 'lab-host',
18 summary: 'Use specific host for Ionic Lab server',
19 default: 'localhost',
20 groups: ["advanced" /* ADVANCED */],
21 spec: { value: 'host' },
22 hint: color_1.weak('(--lab)'),
23 },
24 {
25 name: 'lab-port',
26 summary: 'Use specific port for Ionic Lab server',
27 default: serve_1.DEFAULT_LAB_PORT.toString(),
28 groups: ["advanced" /* ADVANCED */],
29 spec: { value: 'port' },
30 hint: color_1.weak('(--lab)'),
31 },
32 {
33 name: 'open',
34 summary: 'Do not open a browser window',
35 type: Boolean,
36 default: true,
37 },
38 {
39 name: 'browser',
40 summary: `Specifies the browser to use (${serve_1.BROWSERS.map(b => color_1.input(b)).join(', ')})`,
41 aliases: ['w'],
42 groups: ["advanced" /* ADVANCED */],
43 },
44 {
45 name: 'browseroption',
46 summary: `Specifies a path to open to (${color_1.input('/#/tab/dash')})`,
47 aliases: ['o'],
48 groups: ["advanced" /* ADVANCED */],
49 spec: { value: 'path' },
50 },
51 {
52 name: 'lab',
53 summary: 'Test your apps on multiple platform types in the browser',
54 type: Boolean,
55 aliases: ['l'],
56 },
57 ];
58 const exampleCommands = ['', '--external', '--lab'];
59 const footnotes = [];
60 let description = `
61Easily spin up a development server which launches in your browser. It watches for changes in your source files and automatically reloads with the updated build.
62
63By default, ${color_1.input('ionic serve')} boots up a development server on ${color_1.input('localhost')}. To serve to your LAN, specify the ${color_1.input('--external')} option, which will use all network interfaces and print the external address(es) on which your app is being served.
64
65Try the ${color_1.input('--lab')} option to see multiple platforms at once.`;
66 const runner = this.project && await this.project.getServeRunner();
67 if (runner) {
68 const libmetadata = await runner.getCommandMetadata();
69 groups.push(...libmetadata.groups || []);
70 options = lodash.uniqWith([...libmetadata.options || [], ...options], (optionA, optionB) => optionA.name === optionB.name);
71 description += `\n\n${(libmetadata.description || '').trim()}`;
72 footnotes.push(...libmetadata.footnotes || []);
73 exampleCommands.push(...libmetadata.exampleCommands || []);
74 }
75 return {
76 name: 'serve',
77 type: 'project',
78 summary: 'Start a local dev server for app dev/testing',
79 description,
80 footnotes,
81 groups,
82 exampleCommands,
83 options,
84 };
85 }
86 async preRun(inputs, options, { location }) {
87 const parts = executor_1.getFullCommandParts(location);
88 const alias = lodash.last(parts);
89 if (alias === 'lab') {
90 options['lab'] = true;
91 }
92 if (options['nolivereload']) {
93 this.env.log.warn(`The ${color_1.input('--nolivereload')} option has been deprecated. Please use ${color_1.input('--no-livereload')}.`);
94 options['livereload'] = false;
95 }
96 if (options['nobrowser']) {
97 this.env.log.warn(`The ${color_1.input('--nobrowser')} option has been deprecated. Please use ${color_1.input('--no-open')}.`);
98 options['open'] = false;
99 }
100 if (options['b']) {
101 options['open'] = false;
102 }
103 if (options['noproxy']) {
104 this.env.log.warn(`The ${color_1.input('--noproxy')} option has been deprecated. Please use ${color_1.input('--no-proxy')}.`);
105 options['proxy'] = false;
106 }
107 if (options['x']) {
108 options['proxy'] = false;
109 }
110 }
111 async run(inputs, options, runinfo) {
112 if (!this.project) {
113 throw new errors_1.FatalException(`Cannot run ${color_1.input('ionic serve')} outside a project directory.`);
114 }
115 try {
116 const runner = await this.project.requireServeRunner();
117 const runnerOpts = runner.createOptionsFromCommandLine(inputs, options);
118 await runner.run(runnerOpts);
119 }
120 catch (e) {
121 if (e instanceof errors_1.RunnerException) {
122 throw new errors_1.FatalException(e.message);
123 }
124 throw e;
125 }
126 await utils_process_1.sleepForever();
127 }
128}
129exports.ServeCommand = ServeCommand;
130class LabCommand extends ServeCommand {
131 async getMetadata() {
132 const metadata = await super.getMetadata();
133 const groups = [...metadata.groups || [], "hidden" /* HIDDEN */];
134 const exampleCommands = [...metadata.exampleCommands || []].filter(c => !c.includes('--lab'));
135 return {
136 ...metadata,
137 summary: 'Start Ionic Lab for multi-platform dev/testing',
138 description: `
139Start an instance of ${color_1.strong('Ionic Lab')}, a tool for developing Ionic apps for multiple platforms at once side-by-side.
140
141${color_1.input('ionic lab')} is just a convenient shortcut for ${color_1.input('ionic serve --lab')}.`,
142 groups,
143 exampleCommands,
144 };
145 }
146}
147exports.LabCommand = LabCommand;