Skip to content

Commit

Permalink
Improved cli logs and arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
albbus-stack committed Aug 26, 2023
1 parent 7392df6 commit 744ce39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pnpm create t4-app
If you would like to use Tauri use:

```bash
pnpm create t4-app yourappname --tauri
pnpm create t4-app --tauri
```

## 🧩 VSCode Extension
Expand Down
43 changes: 31 additions & 12 deletions apps/cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ const rl = readline.createInterface({

const repositoryUrl = 'https://github.com/timothymiller/t4-app'

const [projectFolder, ...commandLineArgs] = process.argv.slice(2)
let [projectFolder, ...commandLineArgs] = process.argv.slice(2)

// Parse command line arguments correctly even with no projectFolder specified
if(projectFolder && projectFolder.startsWith('--')){
commandLineArgs.push(projectFolder)
projectFolder = undefined
}
if(!projectFolder && commandLineArgs.length > 1){
commandLineArgs.every((arg)=>{
if(!arg.startsWith('--')){
projectFolder = arg
return false
}
return true
})
}
const useTauri = commandLineArgs.includes('--tauri')

const generateRepositoryBranch = () => {
Expand Down Expand Up @@ -81,11 +96,11 @@ const setupProject = async (folderName) => {
try {
console.log(chalk.yellow(`
👉 Setting up a new t4 project.
Follow the steps below to create your project:
1. Cloning the t4-app repository into the specified folder.
2. Removing unnecessary files.
3. Installing dependencies.
4. Generating the Drizzle client.
This script follows the steps below to create your project:
1. Clone the t4-app repository into the specified folder.
2. Remove unnecessary files.
3. Install dependencies.
4. Generate the Drizzle client.
`))

await cloneRepository(folderName)
Expand All @@ -108,7 +123,7 @@ Follow the steps below to create your project:
`))

console.log(chalk.green.bold(`
Successfully created t4 project!
🚀 Successfully created t4 project!
Make sure you have a Supabase account and have created a new project.
After filling out your .env file, run 'pnpm migrate:local' to create your database tables.
To start the API and web development servers, run 'pnpm api' and 'pnpm web' in separate terminal tabs.
Expand All @@ -127,14 +142,18 @@ const logo = `
\\::\\ \\ \\::\\_\\::\\/_/\\ \\::(_) \\ \\\\:(_) \\ \\\\:(_) \\ \\
\\::\\ \\ \\_::: __\\/ \\:: __ \\ \\\\: ___\\/ \\: ___\\/
\\::\\ \\ \\::\\ \\ \\:.\\ \\ \\ \\\\ \\ \\ \\ \\ \\
\\__\\/ \\__\\/ \\__\\/\\__\\/ \\_\\/ \\`
\\__\\/ \\__\\/ \\__\\/\\__\\/ \\_\\/ \\_\\/`

console.log(chalk.green.bold(logo))
console.log(chalk.magentaBright.bold('"Type-Safe, Full-Stack Starter Kit for React Native + Web" 🚀'))
console.log(chalk.magentaBright.bold('ft. Tamagui + TypeScript + tRPC + Turborepo'))
console.log(chalk.magentaBright.bold('\n"Type-Safe, Full-Stack Starter Kit for React Native + Web"'))
console.log(chalk.magentaBright.bold(' ft. Tamagui + TypeScript + tRPC + Turborepo'))

if(repositoryBranch){
console.log(chalk.yellow.bold(`\n⚠ Cloning ${repositoryBranch.replace('-b', '').replace('--single-branch', '').trim()} branch.`))
}

if (!projectFolder) {
console.log(chalk.green.bold('Enter the name of the project:'))
console.log(chalk.green.bold('\nEnter the name of the project:'))

try {
const folderName = await promptQuestion('> ')
Expand Down Expand Up @@ -173,7 +192,7 @@ const removePaths = async (paths) => {
console.log(`Removed: ${pathToRemove}`);
}

console.log('All paths removed successfully!');
console.log('All paths removed successfully!\n');
} catch (error) {
console.error('Error removing paths:', error);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-t4-app",
"bin": "./bin/index.js",
"version": "2.2.7",
"version": "2.2.8",
"license": "Apache-2.0",
"description": "Easily Create Type-Safe, Full-Stack Apps for React Native + Web using the t4 stack.",
"dependencies": {
Expand Down

0 comments on commit 744ce39

Please sign in to comment.