UNPKG

2.8 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var path = require("path");
4var logger_1 = require("../logger");
5var get_absolute_path_1 = require("../helpers/get-absolute-path");
6var check_schema_match_1 = require("./check-schema-match");
7/**
8 * @internal Do not output this function in generated dts for the npm package
9 */
10function loadConfigFile(configPath) {
11 var possibleConfig = require(get_absolute_path_1.getAbsolutePath(configPath));
12 var errors = [];
13 if (!check_schema_match_1.checkSchemaMatch(possibleConfig, configScheme, errors)) {
14 logger_1.errorLog(errors.join('\n'));
15 throw new Error('Cannot parse config file');
16 }
17 if (!Array.isArray(possibleConfig.entries) || possibleConfig.entries.length === 0) {
18 throw new Error('No entries found');
19 }
20 var configFolder = path.dirname(configPath);
21 possibleConfig.entries.forEach(function (entry) {
22 entry.filePath = get_absolute_path_1.getAbsolutePath(entry.filePath, configFolder);
23 if (entry.outFile !== undefined) {
24 entry.outFile = get_absolute_path_1.getAbsolutePath(entry.outFile, configFolder);
25 }
26 });
27 if (possibleConfig.compilationOptions !== undefined && possibleConfig.compilationOptions.preferredConfigPath !== undefined) {
28 possibleConfig.compilationOptions.preferredConfigPath = get_absolute_path_1.getAbsolutePath(possibleConfig.compilationOptions.preferredConfigPath, configFolder);
29 }
30 return possibleConfig;
31}
32exports.loadConfigFile = loadConfigFile;
33var configScheme = {
34 compilationOptions: {
35 followSymlinks: check_schema_match_1.schemaPrimitiveValues.boolean,
36 preferredConfigPath: check_schema_match_1.schemaPrimitiveValues.string,
37 },
38 entries: [
39 {
40 filePath: check_schema_match_1.schemaPrimitiveValues.requiredString,
41 outFile: check_schema_match_1.schemaPrimitiveValues.string,
42 failOnClass: check_schema_match_1.schemaPrimitiveValues.boolean,
43 noCheck: check_schema_match_1.schemaPrimitiveValues.boolean,
44 libraries: {
45 allowedTypesLibraries: [check_schema_match_1.schemaPrimitiveValues.string],
46 importedLibraries: [check_schema_match_1.schemaPrimitiveValues.string],
47 inlinedLibraries: [check_schema_match_1.schemaPrimitiveValues.string],
48 },
49 output: {
50 inlineDeclareGlobals: check_schema_match_1.schemaPrimitiveValues.boolean,
51 inlineDeclareExternals: check_schema_match_1.schemaPrimitiveValues.boolean,
52 sortNodes: check_schema_match_1.schemaPrimitiveValues.boolean,
53 umdModuleName: check_schema_match_1.schemaPrimitiveValues.string,
54 },
55 },
56 ],
57};