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
+13 -12
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 });