Stiglo je novo izdanje. Osvježi stranu.
Pravo na uvid u kod. Otvoren protokol omogućava nezavisne operatere i interoperabilnost. Manifest
Izvor
4d7883a894b3
- server.js
- lib/auth.js
- lib/build.js
- lib/cards.js
- lib/db.js
- lib/gradovi.js
- lib/icons.js
- lib/imena.js
- lib/jezik.js
- lib/kartapodaci.js
- lib/lekcije.js
- lib/md.js
- lib/mehanika.js
- lib/mreza.js
- lib/pages.js
- lib/registar.js
- lib/routes.js
- lib/schema2.js
- lib/views.js
- seed/content.mjs
- seed/seed.mjs
- public/app.js
- public/style.css
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