Skip to content

Commit

Permalink
feat(cli): add prompts for select formatter and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Jul 23, 2024
1 parent 76757ea commit f320eba
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 48 deletions.
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"@rapidapp/config": "workspace:*",
"@rapidapp/scanner": "workspace:*",
"@types/node": "20.14.11",
"@types/prompts": "2.4.9",
"@vercel/ncc": "0.38.1",
"commander": "12.1.0",
"conf": "13.0.1",
"ora": "8.0.1",
"picocolors": "1.0.1",
"prompts": "2.4.2",
"typescript": "5.5.4",
"update-check": "1.5.4",
"vitest": "2.0.4"
Expand Down
94 changes: 52 additions & 42 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
import { cyan, green } from 'picocolors'
import { program } from '../'

export function addCommand(name: string) {
const projectPath = name
const options = this.opts()

if (!projectPath) {
console.log(
`\nPlease specify the project directory:\n ${cyan(program.name())} ${cyan('add')} ${green(
'<project-directory>',
)} ${cyan('[tools]')}\nFor example:\n ${cyan(program.name())} ${cyan('add')} ${green('website')} ${cyan(
'--linter eslint',
)}\n\nRun ${cyan(`${program.name()} help add`)} to see all options.`,
)

process.exit(1)
}

// TODO: Show a prompt to select the tool to add
if (Object.keys(options).length === 0) {
console.log(
`\nPlease specify the tool to add:\n ${cyan(program.name())} ${cyan('add <project-directory>')} ${green(
'[tools]',
)}\nFor example:\n ${cyan(program.name())} ${cyan('add website')} ${green(
'--linter eslint --formatter prettier',
)}\n\nRun ${cyan(`${program.name()} help add`)} to see all options.`,
)

process.exit(1)
}

if (options.L != null && options.L !== true) {
console.log(options.L)
}

if (options.F != null && options.F !== true) {
console.log(options.F)
}

if (options.Gh != null && options.Gh !== true) {
console.log(options.Gh)
import prompts from 'prompts'

export async function addCommand(tools: string[]) {
const projectPath = process.cwd()

if (tools.length === 0) {
const { type } = await prompts([
{
type: 'multiselect',
name: 'type',
message: 'Select type of tools to add',
choices: [
{ title: 'Linter', value: 'linter' },
{ title: 'Formatter', value: 'formatter' },
],
},
])

if (!Array.isArray(type)) {
return
}

// TODO: if select biome, ask if want to formatter
if (type.includes('linter')) {
const { linter } = await prompts([
{
type: 'select',
name: 'linter',
message: 'Select linter to add',
choices: [
{ title: 'Biome', value: 'biome' },
{ title: 'ESLint', value: 'eslint' },
],
},
])
}

if (type.includes('formatter')) {
const { formatter } = await prompts([
{
type: 'select',
name: 'formatter',
message: 'Select linter to add',
choices: [
{ title: 'Biome', value: 'biome' },
{ title: 'Prettier', value: 'prettier' },
],
},
])
}

return
}
}
3 changes: 3 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './add'
export * from './config'
export * from './scan'
11 changes: 5 additions & 6 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Conf from 'conf'
import { green } from 'picocolors'

import packageJson from '../package.json'
import { configCommand } from './commands/config'
import { scannerCommand } from './commands/scan'
import { addCommand, configCommand, scannerCommand } from './commands'
import { checkUpdates } from './utils/checkUpdates'

export const conf = new Conf({
Expand Down Expand Up @@ -48,10 +47,10 @@ program
// TODO: support git hooks
// TODO: support oxc
// TODO: add description
// program
// .command('add')
// .addArgument(new Argument('[tools...]').choices(['biome', 'prettier', 'eslint']))
// .action(addCommand)
program
.command('add')
.addArgument(new Argument('[tools...]').choices(['biome', 'prettier', 'eslint']))
.action(addCommand)

// TODO: add option --output -o support csv, json yaml html table
// TODO: add description
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f320eba

Please sign in to comment.