42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import os from "node:os";
|
|
import fs from "node:fs";
|
|
import rls from "readline-sync";
|
|
const configFilePath = `${os.homedir()}/.infisical-env.config.json`;
|
|
|
|
const configTemplate = {
|
|
projects: [],
|
|
storeTokens: false,
|
|
infisicalInstance: "https://app.infisical.com"
|
|
}
|
|
|
|
export function loadConfig(){
|
|
return JSON.parse(fs.readFileSync(configFilePath));
|
|
}
|
|
|
|
export function upsertConfig(){
|
|
if(fs.existsSync(configFilePath)) return;
|
|
generateConfig();
|
|
}
|
|
|
|
export function writeConfig(overrides){
|
|
const config = {...configTemplate, ...overrides};
|
|
fs.writeFileSync(configFilePath, JSON.stringify(config));
|
|
}
|
|
|
|
export function generateConfig(){
|
|
const url = rls.question("Infisical Instance: ");
|
|
const store = rls.keyInYNStrict("Store Tokens? (Will Be Unencrypted)");
|
|
const projectOptions = ["Add Project", "Exit"];
|
|
const envOptions = ["Add Environment", "Exit"];
|
|
const pathOptions = ["Add Path", "Exit"];
|
|
var opt;
|
|
projLoop: while(1){
|
|
opt = rls.keyInSelect(projectOptions, "Select");
|
|
if(opt !== 1) break projLoop;
|
|
envLoop: while(1){
|
|
opt = rls.keyInSelect(projectOptions, "Select");
|
|
}
|
|
}
|
|
console.log({infisicalInstance: url, storeTokens: store});
|
|
|
|
}
|