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

feat: add create project for supabase #1

Merged
merged 30 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f767a34
feat: add create project for supabase
KarolinaKopacz Oct 10, 2024
eed0fdc
chore: trigger Prettier workflow
maneike Oct 10, 2024
128983c
Prettified Code!
maneike Oct 10, 2024
9c96146
Merge branch 'main' into feat/create-supabase-project
maneike Oct 10, 2024
dca1109
Prettified Code!
maneike Oct 10, 2024
365e5a9
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
400e99e
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
c86d876
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
35d37c4
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
0eff3ff
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
974f354
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 11, 2024
3ff5d3a
feat: remove unused code
KarolinaKopacz Oct 11, 2024
001d5a9
feat(create-turbo): apply official-starter transform
turbobot-temp Oct 14, 2024
88bd5a7
feat: fix confirmOnKeyPress func
KarolinaKopacz Oct 14, 2024
ab033a9
Merge branch 'feat/create-supabase-project' of github.com:tonik/stapl…
maneike Oct 14, 2024
100cf23
Merge branch 'main' into feat/create-supabase-project
maneike Oct 14, 2024
07c1e6e
merge commit
KarolinaKopacz Oct 15, 2024
2367120
feat: get supabase project url and anon key
KarolinaKopacz Oct 15, 2024
a3f7f54
Merge branch 'main' into feat/create-supabase-project
KarolinaKopacz Oct 15, 2024
f24d603
feat: separate supabase functions
KarolinaKopacz Oct 15, 2024
cf8ab41
feat: delete supabase folder
KarolinaKopacz Oct 15, 2024
0df1f04
Merge branch 'feat/create-supabase-project' of github.com:tonik/stapl…
maneike Oct 16, 2024
5f31299
refactor: folder name typo
maneike Oct 16, 2024
afe3199
refactor: redundant names
maneike Oct 16, 2024
122f044
feat: chdir to root after supabase install
maneike Oct 16, 2024
fb79664
fix: errors
maneike Oct 17, 2024
c6a2aae
Merge branch 'main' into feat/create-supabase-project
maneike Oct 17, 2024
d7ac113
refactor: rename id to refId + change linking command
maneike Oct 17, 2024
933ffc8
chore: remove dotenv from package.json
maneike Oct 17, 2024
74872b5
feat: add dotenv to template in order for the with-env script to work
maneike Oct 17, 2024
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
16 changes: 8 additions & 8 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from "child_process";
import { createEnvFile } from "./utils/env/createEnvFile";
import { preparePayload } from "./utils/payload/install";
import { installSupabase } from "./utils/supabase/install";
import { prettify } from "./utils/prettier/prettify";
import { prepareDrink } from "./utils/bar/prepareDrink";
import { execSync } from 'child_process';
import { prepareDrink } from './utils/bar/prepareDrink';
import { createEnvFile } from './utils/env/createEnvFile';
import { preparePayload } from './utils/payload/install';
import { prettify } from './utils/prettier/prettify';
import { installSupabase } from './utils/supabase/install';

