const fs = require ( "fs" ) ; const path = require ( "path" ) ; const util = require ( "util" ) ; const testPackages = [ "@types/mocha" , "@types/node" , "current-processes" , "mocha" , "office-addin-mock" , "office-addin-test-helpers" , "office-addin-test-server" , "ts-node" , ] ; const readFileAsync = util . promisify ( fs . readFile ) ; const unlinkFileAsync = util . promisify ( fs . unlink ) ; const writeFileAsync = util . promisify ( fs . writeFile ) ; async function removeTestInfraStructure ( ) { deleteFolder ( path . resolve ( `./test` ) ) ; deleteFolder ( path . resolve ( `./.github` ) ) ; deleteFolder ( path . resolve ( `./.azure-devops` ) ) ; await updatePackageJsonFile ( ) ; await updateLaunchJsonFile ( ) ; await unlinkFileAsync ( "./convertToSingleHost.js" ) ; } async function updatePackageJsonFile ( ) { const packageJson = `./package.json` ; const data = await readFileAsync ( packageJson , "utf8" ) ; let content = JSON . parse ( data ) ; Object . keys ( content . scripts ) . forEach ( function ( key ) { if ( key === "convert-to-single-host" || key === "test" ) { delete content . scripts [ key ] ; } } ) ; Object . keys ( content . devDependencies ) . forEach ( function ( key ) { if ( testPackages . includes ( key ) ) { delete content . devDependencies [ key ] ; } } ) ; await writeFileAsync ( packageJson , JSON . stringify ( content , null , 2 ) ) ; } async function updateLaunchJsonFile ( ) { const launchJson = `.vscode/launch.json` ; const launchJsonContent = await readFileAsync ( launchJson , "utf8" ) ; const regex = /(.+{\r?\n.*"name": "Debug (?:UI|Unit) Tests",\r?\n(?:.*\r?\n)*?.*},.*\r?\n)/gm ; const updatedContent = launchJsonContent . replace ( regex , "" ) ; await writeFileAsync ( launchJson , updatedContent ) ; } function deleteFolder ( folder ) { try { if ( fs . existsSync ( folder ) ) { fs . readdirSync ( folder ) . forEach ( function ( file , index ) { const curPath = `${ folder }/${ file }` ; if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) { deleteFolder ( curPath ) ; } else { fs . unlinkSync ( curPath ) ; } } ) ; fs . rmdirSync ( folder ) ; } } catch ( err ) { throw new Error ( `Unable to delete folder "${ folder }".\n${ err }` ) ; } } /**
 * Remove test infrastructure from project.
 */ removeTestInfraStructure ( ) . catch ( ( err ) => { console . error ( `Error: ${ err instanceof Error ? err . message : err }` ) ; process . exitCode = 1 ; } ) ;