@vxrn/takeout-cli
Version:
CLI tools for Takeout starter kit - interactive onboarding and project setup
62 lines (61 loc) • 2.22 kB
JavaScript
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
function updatePackageJson(cwd, updates) {
var packagePath = join(cwd, "package.json");
if (!existsSync(packagePath)) return {
success: !1,
error: "package.json not found"
};
try {
var 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) {
var configPath = join(cwd, "app.config.ts");
if (!existsSync(configPath)) return {
success: !1,
error: "app.config.ts not found"
};
try {
var 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) {
var marker = join(cwd, ".onboarded");
try {
var 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.native.js.map