UNPKG

@vxrn/takeout-cli

Version:

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

62 lines (61 loc) 2.23 kB
import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; function updatePackageJson(cwd, updates) { const packagePath = join(cwd, "package.json"); if (!existsSync(packagePath)) return { success: !1, error: "package.json not found" }; try { const content = readFileSync(packagePath, "utf-8"), pkg = JSON.parse(content); return updates.name && (pkg.name = updates.name), updates.description && (pkg.description = updates.description), writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + ` `, "utf-8"), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } function updateAppConfig(cwd, updates) { const configPath = join(cwd, "app.config.ts"); if (!existsSync(configPath)) return { success: !1, error: "app.config.ts not found" }; try { let content = readFileSync(configPath, "utf-8"); return updates.name && (content = content.replace(/(name:\s*['"])([^'"]+)(['"])/, `$1${updates.name}$3`)), updates.slug && (content = content.replace(/(slug:\s*['"])([^'"]+)(['"])/, `$1${updates.slug}$3`)), updates.bundleId && (content = content.replace(/(bundleIdentifier:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`), content = content.replace(/(package:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`)), writeFileSync(configPath, content, "utf-8"), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } function checkOnboarded(cwd) { return existsSync(join(cwd, ".onboarded")); } function markOnboarded(cwd) { const marker = join(cwd, ".onboarded"); try { const timestamp = (/* @__PURE__ */new Date()).toISOString(); return writeFileSync(marker, `Onboarded at: ${timestamp} Run 'bun onboard' to reconfigure. `, "utf-8"), { success: !0 }; } catch (error) { return { success: !1, error: error instanceof Error ? error.message : "Unknown error" }; } } export { checkOnboarded, markOnboarded, updateAppConfig, updatePackageJson }; //# sourceMappingURL=files.mjs.map