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,
});
const { apiKey: key, database, outfile, debug, envfile } = args.values;
if (envfile && typeof envfile == "string") {
const finalEnvPath = path_1.default.resolve(process.cwd(), envfile);
let appendedEnv = {};
if (args.values.envfile && typeof args.values.envfile == "string") {
const finalEnvPath = path_1.default.resolve(process.cwd(), args.values.envfile);
if (fs_1.default.existsSync(finalEnvPath)) {
const appendedEnv = (0, parse_env_1.default)(finalEnvPath);
if (debug) {
appendedEnv = (0, parse_env_1.default)(finalEnvPath);
if (args.values.debug) {
(0, debug_log_1.default)({
log: appendedEnv,
label: "Appended env",
@ -61,14 +61,14 @@ if (envfile && typeof envfile == "string") {
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* () {
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)({
log: args.values,
label: "Arguments",
@ -92,7 +92,7 @@ if (envfile && typeof envfile == "string") {
throw new Error("Database name is required");
if (!key || typeof key !== "string")
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");
const schema = yield __1.default.getSchema({
key,
@ -103,7 +103,7 @@ if (envfile && typeof envfile == "string") {
if (!dbSchema)
throw new Error("No schema found");
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);
if (!fs_1.default.existsSync(ourfileDir)) {
fs_1.default.mkdirSync(ourfileDir, { recursive: true });

View File

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

View File

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