generated from nhcarrigan/template
feat: add npm audit script, crowdin helpers now write data to disk
Node.js CI / Lint and Test (push) Failing after 34s
Node.js CI / Lint and Test (push) Failing after 34s
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { readFile, appendFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { getLanguages } from "./utils/getLanguages.js";
|
||||
import type { String } from "./interfaces/string.js";
|
||||
|
||||
const projectId = process.env.CROWDIN_PROJECT_ID;
|
||||
const apiUrl = process.env.CROWDIN_API_URL;
|
||||
const token = process.env.CROWDIN_TOKEN;
|
||||
|
||||
if (
|
||||
projectId === undefined
|
||||
|| projectId === ""
|
||||
|| apiUrl === undefined
|
||||
|| apiUrl === ""
|
||||
|| token === undefined
|
||||
|| token === ""
|
||||
) {
|
||||
throw new Error(`Project ID or API URL is missing! Did you run this script with 'op run'?`);
|
||||
}
|
||||
|
||||
const logPath
|
||||
= join(import.meta.dirname, "..", "..", "data", "crowdin-strings-hidden.txt");
|
||||
|
||||
const languages = await getLanguages(projectId, apiUrl, token);
|
||||
console.log(`Found ${languages.length.toString()} active languages.`);
|
||||
const rawStrings = await readFile(
|
||||
join(import.meta.dirname, "..", "..", "data", "crowdin-strings.json"),
|
||||
"utf-8",
|
||||
);
|
||||
const strings: Array<String["data"][0]["data"]> = JSON.parse(rawStrings);
|
||||
console.log(`Found ${strings.length.toString()} strings.`);
|
||||
|
||||
const log = await readFile(
|
||||
logPath,
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const processedIds = log.split("\n");
|
||||
|
||||
const unprocessedStrings = strings.filter((string) => {
|
||||
return !processedIds.includes(string.id.toString());
|
||||
});
|
||||
|
||||
const hidden = unprocessedStrings.filter((string) => {
|
||||
return string.isHidden;
|
||||
});
|
||||
|
||||
console.log(`Processing ${hidden.length.toString()} hidden strings.`);
|
||||
|
||||
for (const string of hidden) {
|
||||
console.log(`Deleting translations for ${string.id.toString()}`);
|
||||
await Promise.all(languages.map(async(language) => {
|
||||
await fetch(`${apiUrl}/projects/${projectId}/translations`, {
|
||||
body: JSON.stringify({
|
||||
languageId: language,
|
||||
stringId: string.id,
|
||||
}),
|
||||
headers: {
|
||||
"authorization": `Bearer ${token}`,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- header.
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "DELETE",
|
||||
});
|
||||
}));
|
||||
await appendFile(logPath, `${string.id.toString()}\n`);
|
||||
}
|
||||
|
||||
console.log("Completed!");
|
||||
Reference in New Issue
Block a user