import { ensureDir , existsSync , readJson , remove , writeJson } from "fs-extra" ; import { resolve } from "path" ; import { MonoRepo , Package } from "./types" ; param { string } monoRepoDir returns { Promise } export const deleteMonoRepo = async ( monoRepoDir ) : Promise < void > => { await remove ( monoRepoDir ) ; } ; param { string } monoRepoDir param { Object } monoRepo param { Object [ ] } packages returns { Promise } export const createMonoRepo = async ( monoRepoDir , monoRepo , packages ) : Promise < void > => { await deleteMonoRepo ( monoRepoDir ) ; await ensureDir ( monoRepoDir ) ; await writeJson ( resolve ( monoRepoDir , "package.json" ) , { ... monoRepo , private : true } , { spaces : 2 } ) ; await Promise . all ( packages . map ( async ( x ) => { await ensureDir ( x . __dir ) ; await writeJson ( resolve ( x . __dir , "package.json" ) , x , { spaces : 2 } ) ; } ) ) ; } ; param { string } currentDir returns { Promise } export const getMonoRepo = async ( currentDir ) : Promise < MonoRepo | null > => { const packageJsonExists = existsSync ( resolve ( currentDir , "package.json" ) ) ; if ( packageJsonExists ) { const packageJson = await readJson ( resolve ( currentDir , "package.json" ) ) ; if ( packageJson . private === true && Array . isArray ( packageJson . workspaces ) ) { return { ... packageJson , __dir : currentDir } ; } } const directoryUp = resolve ( currentDir , ".." ) ; if ( directoryUp === currentDir ) { return null ; } return getMonoRepo ( directoryUp ) ; } ;