@hairy/lnv
Version:
Loading environment variables in Next.js and other frameworks can be quite cumbersome, and using dotenv or vault at runtime is also inconvenient. That's why my created this tool
49 lines (46 loc) • 1.19 kB
JavaScript
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
import {
lnv
} from "./chunk-B2BTLDZV.js";
// src/cli/lnv.ts
async function registerLnvCommand(cli) {
const args = cli.usage("lnv <entry> [args]").alias("h", "help").option("value", {
describe: "set environment variables",
type: "array",
alias: "v"
}).option("depth", {
describe: "depth find and merge environment variables",
type: "boolean",
alias: "d"
}).option("entry", {
describe: "Manual selection entry",
type: "array",
alias: "e"
}).option("run", {
describe: "load runtime environment and run any scripts",
type: "string",
alias: "r"
}).option("write", {
describe: "expose and write environment variables to .env file",
type: "boolean"
}).help().parse();
const entries = [...args._ || [], ...args.entry || []];
const env = args.value?.reduce(
(acc, cur) => {
const [key, value] = cur.split("=");
acc[key] = value;
return acc;
},
{}
);
await lnv({
write: args.write,
run: args.run,
depth: args.depth,
entries,
env
});
}
export {
registerLnvCommand
};