srijeda, 11. novembar 2026. · Godina I · Broj 15 · Cijena: 0 dinara
JUGOSLOVENSKI FORUM

Glasilo YU mreže · NEMA GRANICA ZA ZNANJE

Prijava Upis
Pravo na uvid u kod. Otvoren protokol omogućava nezavisne operatere i interoperabilnost. Manifest

Izvor

4d7883a894b3

   1 // Build id = sha256 over every file under app/ (sorted relative paths + contents), excluding tests and local data.
   2 import crypto from 'node:crypto';
   3 import fs from 'node:fs';
   4 import path from 'node:path';
   5 
   6 const SKIP = new Set(['test', 'data', 'node_modules', '.local']);
   7 
   8 export function files(root) {
   9   const out = [];
  10   const walk = (dir, rel) => {
  11     for (const ent of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
  12       if (SKIP.has(ent.name) || ent.name.startsWith('.')) continue;
  13       const r = rel ? rel + '/' + ent.name : ent.name;
  14       if (ent.isDirectory()) walk(path.join(dir, ent.name), r);
  15       else if (ent.isFile()) out.push(r);
  16     }
  17   };
  18   walk(root, '');
  19   return out;
  20 }
  21 
  22 export function buildId(root = path.resolve(import.meta.dirname, '..')) {
  23   const h = crypto.createHash('sha256');
  24   for (const f of files(root)) {
  25     h.update(f + '\0');
  26     h.update(fs.readFileSync(path.join(root, f)));
  27     h.update('\0');
  28   }
  29   return h.digest('hex').slice(0, 12);
  30 }
  31 
  32 if (process.argv[1] && import.meta.url === new URL('file://' + path.resolve(process.argv[1])).href) {
  33   console.log(buildId(process.argv[2] || path.resolve(path.dirname(new URL(import.meta.url).pathname), '..')));
  34 }
  35