Skip to content

Commit

Permalink
feat: improve readibility to the max
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike committed Oct 31, 2024
1 parent eed6243 commit 21b6638
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 205 deletions.
6 changes: 6 additions & 0 deletions .changeset/fresh-cougars-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tonik/create-stapler-app-core': minor
'@tonik/create-stapler-app': minor
---

Improve readibility EVEN MORE
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 12 additions & 17 deletions packages/core/utils/github/ghInstaller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -33,32 +28,32 @@ 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;
case 'win32': // Windows
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;
}
};
Expand Down
15 changes: 5 additions & 10 deletions packages/core/utils/github/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gradient from 'gradient-string';
import { getLogColor } from '../shared/getLogColor';
import { installGitHubCLI, isGitHubCLIInstalled } from './ghInstaller';
import {
authenticateGitHub,
Expand All @@ -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...');
Expand All @@ -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
}

Expand Down
23 changes: 9 additions & 14 deletions packages/core/utils/github/repositoryManager.ts
Original file line number Diff line number Diff line change
@@ -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<string> => {
// Remove any existing numbering pattern from the end
const cleanBaseName = baseName.replace(/-\d+$/, '');
Expand Down Expand Up @@ -55,7 +50,7 @@ export const isGitHubAuthenticated = (): boolean => {
};

export const authenticateGitHub = async (): Promise<boolean> => {
console.log(githubGradient('Attempting to authenticate with GitHub...'));
getLogColor('github', 'Attempting to authenticate...');

execSync('gh auth login', { stdio: 'inherit' });

Expand All @@ -76,14 +71,14 @@ export const fetchGitHubUsername = async (): Promise<string | null> => {
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;
}
};
Expand All @@ -93,7 +88,7 @@ export const createGitHubRepository = async (
repositoryVisibility: 'public' | 'private',
username: string,
): Promise<string | undefined> => {
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)"`;
Expand All @@ -119,15 +114,15 @@ 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}`;

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
}

Expand All @@ -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 = [
Expand Down
13 changes: 4 additions & 9 deletions packages/core/utils/payload/install.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
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/');

prepareTsConfig();

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\\)/ \\;`,
{
stdio: 'inherit',
},
);

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
Expand Down
9 changes: 2 additions & 7 deletions packages/core/utils/payload/preparePayloadConfig.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 2 additions & 7 deletions packages/core/utils/payload/prepareTsConfig.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
9 changes: 2 additions & 7 deletions packages/core/utils/payload/removeTurboFlag.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
11 changes: 3 additions & 8 deletions packages/core/utils/payload/updatePackages.ts
Original file line number Diff line number Diff line change
@@ -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',
});
Expand Down
8 changes: 2 additions & 6 deletions packages/core/utils/prettier/prettify.ts
Original file line number Diff line number Diff line change
@@ -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/',
Expand Down
9 changes: 2 additions & 7 deletions packages/core/utils/shared/continueOnKeypress.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
console.log(supabaseGradient(message));
getLogColor('supabase', message);

const rl = readline.createInterface({
input: process.stdin,
Expand Down
Loading

0 comments on commit 21b6638

Please sign in to comment.