{"version":3,"file":"impl-vT81cEv-.mjs","names":[],"sources":["../src/lib/code-scanning/findCodePackagesInFolder.ts","../src/commands/inventory/scan-packages/impl.ts"],"sourcesContent":["import { getEntries } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport fastGlob from 'fast-glob';\n\nimport { CodePackageInput } from '../../codecs.js';\nimport { logger } from '../../logger.js';\nimport { CODE_SCANNING_CONFIGS } from './constants.js';\n\n/**\n * Helper to scan and discovery all of the code packages within a folder\n *\n * @param options - Options\n * @returns the list of integrations\n */\nexport async function findCodePackagesInFolder({\n  scanPath,\n  ignoreDirs = [],\n  repositoryName,\n}: {\n  /** The name of the github repository reporting packages for */\n  repositoryName: string;\n  /** Where to look for package.json files */\n  scanPath: string;\n  /** The directories to ignore (excludes node_modules and serverless-build) */\n  ignoreDirs?: string[];\n}): Promise<CodePackageInput[]> {\n  const allCodePackages = await Promise.all(\n    getEntries(CODE_SCANNING_CONFIGS).map(async ([codePackageType, config]) => {\n      const { ignoreDirs: configIgnoreDirs, supportedFiles, scanFunction } = config;\n      const dirsToIgnore = [...ignoreDirs, ...configIgnoreDirs].filter((dir) => dir.length > 0);\n      try {\n        const filesToScan: string[] = await fastGlob(`${scanPath}/**/${supportedFiles.join('|')}`, {\n          ignore: dirsToIgnore.map((dir: string) => `${scanPath}/**/${dir}`),\n          unique: true,\n          onlyFiles: true,\n        });\n        logger.info(\n          colors.magenta(`Scanning: ${filesToScan.length} files of type ${codePackageType}`),\n        );\n        const allPackages = filesToScan\n          .map((filePath) =>\n            scanFunction(filePath).map((result) => ({\n              ...result,\n              relativePath: filePath.replace(`${scanPath}/`, ''),\n            })),\n          )\n          .flat();\n        logger.info(\n          colors.green(\n            `Found: ${allPackages.length} packages and ${\n              allPackages.map(({ softwareDevelopmentKits = [] }) => softwareDevelopmentKits).flat()\n                .length\n            } sdks`,\n          ),\n        );\n\n        return allPackages.map(\n          (pkg): CodePackageInput => ({\n            ...pkg,\n            type: codePackageType,\n            repositoryName,\n          }),\n        );\n      } catch (error) {\n        throw new Error(`Error scanning globs ${supportedFiles} with error: ${error}`);\n      }\n    }),\n  );\n\n  return allCodePackages.flat();\n}\n","import { execSync } from 'child_process';\n\nimport { buildTranscendGraphQLClient } from '@transcend-io/sdk';\nimport colors from 'colors';\n\nimport { ADMIN_DASH } from '../../../constants.js';\nimport type { LocalContext } from '../../../context.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { findCodePackagesInFolder } from '../../../lib/code-scanning/index.js';\nimport { syncCodePackages } from '../../../lib/graphql/index.js';\nimport { logger } from '../../../logger.js';\n\nconst REPO_ERROR =\n  'A repository name must be provided. ' +\n  'You can specify using --repositoryName=$REPO_NAME or by ensuring the ' +\n  'command \"git config --get remote.origin.url\" returns the name of the repository';\n\nexport interface ScanPackagesCommandFlags {\n  auth: string;\n  scanPath: string;\n  ignoreDirs?: string[];\n  repositoryName?: string;\n  transcendUrl: string;\n}\n\nexport async function scanPackages(\n  this: LocalContext,\n  { auth, scanPath, ignoreDirs, repositoryName, transcendUrl }: ScanPackagesCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n\n  // Ensure repository name is specified\n  let gitRepositoryName = repositoryName;\n  if (!gitRepositoryName) {\n    try {\n      const name = execSync(`cd ${scanPath} && git config --get remote.origin.url`);\n      // Trim and parse the URL\n      const url = name.toString('utf-8').trim();\n      [gitRepositoryName] = !url.includes('https:')\n        ? (url.split(':').pop() || '').split('.')\n        : url.split('/').slice(3).join('/').split('.');\n      if (!gitRepositoryName) {\n        logger.error(colors.red(REPO_ERROR));\n        this.process.exit(1);\n      }\n    } catch (err) {\n      logger.error(colors.red(`${REPO_ERROR} - Got error: ${err.message}`));\n      this.process.exit(1);\n    }\n  }\n\n  // Create a GraphQL client\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n  // Scan the codebase to discovery packages\n  const results = await findCodePackagesInFolder({\n    scanPath,\n    ignoreDirs,\n    repositoryName: gitRepositoryName,\n  });\n\n  // Report scan to Transcend\n  await syncCodePackages(client, results);\n\n  const newUrl = new URL(ADMIN_DASH);\n  newUrl.pathname = '/code-scanning/code-packages';\n\n  // Indicate success\n  logger.info(\n    colors.green(\n      `Scan found ${results.length} packages at ${scanPath}! ` + `View results at '${newUrl.href}'`,\n    ),\n  );\n}\n"],"mappings":"qbAcA,eAAsB,EAAyB,CAC7C,WACA,aAAa,EAAE,CACf,kBAQ8B,CA4C9B,OAAO,MA3CuB,QAAQ,IACpC,EAAW,EAAsB,CAAC,IAAI,MAAO,CAAC,EAAiB,KAAY,CACzE,GAAM,CAAE,WAAY,EAAkB,iBAAgB,gBAAiB,EACjE,EAAe,CAAC,GAAG,EAAY,GAAG,EAAiB,CAAC,OAAQ,GAAQ,EAAI,OAAS,EAAE,CACzF,GAAI,CACF,IAAM,EAAwB,MAAM,EAAS,GAAG,EAAS,MAAM,EAAe,KAAK,IAAI,GAAI,CACzF,OAAQ,EAAa,IAAK,GAAgB,GAAG,EAAS,MAAM,IAAM,CAClE,OAAQ,GACR,UAAW,GACZ,CAAC,CACF,EAAO,KACL,EAAO,QAAQ,aAAa,EAAY,OAAO,iBAAiB,IAAkB,CACnF,CACD,IAAM,EAAc,EACjB,IAAK,GACJ,EAAa,EAAS,CAAC,IAAK,IAAY,CACtC,GAAG,EACH,aAAc,EAAS,QAAQ,GAAG,EAAS,GAAI,GAAG,CACnD,EAAE,CACJ,CACA,MAAM,CAUT,OATA,EAAO,KACL,EAAO,MACL,UAAU,EAAY,OAAO,gBAC3B,EAAY,KAAK,CAAE,0BAA0B,EAAE,IAAO,EAAwB,CAAC,MAAM,CAClF,OACJ,OACF,CACF,CAEM,EAAY,IAChB,IAA2B,CAC1B,GAAG,EACH,KAAM,EACN,iBACD,EACF,OACM,EAAO,CACd,MAAU,MAAM,wBAAwB,EAAe,eAAe,IAAQ,GAEhF,CACH,EAEsB,MAAM,CCzD/B,MAAM,EACJ,2LAYF,eAAsB,EAEpB,CAAE,OAAM,WAAU,aAAY,iBAAg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