From 669623a228dfdef11316e69d8a188505a0924eb6 Mon Sep 17 00:00:00 2001 From: Alex Ma Date: Fri, 16 Jul 2021 11:01:31 -0700 Subject: [PATCH] Removed async copy in rename function (#16209) * Removed async copy in rename function * added comments and removed async --- build/lib/locFunc.js | 39 ++++++++++++++++++++------------------ build/lib/locFunc.ts | 45 +++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/build/lib/locFunc.js b/build/lib/locFunc.js index df555307d2..514596ee6e 100644 --- a/build/lib/locFunc.js +++ b/build/lib/locFunc.js @@ -266,18 +266,6 @@ function refreshLangpacks() { if (languageId === "zh-tw") { languageId = "zh-hant"; } - //remove extensions not part of ADS. - if (fs.existsSync(translationDataFolder)) { - let totalExtensions = fs.readdirSync(path.join(translationDataFolder, 'extensions')); - for (let extensionTag in totalExtensions) { - let extensionFileName = totalExtensions[extensionTag]; - let xlfPath = path.join(location, `${languageId}`, extensionFileName.replace('.i18n.json', '.xlf')); - if (!(fs.existsSync(xlfPath) || VSCODEExtensions.indexOf(extensionFileName.replace('.i18n.json', '')) !== -1)) { - let filePath = path.join(translationDataFolder, 'extensions', extensionFileName); - rimraf.sync(filePath); - } - } - } console.log(`Importing translations for ${languageId} from '${location}' to '${translationDataFolder}' ...`); let translationPaths = []; gulp.src(path.join(location, languageId, '**', '*.xlf')) @@ -356,6 +344,8 @@ function renameVscodeLangpacks() { } let locADSFolder = path.join('.', 'i18n', `ads-language-pack-${langId}`); let locVSCODEFolder = path.join('.', 'i18n', `vscode-language-pack-${langId}`); + let translationDataFolder = path.join(locVSCODEFolder, 'translations'); + let xlfFolder = path.join('.', 'resources', 'xlf'); try { fs.statSync(locVSCODEFolder); } @@ -363,13 +353,26 @@ function renameVscodeLangpacks() { console.log('vscode pack is not in ADS yet: ' + langId); continue; } - gulp.src(path.join(locADSFolder, '*.md')) - .pipe(rename(filepath => filepath.dirname = '')) - .pipe(gulp.dest(locVSCODEFolder)) - .on('end', () => { - rimraf.sync(locADSFolder); - fs.renameSync(locVSCODEFolder, locADSFolder); + // Delete extension files in vscode language pack that are not in ADS. + if (fs.existsSync(translationDataFolder)) { + let totalExtensions = fs.readdirSync(path.join(translationDataFolder, 'extensions')); + for (let extensionTag in totalExtensions) { + let extensionFileName = totalExtensions[extensionTag]; + let xlfPath = path.join(xlfFolder, `${langId}`, extensionFileName.replace('.i18n.json', '.xlf')); + if (!(fs.existsSync(xlfPath) || VSCODEExtensions.indexOf(extensionFileName.replace('.i18n.json', '')) !== -1)) { + let filePath = path.join(translationDataFolder, 'extensions', extensionFileName); + rimraf.sync(filePath); + } + } + } + //Get list of md files in ADS langpack, to copy to vscode langpack prior to renaming. + let globArray = glob.sync(path.join(locADSFolder, '*.md')); + //Copy files to vscode langpack, then remove the ADS langpack, and finally rename the vscode langpack to match the ADS one. + globArray.forEach(element => { + fs.copyFileSync(element, path.join(locVSCODEFolder, path.parse(element).base)); }); + rimraf.sync(locADSFolder); + fs.renameSync(locVSCODEFolder, locADSFolder); } console.log("Langpack Rename Completed."); return Promise.resolve(); diff --git a/build/lib/locFunc.ts b/build/lib/locFunc.ts index cc199694ae..05128ba18d 100644 --- a/build/lib/locFunc.ts +++ b/build/lib/locFunc.ts @@ -287,20 +287,6 @@ export function refreshLangpacks(): Promise { languageId = "zh-hant"; } - //remove extensions not part of ADS. - if (fs.existsSync(translationDataFolder)) { - let totalExtensions = fs.readdirSync(path.join(translationDataFolder, 'extensions')); - for (let extensionTag in totalExtensions) { - let extensionFileName = totalExtensions[extensionTag]; - let xlfPath = path.join(location, `${languageId}`, extensionFileName.replace('.i18n.json', '.xlf')) - if (!(fs.existsSync(xlfPath) || VSCODEExtensions.indexOf(extensionFileName.replace('.i18n.json', '')) !== -1)) { - let filePath = path.join(translationDataFolder, 'extensions', extensionFileName); - rimraf.sync(filePath); - } - } - } - - console.log(`Importing translations for ${languageId} from '${location}' to '${translationDataFolder}' ...`); let translationPaths: any = []; gulp.src(path.join(location, languageId, '**', '*.xlf')) @@ -380,6 +366,8 @@ export function renameVscodeLangpacks(): Promise { } let locADSFolder = path.join('.', 'i18n', `ads-language-pack-${langId}`); let locVSCODEFolder = path.join('.', 'i18n', `vscode-language-pack-${langId}`); + let translationDataFolder = path.join(locVSCODEFolder, 'translations'); + let xlfFolder = path.join('.', 'resources', 'xlf'); try { fs.statSync(locVSCODEFolder); } @@ -387,13 +375,28 @@ export function renameVscodeLangpacks(): Promise { console.log('vscode pack is not in ADS yet: ' + langId); continue; } - gulp.src(path.join(locADSFolder, '*.md')) - .pipe(rename(filepath => filepath.dirname = '')) - .pipe(gulp.dest(locVSCODEFolder)) - .on('end', () => { - rimraf.sync(locADSFolder); - fs.renameSync(locVSCODEFolder, locADSFolder); - }); + // Delete extension files in vscode language pack that are not in ADS. + if (fs.existsSync(translationDataFolder)) { + let totalExtensions = fs.readdirSync(path.join(translationDataFolder, 'extensions')); + for (let extensionTag in totalExtensions) { + let extensionFileName = totalExtensions[extensionTag]; + let xlfPath = path.join(xlfFolder, `${langId}`, extensionFileName.replace('.i18n.json', '.xlf')) + if (!(fs.existsSync(xlfPath) || VSCODEExtensions.indexOf(extensionFileName.replace('.i18n.json', '')) !== -1)) { + let filePath = path.join(translationDataFolder, 'extensions', extensionFileName); + rimraf.sync(filePath); + } + } + } + + //Get list of md files in ADS langpack, to copy to vscode langpack prior to renaming. + let globArray = glob.sync(path.join(locADSFolder, '*.md')); + + //Copy files to vscode langpack, then remove the ADS langpack, and finally rename the vscode langpack to match the ADS one. + globArray.forEach(element => { + fs.copyFileSync(element, path.join(locVSCODEFolder,path.parse(element).base)); + }); + rimraf.sync(locADSFolder); + fs.renameSync(locVSCODEFolder, locADSFolder); } console.log("Langpack Rename Completed.");