domma-cms 0.25.11 → 0.25.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +2 -6
- package/bin/update.js +1 -4
- package/package.json +2 -1
- package/plugins/analytics/plugin.js +30 -4
- package/plugins/analytics/plugin.json +5 -5
package/bin/cli.js
CHANGED
|
@@ -322,12 +322,8 @@ content/media/
|
|
|
322
322
|
*.log
|
|
323
323
|
.domma-backups/
|
|
324
324
|
|
|
325
|
-
# Analytics plugin runtime counters
|
|
326
|
-
|
|
327
|
-
plugins/analytics/stats.json
|
|
328
|
-
plugins/analytics/daily.json
|
|
329
|
-
plugins/analytics/lifetime.json
|
|
330
|
-
plugins/analytics/journeys.json
|
|
325
|
+
# Analytics plugin runtime counters (written on every page hit). Never track.
|
|
326
|
+
plugins/analytics/data/
|
|
331
327
|
`;
|
|
332
328
|
|
|
333
329
|
step('Writing .gitignore');
|
package/bin/update.js
CHANGED
|
@@ -475,10 +475,7 @@ export default async function update(_positional, flags) {
|
|
|
475
475
|
const gitignorePath = path.join(cwd, '.gitignore');
|
|
476
476
|
const requiredIgnores = [
|
|
477
477
|
'.domma-backups/',
|
|
478
|
-
'plugins/analytics/
|
|
479
|
-
'plugins/analytics/daily.json',
|
|
480
|
-
'plugins/analytics/lifetime.json',
|
|
481
|
-
'plugins/analytics/journeys.json',
|
|
478
|
+
'plugins/analytics/data/',
|
|
482
479
|
];
|
|
483
480
|
const current = existsSync(gitignorePath) ? readFileSync(gitignorePath, 'utf8') : '';
|
|
484
481
|
const missing = requiredIgnores.filter(entry => !current.split(/\r?\n/).includes(entry));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "domma-cms",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.12",
|
|
4
4
|
"description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "server/server.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"config/",
|
|
21
21
|
"!config/connections.json",
|
|
22
22
|
"plugins/",
|
|
23
|
+
"!plugins/analytics/data",
|
|
23
24
|
"!plugins/analytics/stats.json",
|
|
24
25
|
"!plugins/analytics/daily.json",
|
|
25
26
|
"!plugins/analytics/lifetime.json",
|
|
@@ -19,10 +19,17 @@ import path from 'path';
|
|
|
19
19
|
import {fileURLToPath} from 'url';
|
|
20
20
|
|
|
21
21
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
|
|
23
|
+
// Runtime counters live under data/ — the carve-out that BOTH update paths
|
|
24
|
+
// preserve (siteCmsUpdater's copyPlugin backs up data/; `domma-cms update`
|
|
25
|
+
// keeps 'data' in its preserve set). Pre-2.1 they sat in the plugin root and
|
|
26
|
+
// were overwritten by the manager's copy on every plugin push. On first boot
|
|
27
|
+
// migrateToDataDir() moves any pre-2.1 root files across.
|
|
28
|
+
const DATA_DIR = path.join(__dirname, 'data');
|
|
29
|
+
const LIFETIME_FILE = path.join(DATA_DIR, 'lifetime.json');
|
|
30
|
+
const DAILY_FILE = path.join(DATA_DIR, 'daily.json');
|
|
31
|
+
const LEGACY_FILE = path.join(DATA_DIR, 'stats.json');
|
|
32
|
+
const JOURNEYS_FILE = path.join(DATA_DIR, 'journeys.json');
|
|
26
33
|
const JOURNEY_DAILY_CAP = 5000;
|
|
27
34
|
const REALTIME_WINDOW_MS = 5 * 60 * 1000;
|
|
28
35
|
|
|
@@ -35,11 +42,29 @@ async function readJson(file, fallback) {
|
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
async function writeJson(file, data) {
|
|
45
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
38
46
|
const tmp = file + '.tmp';
|
|
39
47
|
await fs.writeFile(tmp, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
40
48
|
await fs.rename(tmp, file);
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/**
|
|
52
|
+
* One-shot relocation of pre-2.1 counters from the plugin root into data/.
|
|
53
|
+
* Runs before migrateLegacy() so the rest of the plugin only ever sees data/.
|
|
54
|
+
*/
|
|
55
|
+
async function migrateToDataDir() {
|
|
56
|
+
await fs.mkdir(DATA_DIR, { recursive: true });
|
|
57
|
+
for (const name of ['lifetime.json', 'daily.json', 'journeys.json', 'stats.json']) {
|
|
58
|
+
const dest = path.join(DATA_DIR, name);
|
|
59
|
+
try { await fs.access(dest); continue; } catch { /* dest absent — maybe move */ }
|
|
60
|
+
const oldPath = path.join(__dirname, name);
|
|
61
|
+
try {
|
|
62
|
+
await fs.access(oldPath);
|
|
63
|
+
await fs.rename(oldPath, dest);
|
|
64
|
+
} catch { /* no pre-2.1 file to move */ }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
43
68
|
/**
|
|
44
69
|
* One-shot migration from the legacy flat stats.json.
|
|
45
70
|
* Preserves existing totals as lifetime numbers; daily history starts empty.
|
|
@@ -253,6 +278,7 @@ export default async function analyticsPlugin(fastify, options) {
|
|
|
253
278
|
const { authenticate, requireAdmin } = options.auth;
|
|
254
279
|
const settings = options.settings || {};
|
|
255
280
|
|
|
281
|
+
await migrateToDataDir();
|
|
256
282
|
await migrateLegacy();
|
|
257
283
|
|
|
258
284
|
fastify.decorate('analytics', {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "analytics",
|
|
3
3
|
"displayName": "Analytics",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Page view analytics with daily trends, time-range filtering, top-pages table and CSV export. Honours Do-Not-Track and dedups per session.",
|
|
6
6
|
"author": "Darryl Waterhouse",
|
|
7
7
|
"date": "2026-05-04",
|
|
@@ -37,19 +37,19 @@
|
|
|
37
37
|
"scaffold": {
|
|
38
38
|
"reset": [
|
|
39
39
|
{
|
|
40
|
-
"path": "lifetime.json",
|
|
40
|
+
"path": "data/lifetime.json",
|
|
41
41
|
"content": "{}"
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
|
-
"path": "daily.json",
|
|
44
|
+
"path": "data/daily.json",
|
|
45
45
|
"content": "{}"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
"path": "journeys.json",
|
|
48
|
+
"path": "data/journeys.json",
|
|
49
49
|
"content": "{}"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
"path": "stats.json",
|
|
52
|
+
"path": "data/stats.json",
|
|
53
53
|
"content": "{}"
|
|
54
54
|
}
|
|
55
55
|
]
|