1 | "use strict";
|
2 | var __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 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 |
|
15 | var CONFIG_FILE_NAME = 'tractor.conf.js';
|
16 |
|
17 | var logger_1 = require("@tractor/logger");
|
18 | var path = require("path");
|
19 |
|
20 | var default_conf_1 = require("./default.conf");
|
21 |
|
22 | var error_handler_1 = require("@tractor/error-handler");
|
23 | var config;
|
24 | function 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 | }
|
30 | exports.getConfig = getConfig;
|
31 | function 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 | }
|
47 | exports.loadConfig = loadConfig;
|
48 | function isESM(userConfig) {
|
49 | return !!userConfig.default;
|
50 | }
|
51 |
|
\ | No newline at end of file |