Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / inbox-desktop / tasks / extract-translations.mjs
blob1c056c0f9b8e88db582861c3bb03de4af80d895b
1 /**
2  * Command to extract source strings for translations
3  * @link {https://confluence.protontech.ch/display/CP/Localisation+on+Front-end+-+rules+and+best+practices}
4  * ex:
5  * `node tasks/extract-translations.mjs` output -> `po/template.pot`
6  */
7 import path from "node:path";
8 import { constants as FS_CONSTANTS } from "node:fs";
9 import { mkdir, access, rm } from "node:fs/promises";
10 import { execaCommand } from "execa";
12 const DEFAULT_LANGUAGE = "en";
13 const PO_OUTPUT_FILE = "po/template.pot";
15 /**
16  * Test if a path exists
17  * @param {string} itemPath path to a file/directory
18  * @return {Promise<bool>} True if it exists
19  */
20 export const pathExists = async (itemPath) => {
21     try {
22         await access(itemPath, FS_CONSTANTS.R_OK);
23         return true;
24     } catch (e) {
25         return false;
26     }
29 async function main() {
30     const rootDir = path.dirname(PO_OUTPUT_FILE);
32     // always clean previous file -> if we test on our own pc
33     if (await pathExists(PO_OUTPUT_FILE)) {
34         await rm(PO_OUTPUT_FILE);
35     }
37     await mkdir(rootDir, { recursive: true });
39     await execaCommand(`npx ttag init ${DEFAULT_LANGUAGE} ${PO_OUTPUT_FILE}`);
40     await execaCommand(`npx ttag update ${PO_OUTPUT_FILE} src`);
41     console.log("source string extracted to", PO_OUTPUT_FILE);
44 main();