Skip to content

Commit

Permalink
Merge pull request #15 from tonik/refactor/replace-global-packages-in…
Browse files Browse the repository at this point in the history
…stallation

Refactor/replace global packages installation
  • Loading branch information
maneike authored Oct 29, 2024
2 parents f4d78ef + 05160c1 commit f7eb43c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 69 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

**Stapler** is a CLI tool that scaffolds an entire fullstack app using a monorepo structure. It integrates **Next.js**, **Supabase**, **Payload CMS**, **Vercel**, and more, leveraging **Turbo** and **pnpm** to optimize your development workflow.

## Requirements
- node.js
- npx

## Features

- **Fullstack scaffolding**: Quickly set up a monorepo with Next.js, Supabase, Payload CMS, and Vercel.
Expand Down
8 changes: 5 additions & 3 deletions packages/core/utils/supabase/connectProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const instructions = [
export const connectSupabaseProject = async (projectName: string, currentDir: string) => {
try {
console.log('🖇️ Getting information about newly created Supabase project...');
const { stdout: projectsList } = await execAsync('supabase projects list');
const { stdout: projectsList } = await execAsync('npx supabase projects list');
const projects = parseProjectsList(projectsList);
const newProject = projects.find((project) => project.name === projectName);

Expand All @@ -31,7 +31,9 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st
}

console.log('🖇️ Getting Supabase project keys...');
const { stdout: projectAPIKeys } = await execAsync(`supabase projects api-keys --project-ref ${newProject.refId}`);
const { stdout: projectAPIKeys } = await execAsync(
`npx supabase projects api-keys --project-ref ${newProject.refId}`,
);

const { anonKey, serviceRoleKey } = getSupabaseKeys(projectAPIKeys);

Expand All @@ -52,7 +54,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st
});

console.log('🖇️ Linking Supabase project...');
execSync(`supabase link --project-ref ${newProject.refId}`, { stdio: 'inherit' });
execSync(`npx supabase link --project-ref ${newProject.refId}`, { stdio: 'inherit' });

for (const instruction of instructions) {
console.log(instruction);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/utils/supabase/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execSync } from 'child_process';
export const createSupabaseProject = async (name: string) => {
console.log('🖇️ Creating Supabase project...');

execSync(`supabase projects create ${name}`, {
execSync(`npx supabase projects create ${name}`, {
stdio: 'inherit',
});
};
38 changes: 3 additions & 35 deletions packages/core/utils/supabase/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,16 @@ import path from 'path';
import { supabaseFiles } from '../../templates/supabase/installConfig';
import { templateGenerator } from '../generator/generator';

const checkAndInstallSupabaseCLI = (): void => {
console.log('🖇️ Checking Supabase CLI installation...');

try {
execSync('supabase --version', { stdio: 'ignore' });
} catch (error) {
console.log('🖇️ Installing Supabase CLI...');
try {
// For macOS/Linux using Homebrew
if (process.platform === 'darwin' || process.platform === 'linux') {
execSync('brew install supabase/tap/supabase', { stdio: 'inherit' });
}
// For Windows using npm
else if (process.platform === 'win32') {
execSync('npm install -g supabase', { stdio: 'inherit' });
} else {
throw new Error('Unsupported operating system');
}
} catch (installError) {
console.error('\n🖇️ Failed to install Supabase CLI automatically. Please install it manually:');
console.log('\n🖇️ MacOS/Linux:');
console.log('🖇️ brew install supabase/tap/supabase');
console.log('\n🖇️ Windows:');
console.log('🖇️ npm install -g supabase');
console.log('\n🖇️ For other installation methods, visit:');
console.log('🖇️ https://supabase.com/docs/guides/local-development/cli/getting-started \n');
process.exit(1);
}
}
};

const supabaseLogin = () => {
console.log('🖇️ Logging into Supabase...');

try {
execSync('supabase projects list', { stdio: 'ignore' });
execSync('npx supabase projects list', { stdio: 'ignore' });
console.log('🖇️ Already logged into Supabase. Skipping login.');
return;
} catch (error) {
try {
execSync('supabase login', { stdio: 'inherit' });
execSync('npx supabase login', { stdio: 'inherit' });
} catch {
console.error('\n🖇️ Failed to log in to Supabase.');
console.log('\n🖇️ Please log in manually with "supabase login" and re-run "create-stapler-app".');
Expand All @@ -56,7 +25,7 @@ const supabaseLogin = () => {
const initializeSupabaseProject = (): void => {
console.log('🖇️ Initialize Supabase project...');
try {
execSync(`supabase init`, { stdio: ['pipe'], encoding: 'utf-8' });
execSync(`npx supabase init`, { stdio: ['pipe'], encoding: 'utf-8' });
} catch (error: any) {
const errorMessage = error.stderr;

Expand All @@ -76,7 +45,6 @@ const initializeSupabaseProject = (): void => {
export const installSupabase = async (destinationDirectory: string) => {
console.log('🖇️ Installing supabase-js...');
try {
checkAndInstallSupabaseCLI();
supabaseLogin();
initializeSupabaseProject();
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/utils/vercel/connectWithGH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const connectWithGH = async () => {

for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
execSync('vercel git connect', {
execSync('npx vercel git connect', {
stdio: ['pipe'],
encoding: 'utf-8',
});
Expand Down
34 changes: 5 additions & 29 deletions packages/core/utils/vercel/setupAndCreate.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,29 @@
import { execSync } from 'child_process';

const vercelVersion = (): boolean => {
try {
execSync('vercel --version', { encoding: 'utf8' });
return true;
} catch {
return false;
}
};

const getUserName = (): string | null => {
try {
const user = execSync('vercel whoami', { stdio: 'pipe', encoding: 'utf-8' });
console.log('test', user);
const user = execSync('npx vercel whoami', { stdio: 'pipe', encoding: 'utf-8' });
return user;
} catch {
return null;
}
};

export const setupAndCreateVercelProject = async () => {
console.log('🖇️ Checking if Vercel CLI is installed...');

const isVercelInstalled = vercelVersion();

if (!isVercelInstalled) {
console.log('🖇️ Installing Vercel CLI...');
try {
execSync('npm install -g vercel');
} catch {
console.error('🖇️ Failed to install Vercel CLI...');
process.exit(1);
}
}

const vercelUserName = getUserName();

if (!vercelUserName) {
console.log('🖇️ Logging in to Vercel...');
try {
execSync('vercel login', { stdio: 'inherit' });
execSync('npx vercel login', { stdio: 'inherit' });
} catch (error) {
console.log('\n🖇️ Oops! Something went wrong while logging in to Vercel...');
console.log('🖇️ You might already be logged in with this email in another project.');
console.log(
'🖇️ In this case, select "Continue with Email" and enter the email you\'re already logged in with.\n',
);
try {
execSync('vercel login', { stdio: 'inherit' });
execSync('npx vercel login', { stdio: 'inherit' });
} catch {
console.log('\n🖇️ Please check the error above and try again.');
console.log('🖇️ After successfully logging in with "vercel login", please run create-stapler-app again.\n');
Expand All @@ -59,8 +35,8 @@ export const setupAndCreateVercelProject = async () => {
}

console.log('🖇️ Initializing Vercel project...');
execSync('vercel init');
execSync('npx vercel init');

console.log('🖇️ Linking Vercel project...');
execSync('vercel link', { stdio: 'inherit' });
execSync('npx vercel link', { stdio: 'inherit' });
};

0 comments on commit f7eb43c

Please sign in to comment.