dotmd-cli 0.14.8 → 0.14.10
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/lifecycle.mjs +14 -6
- package/src/rename.mjs +10 -10
package/package.json
CHANGED
package/src/lifecycle.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { isInteractive, promptChoice } from './prompt.mjs';
|
|
|
10
10
|
|
|
11
11
|
function findFileRoot(filePath, config) {
|
|
12
12
|
const roots = config.docsRoots || [config.docsRoot];
|
|
13
|
-
return roots.find(r => filePath.startsWith(r)) ?? config.docsRoot;
|
|
13
|
+
return roots.find(r => filePath.startsWith(r + '/')) ?? config.docsRoot;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function runStatus(argv, config, opts = {}) {
|
|
@@ -63,8 +63,10 @@ export async function runStatus(argv, config, opts = {}) {
|
|
|
63
63
|
|
|
64
64
|
const today = new Date().toISOString().slice(0, 10);
|
|
65
65
|
const archiveDir = path.join(fileRoot, config.archiveDir);
|
|
66
|
-
const
|
|
67
|
-
const
|
|
66
|
+
const relFromRoot = path.relative(fileRoot, filePath);
|
|
67
|
+
const inArchive = relFromRoot.startsWith(config.archiveDir + '/') || relFromRoot.startsWith(config.archiveDir + path.sep);
|
|
68
|
+
const isArchiving = config.lifecycle.archiveStatuses.has(newStatus) && !inArchive;
|
|
69
|
+
const isUnarchiving = !config.lifecycle.archiveStatuses.has(newStatus) && inArchive;
|
|
68
70
|
let finalPath = filePath;
|
|
69
71
|
|
|
70
72
|
if (dryRun) {
|
|
@@ -239,7 +241,10 @@ export function runArchive(argv, config, opts = {}) {
|
|
|
239
241
|
|
|
240
242
|
const filePath = resolveDocPath(input, config);
|
|
241
243
|
if (!filePath) { die(`File not found: ${input}\nSearched: ${toRepoPath(config.repoRoot, config.repoRoot) || '.'}, ${toRepoPath(config.docsRoot, config.repoRoot)}`); }
|
|
242
|
-
|
|
244
|
+
|
|
245
|
+
const archiveFileRoot = findFileRoot(filePath, config);
|
|
246
|
+
const relFromRoot = path.relative(archiveFileRoot, filePath);
|
|
247
|
+
if (relFromRoot.startsWith(config.archiveDir + '/') || relFromRoot.startsWith(config.archiveDir + path.sep)) { die(`Already archived: ${toRepoPath(filePath, config.repoRoot)}`); }
|
|
243
248
|
|
|
244
249
|
const raw = readFileSync(filePath, 'utf8');
|
|
245
250
|
const { frontmatter } = extractFrontmatter(raw);
|
|
@@ -247,7 +252,6 @@ export function runArchive(argv, config, opts = {}) {
|
|
|
247
252
|
const oldStatus = asString(parsed.status) ?? 'unknown';
|
|
248
253
|
|
|
249
254
|
const today = new Date().toISOString().slice(0, 10);
|
|
250
|
-
const archiveFileRoot = findFileRoot(filePath, config);
|
|
251
255
|
const targetDir = path.join(archiveFileRoot, config.archiveDir);
|
|
252
256
|
const targetPath = path.join(targetDir, path.basename(filePath));
|
|
253
257
|
const oldRepoPath = toRepoPath(filePath, config.repoRoot);
|
|
@@ -314,7 +318,11 @@ export function runBulkArchive(argv, config, opts = {}) {
|
|
|
314
318
|
}
|
|
315
319
|
}
|
|
316
320
|
|
|
317
|
-
const unique = [...new Set(matched)].filter(f =>
|
|
321
|
+
const unique = [...new Set(matched)].filter(f => {
|
|
322
|
+
const root = findFileRoot(f, config);
|
|
323
|
+
const rel = path.relative(root, f);
|
|
324
|
+
return !rel.startsWith(config.archiveDir + '/') && !rel.startsWith(config.archiveDir + path.sep);
|
|
325
|
+
});
|
|
318
326
|
if (unique.length === 0) die('No matching files found (already-archived files are excluded).');
|
|
319
327
|
|
|
320
328
|
process.stdout.write(`${unique.length} file(s) to archive:\n`);
|
package/src/rename.mjs
CHANGED
|
@@ -35,18 +35,17 @@ export async function runRename(argv, config, opts = {}) {
|
|
|
35
35
|
die(`File not found: ${oldInput}\nSearched: ${toRepoPath(config.repoRoot, config.repoRoot) || '.'}, ${toRepoPath(config.docsRoot, config.repoRoot)}`);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// Compute new path
|
|
39
|
-
|
|
40
|
-
let newBasename = newInput;
|
|
41
|
-
// If newInput contains a path separator, use just the basename
|
|
38
|
+
// Compute new path — cross-directory if input has slashes, same directory otherwise
|
|
39
|
+
let newPath;
|
|
42
40
|
if (newInput.includes('/') || newInput.includes(path.sep)) {
|
|
43
|
-
|
|
41
|
+
let resolved = newInput;
|
|
42
|
+
if (!resolved.endsWith('.md')) resolved += '.md';
|
|
43
|
+
newPath = path.resolve(config.repoRoot, resolved);
|
|
44
|
+
} else {
|
|
45
|
+
let newBasename = newInput;
|
|
46
|
+
if (!newBasename.endsWith('.md')) newBasename += '.md';
|
|
47
|
+
newPath = path.join(path.dirname(oldPath), newBasename);
|
|
44
48
|
}
|
|
45
|
-
// Add .md if not present
|
|
46
|
-
if (!newBasename.endsWith('.md')) {
|
|
47
|
-
newBasename += '.md';
|
|
48
|
-
}
|
|
49
|
-
const newPath = path.join(oldDir, newBasename);
|
|
50
49
|
|
|
51
50
|
if (existsSync(newPath)) {
|
|
52
51
|
die(`Target already exists: ${toRepoPath(newPath, config.repoRoot)}`);
|
|
@@ -56,6 +55,7 @@ export async function runRename(argv, config, opts = {}) {
|
|
|
56
55
|
const oldRepoPath = toRepoPath(oldPath, config.repoRoot);
|
|
57
56
|
const newRepoPath = toRepoPath(newPath, config.repoRoot);
|
|
58
57
|
const oldBasename = path.basename(oldPath);
|
|
58
|
+
const newBasename = path.basename(newPath);
|
|
59
59
|
|
|
60
60
|
// Scan for references in other docs
|
|
61
61
|
const allFiles = collectDocFiles(config);
|