diff --git a/.changeset/fresh-cougars-study.md b/.changeset/fresh-cougars-study.md new file mode 100644 index 0000000..052be25 --- /dev/null +++ b/.changeset/fresh-cougars-study.md @@ -0,0 +1,6 @@ +--- +'@tonik/create-stapler-app-core': minor +'@tonik/create-stapler-app': minor +--- + +Improve readibility EVEN MORE diff --git a/.changeset/pre.json b/.changeset/pre.json index 066456e..50ae06e 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -14,6 +14,7 @@ "few-parrots-switch", "five-students-care", "four-boats-confess", + "fresh-cougars-study", "honest-parents-tickle", "lazy-steaks-jog", "light-walls-obey", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 83cbb11..44dde8a 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # @tonik/create-stapler-app +## 0.1.0-alpha.22 + +### Minor Changes + +- Improve readibility EVEN MORE + ## 0.1.0-alpha.21 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 81ddcc0..d437ea8 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@tonik/create-stapler-app", - "version": "0.1.0-alpha.21", + "version": "0.1.0-alpha.22", "main": "./dist/index.mjs", "bin": { "create-stapler-app": "./dist/index.mjs" diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 5218e46..1e91144 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,11 @@ # @tonik/create-stapler-app-core +## 0.2.0-alpha.6 + +### Minor Changes + +- Improve readibility EVEN MORE + ## 0.2.0-alpha.5 ### Minor Changes diff --git a/packages/core/package.json b/packages/core/package.json index b26dee9..d141f96 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@tonik/create-stapler-app-core", - "version": "0.2.0-alpha.5", + "version": "0.2.0-alpha.6", "private": true, "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/packages/core/utils/github/ghInstaller.ts b/packages/core/utils/github/ghInstaller.ts index e9e4603..36e2d05 100644 --- a/packages/core/utils/github/ghInstaller.ts +++ b/packages/core/utils/github/ghInstaller.ts @@ -1,11 +1,6 @@ import { execSync } from 'child_process'; import * as os from 'os'; -import gradient from 'gradient-string'; - -const githubGradient = gradient([ - { color: '#3B8640', pos: 0 }, - { color: '#8256D0', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const isGitHubCLIInstalled = (): boolean => { try { @@ -33,10 +28,10 @@ export const installGitHubCLI = (): boolean => { installCommand = 'sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && sudo dnf install gh'; } else { - console.log( - githubGradient('Automatic installation is not supported for your Linux distribution.'), - githubGradient('\n Please visit https://github.com/cli/cli#installation for installation instructions.'), - ); + getLogColor('github', [ + 'Automatic installation is not supported for your Linux distribution.', + '\n Please visit https://github.com/cli/cli#installation for installation instructions.', + ]); return false; } break; @@ -44,21 +39,21 @@ export const installGitHubCLI = (): boolean => { installCommand = 'winget install --id GitHub.cli'; break; default: - console.log( - githubGradient('Automatic installation is not supported for your operating system.'), - githubGradient('\nPlease visit https://github.com/cli/cli#installation for installation instructions.'), - ); + getLogColor('github', [ + 'Automatic installation is not supported for your operating system.', + '\nPlease visit https://github.com/cli/cli#installation for installation instructions.', + ]); return false; } - console.log(githubGradient('Installing GitHub CLI...')); + getLogColor('github', 'Installing GitHub CLI...'); try { execSync(installCommand, { stdio: 'inherit' }); - console.log(githubGradient('GitHub CLI installed successfully.')); + getLogColor('github', 'GitHub CLI installed successfully.'); return true; } catch (error) { console.error('Failed to install GitHub CLI.'); - console.log(githubGradient('Please install it manually from: https://github.com/cli/cli#installation')); + getLogColor('github', 'Please install it manually from: https://github.com/cli/cli#installation'); return false; } }; diff --git a/packages/core/utils/github/install.ts b/packages/core/utils/github/install.ts index d779c77..d3fe1cd 100644 --- a/packages/core/utils/github/install.ts +++ b/packages/core/utils/github/install.ts @@ -1,4 +1,4 @@ -import gradient from 'gradient-string'; +import { getLogColor } from '../shared/getLogColor'; import { installGitHubCLI, isGitHubCLIInstalled } from './ghInstaller'; import { authenticateGitHub, @@ -13,16 +13,11 @@ interface ProjectOptions { visibility: 'public' | 'private'; } -const githubGradient = gradient([ - { color: '#3B8640', pos: 0 }, - { color: '#8256D0', pos: 1 }, -]); - // Helper function to check if GitHub CLI is installed const checkGitHubCLI = () => { - console.log(githubGradient('Checking if GitHub CLI is installed...')); + getLogColor('github', 'Checking if GitHub CLI is installed...'); if (!isGitHubCLIInstalled()) { - console.log(githubGradient('GitHub CLI is not installed.')); + getLogColor('github', 'GitHub CLI is not installed.'); const installed = installGitHubCLI(); if (!installed) { console.error('GitHub CLI installation failed. Exiting...'); @@ -33,11 +28,11 @@ const checkGitHubCLI = () => { // Helper function to ensure GitHub authentication const ensureGitHubAuthentication = () => { - console.log(githubGradient('Checking GitHub authentication status...')); + getLogColor('github', 'Checking authentication status...'); // Check if the user is already authenticated if (isGitHubAuthenticated()) { - console.log(githubGradient('You are already logged in to GitHub.')); + getLogColor('github', 'You are already logged in.'); return; // Exit early if authenticated } diff --git a/packages/core/utils/github/repositoryManager.ts b/packages/core/utils/github/repositoryManager.ts index 10d9957..ef3f824 100644 --- a/packages/core/utils/github/repositoryManager.ts +++ b/packages/core/utils/github/repositoryManager.ts @@ -1,15 +1,10 @@ import { exec, execSync } from 'child_process'; import inquirer from 'inquirer'; import { promisify } from 'util'; -import gradient from 'gradient-string'; +import { getLogColor } from '../shared/getLogColor'; const execAsync = promisify(exec); -const githubGradient = gradient([ - { color: '#3B8640', pos: 0 }, - { color: '#8256D0', pos: 1 }, -]); - const generateUniqueRepoName = async (baseName: string): Promise => { // Remove any existing numbering pattern from the end const cleanBaseName = baseName.replace(/-\d+$/, ''); @@ -55,7 +50,7 @@ export const isGitHubAuthenticated = (): boolean => { }; export const authenticateGitHub = async (): Promise => { - console.log(githubGradient('Attempting to authenticate with GitHub...')); + getLogColor('github', 'Attempting to authenticate...'); execSync('gh auth login', { stdio: 'inherit' }); @@ -76,14 +71,14 @@ export const fetchGitHubUsername = async (): Promise => { const username = execSync('echo "$(gh api user --jq .login)"', { stdio: 'pipe' }).toString().trim(); if (username) { - console.log(githubGradient(`Hello ${username}!`)); + getLogColor('github', `Hello ${username}!`); return username; } else { - console.log(githubGradient('No username returned or an error occurred.')); + getLogColor('github', 'No username returned or an error occurred.'); return null; } } catch (error) { - console.error('Error fetching GitHub username:', error); + console.error('Error fetching username:', error); return null; } }; @@ -93,7 +88,7 @@ export const createGitHubRepository = async ( repositoryVisibility: 'public' | 'private', username: string, ): Promise => { - console.log(githubGradient(`Checking if repository already exists...`)); + getLogColor('github', `Checking if repository already exists...`); // Check if the repository exists const repoCheckCommand = `echo "$(gh repo view ${username}/${projectName} --json name)"`; @@ -119,7 +114,7 @@ export const createGitHubRepository = async ( repoName = confirmedName; } - console.log(githubGradient(`Creating GitHub repository: ${repoName}`)); + getLogColor('github', `Creating repository: ${repoName}`); const visibility = repositoryVisibility === 'public' ? '--public' : '--private'; const command = `gh repo create ${repoName} ${visibility}`; @@ -127,7 +122,7 @@ export const createGitHubRepository = async ( const result = execSync(command); if (result) { - console.log(githubGradient(`Repository successfully created at ${result}`)); + getLogColor('github', `Repository successfully created at ${result}`); return repoName; // Return true to indicate success } @@ -137,7 +132,7 @@ export const createGitHubRepository = async ( // New function to set up the local Git repository export const setupGitRepository = async (projectName: string, username: string) => { - console.log(githubGradient(`Pushing files to repository...`)); + getLogColor('github', `Pushing files to repository...`); // Set the remote origin and push to GitHub const commands = [ diff --git a/packages/core/utils/payload/install.ts b/packages/core/utils/payload/install.ts index 88f8d27..4b1cd98 100644 --- a/packages/core/utils/payload/install.ts +++ b/packages/core/utils/payload/install.ts @@ -1,19 +1,14 @@ import { execSync } from 'child_process'; import { existsSync } from 'fs'; import { join } from 'path'; -import gradient from 'gradient-string'; import { preparePayloadConfig } from './preparePayloadConfig'; import { prepareTsConfig } from './prepareTsConfig'; import { removeTurboFlag } from './removeTurboFlag'; import { updatePackages } from './updatePackages'; - -const payloadGradient = gradient([ - { color: '#12324A', pos: 0 }, - { color: '#E5AA5F', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const preparePayload = async () => { - console.log(payloadGradient('Initializing Payload...')); + getLogColor('payload', 'Initializing...'); process.chdir('./apps/web/'); @@ -21,7 +16,7 @@ export const preparePayload = async () => { updatePackages(); - console.log(payloadGradient('Moving files to (app) directory...')); + getLogColor('payload', ['Moving files to (app) directory...']); execSync( `mkdir -p ./app/\\(app\\) && find ./app -maxdepth 1 ! -path './app' ! -path './app/\\(app\\)' -exec mv {} ./app/\\(app\\)/ \\;`, { @@ -29,7 +24,7 @@ export const preparePayload = async () => { }, ); - console.log(payloadGradient('Installing Payload to Next.js...')); + getLogColor('payload', 'Installing to Next.js...'); execSync(`npx create-payload-app@beta`, { stdio: 'inherit' }); // Payload doesn't work with Turbopack yet diff --git a/packages/core/utils/payload/preparePayloadConfig.ts b/packages/core/utils/payload/preparePayloadConfig.ts index b327350..4c80742 100644 --- a/packages/core/utils/payload/preparePayloadConfig.ts +++ b/packages/core/utils/payload/preparePayloadConfig.ts @@ -1,14 +1,9 @@ import type { PathLike } from 'fs'; import fs from 'fs/promises'; -import gradient from 'gradient-string'; - -const payloadGradient = gradient([ - { color: '#12324A', pos: 0 }, - { color: '#E5AA5F', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const preparePayloadConfig = async (configPath: PathLike) => { - console.log(payloadGradient('Preparing payload.config.ts...')); + getLogColor('payload', 'Preparing payload.config.ts...'); try { // Read the payload.config.ts file diff --git a/packages/core/utils/payload/prepareTsConfig.ts b/packages/core/utils/payload/prepareTsConfig.ts index ac4f59c..6d63ef3 100644 --- a/packages/core/utils/payload/prepareTsConfig.ts +++ b/packages/core/utils/payload/prepareTsConfig.ts @@ -1,14 +1,9 @@ import fs from 'fs'; import path from 'path'; -import gradient from 'gradient-string'; - -const payloadGradient = gradient([ - { color: '#12324A', pos: 0 }, - { color: '#E5AA5F', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const prepareTsConfig = () => { - console.log(payloadGradient('Preparing tsconfig.json...')); + getLogColor('payload', 'Preparing tsconfig.json...'); // Path to your tsconfig.json file const tsconfigPath = path.join(process.cwd(), 'tsconfig.json'); diff --git a/packages/core/utils/payload/removeTurboFlag.ts b/packages/core/utils/payload/removeTurboFlag.ts index c21ace2..a0717ae 100644 --- a/packages/core/utils/payload/removeTurboFlag.ts +++ b/packages/core/utils/payload/removeTurboFlag.ts @@ -1,14 +1,9 @@ import fs from 'fs'; import path from 'path'; -import gradient from 'gradient-string'; - -const payloadGradient = gradient([ - { color: '#12324A', pos: 0 }, - { color: '#E5AA5F', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const removeTurboFlag = () => { - console.log(payloadGradient('Removing --turbo flag from dev script...')); + getLogColor('payload', 'Removing --turbo flag from dev script...'); // Path to your package.json file const packageJsonPath = path.join(process.cwd(), 'package.json'); diff --git a/packages/core/utils/payload/updatePackages.ts b/packages/core/utils/payload/updatePackages.ts index 99f1b5e..fdbf05f 100644 --- a/packages/core/utils/payload/updatePackages.ts +++ b/packages/core/utils/payload/updatePackages.ts @@ -1,18 +1,13 @@ import { execSync } from 'child_process'; -import gradient from 'gradient-string'; - -const payloadGradient = gradient([ - { color: '#12324A', pos: 0 }, - { color: '#E5AA5F', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const updatePackages = () => { - console.log(payloadGradient('Updating Next and React to their respective release candidates...')); + getLogColor('payload', 'Updating Next and React to their respective release candidates...'); execSync(`pnpm up next@rc react@rc react-dom@rc eslint-config-next@rc --reporter silent`, { stdio: 'inherit', }); - console.log(payloadGradient('Installing necessary packages...')); + getLogColor('payload', 'Installing necessary packages...'); execSync(`pnpm i pg sharp --reporter silent`, { stdio: 'inherit', }); diff --git a/packages/core/utils/prettier/prettify.ts b/packages/core/utils/prettier/prettify.ts index c948d83..8033b19 100644 --- a/packages/core/utils/prettier/prettify.ts +++ b/packages/core/utils/prettier/prettify.ts @@ -1,12 +1,8 @@ import { execSync } from 'child_process'; -import gradient from 'gradient-string'; +import { getLogColor } from '../shared/getLogColor'; -const prettifyGradient = gradient([ - { color: '#F11D28', pos: 0 }, - { color: '#FFA12C', pos: 1 }, -]); export const prettify = async () => { - console.log(prettifyGradient('Prettifying...')); + getLogColor('prettier', 'Prettifying...'); const ignorePatterns = [ 'node_modules/', diff --git a/packages/core/utils/shared/continueOnKeypress.ts b/packages/core/utils/shared/continueOnKeypress.ts index 9f5d36f..23374dc 100644 --- a/packages/core/utils/shared/continueOnKeypress.ts +++ b/packages/core/utils/shared/continueOnKeypress.ts @@ -1,13 +1,8 @@ import * as readline from 'readline'; -import gradient from 'gradient-string'; - -const supabaseGradient = gradient([ - { color: '#3ABC82', pos: 0 }, - { color: '#259764', pos: 1 }, -]); +import { getLogColor } from './getLogColor'; export const continueOnAnyKeypress = async (message: string): Promise => { - console.log(supabaseGradient(message)); + getLogColor('supabase', message); const rl = readline.createInterface({ input: process.stdin, diff --git a/packages/core/utils/shared/getLogColor.ts b/packages/core/utils/shared/getLogColor.ts new file mode 100644 index 0000000..e6cb745 --- /dev/null +++ b/packages/core/utils/shared/getLogColor.ts @@ -0,0 +1,55 @@ +import chalk from 'chalk'; +import gradient from 'gradient-string'; + +type Name = 'turborepo' | 'supabase' | 'payload' | 'github' | 'prettier' | 'vercel'; + +const names = [ + { + name: 'turborepo', + prefix: 'Turbo', + colors: ['#0099F7', '#F11712'], + }, + { + name: 'supabase', + prefix: 'Supabase', + colors: ['#3ABC82', '#259764'], + }, + { + name: 'payload', + prefix: 'Payload', + colors: ['#12324A', '#E5AA5F'], + }, + { + name: 'github', + prefix: 'GitHub', + colors: ['#3B8640', '#8256D0'], + }, + { + name: 'prettier', + prefix: 'Prettier', + colors: ['#F11D28', '#FFA12C'], + }, + { + name: 'vercel', + prefix: 'Vercel', + colors: ['#FFF', '#FFF'], + }, +]; + +export const getLogColor = (name: Name, messages: string[] | string) => { + const color = names.find((color) => color.name === name); + if (!color) { + console.log(chalk.red('Invalid color name.')); + return; + } + const gradientColor = gradient(color.colors); + + if (name === 'vercel') { + return console.log( + chalk.bgBlack(gradientColor(`[▲ ${color.prefix}]`)), + typeof messages === 'string' ? messages : messages.join(' '), + ); + } + + return console.log(gradientColor(`[${color.prefix}]`), typeof messages === 'string' ? messages : messages.join(' ')); +}; diff --git a/packages/core/utils/supabase/connectProject.ts b/packages/core/utils/supabase/connectProject.ts index 65178d4..d94dbe0 100644 --- a/packages/core/utils/supabase/connectProject.ts +++ b/packages/core/utils/supabase/connectProject.ts @@ -2,21 +2,16 @@ import { exec, execSync } from 'child_process'; import inquirer from 'inquirer'; import { promisify } from 'util'; import chalk from 'chalk'; -import gradient from 'gradient-string'; import { continueOnAnyKeypress } from '../shared/continueOnKeypress'; import { updateEnvFile } from '../shared/updateEnvFile'; import { getSupabaseKeys, parseProjectsList } from './utils'; +import { getLogColor } from '../shared/getLogColor'; const execAsync = promisify(exec); -const supabaseGradient = gradient([ - { color: '#3ABC82', pos: 0 }, - { color: '#259764', pos: 1 }, -]); - export const connectSupabaseProject = async (projectName: string, currentDir: string) => { try { - console.log(supabaseGradient('Getting information about newly created Supabase project...')); + getLogColor('supabase', 'Getting information about newly created project...'); const { stdout: projectsList } = await execAsync('npx supabase projects list'); const projects = parseProjectsList(projectsList); const newProject = projects.find((project) => project.name === projectName); @@ -27,7 +22,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st ); } - console.log(supabaseGradient('Getting Supabase project keys...')); + getLogColor('supabase', 'Getting project keys...'); const { stdout: projectAPIKeys } = await execAsync( `npx supabase projects api-keys --project-ref ${newProject.refId}`, ); @@ -40,7 +35,7 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st const SUPABASE_URL = `https://${newProject.refId}.supabase.co/`; - console.log(supabaseGradient(`Saving keys to .env...`)); + getLogColor('supabase', `Saving keys to .env...`); await updateEnvFile({ currentDir, pairs: [ @@ -50,18 +45,18 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st ], }); - console.log(supabaseGradient('Linking Supabase project...')); + getLogColor('supabase', 'Linking project...'); execSync(`npx supabase link --project-ref ${newProject.refId}`, { stdio: 'inherit' }); - console.log( - chalk.bold(supabaseGradient('=== Instructions for Supabase Integration with GitHub and Vercel ===')), - supabaseGradient('\n1. You will be redirected to your Supabase project dashboard'), - supabaseGradient('\n2. Find the "GitHub" section and click "Connect".'), - supabaseGradient('\n - Follow the prompts to connect Supabase with your GitHub repository.'), - supabaseGradient('\n3. Then, find the "Vercel" section and click "Connect".'), - supabaseGradient('\n - Follow the prompts to connect Supabase with your Vercel project.'), - chalk.italic(supabaseGradient('\nNOTE: These steps require manual configuration in the Supabase interface.')), - ); + getLogColor('supabase', [ + chalk.bold('=== Instructions for integration with GitHub and Vercel ==='), + '\n1. You will be redirected to your project dashboard', + '\n2. Find the "GitHub" section and click "Connect".', + '\n - Follow the prompts to connect with your GitHub repository.', + '\n3. Then, find the "Vercel" section and click "Connect".', + '\n - Follow the prompts to connect with your Vercel project.', + chalk.italic('\nNOTE: These steps require manual configuration in the Supabase interface.'), + ]); await continueOnAnyKeypress('When you are ready to be redirected to the Supabase page press any key'); await execAsync(`open https://supabase.com/dashboard/project/${newProject.refId}/settings/integrations`); @@ -76,12 +71,11 @@ export const connectSupabaseProject = async (projectName: string, currentDir: st ]); if (!isIntegrationReady) { - console.log( - supabaseGradient( - `You can access your project dashboard at: https://supabase.com/dashboard/project/${newProject.refId}/settings/integrations`, - ), - ); - process.exit(1); + getLogColor( + 'supabase', + `You can access your project dashboard at: https://supabase.com/dashboard/project/${newProject.refId}/settings/integrations`, + ), + process.exit(1); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'; diff --git a/packages/core/utils/supabase/createProject.ts b/packages/core/utils/supabase/createProject.ts index 4c85dba..2240fa3 100644 --- a/packages/core/utils/supabase/createProject.ts +++ b/packages/core/utils/supabase/createProject.ts @@ -1,13 +1,8 @@ import { execSync } from 'child_process'; -import gradient from 'gradient-string'; - -const supabaseGradient = gradient([ - { color: '#3ABC82', pos: 0 }, - { color: '#259764', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const createSupabaseProject = async (name: string) => { - console.log(supabaseGradient('Creating Supabase project...')); + getLogColor('supabase', 'Creating Supabase project...'); execSync(`npx supabase projects create ${name}`, { stdio: 'inherit', diff --git a/packages/core/utils/supabase/install.ts b/packages/core/utils/supabase/install.ts index b189019..6e8aa50 100644 --- a/packages/core/utils/supabase/install.ts +++ b/packages/core/utils/supabase/install.ts @@ -1,67 +1,61 @@ import { execSync } from 'child_process'; import fs from 'fs'; import path from 'path'; -import gradient from 'gradient-string'; import { supabaseFiles } from '../../templates/supabase/installConfig'; import { templateGenerator } from '../generator/generator'; import { getTemplateDirectory } from '../shared/getTemplateDirectory'; - -const supabaseGradient = gradient([ - { color: '#3ABC82', pos: 0 }, - { color: '#259764', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; const supabaseLogin = () => { - console.log(supabaseGradient('Logging into Supabase...')); + getLogColor('supabase', 'Logging in...'); try { execSync('npx supabase projects list', { stdio: 'ignore' }); - console.log(supabaseGradient('Already logged into Supabase.')); + getLogColor('supabase', 'Already logged in.'); return; } catch (error) { try { execSync('npx supabase login', { stdio: 'inherit' }); } catch { console.error('Failed to log in to Supabase.'); - console.log(supabaseGradient('\nPlease log in manually with "supabase login" and re-run "create-stapler-app".')); + getLogColor('supabase', '\nPlease log in manually with "supabase login" and re-run "create-stapler-app".'); process.exit(1); } } }; const initializeSupabaseProject = (): void => { - console.log(supabaseGradient('Initialize Supabase project...')); + getLogColor('supabase', 'Initialize project...'); try { execSync(`npx supabase init`, { stdio: ['pipe'], encoding: 'utf-8' }); } catch (error: any) { const errorMessage = error.stderr; if (errorMessage.includes('file exists')) { - console.log(supabaseGradient('Supabase configuration file already exists.')); + getLogColor('supabase', 'Configuration file already exists.'); return; } else { console.error('Failed to initialize Supabase project with "supabase init".'); - console.log( - supabaseGradient( - '\nPlease review the error message below, follow the initialization instructions, and try running "create-stapler-app" again.', - ), - ); - process.exit(1); + getLogColor( + 'supabase', + '\nPlease review the error message below, follow the initialization instructions, and try running "create-stapler-app" again.', + ), + process.exit(1); } } }; export const installSupabase = async (destinationDirectory: string) => { - console.log(supabaseGradient('Installing supabase-js...')); + getLogColor('supabase', 'Installing supabase-js...'); try { supabaseLogin(); initializeSupabaseProject(); } catch (error) { - console.error('Failed to init Supabase project.', `\nError: ${error}`); + console.error('Failed to init project.', `\nError: ${error}`); process.exit(1); } - console.log(supabaseGradient('Adding Supabase Files...')); + getLogColor('supabase', 'Adding Files...'); const templateDirectory = getTemplateDirectory(`/templates/supabase/files/`); @@ -79,7 +73,7 @@ export const installSupabase = async (destinationDirectory: string) => { process.chdir('supabase'); - console.log(supabaseGradient('Installing Supabase dependencies...')); + getLogColor('supabase', 'Installing dependencies...'); execSync('pnpm i --reporter silent', { stdio: 'inherit' }); diff --git a/packages/core/utils/turbo/create.ts b/packages/core/utils/turbo/create.ts index e9fdcd3..e617788 100644 --- a/packages/core/utils/turbo/create.ts +++ b/packages/core/utils/turbo/create.ts @@ -1,13 +1,8 @@ import { execSync } from 'child_process'; -import gradient from 'gradient-string'; - -const turborepoGradient = gradient([ - { color: '#0099F7', pos: 0 }, - { color: '#F11712', pos: 1 }, -]); +import { getLogColor } from '../shared/getLogColor'; export const createTurboRepo = async (name: string) => { - console.log(turborepoGradient('Creating Turborepo...')); + getLogColor('turborepo', 'Creating...'); execSync(`npx create-turbo@latest ${name} -m pnpm`, { stdio: 'inherit', }); diff --git a/packages/core/utils/vercel/connectWithGH.ts b/packages/core/utils/vercel/connectWithGH.ts index 331d9a0..d8fc8bd 100644 --- a/packages/core/utils/vercel/connectWithGH.ts +++ b/packages/core/utils/vercel/connectWithGH.ts @@ -1,11 +1,11 @@ import { execSync } from 'child_process'; -import chalk from 'chalk'; import { continueOnAnyKeypress } from '../shared/continueOnKeypress'; +import { getLogColor } from '../shared/getLogColor'; const MAX_RETRIES = 3; export const connectWithGH = async () => { - console.log(chalk.bgBlack.hex('#FFF')('▲ Connecting with GitHub repository...')); + getLogColor('vercel', 'Connecting with GitHub repository...'); for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { try { @@ -23,27 +23,23 @@ export const connectWithGH = async () => { if (noConnectionError) { if (attempt === MAX_RETRIES) { - console.log( - chalk.bgBlack.hex('#FFF')( - "▲ Hmm, we've tried connecting a few times but no luck.", - "\n\n ▲ Let's try to set this up manually:", - '\n ▲ 1️⃣ Visit \x1b[36mhttps://vercel.com/account/login-connections\x1b[0m', - '\n ▲ 2️⃣ Click on "GitHub" and complete the authorization', - '\n ▲ 3️⃣ Once done, run \x1b[36mcvercel git connect\x1b\n', - ), - ); + getLogColor('vercel', [ + "Hmm, we've tried connecting a few times but no luck.", + "\n\n Let's try to set this up manually:", + '\n 1️⃣ Visit \x1b[36mhttps://vercel.com/account/login-connections\x1b[0m', + '\n 2️⃣ Click on "GitHub" and complete the authorization', + '\n 3️⃣ Once done, run \x1b[36mcvercel git connect\x1b\n', + ]); } else { - console.log( - chalk.bgBlack.hex('#FFF')( - `▲ 🔄 Attempt ${attempt} of ${MAX_RETRIES}`, - "\n\n▲ It seems you haven't connected your GitHub login with Vercel yet. 🤔", - '\n▲ No worries though! Just head over to \x1b[36mhttps://vercel.com/account/login-connections\x1b[0m$', - '\n▲ and click that "GitHub" button.', - ), - ); + getLogColor('vercel', [ + `🔄 Attempt ${attempt} of ${MAX_RETRIES}`, + "\n\nIt seems you haven't connected your GitHub login with Vercel yet. 🤔", + '\nNo worries though! Just head over to \x1b[36mhttps://vercel.com/account/login-connections\x1b[0m$', + '\nand click that "GitHub" button.', + ]); } - await continueOnAnyKeypress("▲ Once you've done that press any key"); + await continueOnAnyKeypress("Once you've done that press any key"); } } } diff --git a/packages/core/utils/vercel/deploy.ts b/packages/core/utils/vercel/deploy.ts index 0e7eec6..0186b4e 100644 --- a/packages/core/utils/vercel/deploy.ts +++ b/packages/core/utils/vercel/deploy.ts @@ -1,18 +1,16 @@ import fs from 'fs/promises'; -import chalk from 'chalk'; import { connectWithGH } from './connectWithGH'; import { getDeploymentUrl } from './utils/getDeploymentUrl'; +import { getLogColor } from '../shared/getLogColor'; export const deployVercelProject = async () => { try { await connectWithGH(); - } catch (error) { - console.log( - chalk.bgBlack.hex('#FFF')('▲ An unexpected error occurred:', error, '\n▲ Failed to connect GitHub with Vercel'), - ); + } catch (error: any) { + getLogColor('vercel', ['An unexpected error occurred:', error, '\nFailed to connect GitHub with Vercel']); } - console.log(chalk.bgBlack.hex('#FFF')('▲ Creating vercel.json...')); + getLogColor('vercel', 'Creating vercel.json...'); const vercelConfig = { buildCommand: 'pnpm build', @@ -21,15 +19,13 @@ export const deployVercelProject = async () => { await fs.writeFile('vercel.json', JSON.stringify(vercelConfig, null, 2)); - console.log(chalk.bgBlack.hex('#FFF')('▲ Creating production deployment...')); + getLogColor('vercel', 'Creating production deployment...'); const productionUrl = getDeploymentUrl(true); - console.log(chalk.bgBlack.hex('#FFF')('▲ Creating preview deployment...')); + getLogColor('vercel', 'Creating preview deployment...'); const previewUrl = getDeploymentUrl(false); - console.log(chalk.bgBlack.hex('#FFF')(`▲ You can access your preview deployment at: \x1b[36m${previewUrl}\x1b[0m`)); + getLogColor('vercel', `You can access your preview deployment at: \x1b[36m${previewUrl}\x1b[0m`); - console.log( - chalk.bgBlack.hex('#FFF')(`▲ You can access your production deployment at: \x1b[36m${productionUrl}\x1b[0m`), - ); + getLogColor('vercel', `You can access your production deployment at: \x1b[36m${productionUrl}\x1b[0m`); }; diff --git a/packages/core/utils/vercel/setupAndCreate.ts b/packages/core/utils/vercel/setupAndCreate.ts index b61895f..2477bb9 100644 --- a/packages/core/utils/vercel/setupAndCreate.ts +++ b/packages/core/utils/vercel/setupAndCreate.ts @@ -1,5 +1,5 @@ import { execSync } from 'child_process'; -import chalk from 'chalk'; +import { getLogColor } from '../shared/getLogColor'; const getUserName = (): string | null => { try { @@ -14,36 +14,32 @@ export const setupAndCreateVercelProject = async () => { const vercelUserName = getUserName(); if (!vercelUserName) { - console.log(chalk.bgBlack.hex('#FFF')('▲ Logging in to Vercel...')); + getLogColor('vercel', 'Logging in...'); try { execSync('npx vercel login', { stdio: 'inherit' }); } catch (error) { - console.log( - chalk.bgBlack.hex('#FFF')( - '▲ Oops! Something went wrong while logging in to Vercel...', - '\n▲ You might already be logged in with this email in another project.', - '\n▲ In this case, select "Continue with Email" and enter the email you\'re already logged in with.\n', - ), - ); + getLogColor('vercel', [ + 'Oops! Something went wrong while logging in...', + '\nYou might already be logged in with this email in another project.', + '\nIn this case, select "Continue with Email" and enter the email you\'re already logged in with.\n', + ]); try { execSync('npx vercel login', { stdio: 'inherit' }); } catch { - console.log( - chalk.bgBlack.hex('#FFF')( - '▲ Please check the error above and try again.', - '\n▲ After successfully logging in with "vercel login", please run create-stapler-app again.\n', - ), - ); - process.exit(1); + getLogColor('vercel', [ + 'Please check the error above and try again.', + '\nAfter successfully logging in with "vercel login", please run create-stapler-app again.\n', + ]), + process.exit(1); } } } else { - console.log(chalk.bgBlack.hex('#FFF')(`▲ You are logged to Vercel as \x1b[36m${vercelUserName}\x1b[0m`)); + getLogColor('vercel', `You are logged as \x1b[36m${vercelUserName}\x1b[0m`); } - console.log(chalk.bgBlack.hex('#FFF')('▲ Initializing Vercel project...')); + getLogColor('vercel', 'Initializing project...'); execSync('npx vercel init'); - console.log(chalk.bgBlack.hex('#FFF')('\n▲ Linking Vercel project...')); + getLogColor('vercel', '\nLinking project...'); execSync('npx vercel link', { stdio: 'inherit' }); };