UNPKG

@vxrn/takeout-cli

Version:

CLI tools for Takeout starter kit - interactive onboarding and project setup

126 lines (124 loc) 4.63 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var env_exports = {}; __export(env_exports, { copyEnvFile: () => copyEnvFile, createEnvLocal: () => createEnvLocal, envFileExists: () => envFileExists, generateSecret: () => generateSecret, readEnvVariable: () => readEnvVariable, updateEnvVariable: () => updateEnvVariable }); module.exports = __toCommonJS(env_exports); var import_node_crypto = require("node:crypto"), import_node_fs = require("node:fs"), import_node_path = require("node:path"); function generateSecret() { var length = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 32; return (0, import_node_crypto.randomBytes)(length).toString("hex"); } function envFileExists(cwd) { var filename = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ".env"; return (0, import_node_fs.existsSync)((0, import_node_path.join)(cwd, filename)); } function copyEnvFile(cwd, source, target) { var sourcePath = (0, import_node_path.join)(cwd, source), targetPath = (0, import_node_path.join)(cwd, target); if (!(0, import_node_fs.existsSync)(sourcePath)) return { success: !1, error: `Source file ${source} not found` }; if ((0, import_node_fs.existsSync)(targetPath)) return { success: !1, error: `Target file ${target} already exists` }; try { return (0, import_node_fs.copyFileSync)(sourcePath, targetPath), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } function updateEnvVariable(cwd, key, value) { var filename = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".env", envPath = (0, import_node_path.join)(cwd, filename); if (!(0, import_node_fs.existsSync)(envPath)) return { success: !1, error: `${filename} not found` }; try { var content = (0, import_node_fs.readFileSync)(envPath, "utf-8"), keyRegex = new RegExp(`^${key}=.*$`, "m"); return keyRegex.test(content) ? content = content.replace(keyRegex, `${key}=${value}`) : content = content.trimEnd() + ` ${key}=${value} `, (0, import_node_fs.writeFileSync)(envPath, content, "utf-8"), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } function createEnvLocal(cwd) { var envLocalPath = (0, import_node_path.join)(cwd, ".env.local"); if ((0, import_node_fs.existsSync)(envLocalPath)) return { success: !0 }; var template = `# Local environment overrides # This file is gitignored and never committed # Add your personal secrets and local configuration here # These values override .env # Example: # BETTER_AUTH_SECRET=your-secret-here # AWS_ACCESS_KEY_ID=your-key-here `; try { return (0, import_node_fs.writeFileSync)(envLocalPath, template, "utf-8"), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } function readEnvVariable(cwd, key) { var filename = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".env", envPath = (0, import_node_path.join)(cwd, filename); if (!(0, import_node_fs.existsSync)(envPath)) return null; try { var _match_, content = (0, import_node_fs.readFileSync)(envPath, "utf-8"), keyRegex = new RegExp(`^${key}=(.*)$`, "m"), match = content.match(keyRegex); return (match == null || (_match_ = match[1]) === null || _match_ === void 0 ? void 0 : _match_.trim().replace(/^["']|["']$/g, "")) || null; } catch { return null; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { copyEnvFile, createEnvLocal, envFileExists, generateSecret, readEnvVariable, updateEnvVariable }); //# sourceMappingURL=env.js.map