import getPathToTargetWorkspaceRootDirFromCLIArgs from './getPathToTargetWorkspaceRootDirFromCLIArgs' ; import getTargetWorkspaceRootPackageJsonConfigContent from './getTargetWorkspaceRootPackageJsonConfigContent' ; import getTargetWorkspacePackagesAbsolutePaths from './getTargetWorkspacePackagesAbsolutePaths' ; import getPackageJsonConfigContentFromProvidedPackagePath from './getPackageJsonConfigContentFromProvidedPackagePath' ; import { TGetTargetWorkspaceInfo , TargetWorkspaceInfo , TargetPackageInfo , } from '../../types' ; /**
 * Find and read all workspace info (root info, packages, scripts, versions, etc.) from the target workspace directory.
 */ const getTargetWorkspaceInfo = async ( ) => { const pathToTargetWorkspaceDir = getPathToTargetWorkspaceRootDirFromCLIArgs ( ) ; const targetWorkspaceRootPackageJsonConfigContent = await getTargetWorkspaceRootPackageJsonConfigContent ( ) ; const targetWorkspacePackagesAbsolutePaths = await getTargetWorkspacePackagesAbsolutePaths ( ) ; const packagesPkgJsonConfigContent = await Promise . all ( targetWorkspacePackagesAbsolutePaths . map ( pathToPackageDir => getPackageJsonConfigContentFromProvidedPackagePath ( pathToPackageDir ) ) ) ; const packagesInfo = packagesPkgJsonConfigContent . reduce ( ( acc , packagePkgJsonConfigContent ) : TargetWorkspaceInfo [ 'packagesInfo' ] => { const packageInfo = { pathToPackageDir : '' , packageJsonConfigContent : packagePkgJsonConfigContent , } ; return { ... acc , [ packagePkgJsonConfigContent . name as string ] : packageInfo , } ; } , { } ) as TargetWorkspaceInfo [ 'packagesInfo' ] ; return { rootInfo : { name : targetWorkspaceRootPackageJsonConfigContent . name as string , pathToRootDir : pathToTargetWorkspaceDir , packageJsonConfigContent : targetWorkspaceRootPackageJsonConfigContent , } , packagesInfo , } ; } ; export default getTargetWorkspaceInfo ;