Skip to content

Commit

Permalink
Generate .env file after build if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
steos committed Jul 26, 2023
1 parent 255ca84 commit f1edda1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ wasm-pack.log
node_modules
/build/*/**
!/build/*/package.json
.env
33 changes: 33 additions & 0 deletions bin/generate-dotenv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fs = require("fs");
const path = require("path");
const opaque = require("../build/ristretto");

function fileExists(file) {
try {
fs.accessSync(file, fs.constants.F_OK);
return true;
} catch (err) {
return false;
}
}

async function main() {
const baseDir = path.join(__dirname, "..");
const envFile = path.join(baseDir, ".env");

if (fileExists(envFile)) {
console.log("opaque .env file already exists, skipping .env write");
return;
}

await opaque.ready;
const serverSetup = opaque.server.createSetup();

const dotEnv = `OPAQUE_SERVER_SETUP=${serverSetup}\n`;

console.log("writing opaque .env file");

fs.writeFileSync(envFile, dotEnv);
}

main();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"typescript": "5.1.3"
},
"scripts": {
"build": "node ./bin/build.js",
"build": "node ./bin/build.js && pnpm gen:dotenv",
"gen:dotenv": "node ./bin/generate-dotenv.js",
"example:fullstack-simple-nextjs:dev": "cd examples/fullstack-simple-nextjs && cross-env OPAQUE_SERVER_SETUP=Ki5T3U21n_UFhcGP5fR_mUstYEItKRsjEJ2UnvvrGasT3wvjdtbluS0BsiR_LtzqX8YLrCyWqQOJDf7cL0C8DRr9pGFBSx0X22ZujePyWpdq4VddBSPm0vIXepDJEBYJjRxmRNh09pLGxk_Y9bQuFWjYInqjcy_zOVsMHPHUkQw pnpm dev",
"example:client-simple-webpack:dev": "cd examples/client-simple-webpack && pnpm dev",
"example:client-with-password-reset:dev": "cd examples/client-with-password-reset && pnpm dev",
Expand Down

0 comments on commit f1edda1

Please sign in to comment.