From e33312e1c157011074971559bb0d40a38ced8ffc Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 12 Jul 2024 22:12:06 -0500 Subject: [PATCH] feat(cli): add new options to scanner --- packages/cli/package.json | 2 +- packages/cli/src/commands/scan.ts | 31 +++++++- packages/cli/src/index.ts | 12 ++- packages/scanner/package.json | 1 - pnpm-lock.yaml | 125 ++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+), 6 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index a6c0734..f0be6aa 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -8,7 +8,6 @@ "name": "Sebastian Beltran" }, "keywords": ["cli", "frameworks", "set up", "rapidapp", "tools"], - "type": "module", "bin": { "rapidapp": "dist/index.js" }, @@ -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", diff --git a/packages/cli/src/commands/scan.ts b/packages/cli/src/commands/scan.ts index 2c2d2e1..0d81c4c 100644 --- a/packages/cli/src/commands/scan.ts +++ b/packages/cli/src/commands/scan.ts @@ -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( @@ -26,6 +40,14 @@ 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) @@ -33,7 +55,8 @@ export const scannerCommand = async (name: string) => { const report = await generateReport(files, { root: resolvedProjectPath, - checkContent: true, + checkContent: preferences.checkContent ?? true, + checkDependencies: preferences.checkDependencies ?? true, }) spinner.stop() @@ -44,5 +67,7 @@ export const scannerCommand = async (name: string) => { }) } catch { spinner.fail() + } finally { + conf.set('preferences', preferences) } } diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index d5e4d57..c4f244e 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -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() }) @@ -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 ', '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) diff --git a/packages/scanner/package.json b/packages/scanner/package.json index 444f1e9..cf1c14a 100644 --- a/packages/scanner/package.json +++ b/packages/scanner/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4213a2a..caede23 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -55,6 +55,9 @@ importers: commander: specifier: 12.1.0 version: 12.1.0 + conf: + specifier: 13.0.1 + version: 13.0.1 ora: specifier: 8.0.1 version: 8.0.1 @@ -880,6 +883,17 @@ packages: engines: {node: '>=0.4.0'} hasBin: true + ajv-formats@3.0.1: + resolution: {integrity: sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==} + peerDependencies: + ajv: ^8.0.0 + peerDependenciesMeta: + ajv: + optional: true + + ajv@8.17.1: + resolution: {integrity: sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==} + ansi-align@3.0.1: resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} @@ -959,6 +973,9 @@ packages: engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0'} hasBin: true + atomically@2.0.3: + resolution: {integrity: sha512-kU6FmrwZ3Lx7/7y3hPS5QnbJfaohcIul5fGqf7ok+4KklIEk9tJ0C2IQPdacSbVUWv6zVHXEBWoWd6NrVMT7Cw==} + available-typed-arrays@1.0.7: resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==} engines: {node: '>= 0.4'} @@ -1132,6 +1149,10 @@ packages: common-ancestor-path@1.0.1: resolution: {integrity: sha512-L3sHRo1pXXEqX8VU28kfgUY+YGsk09hPqZiZmLacNib6XNTCM8ubYeT7ryXQw8asB1sKgcU5lkB7ONug08aB8w==} + conf@13.0.1: + resolution: {integrity: sha512-l9Uwc9eOnz39oADzGO2cSBDi7siv8lwO+31ocQ2nOJijnDiW3pxqm9VV10DPYUO28wW83DjABoUqY1nfHRR2hQ==} + engines: {node: '>=18'} + convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} @@ -1163,6 +1184,10 @@ packages: resolution: {integrity: sha512-t/Ygsytq+R995EJ5PZlD4Cu56sWa8InXySaViRzw9apusqsOO2bQP+SbYzAhR0pFKoB+43lYy8rWban9JSuXnA==} engines: {node: '>= 0.4'} + debounce-fn@6.0.0: + resolution: {integrity: sha512-rBMW+F2TXryBwB54Q0d8drNEI+TfoS9JpNTAoVpukbWEhjXQq4rySFYLaqXMFXwdv61Zb2OHtj5bviSoimqxRQ==} + engines: {node: '>=18'} + debug@4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -1233,6 +1258,10 @@ packages: dlv@1.1.3: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} + dot-prop@9.0.0: + resolution: {integrity: sha512-1gxPBJpI/pcjQhKgIU91II6Wkay+dLcN3M6rf2uwP8hRur3HtQXjVrdAK3sjC0piaEuxzMwjXChcETiJl47lAQ==} + engines: {node: '>=18'} + dset@3.1.3: resolution: {integrity: sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==} engines: {node: '>=4'} @@ -1259,6 +1288,10 @@ packages: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} + env-paths@3.0.0: + resolution: {integrity: sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + es-abstract@1.23.3: resolution: {integrity: sha512-e+HfNH61Bj1X9/jLc5v1owaLYuHdeHHSQlkhCBiTK8rBvKaULl/beGMxwrMXjpYrv4pz22BlY570vVePA2ho4A==} engines: {node: '>= 0.4'} @@ -1347,10 +1380,16 @@ packages: extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + fast-deep-equal@3.1.3: + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} + fast-uri@3.0.1: + resolution: {integrity: sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==} + fastq@1.17.1: resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} @@ -1764,6 +1803,12 @@ packages: engines: {node: '>=4'} hasBin: true + json-schema-traverse@1.0.0: + resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} + + json-schema-typed@8.0.1: + resolution: {integrity: sha512-XQmWYj2Sm4kn4WeTYvmpKEbyPsL7nBsb647c7pMe6l02/yx2+Jfc4dT6UZkEXnIUb5LhD55r2HPsJ1milQ4rDg==} + json5@2.2.3: resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} engines: {node: '>=6'} @@ -2039,6 +2084,10 @@ packages: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} + mimic-function@5.0.1: + resolution: {integrity: sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==} + engines: {node: '>=18'} + minimatch@9.0.3: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} engines: {node: '>=16 || 14 >=14.17'} @@ -2354,6 +2403,10 @@ packages: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} + require-from-string@2.0.2: + resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} + engines: {node: '>=0.10.0'} + resolve-from@5.0.0: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} @@ -2565,6 +2618,9 @@ packages: resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} engines: {node: '>=0.10.0'} + stubborn-fs@1.2.5: + resolution: {integrity: sha512-H2N9c26eXjzL/S/K+i/RHHcFanE74dptvvjM8iwzwbVcWY/zjBbgRqF3K0DY4+OD+uTTASTBvDoxPDaPN02D7g==} + style-to-object@0.4.4: resolution: {integrity: sha512-HYNoHZa2GorYNyqiCaBgsxvcJIn7OHq6inEga+E6Ke3m5JkoqpQbnFssk4jwe+K7AhGa2fcha4wSOf1Kn01dMg==} @@ -2696,6 +2752,10 @@ packages: resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} engines: {node: '>=12.20'} + type-fest@4.21.0: + resolution: {integrity: sha512-ADn2w7hVPcK6w1I0uWnM//y1rLXZhzB9mr0a3OirzclKF1Wp6VzevUmzz/NRAWunOT6E8HrnpGY7xOfc6K57fA==} + engines: {node: '>=16'} + typed-array-buffer@1.0.2: resolution: {integrity: sha512-gEymJYKZtKXzzBzM4jqa9w6Q1Jjm7x2d+sh19AdsD4wqnMPDYyvwpsIc2Q/835kHuo3BEQ7CjelGhfTsoBb2MQ==} engines: {node: '>= 0.4'} @@ -2723,6 +2783,10 @@ packages: engines: {node: '>=14.17'} hasBin: true + uint8array-extras@1.3.0: + resolution: {integrity: sha512-npBAT0ZIX6mAIG7SF6G4LF1BIoRx3h+HVajSplHx0XmOD0Ug4qio5Yhcajn72i5OEj/qkk1OFaYh2PhqHBV33w==} + engines: {node: '>=18'} + unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} @@ -2941,6 +3005,9 @@ packages: whatwg-url@7.1.0: resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} + when-exit@2.1.3: + resolution: {integrity: sha512-uVieSTccFIr/SFQdFWN/fFaQYmV37OKtuaGphMAzi4DmmUlrvRBJW5WSLkHyjNQY/ePJMz3LoiX9R3yy1Su6Hw==} + which-boxed-primitive@1.0.2: resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} @@ -3860,6 +3927,17 @@ snapshots: acorn@8.12.1: {} + ajv-formats@3.0.1(ajv@8.17.1): + optionalDependencies: + ajv: 8.17.1 + + ajv@8.17.1: + dependencies: + fast-deep-equal: 3.1.3 + fast-uri: 3.0.1 + json-schema-traverse: 1.0.0 + require-from-string: 2.0.2 + ansi-align@3.0.1: dependencies: string-width: 4.2.3 @@ -4005,6 +4083,11 @@ snapshots: - terser - typescript + atomically@2.0.3: + dependencies: + stubborn-fs: 1.2.5 + when-exit: 2.1.3 + available-typed-arrays@1.0.7: dependencies: possible-typed-array-names: 1.0.0 @@ -4179,6 +4262,18 @@ snapshots: common-ancestor-path@1.0.1: {} + conf@13.0.1: + dependencies: + ajv: 8.17.1 + ajv-formats: 3.0.1(ajv@8.17.1) + atomically: 2.0.3 + debounce-fn: 6.0.0 + dot-prop: 9.0.0 + env-paths: 3.0.0 + json-schema-typed: 8.0.1 + semver: 7.6.2 + uint8array-extras: 1.3.0 + convert-source-map@2.0.0: {} cookie@0.6.0: {} @@ -4211,6 +4306,10 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.1 + debounce-fn@6.0.0: + dependencies: + mimic-function: 5.0.1 + debug@4.3.4: dependencies: ms: 2.1.2 @@ -4264,6 +4363,10 @@ snapshots: dlv@1.1.3: {} + dot-prop@9.0.0: + dependencies: + type-fest: 4.21.0 + dset@3.1.3: {} eastasianwidth@0.2.0: {} @@ -4283,6 +4386,8 @@ snapshots: entities@4.5.0: {} + env-paths@3.0.0: {} + es-abstract@1.23.3: dependencies: array-buffer-byte-length: 1.0.1 @@ -4457,6 +4562,8 @@ snapshots: extend@3.0.2: {} + fast-deep-equal@3.1.3: {} + fast-glob@3.3.2: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -4465,6 +4572,8 @@ snapshots: merge2: 1.4.1 micromatch: 4.0.5 + fast-uri@3.0.1: {} + fastq@1.17.1: dependencies: reusify: 1.0.4 @@ -4959,6 +5068,10 @@ snapshots: jsesc@2.5.2: {} + json-schema-traverse@1.0.0: {} + + json-schema-typed@8.0.1: {} + json5@2.2.3: {} jsonc-parser@2.3.1: {} @@ -5525,6 +5638,8 @@ snapshots: mimic-fn@4.0.0: {} + mimic-function@5.0.1: {} + minimatch@9.0.3: dependencies: brace-expansion: 2.0.1 @@ -5893,6 +6008,8 @@ snapshots: require-directory@2.1.1: {} + require-from-string@2.0.2: {} + resolve-from@5.0.0: {} restore-cursor@4.0.0: @@ -6152,6 +6269,8 @@ snapshots: strip-json-comments@2.0.1: {} + stubborn-fs@1.2.5: {} + style-to-object@0.4.4: dependencies: inline-style-parser: 0.1.1 @@ -6267,6 +6386,8 @@ snapshots: type-fest@2.19.0: {} + type-fest@4.21.0: {} + typed-array-buffer@1.0.2: dependencies: call-bind: 1.0.7 @@ -6307,6 +6428,8 @@ snapshots: typescript@5.5.3: {} + uint8array-extras@1.3.0: {} + unbox-primitive@1.0.2: dependencies: call-bind: 1.0.7 @@ -6552,6 +6675,8 @@ snapshots: tr46: 1.0.1 webidl-conversions: 4.0.2 + when-exit@2.1.3: {} + which-boxed-primitive@1.0.2: dependencies: is-bigint: 1.0.4