@vxrn/takeout-cli
Version:
CLI tools for Takeout starter kit - interactive onboarding and project setup
147 lines (146 loc) • 9.38 kB
JavaScript
;
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 onboard_exports = {};
__export(onboard_exports, {
onboardCommand: () => onboardCommand
});
module.exports = __toCommonJS(onboard_exports);
var import_citty = require("citty"), import_node_child_process = require("node:child_process"), import_env = require("../utils/env"), import_files = require("../utils/files"), import_ports = require("../utils/ports"), import_prerequisites = require("../utils/prerequisites"), import_prompts = require("../utils/prompts"), onboardCommand = (0, import_citty.defineCommand)({
meta: {
name: "onboard",
description: "Interactive onboarding for Takeout starter kit"
},
args: {
skip: {
type: "boolean",
description: "Skip interactive prompts",
default: !1
}
},
async run(param) {
var { args } = param, cwd = process.cwd();
if (args.skip) {
(0, import_prompts.showInfo)("Skipping onboarding (--skip flag)");
return;
}
(0, import_prompts.displayWelcome)(), (0, import_prompts.showStep)("Checking prerequisites..."), console.info();
var checks = (0, import_prerequisites.checkAllPrerequisites)();
(0, import_prompts.displayPrerequisites)(checks);
var hasRequired = (0, import_prerequisites.hasRequiredPrerequisites)(checks);
if (!hasRequired) {
(0, import_prompts.showWarning)("Some required prerequisites are missing. You can continue, but setup may fail.");
var shouldContinue = await (0, import_prompts.confirmContinue)("Continue anyway?", !1);
if (!shouldContinue) {
(0, import_prompts.displayOutro)("Setup cancelled. Install prerequisites and try again.");
return;
}
}
console.info(), (0, import_prompts.showStep)("Setting up environment files..."), console.info();
var hasEnv = (0, import_env.envFileExists)(cwd, ".env");
if (hasEnv) {
(0, import_prompts.showInfo)(".env file already exists");
var shouldReconfigure = await (0, import_prompts.confirmContinue)("Reconfigure environment?", !1);
shouldReconfigure ? await setupEnvironment(cwd) : (0, import_prompts.showInfo)("Skipping environment setup");
} else
await setupEnvironment(cwd);
console.info(), (0, import_prompts.showStep)("Configuring project identity..."), console.info();
var shouldCustomize = await (0, import_prompts.confirmContinue)("Customize project name and bundle identifier?", !1);
shouldCustomize ? await customizeProject(cwd) : (0, import_prompts.showInfo)("Keeping default project configuration"), console.info(), (0, import_prompts.showStep)("Starting development services..."), console.info();
var portChecks = (0, import_ports.checkAllPorts)(), conflicts = (0, import_ports.getConflictingPorts)(portChecks);
conflicts.length > 0 && ((0, import_prompts.displayPortConflicts)(conflicts), (0, import_prompts.showWarning)("Some ports are already in use. You may need to stop other services."));
var shouldStartServices = await (0, import_prompts.confirmContinue)("Start Docker services (PostgreSQL, Zero, MinIO)?", !0);
shouldStartServices ? await startServices(cwd) : ((0, import_prompts.showInfo)("Skipping service startup"), (0, import_prompts.showInfo)("Run 'bun backend' to start services later")), console.info(), (0, import_prompts.showStep)("Setup complete!"), console.info(), (0, import_prompts.showSuccess)("\u2713 Environment configured"), (0, import_prompts.showSuccess)("\u2713 Project ready for development"), (0, import_files.markOnboarded)(cwd), console.info(), (0, import_prompts.showInfo)("Next steps:"), console.info(), console.info(" bun dev # Start development server"), console.info(" bun ios # Run iOS simulator"), console.info(" bun android # Run Android emulator"), console.info(), console.info("Documentation: /docs"), console.info();
var shouldStart = await (0, import_prompts.confirmContinue)("Start development server now?", !0);
if (shouldStart) {
console.info(), (0, import_prompts.showInfo)("Starting development server..."), console.info();
try {
(0, import_node_child_process.execSync)("bun dev", {
stdio: "inherit",
cwd
});
} catch {
(0, import_prompts.showInfo)("Development server stopped");
}
}
(0, import_prompts.displayOutro)("Happy coding! \u{1F680}");
}
});
async function setupEnvironment(cwd) {
var copyResult = (0, import_env.copyEnvFile)(cwd, ".env.development", ".env");
if (!copyResult.success) {
(0, import_prompts.showError)(`Failed to create .env: ${copyResult.error}`);
return;
}
(0, import_prompts.showSuccess)("Created .env from .env.development");
var useExisting = await (0, import_prompts.confirmContinue)("Use existing BETTER_AUTH_SECRET from .env.development?", !0);
if (!useExisting) {
var secret = (0, import_env.generateSecret)();
(0, import_env.updateEnvVariable)(cwd, "BETTER_AUTH_SECRET", secret), (0, import_prompts.showSuccess)("Generated new BETTER_AUTH_SECRET");
}
var setupGithub = await (0, import_prompts.confirmContinue)("Set up GitHub OAuth?", !1);
if (setupGithub) {
var clientId = await (0, import_prompts.promptText)("GitHub Client ID:", void 0, "Iv23liNaYfNSauaySodL");
clientId && (0, import_env.updateEnvVariable)(cwd, "ONECHAT_GITHUB_CLIENT_ID", clientId);
var clientSecret = await (0, import_prompts.promptText)("GitHub Client Secret (optional):", void 0, "Leave empty to skip");
clientSecret && (0, import_env.updateEnvVariable)(cwd, "ONECHAT_GITHUB_CLIENT_SECRET", clientSecret);
}
(0, import_env.createEnvLocal)(cwd), (0, import_prompts.showSuccess)("Created .env.local for personal overrides");
}
async function customizeProject(cwd) {
var projectName = await (0, import_prompts.promptText)("Project name:", "takeout", "my-awesome-app"), slug = await (0, import_prompts.promptText)("Project slug (URL-friendly):", projectName.toLowerCase().replace(/\s+/g, "-"), "my-awesome-app"), bundleId = await (0, import_prompts.promptText)("Bundle identifier:", `com.${slug}.app`, "com.example.app"), domain = await (0, import_prompts.promptText)("Development domain:", "localhost:8081", "localhost:8081"), pkgResult = (0, import_files.updatePackageJson)(cwd, {
name: projectName,
description: `${projectName} - Built with Takeout starter kit`
});
pkgResult.success ? (0, import_prompts.showSuccess)("Updated package.json") : (0, import_prompts.showError)(`Failed to update package.json: ${pkgResult.error}`);
var configResult = (0, import_files.updateAppConfig)(cwd, {
name: projectName,
slug,
bundleId
});
configResult.success ? (0, import_prompts.showSuccess)("Updated app.config.ts") : (0, import_prompts.showError)(`Failed to update app.config.ts: ${configResult.error}`);
var serverUrl = `http://${domain}`;
(0, import_env.updateEnvVariable)(cwd, "BETTER_AUTH_URL", serverUrl), (0, import_env.updateEnvVariable)(cwd, "ONE_SERVER_URL", serverUrl), (0, import_prompts.showSuccess)("Updated environment URLs");
}
async function startServices(cwd) {
var spinner = (0, import_prompts.showSpinner)("Starting Docker services...");
try {
(0, import_node_child_process.execSync)("bun backend", {
stdio: "ignore",
cwd
}), await new Promise(function(resolve) {
return setTimeout(resolve, 3e3);
}), spinner.stop("Docker services started"), (0, import_prompts.showSuccess)("\u2713 PostgreSQL running on port 5432"), (0, import_prompts.showSuccess)("\u2713 Zero sync running on port 4848"), (0, import_prompts.showSuccess)("\u2713 MinIO (S3) running on port 9090");
var shouldMigrate = await (0, import_prompts.confirmContinue)("Run database migrations?", !0);
if (shouldMigrate) {
var migrateSpinner = (0, import_prompts.showSpinner)("Running migrations...");
try {
(0, import_node_child_process.execSync)("bun migrate", {
stdio: "ignore",
cwd
}), migrateSpinner.stop("Database migrated"), (0, import_prompts.showSuccess)("\u2713 Database migrations complete");
} catch {
migrateSpinner.stop("Migration failed"), (0, import_prompts.showError)("Failed to run migrations"), (0, import_prompts.showInfo)("Try running 'bun migrate' manually");
}
}
} catch (error) {
spinner.stop("Failed to start services"), (0, import_prompts.showError)(error instanceof Error ? error.message : "Unknown error"), (0, import_prompts.showInfo)("Try running 'bun backend' manually");
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
onboardCommand
});
//# sourceMappingURL=onboard.js.map