DSLO commited on
Commit
f5adefe
·
verified ·
1 Parent(s): 0521d46

Create ledger.js

Browse files
Files changed (1) hide show
  1. ledger.js +37 -0
ledger.js ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ledger.js
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const LEDGER_DIR = path.join(__dirname, 'ledger');
7
+
8
+ function ensureLedgerDir() {
9
+ if (!fs.existsSync(LEDGER_DIR)) {
10
+ fs.mkdirSync(LEDGER_DIR);
11
+ }
12
+ }
13
+
14
+ function timestampForFilename() {
15
+ const now = new Date();
16
+ const iso = now.toISOString(); // e.g. 2026-06-28T16:12:34.567Z
17
+ return iso.replace(/[:.]/g, '-');
18
+ }
19
+
20
+ function writeLedgerEntry(entry) {
21
+ ensureLedgerDir();
22
+
23
+ const filename = `${timestampForFilename()}.json`;
24
+ const filepath = path.join(LEDGER_DIR, filename);
25
+
26
+ const payload = {
27
+ engineVersion: 'v0.2-ledger',
28
+ createdAt: new Date().toISOString(),
29
+ entry,
30
+ };
31
+
32
+ fs.writeFileSync(filepath, JSON.stringify(payload, null, 2), 'utf8');
33
+
34
+ return filepath;
35
+ }
36
+
37
+ module.exports = { writeLedgerEntry };