Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/db/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGODB_CONNECTION_STRING: mongodb://localhost:27017/embalse-info
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"postinstall": "node setup.js",
"build": "run-p clean type-check build:db",
"build:db": "tsc",
"clean": "rimraf dist",
Expand Down
26 changes: 26 additions & 0 deletions packages/db/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const mongoDataPath = path.resolve(__dirname, "mongo-data");
const envExamplePath = path.resolve(__dirname, ".env.example");
const envPath = path.resolve(__dirname, ".env");

try {
// Create directory mongo-data
if (!fs.existsSync(mongoDataPath)) {
fs.mkdirSync(mongoDataPath, { recursive: true });
}

// Copy .env.example a .env
if (!fs.existsSync(envPath)) {
if (fs.existsSync(envExamplePath)) {
fs.copyFileSync(envExamplePath, envPath);
}
}
} catch (error) {
process.exit(1);
}