const fs = require("node:fs/promises"); /** Give the generated MSI shortcut its own optional component. */ module.exports = async function msiShortcuts(projectFile) { let xml = await fs.readFile(projectFile, "utf8"); const shortcut = xml.match(/]*\/>/g); if ( shortcut?.length !== 1 || !xml.includes('') ) { throw new Error( "Unexpected MSI template: desktop shortcut or assisted UI missing", ); } const link = shortcut[0].replace( ' Advertise="yes"', ' Target="[#mainExecutable]"', ); xml = xml.replace(shortcut[0], ""); xml = xml.replace( '', '\n ', ); xml = xml.replace( "", ` TERMIX_DESKTOP_SHORTCUT = "1" ${link} WixAppFolder = "WixPerMachineFolder" WixAppFolder = "WixPerUserFolder" 1 1 `, ); xml = xml.replace( /(1<\/Publish>/g, 'WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"', ); xml = xml.replace( /(') ) { throw new Error("Unexpected MSI template: shortcut dialog routing missing"); } await fs.writeFile(projectFile, xml); };