This commit is contained in:
Benjamin Toby 2025-04-17 11:33:05 +01:00
parent d41d28104f
commit ba1a4aeeb8
3 changed files with 25 additions and 24 deletions

View File

@ -48,12 +48,12 @@ const args = (0, util_1.parseArgs)({
}, },
strict: false, strict: false,
}); });
const { apiKey: key, database, outfile, debug, envfile } = args.values; let appendedEnv = {};
if (envfile && typeof envfile == "string") { if (args.values.envfile && typeof args.values.envfile == "string") {
const finalEnvPath = path_1.default.resolve(process.cwd(), envfile); const finalEnvPath = path_1.default.resolve(process.cwd(), args.values.envfile);
if (fs_1.default.existsSync(finalEnvPath)) { if (fs_1.default.existsSync(finalEnvPath)) {
const appendedEnv = (0, parse_env_1.default)(finalEnvPath); appendedEnv = (0, parse_env_1.default)(finalEnvPath);
if (debug) { if (args.values.debug) {
(0, debug_log_1.default)({ (0, debug_log_1.default)({
log: appendedEnv, log: appendedEnv,
label: "Appended env", label: "Appended env",
@ -61,14 +61,14 @@ if (envfile && typeof envfile == "string") {
addTime: true, addTime: true,
}); });
} }
for (const [key, value] of Object.entries(appendedEnv)) {
process.env[key] = value;
}
} }
} }
const finalEnv = Object.assign(Object.assign({}, process.env), appendedEnv);
(() => __awaiter(void 0, void 0, void 0, function* () { (() => __awaiter(void 0, void 0, void 0, function* () {
try { try {
if (debug) { const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
if (args.values.debug) {
(0, debug_log_1.default)({ (0, debug_log_1.default)({
log: args.values, log: args.values,
label: "Arguments", label: "Arguments",
@ -92,7 +92,7 @@ if (envfile && typeof envfile == "string") {
throw new Error("Database name is required"); throw new Error("Database name is required");
if (!key || typeof key !== "string") if (!key || typeof key !== "string")
throw new Error("API key is required"); throw new Error("API key is required");
if (!outfile || typeof outfile !== "string") if (!args.values.outfile || typeof args.values.outfile !== "string")
throw new Error("Outfile are required"); throw new Error("Outfile are required");
const schema = yield __1.default.getSchema({ const schema = yield __1.default.getSchema({
key, key,
@ -103,7 +103,7 @@ if (envfile && typeof envfile == "string") {
if (!dbSchema) if (!dbSchema)
throw new Error("No schema found"); throw new Error("No schema found");
const definitions = (0, db_schema_to_type_1.default)({ dbSchema }); const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
const finalOutfile = path_1.default.resolve(process.cwd(), outfile); const finalOutfile = path_1.default.resolve(process.cwd(), args.values.outfile);
const ourfileDir = path_1.default.dirname(finalOutfile); const ourfileDir = path_1.default.dirname(finalOutfile);
if (!fs_1.default.existsSync(ourfileDir)) { if (!fs_1.default.existsSync(ourfileDir)) {
fs_1.default.mkdirSync(ourfileDir, { recursive: true }); fs_1.default.mkdirSync(ourfileDir, { recursive: true });

View File

@ -39,14 +39,14 @@ const args = parseArgs({
strict: false, strict: false,
}); });
const { apiKey: key, database, outfile, debug, envfile } = args.values; let appendedEnv: { [k: string]: string } = {};
if (envfile && typeof envfile == "string") { if (args.values.envfile && typeof args.values.envfile == "string") {
const finalEnvPath = path.resolve(process.cwd(), envfile); const finalEnvPath = path.resolve(process.cwd(), args.values.envfile);
if (fs.existsSync(finalEnvPath)) { if (fs.existsSync(finalEnvPath)) {
const appendedEnv = parseEnv(finalEnvPath); appendedEnv = parseEnv(finalEnvPath);
if (debug) { if (args.values.debug) {
debugLog({ debugLog({
log: appendedEnv, log: appendedEnv,
label: "Appended env", label: "Appended env",
@ -54,16 +54,17 @@ if (envfile && typeof envfile == "string") {
addTime: true, addTime: true,
}); });
} }
}
}
for (const [key, value] of Object.entries(appendedEnv)) { const finalEnv = { ...process.env, ...appendedEnv };
process.env[key] = value;
}
}
}
(async () => { (async () => {
try { try {
if (debug) { const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
if (args.values.debug) {
debugLog({ debugLog({
log: args.values, log: args.values,
label: "Arguments", label: "Arguments",
@ -88,7 +89,7 @@ if (envfile && typeof envfile == "string") {
throw new Error("Database name is required"); throw new Error("Database name is required");
if (!key || typeof key !== "string") if (!key || typeof key !== "string")
throw new Error("API key is required"); throw new Error("API key is required");
if (!outfile || typeof outfile !== "string") if (!args.values.outfile || typeof args.values.outfile !== "string")
throw new Error("Outfile are required"); throw new Error("Outfile are required");
const schema = await datasquirel.getSchema({ const schema = await datasquirel.getSchema({
@ -103,7 +104,7 @@ if (envfile && typeof envfile == "string") {
const definitions = dbSchemaToType({ dbSchema }); const definitions = dbSchemaToType({ dbSchema });
const finalOutfile = path.resolve(process.cwd(), outfile); const finalOutfile = path.resolve(process.cwd(), args.values.outfile);
const ourfileDir = path.dirname(finalOutfile); const ourfileDir = path.dirname(finalOutfile);
if (!fs.existsSync(ourfileDir)) { if (!fs.existsSync(ourfileDir)) {
fs.mkdirSync(ourfileDir, { recursive: true }); fs.mkdirSync(ourfileDir, { recursive: true });

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "4.3.4", "version": "4.3.5",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {