import { useAppContext } from '@modern-js/core' ; import { getMonorepoBaseData } from '../parse-config/monorepo' ; import { runBuildTask , runAllBuildTask } from '../features/build' ; import { getProjects } from '../projects/get-projects' ; import { initDAG } from '../dag' ; export interface IBuildCommandOption { self ? : boolean ; dept ? : boolean ; deps ? : boolean ; onlySelf : boolean ; all : boolean ; contentHash ? : boolean ; gitHash ? : boolean ; } export const build = async ( targetProjectName , option ) => { const { appDirectory } = useAppContext ( ) ; const { self = true , dept = false , deps = true , onlySelf = false , all = false , contentHash = false , gitHash = false , } = option ; const projects = await getProjects ( { packagesMatchs : { enableAutoFinder : true } } , appDirectory ) ; const operator = initDAG ( projects ) ; operator . checkCircle ( ) ; const { rootPath , packageManager } = getMonorepoBaseData ( appDirectory ) ; const overrideConfig = { } ; if ( all ) { overrideConfig . disableWithDeps = false ; overrideConfig . withSelf = true ; overrideConfig . withDept = true ; } if ( targetProjectName ) { runBuildTask ( targetProjectName , operator , { rootPath , packageManager , withSelf : self , withDept : dept , onlySelf , disableWithDeps : ! deps , disableContentHash : ! contentHash , enableGitHash : gitHash , ... overrideConfig , } ) ; } else { const currentDir = process . cwd ( ) ; if ( currentDir === appDirectory ) { await runAllBuildTask ( operator , { rootPath : currentDir , packageManager , disableContentHash : ! contentHash , enableGitHash : gitHash , } ) ; } } } ;