Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: init example error #24

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function action(framework, options) {
default: `my-${framework}-app`,
})

if (options.example) await createFromExample(framework, dir)
if (options.example) return await createFromExample(framework, dir)

const providers = await checkbox({
instructions: false,
Expand All @@ -53,7 +53,8 @@ export async function action(framework, options) {
})
adapter = adapter === "none" ? undefined : adapter

await scaffoldProject({ framework, dir, providers, adapter })
//TODO implement scaffolding
// await scaffoldProject({ framework, dir, providers, adapter })
} catch (e) {
if (!(e instanceof Error)) return
if (e.message.startsWith("User force closed")) return
Expand All @@ -69,22 +70,28 @@ export async function action(framework, options) {
async function createFromExample(framework, dir) {
const { src, demo } = meta.frameworks[framework]
execSync(`git clone ${src} ${dir}`)

console.log(`Change directory to ${dir}`)
process.chdir(dir)
console.log("Now in:", process.cwd())
if (
await confirm({
message: "Initiailze .env with `AUTH_SECRET`",
message: "Initialize .env with `AUTH_SECRET`",
default: true,
})
) {
execSync(`cd ${dir}`)
await secretAction({ path: dir })
await secretAction({ path: "" })
}

await install()

console.log(`
Project ${y.italic(`\`${dir}\``)} has been created.
Source code: ${src}
Deployed demo: ${demo}`)
Project ${y.italic(`\`${dir}\``)} has been created.`)
//TODO: Add Implement publish to github
//TODO: Add Implement deploy to vercel
// Source code: ${src}
// Deployed demo: ${demo}
// `)
}

/**
Expand All @@ -98,13 +105,8 @@ async function scaffoldProject(options) {
pkgManager
)} at ${y.bold(dir)}...`
)
throw new Error("Scaffolding not implemented. Please use `init --example`")
console.log(`Create directory ${dir}`)
await mkdir(dir)
console.log(`Change directory to ${dir}`)
execSync(`cd ${dir}`)
console.log(`Initialize ${pkgManager} project`)
execSync(`${pkgManager} init`)
return console.warn("Scaffolding function is not yet implemented.")
// throw new Error("Scaffolding not implemented. Please use `init --example`")
// console.log(`Add ${framework} to ${pkgManager}`)
// execSync(`${pkgManager} install ${framework}`)
for (const provider of providers) {
Expand Down
2 changes: 2 additions & 0 deletions lib/pkg-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export async function install() {
/** Spawn the installation process. */
const child = spawn(packageManager, args, {
stdio: "inherit",
shell: true, // TODO make sure it doesn't have consequences to the security
env: {
...process.env,
ADBLOCK: "1",
Expand All @@ -59,6 +60,7 @@ export async function install() {
DISABLE_OPENCOLLECTIVE: "1",
},
})
child.on("error", reject)
child.on("close", (code) => {
if (code !== 0) {
reject({ command: `${packageManager} ${args.join(" ")}` })
Expand Down