1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
|
5 | * This code may only be used under the BSD style license found at
|
6 | * http://polymer.github.io/LICENSE.txt
|
7 | * The complete set of authors may be found at
|
8 | * http://polymer.github.io/AUTHORS.txt
|
9 | * The complete set of contributors may be found at
|
10 | * http://polymer.github.io/CONTRIBUTORS.txt
|
11 | * Code distributed by Google as part of the polymer project is also
|
12 | * subject to an additional IP rights grant found at
|
13 | * http://polymer.github.io/PATENTS.txt
|
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 | // Be mindful of adding imports here, as this is on the hot path of all
|
25 | // commands.
|
26 | const fs = require("fs");
|
27 | const inquirer = require("inquirer");
|
28 | const child_process_1 = require("mz/child_process");
|
29 | const path = require("path");
|
30 | /**
|
31 | * Check if the current shell environment is MinGW. MinGW can't handle some
|
32 | * yeoman features, so we can use this check to downgrade gracefully.
|
33 | */
|
34 | function checkIsMinGW() {
|
35 | const isWindows = /^win/.test(process.platform);
|
36 | if (!isWindows) {
|
37 | return false;
|
38 | }
|
39 | // uname might not exist if using cmd or powershell,
|
40 | // which would throw an exception
|
41 | try {
|
42 | const uname = child_process_1.execSync('uname -s').toString();
|
43 | return !!/^mingw/i.test(uname);
|
44 | }
|
45 | catch (error) {
|
46 | return false;
|
47 | }
|
48 | }
|
49 | /**
|
50 | * A wrapper around inquirer prompt that works around its awkward (incorrect?)
|
51 | * typings, and is intended for asking a single list-based question.
|
52 | */
|
53 | function prompt(question) {
|
54 | return __awaiter(this, void 0, void 0, function* () {
|
55 | // Some windows emulators (mingw) don't handle arrows correctly
|
56 | // https://github.com/SBoudrias/Inquirer.js/issues/266
|
57 | // Fall back to rawlist and use number input
|
58 | // Credit to
|
59 | // https://gist.github.com/geddski/c42feb364f3c671d22b6390d82b8af8f
|
60 | const rawQuestion = {
|
61 | type: checkIsMinGW() ? 'rawlist' : 'list',
|
62 | name: 'foo',
|
63 | message: question.message,
|
64 | choices: question.choices,
|
65 | };
|
66 | // TODO(justinfagnani): the typings for inquirer appear wrong
|
67 | // tslint:disable-next-line: no-any
|
68 | const answers = yield inquirer.prompt([rawQuestion]);
|
69 | return answers.foo;
|
70 | });
|
71 | }
|
72 | exports.prompt = prompt;
|
73 | function indent(str, additionalIndentation = ' ') {
|
74 | return str.split('\n')
|
75 | .map((s) => s ? additionalIndentation + s : '')
|
76 | .join('\n');
|
77 | }
|
78 | exports.indent = indent;
|
79 | function dashToCamelCase(text) {
|
80 | return text.replace(/-([a-z])/g, (v) => v[1].toUpperCase());
|
81 | }
|
82 | exports.dashToCamelCase = dashToCamelCase;
|
83 | /**
|
84 | * Gets the root source files of the project, for analysis & linting.
|
85 | *
|
86 | * First looks for explicit options on the command line, then looks in
|
87 | * the config file. If none are specified in either case, returns undefined.
|
88 | *
|
89 | * Returned file paths are relative from config.root.
|
90 | */
|
91 | function getProjectSources(options, config) {
|
92 | return __awaiter(this, void 0, void 0, function* () {
|
93 | const globby = yield Promise.resolve().then(() => require('globby'));
|
94 | if (options.input !== undefined && options.input.length > 0) {
|
95 | // Files specified from the command line are relative to the current
|
96 | // working directory (which is usually, but not always, config.root).
|
97 | const absPaths = yield globby(options.input, { root: process.cwd() });
|
98 | return absPaths.map((p) => path.relative(config.root, p));
|
99 | }
|
100 | const candidateFiles = yield globby(config.sources, { root: config.root });
|
101 | candidateFiles.push(...config.fragments);
|
102 | if (config.shell) {
|
103 | candidateFiles.push(config.shell);
|
104 | }
|
105 | /**
|
106 | * A project config will always have an entrypoint of
|
107 | * `${config.root}/index.html`, even if the polymer.json file is
|
108 | * totally blank.
|
109 | *
|
110 | * So we should only return config.entrypoint here if:
|
111 | * - the user has specified other sources in their config file
|
112 | * - and if the entrypoint ends with index.html, we only include it if it
|
113 | * exists on disk.
|
114 | */
|
115 | if (candidateFiles.length > 0 && config.entrypoint) {
|
116 | if (!config.entrypoint.endsWith('index.html') ||
|
117 | fs.existsSync(config.entrypoint)) {
|
118 | candidateFiles.push(config.entrypoint);
|
119 | }
|
120 | }
|
121 | if (candidateFiles.length > 0) {
|
122 | // Files in the project config are all absolute paths.
|
123 | return [...new Set(candidateFiles.map((absFile) => path.relative(config.root, absFile)))];
|
124 | }
|
125 | return undefined;
|
126 | });
|
127 | }
|
128 | exports.getProjectSources = getProjectSources;
|
129 | //# sourceMappingURL=util.js.map |
\ | No newline at end of file |