-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c31e316
commit 759db40
Showing
2 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const util = require("node:util"); | ||
const asyncExec = util.promisify(require("node:child_process").exec); | ||
const fs = require("node:fs/promises"); | ||
const { existsSync } = require("node:fs"); | ||
|
||
async function setup() { | ||
const { stdout: pnpmVersion } = await asyncExec("pnpm --version"); | ||
|
||
if (!pnpmVersion) { | ||
throw new Error("`pnpm` is required to run this script."); | ||
} | ||
|
||
console.info( | ||
"Welcome! We're just settings things up, hold a minute... π°οΈ \n" | ||
); | ||
|
||
const packageJsonExists = existsSync("./package.json"); | ||
|
||
if (!packageJsonExists) { | ||
await asyncExec("pnpm init").catch((err) => console.error(err)); | ||
} | ||
|
||
console.info("Adding dependencies... π¦"); | ||
await asyncExec("pnpm i -D @clack/prompts picocolors degit").catch((err) => | ||
console.error(err) | ||
); | ||
|
||
console.info("Adding scripts... π"); | ||
const packageJsonString = await fs.readFile("./package.json", { | ||
encoding: "utf8", | ||
}); | ||
|
||
if (packageJsonString) { | ||
try { | ||
let packageJsonParsed = JSON.parse(packageJsonString); | ||
packageJsonParsed.scripts["db:install-modules"] = | ||
"node ./scripts/wizard.js"; | ||
const newPacakgeJson = JSON.stringify(packageJsonParsed, null, 2); | ||
await fs.writeFile("./package.json", newPacakgeJson); | ||
} catch (err) { | ||
throw new Error(`Failed parsing \`package.json\` file: ${err}`); | ||
} | ||
} | ||
|
||
console.info( | ||
"β Success: You can run the Supabase Modules wizard using `pnpm db:install-modules`" | ||
); | ||
} | ||
|
||
setup().catch((err) => console.error(`Error: setup.ts failed with: ${err}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
const { | ||
intro, | ||
outro, | ||
confirm, | ||
select, | ||
multiselect, | ||
spinner, | ||
isCancel, | ||
cancel, | ||
text, | ||
} = require("@clack/prompts"); | ||
const color = require("picocolors"); | ||
const { existsSync } = require("node:fs"); | ||
|
||
const util = require("node:util"); | ||
const asyncExec = util.promisify(require("node:child_process").exec); | ||
|
||
function handleCancel(currentProcess, message = "Operation cancelled") { | ||
if (isCancel(currentProcess)) { | ||
cancel(message); | ||
return process.exit(0); | ||
} | ||
} | ||
|
||
async function wizard() { | ||
intro(`Welcome to ${color.magenta("Supabase Modules")} π₯‘`); | ||
|
||
const projectStarter = await select({ | ||
message: `${color.italic("How")} would you like to begin?`, | ||
default: "from-example", | ||
options: [ | ||
{ | ||
label: "Start from an Example", | ||
value: "from-example", | ||
hint: "Jumpstart your development by cloning an Example project", | ||
}, | ||
{ | ||
label: "Add to Existing Project", | ||
value: "existing-project", | ||
hint: "Enhance your current project by directly integrating Supabase Modules", | ||
}, | ||
], | ||
}); | ||
|
||
handleCancel(projectStarter); | ||
|
||
if (projectStarter === "from-example") { | ||
const dir = await text({ | ||
message: `Which is your ${color.italic("project's working directory")}?`, | ||
initialValue: ".", | ||
validate: (dirInput) => { | ||
const dirExists = existsSync(dirInput); | ||
if (!dirExists) { | ||
return "Not found - please make sure the directory provided exists."; | ||
} | ||
}, | ||
}); | ||
|
||
handleCancel(dir); | ||
|
||
const installAllModules = await confirm({ | ||
message: `Would you like to install ${color.italic("all modules")}?`, | ||
default: true, | ||
}); | ||
|
||
handleCancel(installAllModules); | ||
|
||
if (installAllModules) { | ||
const s = spinner(); | ||
s.start("Installing project files... π·π½"); | ||
await asyncExec( | ||
`degit iamhectorsosa/iamhectorsosa/src/components/layout ${dir}/supabase --force` | ||
); | ||
await asyncExec( | ||
`degit iamhectorsosa/iamhectorsosa/src/components/providers ${dir}/modules --force` | ||
); | ||
|
||
s.stop("Project files successfully installed π·π½"); | ||
|
||
outro( | ||
`β ${color.green( | ||
"Success" | ||
)}: All set! Make sure to check out our docs at: \n ${color.magenta( | ||
"https://supabase-modules-docs.vercel.app" | ||
)} (hold cmd or ctl to click on URL)` | ||
); | ||
return process.exit(0); | ||
} | ||
|
||
const modulesToInstall = await multiselect({ | ||
message: `${color.italic( | ||
"Select which modules" | ||
)} would you like to install.`, | ||
options: [ | ||
{ value: "auth", label: "Authentication" }, | ||
{ value: "profile", label: "Profile" }, | ||
], | ||
}); | ||
|
||
handleCancel(modulesToInstall); | ||
|
||
const s = spinner(); | ||
s.start("Installing project files... π·π½"); | ||
|
||
for (module in modulesToInstall) { | ||
await asyncExec( | ||
`degit iamhectorsosa/iamhectorsosa/src/components/layout ${dir}/supabase --force` | ||
); | ||
} | ||
|
||
s.stop("Project files successfully installed π·π½"); | ||
|
||
outro( | ||
`β ${color.green( | ||
"Success" | ||
)}: All set! Make sure to check out our docs at: \n ${color.magenta( | ||
"https://supabase-modules-docs.vercel.app" | ||
)} (hold cmd or ctl to click on URL)` | ||
); | ||
return process.exit(0); | ||
} | ||
|
||
outro( | ||
`β ${color.green`Nothing to install!`} Make sure to check out our docs at: \n ${color.magenta( | ||
"https://supabase-modules-docs.vercel.app" | ||
)} (hold cmd or ctl to click on URL)` | ||
); | ||
} | ||
|
||
wizard().catch((err) => | ||
console.error(`${color.red`Error: wizard.js failed with`} ${err}`) | ||
); |