Skip to content

Commit

Permalink
chore(cli): convert binary from bash to mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Jul 10, 2024
1 parent 817850b commit 5846fba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
48 changes: 48 additions & 0 deletions apps/cli/bin/opentrader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node

import { readFile } from "fs/promises";
import { spawn } from "child_process";
import { fileURLToPath } from "url";
import { dirname } from "path";

// Determine the script's directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Path to the file containing the admin password
const passwordFile = `${process.env.HOME}/.opentrader/pass`;

// Function to read the password file
async function readPasswordFile(filePath) {
try {
const data = await readFile(filePath, "utf-8");
return data.trim();
} catch (error) {
console.error("Password file not found!");
process.exit(1);
}
}

// Main function to run the script
async function main() {
const adminPassword = await readPasswordFile(passwordFile);

// Set environment variables
const env = {
...process.env,
ADMIN_PASSWORD: adminPassword,
DATABASE_URL: `file:${process.env.HOME}/.opentrader/dev.db`,
};

// Run the Node.js script
const args = [`${__dirname}/../dist/main.mjs`, ...process.argv.slice(2)];
const child = spawn("node", args, { env, stdio: "inherit" });

child.on("close", (code) => {
if (code !== 0) {
console.error(`Process exited with code ${code}`);
}
});
}

main();
19 changes: 0 additions & 19 deletions apps/cli/bin/opentrader.sh

This file was deleted.

4 changes: 2 additions & 2 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opentrader",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "",
"type": "module",
"main": "dist/main.mjs",
Expand Down Expand Up @@ -57,6 +57,6 @@
"zod": "3.23.8"
},
"bin": {
"opentrader": "./bin/opentrader.sh"
"opentrader": "./bin/opentrader.mjs"
}
}

0 comments on commit 5846fba

Please sign in to comment.