UNPKG

1.83 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14// Constants:
15var CONFIG_FILE_NAME = 'tractor.conf.js';
16// Utilites:
17var logger_1 = require("@tractor/logger");
18var path = require("path");
19// Dependencies:
20var default_conf_1 = require("./default.conf");
21// Errors:
22var error_handler_1 = require("@tractor/error-handler");
23var config;
24function getConfig() {
25 if (!config) {
26 throw new error_handler_1.TractorError("\n You must call `loadConfig()` before you can use `getConfig()`!\n\n Example:\n\n import { loadConfig } from '@tractor/config-loader';\n\n const config = loadConfig(process.cwd(), 'path/to/my/config');\n ");
27 }
28 return config;
29}
30exports.getConfig = getConfig;
31function loadConfig(cwd, configPath) {
32 if (configPath === void 0) { configPath = CONFIG_FILE_NAME; }
33 logger_1.info('Loading config...');
34 var fullConfigPath = path.resolve(cwd, configPath);
35 var userConfig;
36 try {
37 var loadedConfig = require(fullConfigPath);
38 userConfig = isESM(loadedConfig) ? loadedConfig.default : loadedConfig;
39 }
40 catch (e) {
41 userConfig = {};
42 }
43 config = __assign({}, default_conf_1.DEFAULT_TRACTOR_CONFIG, userConfig);
44 config.cwd = cwd;
45 return config;
46}
47exports.loadConfig = loadConfig;
48function isESM(userConfig) {
49 return !!userConfig.default;
50}
51//# sourceMappingURL=load-config.js.map
\No newline at end of file