Skip to content

Commit

Permalink
Check if src and data exist before creating them
Browse files Browse the repository at this point in the history
  • Loading branch information
nshiab committed Oct 9, 2024
1 parent 605553e commit 0107d38
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions simple-data-analysis.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { execSync } from "node:child_process";
import { mkdirSync, readdirSync, writeFileSync } from "node:fs";
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
import process from "node:process";

console.log("\nStarting sda setup...");
Expand Down Expand Up @@ -201,15 +201,20 @@ if (runtime === "deno") {
`import { prettyDuration } from "@nshiab/journalism";`
);
}
mkdirSync("src");
if (!existsSync("src")) {
mkdirSync("src");
}
if (language === "ts") {
writeFileSync("src/main.ts", mainContent);
console.log(" => src/main.ts has been created.");
} else {
writeFileSync("main.js", mainContent);
console.log(" => src/main.js has been created.");
}
mkdirSync("data");

if (!existsSync("data")) {
mkdirSync("data");
}
writeFileSync("data/temp.csv", data);
console.log(" => data/temp.csv has been created.");

Expand Down

0 comments on commit 0107d38

Please sign in to comment.