diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 0ef91a1..e6aec5b 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node -import { Command } from "commander"; -import inquirer from "inquirer"; -import chalk from "chalk"; -import { createProject } from "@create-stapler-app/core"; +import { Command } from 'commander'; +import inquirer from 'inquirer'; +import chalk from 'chalk'; +import { createProject } from '@create-stapler-app/core'; const asciiArt = ` .&&&% &&&& @@ -17,32 +17,32 @@ const asciiArt = ` `; function displayHeader() { - console.log(chalk.hex("#3100F5").bold(asciiArt)); - console.log(chalk.bold("\n🍸 Welcome to Stapler!\n")); + console.log(chalk.hex('#3100F5').bold(asciiArt)); + console.log(chalk.bold('\n🍸 Welcome to Stapler!\n')); } const program = new Command(); program - .name("create-stapler-app") - .description("CLI to bootstrap a new tonik-infused app") - .version("0.1.0") - .hook("preAction", () => { + .name('create-stapler-app') + .description('CLI to bootstrap a new tonik-infused app') + .version('0.1.0') + .hook('preAction', () => { displayHeader(); }); const createAction = async () => { const answers = await inquirer.prompt([ { - type: "input", - name: "name", - message: "What is your project named?", - default: "my-stapled-app", + type: 'input', + name: 'name', + message: 'What is your project named?', + default: 'my-stapled-app', }, { - type: "confirm", - name: "usePayload", - message: "Would you like to add Payload to your app?", + type: 'confirm', + name: 'usePayload', + message: 'Would you like to add Payload to your app?', default: true, }, // we dont support Inngest yet @@ -57,10 +57,7 @@ const createAction = async () => { await createProject(answers); }; -program - .command("create") - .description("Create a new tonik-infused app") - .action(createAction); +program.command('create').description('Create a new tonik-infused app').action(createAction); // Set "create" as the default command program.action(createAction); diff --git a/packages/core/index.ts b/packages/core/index.ts index 5f49a33..23c834a 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -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 { 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'; interface ProjectOptions { name: string; @@ -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); diff --git a/packages/core/templates/supabase/files/client.ts b/packages/core/templates/supabase/files/client.ts index 3154c4b..af73c7c 100644 --- a/packages/core/templates/supabase/files/client.ts +++ b/packages/core/templates/supabase/files/client.ts @@ -1,14 +1,11 @@ -import { createBrowserClient } from "@supabase/ssr"; +import { createBrowserClient } from '@supabase/ssr'; -import type { Database } from "./types"; +import type { Database } from './types'; interface CreateClientOptions { supabaseUrl: string; supabaseAnonKey: string; } -export const createClient = ({ - supabaseUrl, - supabaseAnonKey, -}: CreateClientOptions) => +export const createClient = ({ supabaseUrl, supabaseAnonKey }: CreateClientOptions) => createBrowserClient(supabaseUrl, supabaseAnonKey); diff --git a/packages/core/templates/supabase/files/index.ts b/packages/core/templates/supabase/files/index.ts index 11348d9..e90c600 100644 --- a/packages/core/templates/supabase/files/index.ts +++ b/packages/core/templates/supabase/files/index.ts @@ -1,8 +1,8 @@ -import type * as supabase from "@supabase/supabase-js"; +import type * as supabase from '@supabase/supabase-js'; -import type { Database } from "./types"; +import type { Database } from './types'; -export type { CookieStore } from "./types"; +export type { CookieStore } from './types'; export type Session = supabase.Session; export type SupabaseClient = supabase.SupabaseClient; export type User = supabase.User; diff --git a/packages/core/templates/supabase/files/middleware.ts b/packages/core/templates/supabase/files/middleware.ts index dbfa07c..9ba642e 100644 --- a/packages/core/templates/supabase/files/middleware.ts +++ b/packages/core/templates/supabase/files/middleware.ts @@ -1,62 +1,55 @@ -import type { CookieOptions } from "@supabase/ssr"; -import type { NextRequest } from "next/server"; -import { createServerClient } from "@supabase/ssr"; +import type { CookieOptions } from '@supabase/ssr'; +import type { NextRequest } from 'next/server'; +import { createServerClient } from '@supabase/ssr'; -import type { Database } from "./types"; +import type { Database } from './types'; interface CreateMiddlewareOptions { supabaseUrl: string; supabaseAnonKey: string; } -export const createMiddleware = ({ - supabaseAnonKey, - supabaseUrl, -}: CreateMiddlewareOptions) => +export const createMiddleware = ({ supabaseAnonKey, supabaseUrl }: CreateMiddlewareOptions) => async function middleware(request: NextRequest) { const cookiesToSet: { name: string; value: string; }[] = []; - const supabase = createServerClient( - supabaseUrl, - supabaseAnonKey, - { - cookies: { - get(name: string) { - const cookieValue = request.cookies.get(name)?.value; - return cookieValue; - }, - set(name: string, value: string, options: CookieOptions) { - request.cookies.set({ - name, - value, - ...options, - }); - - cookiesToSet.push({ - name, - value, - ...options, - }); - }, - remove(name: string, options: CookieOptions) { - request.cookies.set({ - name, - value: "", - ...options, - }); - - cookiesToSet.push({ - name, - value: "", - ...options, - }); - }, + const supabase = createServerClient(supabaseUrl, supabaseAnonKey, { + cookies: { + get(name: string) { + const cookieValue = request.cookies.get(name)?.value; + return cookieValue; + }, + set(name: string, value: string, options: CookieOptions) { + request.cookies.set({ + name, + value, + ...options, + }); + + cookiesToSet.push({ + name, + value, + ...options, + }); + }, + remove(name: string, options: CookieOptions) { + request.cookies.set({ + name, + value: '', + ...options, + }); + + cookiesToSet.push({ + name, + value: '', + ...options, + }); }, }, - ); + }); const { data } = await supabase.auth.getUser(); diff --git a/packages/core/templates/supabase/files/next_api_endpoint.ts b/packages/core/templates/supabase/files/next_api_endpoint.ts index f15302e..83dda1f 100644 --- a/packages/core/templates/supabase/files/next_api_endpoint.ts +++ b/packages/core/templates/supabase/files/next_api_endpoint.ts @@ -1,11 +1,8 @@ -import type { NextApiRequest, NextApiResponse } from "next"; -import { supabase } from "../../lib/supabase"; +import type { NextApiRequest, NextApiResponse } from 'next'; +import { supabase } from '../../lib/supabase'; -export default async function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - const { data, error } = await supabase.from("your_table").select("*"); +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { data, error } = await supabase.from('your_table').select('*'); if (error) { return res.status(500).json({ error: error.message }); diff --git a/packages/core/templates/supabase/files/server.ts b/packages/core/templates/supabase/files/server.ts index 5c4a62f..5fbd1ce 100644 --- a/packages/core/templates/supabase/files/server.ts +++ b/packages/core/templates/supabase/files/server.ts @@ -1,7 +1,7 @@ -import type { CookieOptions } from "@supabase/ssr"; -import { createServerClient } from "@supabase/ssr"; +import type { CookieOptions } from '@supabase/ssr'; +import { createServerClient } from '@supabase/ssr'; -import type { CookieStore, Database } from "./types"; +import type { CookieStore, Database } from './types'; interface BaseOptions { supabaseApiUrl: string; @@ -14,34 +14,30 @@ interface BaseOptions { } export function createClient(configOptions: BaseOptions) { - return createServerClient( - configOptions.supabaseApiUrl, - configOptions.supabaseKey, - { - cookies: { - get(name: string) { - return configOptions.cookieStore?.get(name)?.value; - }, - set(name: string, value: string, options: CookieOptions) { - try { - configOptions.cookieStore?.set({ name, value, ...options }); - } catch (error) { - // The `set` method was called from a Server Component. - // This can be ignored if you have middleware refreshing - // user sessions. - } - }, - remove(name: string, options: CookieOptions) { - try { - configOptions.cookieStore?.set({ name, value: "", ...options }); - } catch (error) { - // The `set` method was called from a Server Component. - // The `delete` method was called from a Server Component. - // This can be ignored if you have middleware refreshing - // user sessions. - } - }, + return createServerClient(configOptions.supabaseApiUrl, configOptions.supabaseKey, { + cookies: { + get(name: string) { + return configOptions.cookieStore?.get(name)?.value; + }, + set(name: string, value: string, options: CookieOptions) { + try { + configOptions.cookieStore?.set({ name, value, ...options }); + } catch (error) { + // The `set` method was called from a Server Component. + // This can be ignored if you have middleware refreshing + // user sessions. + } + }, + remove(name: string, options: CookieOptions) { + try { + configOptions.cookieStore?.set({ name, value: '', ...options }); + } catch (error) { + // The `set` method was called from a Server Component. + // The `delete` method was called from a Server Component. + // This can be ignored if you have middleware refreshing + // user sessions. + } }, }, - ); + }); } diff --git a/packages/core/templates/supabase/files/types.ts b/packages/core/templates/supabase/files/types.ts index 52607e5..50e9924 100644 --- a/packages/core/templates/supabase/files/types.ts +++ b/packages/core/templates/supabase/files/types.ts @@ -1,4 +1,4 @@ -export type * from "./types.gen"; +export type * from './types.gen'; export interface CookieStore { get(name: string): { value: string } | undefined; set(options: { name: string; value: string }): void; diff --git a/packages/core/templates/supabase/installConfig.ts b/packages/core/templates/supabase/installConfig.ts index 7efcb04..b78e264 100644 --- a/packages/core/templates/supabase/installConfig.ts +++ b/packages/core/templates/supabase/installConfig.ts @@ -1,15 +1,15 @@ export const supabaseFiles = [ { - path: "supabase/src/", - files: ["client.ts", "index.ts", "middleware.ts", "server.ts", "types.ts"], + path: 'supabase/src/', + files: ['client.ts', 'index.ts', 'middleware.ts', 'server.ts', 'types.ts'], }, { - path: "supabase/", - files: ["package"], + path: 'supabase/', + files: ['package'], rename: [ { - from: "package", - to: "package.json", + from: 'package', + to: 'package.json', }, ], }, diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 2827de4..7ea641c 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -10,10 +10,6 @@ "declaration": true, // Ensure TypeScript generates declaration files "emitDeclarationOnly": true // Only emit declaration files without compiling the code }, - "include": [ - "index.ts", - "utils/**/*.ts", - "templates/supabase/installConfig.ts" - ], + "include": ["index.ts", "utils/**/*.ts", "templates/supabase/installConfig.ts"], "exclude": ["node_modules", "dist", "templates/supabase/files/**/*"] } diff --git a/packages/core/utils/bar/prepareDrink.ts b/packages/core/utils/bar/prepareDrink.ts index 4d9bfad..fd52304 100644 --- a/packages/core/utils/bar/prepareDrink.ts +++ b/packages/core/utils/bar/prepareDrink.ts @@ -1,6 +1,6 @@ const getName = (name: string) => { if (!name) { - return "."; + return '.'; } return name; @@ -8,24 +8,17 @@ const getName = (name: string) => { export const prepareDrink = (name: string) => { setTimeout(() => { - console.log("🍸 Filling a high ball glass with ice..."); + console.log('🍸 Filling a high ball glass with ice...'); setTimeout(() => { - console.log("🍸 Adding gin and lime juice..."); + console.log('🍸 Adding gin and lime juice...'); setTimeout(() => { - console.log("🍸 Topping with", "\x1b[34mTonik\x1b[0m..."); + console.log('🍸 Topping with', '\x1b[34mTonik\x1b[0m...'); setTimeout(() => { - console.log("🍸 Garnishing with lime wedge..."); + console.log('🍸 Garnishing with lime wedge...'); setTimeout(() => { - console.log( - `\x1b[32m%s\x1b[0m`, - `🍸 Your Stapled ${getName(name)} is ready!`, - `\x1b[0m`, - ); + console.log(`\x1b[32m%s\x1b[0m`, `🍸 Your Stapled ${getName(name)} is ready!`, `\x1b[0m`); // I'm too lazy to mess with modules building to allow coloring library to be installed lol - console.log( - `🍸 You can now run:`, - `\x1b[36mcd ${name} && pnpm dev\x1b[0m`, - ); + console.log(`🍸 You can now run:`, `\x1b[36mcd ${name} && pnpm dev\x1b[0m`); }, 1000); }, 1000); }, 1000); diff --git a/packages/core/utils/env/createEnvFile.ts b/packages/core/utils/env/createEnvFile.ts index bea7556..e58c93b 100644 --- a/packages/core/utils/env/createEnvFile.ts +++ b/packages/core/utils/env/createEnvFile.ts @@ -1,13 +1,13 @@ -import * as fs from "fs"; -import * as path from "path"; +import * as fs from 'fs'; +import * as path from 'path'; -const requiredEnvVariables: Record = { - NEXT_PUBLIC_SUPABASE_URL: "required", - NEXT_PUBLIC_SUPABASE_ANON_KEY: "required", - SUPABASE_URL: "required", - SUPABASE_ANON_KEY: "required", - SUPABASE_JWT_SECRET: "required", - SUPABASE_SERVICE_ROLE_KEY: "required", +const requiredEnvVariables: Record = { + NEXT_PUBLIC_SUPABASE_URL: 'required', + NEXT_PUBLIC_SUPABASE_ANON_KEY: 'required', + SUPABASE_URL: 'required', + SUPABASE_ANON_KEY: 'required', + SUPABASE_JWT_SECRET: 'required', + SUPABASE_SERVICE_ROLE_KEY: 'required', // DATABASE_URI:"required", // this is created by Payload in web app directory // PAYLOAD_SECRET:"required", // this is created by Payload in web app directory // INNGEST_API_KEY: "required", @@ -16,11 +16,11 @@ const requiredEnvVariables: Record = { // Function to create .env file with empty fields export const createEnvFile = (destinationDirectory: string) => { - console.log("🍸 Creating .env file..."); - let envTemplate = ""; + console.log('🍸 Creating .env file...'); + let envTemplate = ''; for (const [key, status] of Object.entries(requiredEnvVariables)) { envTemplate += `${key}=\n`; } - fs.writeFileSync(path.resolve(destinationDirectory, ".env"), envTemplate); + fs.writeFileSync(path.resolve(destinationDirectory, '.env'), envTemplate); }; diff --git a/packages/core/utils/generator/generator.ts b/packages/core/utils/generator/generator.ts index 9b0a42e..3d9c4e6 100644 --- a/packages/core/utils/generator/generator.ts +++ b/packages/core/utils/generator/generator.ts @@ -1,5 +1,5 @@ -import fs from "fs"; -import path from "path"; +import fs from 'fs'; +import path from 'path'; interface TemplateFilesObject { path: string; @@ -11,21 +11,13 @@ interface TemplateFilesObject { } export type Template = TemplateFilesObject[]; -export const templateGenerator = ( - template: Template, - templateDir: string, - destinationDir: string, -) => { +export const templateGenerator = (template: Template, templateDir: string, destinationDir: string) => { template.forEach((templateFilesObject) => { templateFilesObject.files.forEach((file) => { // Construct source and destination paths const source = path.join(templateDir, file); // console.log(source); - const destination = path.join( - destinationDir, - templateFilesObject.path, - file, - ); + const destination = path.join(destinationDir, templateFilesObject.path, file); // check if the directory exists, if not create it if (!fs.existsSync(path.join(destinationDir, templateFilesObject.path))) { fs.mkdirSync(path.join(destinationDir, templateFilesObject.path), { @@ -37,16 +29,8 @@ export const templateGenerator = ( // Handle file renaming if needed if (templateFilesObject.rename) { templateFilesObject.rename.forEach((rename) => { - const oldPath = path.join( - process.cwd(), - templateFilesObject.path, - rename.from, - ); - const newPath = path.join( - process.cwd(), - templateFilesObject.path, - rename.to, - ); + const oldPath = path.join(process.cwd(), templateFilesObject.path, rename.from); + const newPath = path.join(process.cwd(), templateFilesObject.path, rename.to); fs.renameSync(oldPath, newPath); }); } diff --git a/packages/core/utils/payload/install.ts b/packages/core/utils/payload/install.ts index 3f66fb4..d212ed6 100644 --- a/packages/core/utils/payload/install.ts +++ b/packages/core/utils/payload/install.ts @@ -1,42 +1,42 @@ -import { execSync } from "child_process"; -import { existsSync } from "fs"; -import { join } from "path"; -import { removeTurboFlag } from "./removeTurboFlag"; -import { prepareTsConfig } from "./prepareTsConfig"; -import { updatePackages } from "./updatePackages"; -import { preparePayloadConfig } from "./preparePayloadConfig"; +import { execSync } from 'child_process'; +import { existsSync } from 'fs'; +import { join } from 'path'; +import { removeTurboFlag } from './removeTurboFlag'; +import { prepareTsConfig } from './prepareTsConfig'; +import { updatePackages } from './updatePackages'; +import { preparePayloadConfig } from './preparePayloadConfig'; export const preparePayload = async () => { - console.log("🍸 Initializing Payload..."); + console.log('🍸 Initializing Payload...'); - process.chdir("./apps/web/"); + process.chdir('./apps/web/'); prepareTsConfig(); updatePackages(); - console.log("🍸 Moving files to (app) directory..."); + console.log('🍸 Moving files to (app) directory...'); execSync( `mkdir -p ./app/\\(app\\) && find ./app -maxdepth 1 ! -path './app' ! -path './app/\\(app\\)' -exec mv {} ./app/\\(app\\)/ \\;`, { - stdio: "inherit", + stdio: 'inherit', }, ); - console.log("🍸 Installing Payload to Next.js..."); - execSync(`npx create-payload-app@beta`, { stdio: "inherit" }); + console.log('🍸 Installing Payload to Next.js...'); + execSync(`npx create-payload-app@beta`, { stdio: 'inherit' }); // Payload doesn't work with Turbopack yet removeTurboFlag(); // Check if the payload configuration file exists - const payloadConfigPath = join(process.cwd(), "payload.config.ts"); + const payloadConfigPath = join(process.cwd(), 'payload.config.ts'); if (!existsSync(payloadConfigPath)) { - console.error("🍸 Payload installation cancelled/failed."); + console.error('🍸 Payload installation cancelled/failed.'); } else { await preparePayloadConfig(payloadConfigPath); } // get back to the root directory - process.chdir("../../"); + process.chdir('../../'); }; diff --git a/packages/core/utils/payload/preparePayloadConfig.ts b/packages/core/utils/payload/preparePayloadConfig.ts index 345402f..4a561e0 100644 --- a/packages/core/utils/payload/preparePayloadConfig.ts +++ b/packages/core/utils/payload/preparePayloadConfig.ts @@ -1,31 +1,25 @@ -import type { PathLike } from "fs"; -import fs from "fs/promises"; +import type { PathLike } from 'fs'; +import fs from 'fs/promises'; export const preparePayloadConfig = async (configPath: PathLike) => { - console.log("🍸 Preparing payload.config.ts..."); + console.log('🍸 Preparing payload.config.ts...'); try { // Read the payload.config.ts file - const data = await fs.readFile(configPath, "utf8"); + const data = await fs.readFile(configPath, 'utf8'); // Use regex to find the "pool" object and append "schemaName: 'payload'" to the pool configuration - const updatedConfig = data.replace( - /pool:\s*{([^}]*)connectionString[^}]*}/, - (match, group1) => { - if (match.includes("schemaName")) { - return match; // If "schemaName" already exists, return the match unchanged - } - // Append schemaName to the existing pool configuration (avoiding the extra comma) - return match.replace( - group1.trimEnd(), - `${group1.trimEnd()} schemaName: 'payload',\n`, - ); - }, - ); + const updatedConfig = data.replace(/pool:\s*{([^}]*)connectionString[^}]*}/, (match, group1) => { + if (match.includes('schemaName')) { + return match; // If "schemaName" already exists, return the match unchanged + } + // Append schemaName to the existing pool configuration (avoiding the extra comma) + return match.replace(group1.trimEnd(), `${group1.trimEnd()} schemaName: 'payload',\n`); + }); // Write the updated payload.config.ts back to the file await fs.writeFile(configPath, updatedConfig); } catch (err) { - console.error("🍸 Error during processing payload.config.ts", err); + console.error('🍸 Error during processing payload.config.ts', err); } }; diff --git a/packages/core/utils/payload/prepareTsConfig.ts b/packages/core/utils/payload/prepareTsConfig.ts index b77e249..f222b50 100644 --- a/packages/core/utils/payload/prepareTsConfig.ts +++ b/packages/core/utils/payload/prepareTsConfig.ts @@ -1,16 +1,16 @@ -import fs from "fs"; -import path from "path"; +import fs from 'fs'; +import path from 'path'; export const prepareTsConfig = () => { - console.log("🍸 Preparing tsconfig.json..."); + console.log('🍸 Preparing tsconfig.json...'); // Path to your tsconfig.json file - const tsconfigPath = path.join(process.cwd(), "tsconfig.json"); + const tsconfigPath = path.join(process.cwd(), 'tsconfig.json'); // Read the tsconfig.json file - fs.readFile(tsconfigPath, "utf8", (err, data) => { + fs.readFile(tsconfigPath, 'utf8', (err, data) => { if (err) { - console.error("🍸 Error reading tsconfig.json", err); + console.error('🍸 Error reading tsconfig.json', err); return; } @@ -28,12 +28,12 @@ export const prepareTsConfig = () => { } // Append the "@payload-config" path - tsconfig.compilerOptions.paths["@payload-config"] = ["./payload.config.ts"]; + tsconfig.compilerOptions.paths['@payload-config'] = ['./payload.config.ts']; // Write the updated tsconfig.json back to the file fs.writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2), (err) => { if (err) { - console.error("🍸 Error writing to tsconfig.json", err); + console.error('🍸 Error writing to tsconfig.json', err); } }); }); diff --git a/packages/core/utils/payload/removeTurboFlag.ts b/packages/core/utils/payload/removeTurboFlag.ts index 23b6318..ed51579 100644 --- a/packages/core/utils/payload/removeTurboFlag.ts +++ b/packages/core/utils/payload/removeTurboFlag.ts @@ -1,16 +1,16 @@ -import fs from "fs"; -import path from "path"; +import fs from 'fs'; +import path from 'path'; export const removeTurboFlag = () => { - console.log("🍸 Removing --turbo flag from dev script..."); + console.log('🍸 Removing --turbo flag from dev script...'); // Path to your package.json file - const packageJsonPath = path.join(process.cwd(), "package.json"); + const packageJsonPath = path.join(process.cwd(), 'package.json'); // Read the package.json file - fs.readFile(packageJsonPath, "utf8", (err: Error | null, data: string) => { + fs.readFile(packageJsonPath, 'utf8', (err: Error | null, data: string) => { if (err) { - console.error("🍸 Error reading package.json", err); + console.error('🍸 Error reading package.json', err); return; } @@ -19,20 +19,14 @@ export const removeTurboFlag = () => { // Remove '--turbo' flag from the "dev" script if (packageJson.scripts && packageJson.scripts.dev) { - packageJson.scripts.dev = packageJson.scripts.dev - .replace("--turbo", "") - .trim(); + packageJson.scripts.dev = packageJson.scripts.dev.replace('--turbo', '').trim(); } // Write the updated package.json back to the file - fs.writeFile( - packageJsonPath, - JSON.stringify(packageJson, null, 2), - (err: Error | null) => { - if (err) { - console.error("🍸 Error writing to package.json", err); - } - }, - ); + fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), (err: Error | null) => { + if (err) { + console.error('🍸 Error writing to package.json', err); + } + }); }); }; diff --git a/packages/core/utils/payload/updatePackages.ts b/packages/core/utils/payload/updatePackages.ts index 63251ac..d014059 100644 --- a/packages/core/utils/payload/updatePackages.ts +++ b/packages/core/utils/payload/updatePackages.ts @@ -1,15 +1,13 @@ -import { execSync } from "child_process"; +import { execSync } from 'child_process'; export const updatePackages = () => { - console.log( - "🍸 Updating Next and React to their respective release candidates...", - ); + console.log('🍸 Updating Next and React to their respective release candidates...'); execSync(`pnpm up next@rc react@rc react-dom@rc eslint-config-next@rc`, { - stdio: "inherit", + stdio: 'inherit', }); - console.log("🍸 Installing necessary packages..."); + console.log('🍸 Installing necessary packages...'); execSync(`pnpm i pg sharp`, { - stdio: "inherit", + stdio: 'inherit', }); }; diff --git a/packages/core/utils/prettier/prettify.ts b/packages/core/utils/prettier/prettify.ts index 654eff1..cc56870 100644 --- a/packages/core/utils/prettier/prettify.ts +++ b/packages/core/utils/prettier/prettify.ts @@ -1,18 +1,18 @@ -import { execSync } from "child_process"; +import { execSync } from 'child_process'; export const prettify = async () => { - console.log("🍸 Prettifying your Stapler..."); + console.log('🍸 Prettifying your Stapler...'); const ignorePatterns = [ - "node_modules/", - "dist/", - "build/", - ".turbo/", - ".next/", + 'node_modules/', + 'dist/', + 'build/', + '.turbo/', + '.next/', `\\(app\\)/`, - "payload-types.ts", + 'payload-types.ts', `\\(payload\\)/`, - "*.d.ts", + '*.d.ts', ]; ignorePatterns.forEach((pattern) => { @@ -20,6 +20,6 @@ export const prettify = async () => { }); execSync(`npx prettier --write "apps/web/**/*.{ts,tsx}"`, { - stdio: "inherit", + stdio: 'inherit', }); }; diff --git a/packages/core/utils/supabase/install.ts b/packages/core/utils/supabase/install.ts index 1648767..b32037f 100644 --- a/packages/core/utils/supabase/install.ts +++ b/packages/core/utils/supabase/install.ts @@ -1,24 +1,24 @@ -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 { templateGenerator } from '../generator/generator'; +import { supabaseFiles } from '../../templates/supabase/installConfig'; +import path from 'path'; +import fs from 'fs'; export const installSupabase = async (destinationDirectory: string) => { - console.log("🍸 Installing supabase-js..."); - execSync(`supabase init`, { stdio: "inherit" }); + console.log('🍸 Installing supabase-js...'); + execSync(`supabase init`, { stdio: 'inherit' }); - console.log("🍸 Adding Supabase Files..."); - const templateDirectory = path.join(__dirname, "../templates/supabase/files"); + 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' }); + process.chdir('..'); };