1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const fs = require("mz/fs");
|
25 | const path = require("path");
|
26 | const url = require("url");
|
27 | const args_1 = require("./args");
|
28 | const compile_middleware_1 = require("./compile-middleware");
|
29 | const start_server_1 = require("./start_server");
|
30 | const commandLineArgs = require("command-line-args");
|
31 | const commandLineUsage = require("command-line-usage");
|
32 | function run() {
|
33 | return __awaiter(this, void 0, void 0, function* () {
|
34 | const argsWithHelp = args_1.args.concat({
|
35 | name: 'help',
|
36 | description: 'Shows this help message',
|
37 | type: Boolean,
|
38 | });
|
39 |
|
40 | let cliOptions;
|
41 | try {
|
42 | cliOptions = commandLineArgs(argsWithHelp);
|
43 | }
|
44 | catch (e) {
|
45 | printUsage(argsWithHelp);
|
46 | return;
|
47 | }
|
48 | const proxyArgs = {
|
49 | path: cliOptions['proxy-path'],
|
50 | target: cliOptions['proxy-target']
|
51 | };
|
52 | const options = {
|
53 | root: cliOptions.root,
|
54 | compile: cliOptions.compile,
|
55 | moduleResolution: cliOptions['module-resolution'],
|
56 | port: cliOptions.port,
|
57 | hostname: cliOptions.hostname,
|
58 | open: cliOptions.open,
|
59 | browser: cliOptions['browser'],
|
60 | openPath: cliOptions['open-path'],
|
61 | componentDir: cliOptions['component-dir'],
|
62 | componentUrl: cliOptions['component-url'],
|
63 | packageName: cliOptions['package-name'],
|
64 | npm: cliOptions['npm'],
|
65 | protocol: cliOptions['protocol'],
|
66 | keyPath: cliOptions['key'],
|
67 | certPath: cliOptions['cert'],
|
68 | pushManifestPath: cliOptions['manifest'],
|
69 | proxy: proxyArgs.path && proxyArgs.target && proxyArgs,
|
70 | allowOrigin: cliOptions['allow-origin'],
|
71 | };
|
72 | if (cliOptions.help) {
|
73 | printUsage(argsWithHelp);
|
74 | return;
|
75 | }
|
76 | if (cliOptions.version) {
|
77 | console.log(getVersion());
|
78 | return;
|
79 | }
|
80 | if (typeof cliOptions['compile-cache'] === 'number') {
|
81 | console.log(`compile cache set to ${cliOptions['compile-cache']}`);
|
82 | compile_middleware_1.babelCompileCache['max'] = cliOptions['compile-cache'];
|
83 | }
|
84 | const serverInfos = yield start_server_1.startServers(options);
|
85 | if (serverInfos.kind === 'mainline') {
|
86 | const mainlineServer = serverInfos;
|
87 | const urls = start_server_1.getServerUrls(options, mainlineServer.server);
|
88 | console.log(`Files in this directory are available under the following URLs
|
89 | applications: ${url.format(urls.serverUrl)}
|
90 | reusable components: ${url.format(urls.componentUrl)}
|
91 | `);
|
92 | }
|
93 | else {
|
94 |
|
95 |
|
96 | const urls = start_server_1.getServerUrls(options, serverInfos.control.server);
|
97 | console.log(`Started multiple servers with different variants:
|
98 | More info here: ${url.format(urls.serverUrl)}`);
|
99 | }
|
100 | return serverInfos;
|
101 | });
|
102 | }
|
103 | exports.run = run;
|
104 | function printUsage(options) {
|
105 | const usage = commandLineUsage([{
|
106 | header: 'A development server for Polymer projects',
|
107 | title: 'polyserve',
|
108 | optionList: options,
|
109 | }]);
|
110 | console.log(usage);
|
111 | }
|
112 | function getVersion() {
|
113 | const packageFilePath = path.resolve(__dirname, '../package.json');
|
114 | const packageFile = fs.readFileSync(packageFilePath).toString();
|
115 | const packageJson = JSON.parse(packageFile);
|
116 | const version = packageJson['version'];
|
117 | return version;
|
118 | }
|
119 |
|
\ | No newline at end of file |