Files
freeCodeCamp/tools/crowdin/actions/remove-deleted-files/index.js
Randell Dawson 7a0d885813 fix(tools): Modiify removeDeletedFiles function to find all files instead of just markdown (#40887)
* fix: corrected file deletion function

* fix(tools): include dict

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix(tools): concat is non-mutating oops

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-02-02 20:42:23 -08:00

51 lines
1.8 KiB
JavaScript

require('dotenv').config({ path: `${__dirname}/../../.env` });
// const core = require('@actions/core');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const { getFiles, deleteFile } = require('../../utils/files');
const getOutputFromCommand = async command => {
try {
const { stdout } = await exec(command);
return stdout;
} catch (err) {
console.log('Error');
console.log('command');
console.log(command + '\n');
console.log(err.message);
return null;
}
};
const removeDeletedFiles = async projectId => {
console.log('start deleting source files no longer in English curriculum...');
const crowdinFiles = await getFiles(projectId);
if (crowdinFiles && crowdinFiles.length) {
const challengeCommand = 'find curriculum/challenges/english -name \\*.*';
const listOfEnglishFiles = await getOutputFromCommand(challengeCommand);
const dictionaryCommand =
'find curriculum/dictionaries/english -name \\*.*';
const listOfDictFiles = await getOutputFromCommand(dictionaryCommand);
let curriculumFilesArr = listOfEnglishFiles.split('\n');
curriculumFilesArr = curriculumFilesArr.concat(listOfDictFiles.split('\n'));
if (curriculumFilesArr.length) {
const curriculumLookup = curriculumFilesArr.reduce((obj, filename) => {
return { ...obj, [filename]: 1 };
}, {});
for (let { fileId, path: crowdinFilePath } of crowdinFiles) {
if (!curriculumLookup.hasOwnProperty(crowdinFilePath)) {
await deleteFile(projectId, fileId, crowdinFilePath);
}
}
}
} else {
console.log(`WARNING! No Crowdin files found for projectId ${projectId}`);
}
console.log('deleting source non-existent source files complete');
};
const projectId = process.env.CROWDIN_PROJECT_ID;
removeDeletedFiles(projectId);