Skip to content

Commit

Permalink
feat(cli): add new options to scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Jul 13, 2024
1 parent e3d5f13 commit e33312e
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"name": "Sebastian Beltran"
},
"keywords": ["cli", "frameworks", "set up", "rapidapp", "tools"],
"type": "module",
"bin": {
"rapidapp": "dist/index.js"
},
Expand All @@ -26,6 +25,7 @@
"@types/node": "20.14.10",
"@vercel/ncc": "0.38.1",
"commander": "12.1.0",
"conf": "13.0.1",
"ora": "8.0.1",
"picocolors": "1.0.1",
"typescript": "5.5.3",
Expand Down
31 changes: 28 additions & 3 deletions packages/cli/src/commands/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ import path from 'node:path'

import { generateReport } from '@rapidapp/scanner'
import { scanFolder } from '@rapidapp/scanner/helpers'
import Conf from 'conf'

import ora from 'ora'
import { cyan, green } from 'picocolors'

import { program } from '../'

export const scannerCommand = async (name: string) => {
export const scannerCommand = async (
name: string,
options: { checkContent?: boolean; checkDependencies?: boolean },
) => {
const conf = new Conf({ projectName: 'rapidapp' })

if (program.opts().resetPreferences) {
conf.clear()
console.log('Preferences reset successfully')
return
}

const spinner = ora('Scanning project')
spinner.color = 'green'
spinner.start()

const projectPath = name
const preferences = (conf.get('preferences') || {}) as { checkContent?: boolean; checkDependencies?: boolean }

const projectPath = name || process.cwd()

if (!projectPath) {
console.log(
Expand All @@ -26,14 +40,23 @@ export const scannerCommand = async (name: string) => {
process.exit(1)
}

if (process.argv.includes('--check-content') || process.argv.includes('--no-check-content')) {
preferences.checkContent = options.checkContent ?? true
}

if (process.argv.includes('--check-dependencies') || process.argv.includes('--no-check-dependencies')) {
preferences.checkDependencies = options.checkDependencies ?? true
}
console.log(preferences.checkDependencies)
try {
const resolvedProjectPath = path.resolve(projectPath)

const files = await scanFolder(resolvedProjectPath)

const report = await generateReport(files, {
root: resolvedProjectPath,
checkContent: true,
checkContent: preferences.checkContent ?? true,
checkDependencies: preferences.checkDependencies ?? true,
})

spinner.stop()
Expand All @@ -44,5 +67,7 @@ export const scannerCommand = async (name: string) => {
})
} catch {
spinner.fail()
} finally {
conf.set('preferences', preferences)
}
}
12 changes: 11 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { checkUpdates } from './utils/checkUpdates'
export const program = new Command(packageJson.name)
.version(packageJson.version)
.usage(`${green('[command]')} ${green('[options]')}`)
.option('--reset-preferences', 'explicitly tell the CLI to reset any stored preferences')
.hook('postAction', async () => {
await checkUpdates()
})
Expand All @@ -26,6 +27,15 @@ export const program = new Command(packageJson.name)

//TODO: add option --output -o support csv, json yaml html table
//TODO: add option --verbose --quite
program.command('scan').argument('[project-directory]').action(scannerCommand).allowUnknownOption()
program
.command('scan')
.argument('[project-directory]')
.option('-m, --mode <arg>', 'select the mode in which the information will be printed.')
.option('--no-check-content')
.option('--check-content')
.option('--check-dependencies')
.option('--no-check-dependencies')
.action(scannerCommand)
.allowUnknownOption()

program.parse(process.argv)
1 change: 0 additions & 1 deletion packages/scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"description": "Simple scan the technologies used in a TypeScript/JavaScript project.",
"keywords": ["frameworks", "scanner", "files", "projects"],
"license": "MPL-2.0",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
Loading

0 comments on commit e33312e

Please sign in to comment.