{"version":3,"sources":["../../../packages/tools/wac-cli/src/upgrade/file-updater.ts"],"names":[],"mappings":"AAIA,qBAAa,WAAW;IACb,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,GAAG,IAAI;IAgEjI,OAAO,CAAC,oBAAoB;IAqB5B,OAAO,CAAC,0BAA0B;IA4BlC,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;CAQ5B","file":"file-updater.d.ts","sourcesContent":["import fs from 'fs';\r\nimport fse from 'fs-extra';\r\nimport { Common } from '../common';\r\n\r\nexport class FileUpdater {\r\n    public copyNewFiles(audit: boolean, internal: boolean, updateSource: string[], library: boolean, internalOverride: boolean): void {\r\n        if (audit) {\r\n            return;\r\n        }\r\n\r\n        const ignoresPath = Common.cliRootPath + 'templates\\\\ignores';\r\n        const internalPath = Common.cliRootPath + 'templates\\\\internal';\r\n        const libraryPath = Common.cliRootPath + 'templates\\\\library';\r\n        const gulpPath = Common.moduleTemplatePath + 'gulpfile.ts';\r\n        const upgradedTemplatePath = Common.cliRootPath + 'templates\\\\wac-template';\r\n\r\n        fse.copyFileSync(ignoresPath + '\\\\git.txt', '.\\\\.gitignore');\r\n        fse.copyFileSync(ignoresPath + '\\\\npm.txt', '.\\\\.npmignore');\r\n        fse.copyFileSync(ignoresPath + '\\\\browserslistrc.txt', '.\\\\.browserslistrc');\r\n        fse.copyFileSync((internal ? internalPath : upgradedTemplatePath) + '\\\\.eslintrc.json', '.\\\\.eslintrc.json');\r\n        fse.copySync(gulpPath + '\\\\common', '.\\\\gulpfile.ts\\\\common');\r\n        fse.copyFileSync(gulpPath + '\\\\index.ts', '.\\\\gulpfile.ts\\\\index.ts');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\tsconfig.base.json', '.\\\\tsconfig.base.json');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\tsconfig.json', '.\\\\tsconfig.json');\r\n        fse.copyFileSync((library ? libraryPath : upgradedTemplatePath) + '\\\\angular.json', '.\\\\angular.json');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\src\\\\tsconfig.app.json', '.\\\\src\\\\tsconfig.app.json');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\src\\\\tsconfig.spec.json', '.\\\\src\\\\tsconfig.spec.json');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\src\\\\polyfills.ts', '.\\\\src\\\\polyfills.ts');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\src\\\\karma.conf.js', '.\\\\src\\\\karma.conf.js');\r\n        fse.copyFileSync(upgradedTemplatePath + '\\\\src\\\\test.ts', '.\\\\src\\\\test.ts');\r\n\r\n        this.updateGulpConfigFile('.\\\\gulpfile.ts\\\\config-data.ts', library);\r\n\r\n        if (internal || internalOverride) {\r\n            fse.copyFileSync(internalPath + '\\\\version.ts', '.\\\\src\\\\version.ts');\r\n            fse.copySync(internalPath + '\\\\azuredevops', '.\\\\.azuredevops');\r\n            fse.copySync(Common.moduleTemplatePath + '\\\\build', '.\\\\build');\r\n            this.updateLocalizationPipeline('.\\\\loc\\\\locConfig.xml', '.\\\\build\\\\pipelines\\\\localization.yml', updateSource);\r\n            this.updateMainFile(internalPath + '\\\\main.ts', '.\\\\src\\\\main.ts');\r\n            this.updateVersionJson(internalPath + '\\\\version.json', '.\\\\version.json');\r\n        }\r\n\r\n        if (library) {\r\n            fse.copyFileSync(libraryPath + '\\\\tsconfig.lib.json', '.\\\\src\\\\tsconfig.lib.json');\r\n            fse.copyFileSync(libraryPath + '\\\\tsconfig.lib.prod.json', '.\\\\src\\\\tsconfig.lib.prod.json');\r\n            fse.copyFileSync(libraryPath + '\\\\ng-package.json', '.\\\\src\\\\ng-package.json');\r\n            fse.copyFileSync(libraryPath + '\\\\package.json', '.\\\\src\\\\package.json');\r\n            fse.copyFileSync(libraryPath + '\\\\public_api.ts', '.\\\\src\\\\public_api.ts');\r\n\r\n            if (!fse.existsSync('.\\\\src\\\\app\\\\index.ts')) {\r\n                fse.copyFileSync(libraryPath + '\\\\index.ts', '.\\\\src\\\\app\\\\index.ts');\r\n            }\r\n        }\r\n\r\n        if (fse.existsSync('.\\\\tsconfig.inline.json')) {\r\n            fs.unlinkSync('.\\\\tsconfig.inline.json');\r\n        }\r\n\r\n        if (fse.existsSync('.\\\\index.js')) {\r\n            fs.unlinkSync('.\\\\index.js');\r\n        }\r\n\r\n        if (fse.existsSync('.\\\\index.d.ts')) {\r\n            fs.unlinkSync('.\\\\index.d.ts');\r\n        }\r\n\r\n        console.log('All new config and json files have been transferred.');\r\n    }\r\n\r\n    private updateGulpConfigFile(filePath: string, library: boolean): void {\r\n        let fileData = Common.readFileData(filePath);\r\n\r\n        fileData = fileData.replace('\\nfunction gulpConfig():', '\\nexport function gulpConfig():');\r\n        fileData = fileData.replace('\\nexports.gulpConfig = gulpConfig;', '');\r\n\r\n        if (library) {\r\n            if (fileData.search('build: {') === -1) {\r\n                const captureInsertLocation = /(?<=powershell: {[\\s\\S]+\\s+)}/;\r\n                fileData = Common.replaceInString(fileData, captureInsertLocation, `},\\n${' '.repeat(8)}build: {\\n${' '.repeat(12)}library: true\\n${' '.repeat(8)}}`);\r\n            } else if (fileData.search('library: ') === -1) {\r\n                const captureInsertLocation = /(?<=build: ){/;\r\n                fileData = Common.replaceInString(fileData, captureInsertLocation, `{\\n${' '.repeat(12)}library: true,`);\r\n            } else {\r\n                fileData = fileData.replace('library: false', 'library: true');\r\n            }\r\n        }\r\n\r\n        fse.writeFileSync(filePath, fileData);\r\n    }\r\n\r\n    private updateLocalizationPipeline(locFilePath: string, pipelineFilePath: string, updateSource: string[]): void {\r\n        const captureTFSSourceDirectory = /(?<=path=\")%.+%\\\\(?=.*\"\\s)/;\r\n        const captureModuleId = /(?<=name=\").+(?=.*\"\\s)/;\r\n\r\n        if (!fse.existsSync(locFilePath)) {\r\n            const message = `Path ${locFilePath} does not exist. Please verify this file exists.`;\r\n            console.log(message);\r\n            updateSource.push(message + '\\n');\r\n            return;\r\n        }\r\n\r\n        let locFileData = Common.readFileData(locFilePath);\r\n        locFileData = Common.replaceInString(locFileData, captureTFSSourceDirectory, '');\r\n        fse.writeFileSync(locFilePath, locFileData);\r\n\r\n        const moduleId = locFileData.match(captureModuleId);\r\n        if (!moduleId || moduleId.length === 0) {\r\n            const message = `Couldn't retrieve localization module ID from ${locFilePath}, localization ID will need to be updated manually.`;\r\n            console.log(message);\r\n            updateSource.push(message + '\\n');\r\n            return;\r\n        }\r\n\r\n        let pipelineFileData = Common.readFileData(pipelineFilePath);\r\n        pipelineFileData = pipelineFileData.replace('${module-id}', moduleId[0]);\r\n        fse.writeFileSync(pipelineFilePath, pipelineFileData);\r\n    }\r\n\r\n    private updateMainFile(internalFilePath: string, targetFilePath: string) {\r\n        let fileData: string = Common.readFileData(targetFilePath);\r\n        const captureName = /(?<=name: ').*(?=')/;\r\n        const name = fileData.match(captureName)[0];\r\n\r\n        fse.copyFileSync(internalFilePath, targetFilePath);\r\n        fileData = Common.readFileData(targetFilePath);\r\n        fileData = fileData.replace(`{!company-name}.{!product-name}`, name);\r\n\r\n        fse.writeFileSync(targetFilePath, fileData);\r\n    }\r\n\r\n    private updateVersionJson(internalFilePath: string, targetFilePath: string) {\r\n        const newVersion = Common.readFileJSON(internalFilePath).version;\r\n\r\n        const versionData = Common.readFileJSON(targetFilePath);\r\n        versionData.version = newVersion;\r\n\r\n        fse.writeJSONSync(targetFilePath, versionData, { spaces: 2 });\r\n    }\r\n}\r\n"]}