dotmd-cli 0.29.0 → 0.29.1
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/package.json +1 -1
- package/src/validate.mjs +58 -0
package/package.json
CHANGED
package/src/validate.mjs
CHANGED
|
@@ -5,6 +5,44 @@ import { toRepoPath } from './util.mjs';
|
|
|
5
5
|
|
|
6
6
|
const NOW = new Date();
|
|
7
7
|
|
|
8
|
+
// Type-conventional dirs are the directories where `dotmd new <type>` lands
|
|
9
|
+
// live (non-archive) docs of that type. Built-ins use `dir` ('plans'/'prompts')
|
|
10
|
+
// and `targetRoot`. In flat-array root configs (e.g. root: ['docs/plans',
|
|
11
|
+
// 'docs/prompts']), the root itself is a type-conventional dir; in default
|
|
12
|
+
// single-root configs (root: 'docs'), the type-conventional dirs are
|
|
13
|
+
// '<root>/plans' and '<root>/prompts'. This helper builds the union so the
|
|
14
|
+
// archive-drift check works for both layouts. Custom user templates with
|
|
15
|
+
// their own `dir` would extend this; we hard-code the built-in dir names.
|
|
16
|
+
const BUILTIN_TYPE_DIR_NAMES = ['plans', 'prompts'];
|
|
17
|
+
|
|
18
|
+
function liveTypeDirsForRoots(config) {
|
|
19
|
+
const set = new Set();
|
|
20
|
+
const roots = config.docsRoots || (config.docsRoot ? [config.docsRoot] : []);
|
|
21
|
+
for (const root of roots) {
|
|
22
|
+
const rootRel = path.relative(config.repoRoot, root).split(path.sep).join('/');
|
|
23
|
+
// The root itself is a live dir (covers flat-array layouts where the
|
|
24
|
+
// root IS the type-container).
|
|
25
|
+
set.add(rootRel);
|
|
26
|
+
// Each builtin type-dir joined to the root (covers single-root layouts
|
|
27
|
+
// where 'docs' contains 'docs/plans' and 'docs/prompts' subdirs).
|
|
28
|
+
for (const dirName of BUILTIN_TYPE_DIR_NAMES) {
|
|
29
|
+
// Skip if root already ends in this name (no double-nesting like
|
|
30
|
+
// 'docs/prompts/prompts').
|
|
31
|
+
if (path.basename(rootRel) === dirName) continue;
|
|
32
|
+
set.add(rootRel ? `${rootRel}/${dirName}` : dirName);
|
|
33
|
+
}
|
|
34
|
+
// User template dirs from config (extend the set with whatever live
|
|
35
|
+
// dirs custom types declare).
|
|
36
|
+
for (const tmpl of Object.values(config.raw?.templates ?? {})) {
|
|
37
|
+
if (!tmpl || typeof tmpl !== 'object') continue;
|
|
38
|
+
if (tmpl.dir && path.basename(rootRel) !== tmpl.dir) {
|
|
39
|
+
set.add(rootRel ? `${rootRel}/${tmpl.dir}` : tmpl.dir);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return set;
|
|
44
|
+
}
|
|
45
|
+
|
|
8
46
|
function isValidStatus(status, root, config, type) {
|
|
9
47
|
// When a doc declares a known type, that type's status set is authoritative.
|
|
10
48
|
// Falling through to the global union (across all types) would allow a
|
|
@@ -101,6 +139,26 @@ export function validateDoc(doc, frontmatter, headingTitle, config) {
|
|
|
101
139
|
doc.warnings.push({ path: doc.path, level: 'warning', message: 'Archived plan missing `## Closeout` section.' });
|
|
102
140
|
}
|
|
103
141
|
|
|
142
|
+
// Archive drift: a doc with an archive-flagged status (`status: archived` by
|
|
143
|
+
// default) whose parent dir is a "live" type-conventional location is
|
|
144
|
+
// misplaced — `dotmd archive` would have moved it under `<that>/archiveDir/`.
|
|
145
|
+
// Without this check, default `dotmd plans` / `dotmd prompts` views silently
|
|
146
|
+
// drop the file (because they exclude archived paths), and the user gets no
|
|
147
|
+
// signal it exists but is invisible. Nested intentional content (e.g.,
|
|
148
|
+
// `docs/plans/audit/<file>.md`) is in a non-conventional subdir and exempt.
|
|
149
|
+
if (config.lifecycle.archiveStatuses.has(doc.status)) {
|
|
150
|
+
const parentDir = path.dirname(doc.path);
|
|
151
|
+
const liveDirs = liveTypeDirsForRoots(config);
|
|
152
|
+
if (liveDirs.has(parentDir)) {
|
|
153
|
+
const expected = `${parentDir}/${config.archiveDir}/${path.basename(doc.path)}`;
|
|
154
|
+
doc.errors.push({
|
|
155
|
+
path: doc.path,
|
|
156
|
+
level: 'error',
|
|
157
|
+
message: `\`status: ${doc.status}\` but file is a direct child of \`${parentDir}/\`, not \`${parentDir}/${config.archiveDir}/\`. Run \`dotmd archive ${doc.path}\` to relocate to \`${expected}\`, or change the status.`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
104
162
|
// Validate reference fields resolve to existing files
|
|
105
163
|
const docDir = path.dirname(path.join(config.repoRoot, doc.path));
|
|
106
164
|
const allRefFields = [...(config.referenceFields.bidirectional || []), ...(config.referenceFields.unidirectional || [])];
|