From e3d7dcccf20c5d7af1aa84b6f0e98a9334c5a733 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Fri, 27 Feb 2026 11:37:15 +0100 Subject: [PATCH 1/8] Add gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..371ad72b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.idea +.env +node_modules \ No newline at end of file From e690dfbe0cc1c6400ba8c70bfbc36804414f093e Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Fri, 27 Feb 2026 11:47:43 +0100 Subject: [PATCH 2/8] setup npm --- package-lock.json | 13 +++++++++++++ package.json | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..41786c2c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "devportal-docs", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "devportal-docs", + "version": "1.0.0", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..b28c49fe --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "devportal-docs", + "version": "1.0.0", + "description": "This repository contains all some spaces synched from GitBook", + "main": "index.js", + "directories": { + "doc": "docs" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pagopa/devportal-docs.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/pagopa/devportal-docs/issues" + }, + "homepage": "https://github.com/pagopa/devportal-docs#readme" +} From 26e12396ca65d3522a179f84cd30396ea7ae06c2 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Fri, 27 Feb 2026 11:52:21 +0100 Subject: [PATCH 3/8] add node version, set dependencies --- .node-version | 1 + package-lock.json | 231 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 9 +- 3 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 00000000..89b93fd7 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +22.18.0 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 41786c2c..1a45335a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,238 @@ "": { "name": "devportal-docs", "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@types/js-yaml": "^4.0.9", + "@types/node": "^25.2.3", + "ts-node": "^10.9.2", + "typescript": "^5.9.3" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.12.tgz", + "integrity": "sha512-UCYBaeFvM11aU2y3YPZ//O5Rhj+xKyzy7mvcIoAjASbigy8mHMryP5cK7dgjlz2hWxh1g5pLw084E0a/wlUSFQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/js-yaml": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz", + "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "25.3.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.3.2.tgz", + "integrity": "sha512-RpV6r/ij22zRRdyBPcxDeKAzH43phWVKEjL2iksqo1Vz3CuBUrgmPpPhALKiRfU7OMCmeeO9vECBMsV0hMTG8Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/acorn": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.5", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.5.tgz", + "integrity": "sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/diff": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", + "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, "license": "ISC" + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "license": "MIT" + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } } } } diff --git a/package.json b/package.json index b28c49fe..b2f152d0 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,19 @@ "doc": "docs" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "generate_file": "npx ts-node updateCrowdin.ts" }, "repository": { "type": "git", "url": "git+https://github.com/pagopa/devportal-docs.git" }, + "devDependencies": { + "@types/js-yaml": "^4.0.9", + "@types/node": "^25.2.3", + "ts-node": "^10.9.2", + "typescript": "^5.9.3" + }, "keywords": [], "author": "", "license": "ISC", From 24ab6db197eac4138f517a07af035b51dbf42a4a Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Fri, 27 Feb 2026 11:53:28 +0100 Subject: [PATCH 4/8] add base workflow and action --- .github/actions/setup-node/action.yaml | 16 +++++++ .github/workflows/crowdin.yml | 59 ++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/actions/setup-node/action.yaml create mode 100644 .github/workflows/crowdin.yml diff --git a/.github/actions/setup-node/action.yaml b/.github/actions/setup-node/action.yaml new file mode 100644 index 00000000..96e35c7f --- /dev/null +++ b/.github/actions/setup-node/action.yaml @@ -0,0 +1,16 @@ +name: Setup Node.JS +description: Setup Node.JS + +inputs: + package_manager: + description: 'The package manager to use' + default: 'npm' + required: true + +runs: + using: "composite" + steps: + - name: Setup node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + node-version-file: '.node-version' \ No newline at end of file diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml new file mode 100644 index 00000000..d2471c41 --- /dev/null +++ b/.github/workflows/crowdin.yml @@ -0,0 +1,59 @@ +name: Crowdin Action + +on: + push: + branches: [ main ] + +jobs: + synchronize-with-crowdin: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.JS + uses: ./.github/actions/setup-node + + # (Ho mantenuto la tua cache intatta) + - name: Cache npm dependencies + id: cache-npm + uses: actions/cache@v3 # Nota: ho messo v3 standard, se usi hash specifico va bene uguale + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-npm- + + - name: Install dependencies + run: | + npm config set cache ~/.npm + npm ci + + # --- MODIFICA QUI: Aggiunto id: extract_files --- + - name: Generate crowdin file + id: extract_files + run: npm run generate_file + + - name: crowdin action + uses: crowdin/github-action@v2 + with: + upload_sources: true + upload_translations: false + auto_approve_imported: true + download_translations: false + create_pull_request: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} + + # --- MODIFICA QUI: Passaggio dei parametri --- + - name: Trigger download workflow + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: | + gh workflow run getTranslations.yml \ + --repo Uqido/PagopaTranslationPocTarget \ + --ref main \ + -f files='${{ steps.extract_files.outputs.found_files }}' \ No newline at end of file From 7fa86a7999f6a661c18a165e5137eb04fdc846f3 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Fri, 27 Feb 2026 11:57:10 +0100 Subject: [PATCH 5/8] add generation script --- package-lock.json | 21 +++++++++ package.json | 7 ++- src/updateCrowdin.ts | 106 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/updateCrowdin.ts diff --git a/package-lock.json b/package-lock.json index 1a45335a..e06fe54d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "devportal-docs", "version": "1.0.0", "license": "ISC", + "dependencies": { + "js-yaml": "^4.1.1" + }, "devDependencies": { "@types/js-yaml": "^4.0.9", "@types/node": "^25.2.3", @@ -134,6 +137,12 @@ "dev": true, "license": "MIT" }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "license": "Python-2.0" + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -151,6 +160,18 @@ "node": ">=0.3.1" } }, + "node_modules/js-yaml": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", + "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", diff --git a/package.json b/package.json index b2f152d0..cb5e3a45 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "generate_file": "npx ts-node updateCrowdin.ts" + "generate_file": "npx ts-node src/updateCrowdin.ts" }, "repository": { "type": "git", @@ -26,5 +26,8 @@ "bugs": { "url": "https://github.com/pagopa/devportal-docs/issues" }, - "homepage": "https://github.com/pagopa/devportal-docs#readme" + "homepage": "https://github.com/pagopa/devportal-docs#readme", + "dependencies": { + "js-yaml": "^4.1.1" + } } diff --git a/src/updateCrowdin.ts b/src/updateCrowdin.ts new file mode 100644 index 00000000..dc1ec552 --- /dev/null +++ b/src/updateCrowdin.ts @@ -0,0 +1,106 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import * as yaml from 'js-yaml'; +import * as os from 'os'; // Aggiungi questo import per gestire i fine riga + +// --- COSTANTI DI CONFIGURAZIONE --- +const DOCS_DIR = 'docs'; +const CONFIG_FILE = 'crowdin.yml'; + +interface CrowdinFileEntry { + source: string; + translation: string; +} + +interface CrowdinConfig { + base_path?: string; + preserve_hierarchy?: boolean; + files: CrowdinFileEntry[]; + [key: string]: any; +} + +function findMdFiles(dir: string, fileList: string[] = []): string[] { + if (!fs.existsSync(dir)) return fileList; + const files = fs.readdirSync(dir); + files.forEach((file) => { + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + if (stat.isDirectory()) { + findMdFiles(filePath, fileList); + } else { + if (path.extname(file) === '.md') { + fileList.push(filePath.replace(/\\/g, '/')); + } + } + }); + return fileList; +} + +function updateCrowdinConfig() { + console.log(`🔍 Scansione della cartella "${DOCS_DIR}" in corso...`); + + if (!fs.existsSync(DOCS_DIR)) { + console.error(`❌ Errore: La cartella "${DOCS_DIR}" non esiste.`); + process.exit(1); + } + + const mdFiles = findMdFiles(DOCS_DIR); + + if (mdFiles.length === 0) { + console.warn(`âš ī¸ Nessun file .md trovato in "${DOCS_DIR}".`); + return; + } + + // --- 1. Generazione e salvataggio crowdin.yml (LOGICA ESISTENTE) --- + const crowdinFiles: CrowdinFileEntry[] = mdFiles.map((sourcePath) => { + const translationPath = sourcePath.replace(`${DOCS_DIR}/`, `${DOCS_DIR}/%locale%/`); + return { source: sourcePath, translation: translationPath }; + }); + + let otherConfigProps: any = {}; + if (fs.existsSync(CONFIG_FILE)) { + try { + const existingContent = fs.readFileSync(CONFIG_FILE, 'utf8'); + const loadedConfig = yaml.load(existingContent) as CrowdinConfig; + if (loadedConfig) { + const { files, base_path, preserve_hierarchy, ...rest } = loadedConfig; + otherConfigProps = rest; + } + } catch (e) { console.error('❌ Errore lettura crowdin.yml esistente.', e); } + } + + const filesJsonString = JSON.stringify(crowdinFiles, null, 4); + let finalOutput = `"base_path": "."\n\n"preserve_hierarchy": true\n\n`; + for (const key in otherConfigProps) { + finalOutput += `"${key}": ${JSON.stringify(otherConfigProps[key])}\n\n`; + } + finalOutput += `"files": ${filesJsonString}`; + + try { + fs.writeFileSync(CONFIG_FILE, finalOutput, 'utf8'); + console.log(`✅ File ${CONFIG_FILE} aggiornato.`); + } catch (e) { console.error('❌ Errore salvataggio crowdin.yml', e); } + + // --- 2. LOGICA PER GITHUB ACTIONS OUTPUT (NUOVA PARTE) --- + + // Questa variabile esiste SOLO se lo script gira su GitHub Actions + const githubOutputPath = process.env.GITHUB_OUTPUT; + + if (githubOutputPath) { + // Trasformiamo l'array in una stringa JSON semplice (es: ["docs/a.md","docs/b.md"]) + const pathsJson = JSON.stringify(mdFiles); + + // Scriviamo nel file speciale di GitHub usando il formato key=value + // Usiamo os.EOL per essere sicuri di andare a capo correttamente + try { + fs.appendFileSync(githubOutputPath, `found_files=${pathsJson}${os.EOL}`); + console.log(`🚀 Output 'found_files' inviato a GitHub Actions.`); + } catch (error) { + console.error('❌ Impossibile scrivere su GITHUB_OUTPUT:', error); + } + } else { + console.log('â„šī¸ GITHUB_OUTPUT non rilevato (stai eseguendo in locale?), salto questo passaggio.'); + } +} + +updateCrowdinConfig(); \ No newline at end of file From aaadacbd47f97011f7591fe22951c8202a2b27c9 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Mon, 9 Mar 2026 10:50:34 +0100 Subject: [PATCH 6/8] fix logs and add dirname --- src/updateCrowdin.ts | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/updateCrowdin.ts b/src/updateCrowdin.ts index dc1ec552..4fb327af 100644 --- a/src/updateCrowdin.ts +++ b/src/updateCrowdin.ts @@ -4,7 +4,7 @@ import * as yaml from 'js-yaml'; import * as os from 'os'; // Aggiungi questo import per gestire i fine riga // --- COSTANTI DI CONFIGURAZIONE --- -const DOCS_DIR = 'docs'; +const DOCS_DIR = 'docs/8jU9vbiLbvbIk0DuJMvd'; const CONFIG_FILE = 'crowdin.yml'; interface CrowdinFileEntry { @@ -37,21 +37,20 @@ function findMdFiles(dir: string, fileList: string[] = []): string[] { } function updateCrowdinConfig() { - console.log(`🔍 Scansione della cartella "${DOCS_DIR}" in corso...`); + console.log(` --- Searching for "${DOCS_DIR}" ---`); if (!fs.existsSync(DOCS_DIR)) { - console.error(`❌ Errore: La cartella "${DOCS_DIR}" non esiste.`); + console.error(`--- Error: "${DOCS_DIR}" not found. ---`); process.exit(1); } const mdFiles = findMdFiles(DOCS_DIR); if (mdFiles.length === 0) { - console.warn(`âš ī¸ Nessun file .md trovato in "${DOCS_DIR}".`); + console.warn(` --- No file found in "${DOCS_DIR}". ---`); return; } - // --- 1. Generazione e salvataggio crowdin.yml (LOGICA ESISTENTE) --- const crowdinFiles: CrowdinFileEntry[] = mdFiles.map((sourcePath) => { const translationPath = sourcePath.replace(`${DOCS_DIR}/`, `${DOCS_DIR}/%locale%/`); return { source: sourcePath, translation: translationPath }; @@ -66,7 +65,7 @@ function updateCrowdinConfig() { const { files, base_path, preserve_hierarchy, ...rest } = loadedConfig; otherConfigProps = rest; } - } catch (e) { console.error('❌ Errore lettura crowdin.yml esistente.', e); } + } catch (e) { console.error(' --- Error, crowdin.yaml not found ---', e); } } const filesJsonString = JSON.stringify(crowdinFiles, null, 4); @@ -78,28 +77,21 @@ function updateCrowdinConfig() { try { fs.writeFileSync(CONFIG_FILE, finalOutput, 'utf8'); - console.log(`✅ File ${CONFIG_FILE} aggiornato.`); - } catch (e) { console.error('❌ Errore salvataggio crowdin.yml', e); } + console.log(` --- ${CONFIG_FILE} updated.`); + } catch (e) { console.error(' --- There was an error saving crowdin.yaml ---', e); } - // --- 2. LOGICA PER GITHUB ACTIONS OUTPUT (NUOVA PARTE) --- - - // Questa variabile esiste SOLO se lo script gira su GitHub Actions const githubOutputPath = process.env.GITHUB_OUTPUT; if (githubOutputPath) { - // Trasformiamo l'array in una stringa JSON semplice (es: ["docs/a.md","docs/b.md"]) const pathsJson = JSON.stringify(mdFiles); - - // Scriviamo nel file speciale di GitHub usando il formato key=value - // Usiamo os.EOL per essere sicuri di andare a capo correttamente try { fs.appendFileSync(githubOutputPath, `found_files=${pathsJson}${os.EOL}`); - console.log(`🚀 Output 'found_files' inviato a GitHub Actions.`); + console.log(` --- Found files written to GITHUB_OUTPUT: ${pathsJson} ---`); } catch (error) { - console.error('❌ Impossibile scrivere su GITHUB_OUTPUT:', error); + console.error(' --- Unable to write on GITHUB_OUTPUT ---', error); } } else { - console.log('â„šī¸ GITHUB_OUTPUT non rilevato (stai eseguendo in locale?), salto questo passaggio.'); + console.log(' --- GITHUB_OUTPUT environment variable not set. Skipping output to GitHub Actions. ---'); } } From 0b85bb1cd07ad537d37154ebabacc6e12099003b Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Tue, 10 Mar 2026 15:15:11 +0100 Subject: [PATCH 7/8] remove old log --- src/updateCrowdin.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/updateCrowdin.ts b/src/updateCrowdin.ts index 4fb327af..5eaefb06 100644 --- a/src/updateCrowdin.ts +++ b/src/updateCrowdin.ts @@ -1,9 +1,8 @@ import * as fs from 'fs'; import * as path from 'path'; import * as yaml from 'js-yaml'; -import * as os from 'os'; // Aggiungi questo import per gestire i fine riga +import * as os from 'os'; -// --- COSTANTI DI CONFIGURAZIONE --- const DOCS_DIR = 'docs/8jU9vbiLbvbIk0DuJMvd'; const CONFIG_FILE = 'crowdin.yml'; From 6a6f1c101d7ae03c487e2da71e259f51a41cd089 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Wed, 11 Mar 2026 10:47:48 +0100 Subject: [PATCH 8/8] update target repo --- .github/workflows/crowdin.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml index d2471c41..9e75580e 100644 --- a/.github/workflows/crowdin.yml +++ b/.github/workflows/crowdin.yml @@ -15,10 +15,9 @@ jobs: - name: Setup Node.JS uses: ./.github/actions/setup-node - # (Ho mantenuto la tua cache intatta) - name: Cache npm dependencies id: cache-npm - uses: actions/cache@v3 # Nota: ho messo v3 standard, se usi hash specifico va bene uguale + uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} @@ -30,7 +29,6 @@ jobs: npm config set cache ~/.npm npm ci - # --- MODIFICA QUI: Aggiunto id: extract_files --- - name: Generate crowdin file id: extract_files run: npm run generate_file @@ -48,12 +46,11 @@ jobs: CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} - # --- MODIFICA QUI: Passaggio dei parametri --- - name: Trigger download workflow env: GH_TOKEN: ${{ secrets.PAT_TOKEN }} run: | gh workflow run getTranslations.yml \ - --repo Uqido/PagopaTranslationPocTarget \ + --repo pagopa/devportal-docs-translations \ --ref main \ -f files='${{ steps.extract_files.outputs.found_files }}' \ No newline at end of file