tokenize
All checks were successful
Build Docker Images / build-and-push (push) Successful in 1m18s

This commit is contained in:
Michał Zieliński
2025-10-13 22:17:05 +02:00
parent 04174fff3b
commit 8fd8a79d75

View File

@@ -1,25 +1,13 @@
// .gitea/scripts/replaceTokens.js // .gitea/scripts/replaceTokens.js
// Skanuje: // Skanuje:
// - artifacts/frontend/**/*.js // - artifacts/api/appsettings.Production.json (jeśli jest)
// - artifacts/webapi/appsettings.json (jeśli jest) // - artifacts/ui/appsettings.Production.json (jeśli jest)
// - artifacts/webapi/client_secrets.json (jeśli jest)
// Tokeny: #{NAME}# -> wartość z VARIABLES/SECRETS (NAME: uppercased, '-'->'_') // Tokeny: #{NAME}# -> wartość z VARIABLES/SECRETS (NAME: uppercased, '-'->'_')
// Dodatkowo: #{BUILDID}# -> RUN_ID (z ENV) // Dodatkowo: #{BUILDID}# -> RUN_ID (z ENV)
const fs = require('fs'); const fs = require('fs');
const path = require('path'); 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) { function replaceInFile(file, mapToken) {
let data = fs.readFileSync(file, 'utf8'); let data = fs.readFileSync(file, 'utf8');
const re = /#\{(.*?)\}#/g; const re = /#\{(.*?)\}#/g;
@@ -45,31 +33,24 @@ function replaceInFile(file, mapToken) {
return (variables[token] != null ? variables[token] : secrets[token]); return (variables[token] != null ? variables[token] : secrets[token]);
}; };
// 1) Frontend: wszystkie .js const beRoot = path.resolve('artifacts');
const feRoot = path.resolve('artifacts/frontend'); const beFiles = [];
const feFiles = walk(feRoot, (f) => f.endsWith('.js')); ['api/appsettings.Production.json', 'ui/appsettings.Production.json'].forEach((name) => {
// 2) Backend: wybrane pliki jeśli istnieją
const beRoot = path.resolve('artifacts/webapi');
const beFiles = []
;['appsettings.json', 'client_secrets.json'].forEach((name) => {
const p = path.join(beRoot, name); const p = path.join(beRoot, name);
if (fs.existsSync(p)) beFiles.push(p); if (fs.existsSync(p)) beFiles.push(p);
}); });
const files = [...feFiles, ...beFiles]; const files = beFiles;
if (files.length === 0) { 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); process.exit(1);
} }
console.log(`🔎 Tokenizing ${files.length} file(s)`); console.log(`🔎 Tokenizing ${files.length} file(s)`);
const missing = new Set(); const missing = new Set();
// drugi przebieg: wypisz brakujące tokeny, jeśli jakieś zostały w plikach
for (const file of files) { for (const file of files) {
// pierwsze podejście: podstaw wartości
replaceInFile(file, mapToken); replaceInFile(file, mapToken);
} }
for (const file of files) { for (const file of files) {