@launchql/env
Version:
LaunchQL environment management
109 lines (108 loc) • 3.99 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;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveLaunchqlPath = exports.loadConfigSync = exports.loadConfigSyncFromDir = exports.loadConfigFileSync = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const utils_1 = require("./utils");
/**
* Load configuration file with support for both .js and .json formats
* Moved from LaunchQLPackage class for better reusability
*/
const loadConfigFileSync = (configPath) => {
const ext = path.extname(configPath);
switch (ext) {
case '.json':
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
case '.js':
// delete require.cache[require.resolve(configPath)];
const configModule = require(configPath);
return configModule.default || configModule;
default:
throw new Error(`Unsupported config file type: ${ext}`);
}
};
exports.loadConfigFileSync = loadConfigFileSync;
/**
* Load configuration from a specific directory
* Moved from LaunchQLPackage class for better reusability
*/
const loadConfigSyncFromDir = (dir) => {
const configFiles = [
'launchql.config.js',
'launchql.json'
];
for (const filename of configFiles) {
const configPath = path.join(dir, filename);
if (fs.existsSync(configPath)) {
return (0, exports.loadConfigFileSync)(configPath);
}
}
throw new Error('No launchql config file found. Expected one of: ' + configFiles.join(', '));
};
exports.loadConfigSyncFromDir = loadConfigSyncFromDir;
/**
* Load configuration using walkUp to find config files
* Enhanced version that uses the robust config loading logic
*/
const loadConfigSync = (cwd = process.cwd()) => {
const configFiles = ['launchql.config.js', 'launchql.json'];
for (const filename of configFiles) {
try {
const configDir = (0, utils_1.walkUp)(cwd, filename);
return (0, exports.loadConfigSyncFromDir)(configDir);
}
catch {
}
}
return {};
};
exports.loadConfigSync = loadConfigSync;
/**
* Resolve the path to the LaunchQL workspace by finding config files
* Moved from LaunchQLPackage class for better reusability
*/
const resolveLaunchqlPath = (cwd = process.cwd()) => {
const configFiles = ['launchql.config.js', 'launchql.json'];
for (const filename of configFiles) {
try {
return (0, utils_1.walkUp)(cwd, filename);
}
catch {
}
}
return undefined;
};
exports.resolveLaunchqlPath = resolveLaunchqlPath;
;