|
| 1 | +import {cloneRepo} from "../utils/clone-repo"; |
| 2 | +import prompts from "prompts"; |
| 3 | +import {readFileSync, writeFileSync} from "fs"; |
| 4 | +import generateSeedFile from "../utils/generate-seed-file"; |
| 5 | +import {logInfo, logSuccess} from "../utils/logger"; |
| 6 | + |
| 7 | +/** |
| 8 | + * Creates a new Basejump project cloned from a given repo to a given path |
| 9 | + * @param projectRepo |
| 10 | + * @param projectPath |
| 11 | + */ |
| 12 | +export default async ( |
| 13 | + projectRepo: string, |
| 14 | + projectPath: string |
| 15 | +) => { |
| 16 | + // the name of the project is the last part of the projectPath |
| 17 | + const pathProjectName = projectPath.split("/").pop(); |
| 18 | + |
| 19 | + // ask user for project defaults using prompts library |
| 20 | + const {projectName, teamAccounts, personalAccounts, billingProvider} = await prompts([ |
| 21 | + { |
| 22 | + type: "text", |
| 23 | + name: "projectName", |
| 24 | + message: "What is the name of your project?", |
| 25 | + initial: pathProjectName, |
| 26 | + }, |
| 27 | + { |
| 28 | + type: "confirm", |
| 29 | + name: "teamAccounts", |
| 30 | + message: "Do you want to use team accounts?", |
| 31 | + initial: true, |
| 32 | + }, |
| 33 | + { |
| 34 | + type: "confirm", |
| 35 | + name: "personalAccounts", |
| 36 | + message: "Do you want to use personal accounts?", |
| 37 | + initial: true, |
| 38 | + }, |
| 39 | + { |
| 40 | + type: "select", |
| 41 | + name: "billingProvider", |
| 42 | + message: "Which billing provider do you want to use? Billing is disabled by default and this can be changed later.", |
| 43 | + choices: [ |
| 44 | + {title: "None", value: "none"}, |
| 45 | + {title: "Stripe", value: "stripe"} |
| 46 | + ], |
| 47 | + initial: 0, |
| 48 | + } |
| 49 | + ]); |
| 50 | + |
| 51 | + logInfo("Setting up your project..."); |
| 52 | + |
| 53 | + await cloneRepo(projectRepo, projectPath); |
| 54 | + |
| 55 | + // replace the supabase/seeds.sql file with the correct values |
| 56 | + const seedsFile = `${projectPath}/supabase/seed.sql`; |
| 57 | + // we know exactly what we want the file to be, so we just overwrite it with the correct values |
| 58 | + await writeFileSync(seedsFile, generateSeedFile(teamAccounts, personalAccounts, billingProvider), "utf8"); |
| 59 | + |
| 60 | + // replace the supabase project name with the project name |
| 61 | + const supabaseConfigFile = `${projectPath}/supabase/config.toml`; |
| 62 | + // the project name is stored as project_id = "project-name" |
| 63 | + const supabaseConfig = readFileSync(supabaseConfigFile, "utf8"); |
| 64 | + const newSupabaseConfig = supabaseConfig.replace(/project_id = ".*"/, `project_id = "${projectName}"`); |
| 65 | + await writeFileSync(supabaseConfigFile, newSupabaseConfig, "utf8"); |
| 66 | + logSuccess("Project setup complete!"); |
| 67 | + logSuccess(`Your project is ready at ${projectPath}`); |
| 68 | +} |
0 commit comments