UNPKG

1.66 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const fs_1 = tslib_1.__importDefault(require("fs"));
5const humanize_list_1 = tslib_1.__importDefault(require("humanize-list"));
6const BuildError_1 = tslib_1.__importDefault(require("./util/BuildError"));
7const diagnostics_1 = require("./diagnostics");
8function findEntryPoint(possibilities, options) {
9 const { onDiagnostic, notFoundIsFatal, component } = Object.assign({ notFoundIsFatal: true }, options);
10 const foundEntryPoints = possibilities.filter((path) => fs_1.default.existsSync(path));
11 let entryPoint;
12 if (foundEntryPoints.length === 1)
13 entryPoint = foundEntryPoints[0];
14 else if (foundEntryPoints.length === 0) {
15 const possibilitiesStr = humanize_list_1.default(possibilities, { conjunction: 'or' });
16 if (notFoundIsFatal) {
17 throw new BuildError_1.default(`No ${component} entry point found! None of ${possibilitiesStr} are present in the project.`);
18 }
19 else {
20 onDiagnostic({
21 category: diagnostics_1.DiagnosticCategory.Warning,
22 messageText: `This project is being built without a ${component} component. Create a file named ${possibilitiesStr} to add a ${component} component to your project.`,
23 });
24 }
25 }
26 else if (foundEntryPoints.length > 1) {
27 throw new BuildError_1.default(`Multiple ${component} entry points found! ${humanize_list_1.default(foundEntryPoints)} are all valid entry points; rename all but one and try again.`);
28 }
29 return entryPoint;
30}
31exports.default = findEntryPoint;