Removed async copy in rename function (#16209)

* Removed async copy in rename function

* added comments and removed async
This commit is contained in:
Alex Ma
2021-07-16 11:01:31 -07:00
committed by GitHub
parent 96efba004d
commit 669623a228
2 changed files with 45 additions and 39 deletions

View File

@@ -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();

View File

@@ -287,20 +287,6 @@ export function refreshLangpacks(): Promise<void> {
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<void> {
}
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<void> {
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.");