From 8fd8a79d75ae3f4566daa5fcc169f716b339460a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Mon, 13 Oct 2025 22:17:05 +0200 Subject: [PATCH] tokenize --- .gitea/scripts/replaceTokens.js | 37 ++++++++------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/.gitea/scripts/replaceTokens.js b/.gitea/scripts/replaceTokens.js index a0b993a..3de46db 100644 --- a/.gitea/scripts/replaceTokens.js +++ b/.gitea/scripts/replaceTokens.js @@ -1,25 +1,13 @@ // .gitea/scripts/replaceTokens.js // Skanuje: -// - artifacts/frontend/**/*.js -// - artifacts/webapi/appsettings.json (jeśli jest) -// - artifacts/webapi/client_secrets.json (jeśli jest) +// - artifacts/api/appsettings.Production.json (jeśli jest) +// - artifacts/ui/appsettings.Production.json (jeśli jest) // Tokeny: #{NAME}# -> wartość z VARIABLES/SECRETS (NAME: uppercased, '-'->'_') // Dodatkowo: #{BUILDID}# -> RUN_ID (z ENV) const fs = require('fs'); const path = require('path'); -function walk(dir, predicate) { - const out = []; - if (!fs.existsSync(dir)) return out; - for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { - const full = path.join(dir, entry.name); - if (entry.isDirectory()) out.push(...walk(full, predicate)); - else if (predicate(full)) out.push(full); - } - return out; -} - function replaceInFile(file, mapToken) { let data = fs.readFileSync(file, 'utf8'); const re = /#\{(.*?)\}#/g; @@ -44,32 +32,25 @@ function replaceInFile(file, mapToken) { if (token === 'BUILDID') return RUN_ID; return (variables[token] != null ? variables[token] : secrets[token]); }; - - // 1) Frontend: wszystkie .js - const feRoot = path.resolve('artifacts/frontend'); - const feFiles = walk(feRoot, (f) => f.endsWith('.js')); - - // 2) Backend: wybrane pliki jeśli istnieją - const beRoot = path.resolve('artifacts/webapi'); - const beFiles = [] - ;['appsettings.json', 'client_secrets.json'].forEach((name) => { + + const beRoot = path.resolve('artifacts'); + const beFiles = []; + ['api/appsettings.Production.json', 'ui/appsettings.Production.json'].forEach((name) => { const p = path.join(beRoot, name); if (fs.existsSync(p)) beFiles.push(p); }); - const files = [...feFiles, ...beFiles]; + const files = beFiles; if (files.length === 0) { - console.error('❌ No candidate files found to tokenize (frontend .js / backend json).'); + console.error('❌ No candidate files found to tokenize (artifacts/api or artifacts/ui appsettings.Production.json).'); process.exit(1); } console.log(`🔎 Tokenizing ${files.length} file(s)`); const missing = new Set(); - - // drugi przebieg: wypisz brakujące tokeny, jeśli jakieś zostały w plikach + for (const file of files) { - // pierwsze podejście: podstaw wartości replaceInFile(file, mapToken); } for (const file of files) {