interface ProjectOptions {
name: string;
Expand All @@ -16,7 +16,7 @@ export async function createProject(options: ProjectOptions) {

console.log(`🍸 Stapling ${name}...`);
execSync(`npx create-turbo@latest ${name} -m pnpm`, {
stdio: "inherit",
stdio: 'inherit',
});

process.chdir(name);
Expand All @@ -27,7 +27,7 @@ export async function createProject(options: ProjectOptions) {

if (usePayload) await preparePayload();

await installSupabase(currentDir);
await installSupabase(currentDir, name);

await prettify();

Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dev": "tsc -w"
},
"dependencies": {
"fs-extra": "^11.2.0"
"fs-extra": "^11.2.0",
"inquirer": "^10.2.2"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
Expand Down
121 changes: 106 additions & 15 deletions packages/core/utils/supabase/install.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,115 @@
import { execSync } from "child_process";
import { templateGenerator } from "../generator/generator";
import { supabaseFiles } from "../../templates/supabase/installConfig";
import path from "path";
import fs from "fs";
import { execSync } from 'child_process';
import fs from 'fs';
import inquirer from 'inquirer';
import path from 'path';
import { supabaseFiles } from '../../templates/supabase/installConfig';
import { templateGenerator } from '../generator/generator';

export const installSupabase = async (destinationDirectory: string) => {
console.log("🍸 Installing supabase-js...");
execSync(`supabase init`, { stdio: "inherit" });
interface SupabaseProject {
linked: boolean;
org_id: string;
id: string;
name: string;
region: string;
created_at: string;
}

console.log("🍸 Adding Supabase Files...");
const templateDirectory = path.join(__dirname, "../templates/supabase/files");
function parseProjectsList(output: string): SupabaseProject[] {
const lines = output.trim().split('\n');
lines.splice(0, 2);

return lines.map((line) => {
const [linked, org_id, id, name, region, created_at] = line
.split('│')
.map((item) => item.trim());
return {
linked: linked !== '',
org_id,
id,
name,
region,
created_at,
};
});
}

export const installSupabase = async (
destinationDirectory: string,
name: string
) => {
console.log('🍸 Installing supabase-js...');
execSync(`supabase init`, { stdio: 'inherit' });

console.log('🍸 Adding Supabase Files...');
const templateDirectory = path.join(__dirname, '../templates/supabase/files');

templateGenerator(supabaseFiles, templateDirectory, destinationDirectory);
// add "supabase/**" to pnpm-workspace.yaml
const workspacePath = path.join(destinationDirectory, "pnpm-workspace.yaml");
const workspacePath = path.join(destinationDirectory, 'pnpm-workspace.yaml');
const addSupabaseToWorkspace = ` - "supabase/**"`;
fs.appendFileSync(workspacePath, addSupabaseToWorkspace);

process.chdir("supabase");
console.log("🍸 Installing Supabase dependencies...");
execSync("pnpm install", { stdio: "inherit" });
process.chdir("..");
process.chdir('supabase');
console.log('🍸 Installing Supabase dependencies...');
execSync('pnpm install', { stdio: 'inherit' });

console.log('🍸 Creating Supabase project...');

execSync(`supabase projects create ${name}`, {
stdio: 'inherit',
});

// Find the newly created project
const output = execSync('supabase projects list', { encoding: 'utf-8' });
const projects = parseProjectsList(output);
const newProject = projects.find((project) => project.name === name);

console.log('🍸 Linking Supabase project...');
console.log(
'\n=== Instructions for Supabase Integration with GitHub and Vercel ==='
);
console.log(
'🍸 1. In 10s you will be redirect to your supabase project dashboard'
);
console.log('🍸 2. Find the "GitHub" section and click "Connect".');
console.log(
' - Follow the prompts to connect Supabase with your GitHub repository.'
);
console.log('🍸 3. Then, find the "Vercel" section and click "Connect".');
console.log(
' - Follow the prompts to connect Supabase with your Vercel project.'
);
console.log(
'\n 🍸 Please note that these steps require manual configuration in the Supabase interface.\n'
);

await new Promise((resolve) => setTimeout(resolve, 10000));
execSync(
`open https://supabase.com/dashboard/project/${newProject?.id}/settings/integrations`
);

const { ready } = await inquirer.prompt([
{
type: 'confirm',
name: 'ready',
message: '🍸 Have you completed the GitHub and Vercel integration setup?',
default: false,
},
]);

if (ready) {
console.log('🍸 Great! Proceeding with the next steps...');
// Add your next steps here
} else {
console.log(
"🍸 No problem. Please complete the integration when you're ready."
);
console.log(
`🍸 You can access your project dashboard at: https://supabase.com/dashboard/project/${newProject?.id}/settings/integrations`
);
console.log("🍸 Run this script again when you're ready to proceed.");
process.exit(0); // Exit the script if the user is not ready
}

process.chdir('..');
};
Loading