@vendure/cli
Version:
A modern, headless ecommerce framework
93 lines • 4.09 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadVendureConfigFile = loadVendureConfigFile;
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
const ts_node_1 = require("ts-node");
const ast_utils_1 = require("../../utilities/ast-utils");
const utils_1 = require("../../utilities/utils");
async function loadVendureConfigFile(vendureConfig, providedTsConfigPath) {
await Promise.resolve().then(() => __importStar(require('dotenv/config')));
if (!(0, utils_1.isRunningInTsNode)()) {
let tsConfigPath;
if (providedTsConfigPath) {
tsConfigPath = providedTsConfigPath;
}
else {
const tsConfigFile = await (0, ast_utils_1.selectTsConfigFile)();
tsConfigPath = node_path_1.default.join(process.cwd(), tsConfigFile);
}
let tsConfigFileContent;
let tsConfigJson;
try {
tsConfigFileContent = (0, node_fs_1.readFileSync)(tsConfigPath, 'utf-8');
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to read TypeScript config file at ${tsConfigPath}: ${errorMessage}`);
}
try {
tsConfigJson = JSON.parse((0, strip_json_comments_1.default)(tsConfigFileContent));
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to parse TypeScript config file at ${tsConfigPath}: ${errorMessage}`);
}
const compilerOptions = tsConfigJson.compilerOptions;
(0, ts_node_1.register)({
compilerOptions: Object.assign(Object.assign({}, compilerOptions), { moduleResolution: 'NodeNext', module: 'NodeNext' }),
transpileOnly: true,
});
if (compilerOptions.paths) {
const tsConfigPaths = require('tsconfig-paths');
tsConfigPaths.register({
baseUrl: './',
paths: compilerOptions.paths,
});
}
}
const exportedVarName = vendureConfig.getConfigObjectVariableName();
if (!exportedVarName) {
throw new Error('Could not find the exported variable name in the VendureConfig file');
}
const config = require(vendureConfig.sourceFile.getFilePath())[exportedVarName];
return config;
}
//# sourceMappingURL=load-vendure-config-file.js.map