Skip to content

Commit

Permalink
Merge branch 'leerob:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Prathamesh-chougale-17 authored Sep 16, 2024
2 parents abdcfbe + 5b48910 commit 4458965
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ Fun fact: the majority of the UI for this application was built with [v0](https:
git clone https://github.com/leerob/next-saas-starter
pnpm install
pnpm db:setup
pnpm db:migrate
pnpm db:seed
```

Running the setup script will create your `.env` file locally.

## Running Locally

Once you have set up the environment variables and installed dependencies, run the development server:
Expand Down
1 change: 1 addition & 0 deletions app/(dashboard)/terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function Terminal() {
'git clone https://github.com/leerob/next-saas-starter',
'pnpm install',
'pnpm db:setup',
'pnpm db:migrate',
'pnpm db:seed',
'pnpm dev 🎉',
];
Expand Down
10 changes: 9 additions & 1 deletion lib/db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ async function seed() {
await createStripeProducts();
}

seed().catch(console.error);
seed()
.catch((error) => {
console.error('Seed process failed:', error);
process.exit(1);
})
.finally(() => {
console.log('Seed process finished. Exiting...');
process.exit(0);
});
45 changes: 40 additions & 5 deletions lib/db/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,43 @@ function question(query: string): Promise<string> {
}

async function checkStripeCLI() {
console.log('Step 1: Checking if Stripe CLI is installed...');
console.log(
'Step 1: Checking if Stripe CLI is installed and authenticated...'
);
try {
await execAsync('stripe --version');
console.log('Stripe CLI is installed.');

// Check if Stripe CLI is authenticated
try {
await execAsync('stripe config --list');
console.log('Stripe CLI is authenticated.');
} catch (error) {
console.log(
'Stripe CLI is not authenticated or the authentication has expired.'
);
console.log('Please run: stripe login');
const answer = await question(
'Have you completed the authentication? (y/n): '
);
if (answer.toLowerCase() !== 'y') {
console.log(
'Please authenticate with Stripe CLI and run this script again.'
);
process.exit(1);
}

// Verify authentication after user confirms login
try {
await execAsync('stripe config --list');
console.log('Stripe CLI authentication confirmed.');
} catch (error) {
console.error(
'Failed to verify Stripe CLI authentication. Please try again.'
);
process.exit(1);
}
}
} catch (error) {
console.error(
'Stripe CLI is not installed. Please install it and try again.'
Expand All @@ -36,7 +69,9 @@ async function checkStripeCLI() {
'2. Download and install the Stripe CLI for your operating system'
);
console.log('3. After installation, run: stripe login');
console.log('After installation, please run this setup script again.');
console.log(
'After installation and authentication, please run this setup script again.'
);
process.exit(1);
}
}
Expand Down Expand Up @@ -84,13 +119,13 @@ function generateAuthSecret(): string {
}

async function writeEnvFile(envVars: Record<string, string>) {
console.log('Step 6: Writing environment variables to .env.local');
console.log('Step 6: Writing environment variables to .env');
const envContent = Object.entries(envVars)
.map(([key, value]) => `${key}=${value}`)
.join('\n');

await fs.writeFile(path.join(process.cwd(), '.env.local'), envContent);
console.log('.env.local file created with the necessary variables.');
await fs.writeFile(path.join(process.cwd(), '.env'), envContent);
console.log('.env file created with the necessary variables.');
}

async function main() {
Expand Down

0 comments on commit 4458965

Please sign in to comment.