@mintlify/link-rot 3.0.554 → 3.0.556
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.
|
@@ -14,6 +14,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
14
14
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
15
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
16
|
};
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { addLog, SuccessLog, WarningLog, RenamedLog, ErrorLog } from '@mintlify/previewing';
|
|
17
19
|
import { existsSync, renameSync } from 'fs';
|
|
18
20
|
import path from 'path';
|
|
19
21
|
import { removeFileExtension, getPagePaths, addLeadingSlash } from '../prebuild.js';
|
|
@@ -28,53 +30,57 @@ export const renameFilesAndUpdateLinksInContent = (oldFilePathString_1, newFileP
|
|
|
28
30
|
var _a, e_1, _b, _c;
|
|
29
31
|
const oldFilePath = path.parse(path.normalize(oldFilePathString));
|
|
30
32
|
const newFilePath = path.parse(path.normalize(newFilePathString));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
else if (oldFilePath.ext !== newFilePath.ext) {
|
|
35
|
-
if (force) {
|
|
36
|
-
console.log('Warning: the file extensions are not the same.');
|
|
33
|
+
try {
|
|
34
|
+
if (oldFilePath.dir === newFilePath.dir && oldFilePath.base === newFilePath.base) {
|
|
35
|
+
throw new Error('the two file paths are the same.');
|
|
37
36
|
}
|
|
38
|
-
else {
|
|
39
|
-
|
|
37
|
+
else if (oldFilePath.ext !== newFilePath.ext) {
|
|
38
|
+
if (force) {
|
|
39
|
+
addLog(_jsx(WarningLog, { message: "the file extensions are not the same." }));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error('the file extensions are not the same. use the --force flag to override.');
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
// if the file or directory hasn't already been manually renamed, rename it
|
|
46
|
+
if (existsSync(oldFilePathString)) {
|
|
47
|
+
if (!force && existsSync(newFilePathString)) {
|
|
48
|
+
throw new Error('the new file path already exists. use the --force flag to overwrite it.');
|
|
49
|
+
}
|
|
50
|
+
renameSync(oldFilePathString, newFilePathString);
|
|
51
|
+
addLog(_jsx(RenamedLog, { before: oldFilePathString, after: newFilePathString }));
|
|
46
52
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
else if (!force) {
|
|
51
|
-
throw new Error('The old file path does not exist. Use the --force flag to skip the file system renaming.');
|
|
52
|
-
}
|
|
53
|
-
const oldLink = addLeadingSlash(removeFileExtension(oldFilePath));
|
|
54
|
-
const newLink = addLeadingSlash(removeFileExtension(newFilePath));
|
|
55
|
-
const pagesInDirectory = getPagePaths(process.cwd());
|
|
56
|
-
const renameLinkPromises = [];
|
|
57
|
-
try {
|
|
58
|
-
for (var _d = true, pagesInDirectory_1 = __asyncValues(pagesInDirectory), pagesInDirectory_1_1; pagesInDirectory_1_1 = yield pagesInDirectory_1.next(), _a = pagesInDirectory_1_1.done, !_a; _d = true) {
|
|
59
|
-
_c = pagesInDirectory_1_1.value;
|
|
60
|
-
_d = false;
|
|
61
|
-
const filePath = _c;
|
|
62
|
-
renameLinkPromises.push((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
const numRenamedLinks = yield renameInternalLinksInPage(path.resolve(process.cwd(), filePath), oldLink, newLink);
|
|
64
|
-
if (numRenamedLinks > 0) {
|
|
65
|
-
console.log(`Renamed ${numRenamedLinks} link(s) in ${filePath}`);
|
|
66
|
-
}
|
|
67
|
-
}))());
|
|
53
|
+
else if (!force) {
|
|
54
|
+
throw new Error(`the file ${oldFilePathString} does not exist. use the --force flag to skip the file system renaming.`);
|
|
68
55
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
56
|
+
const oldLink = addLeadingSlash(removeFileExtension(oldFilePath));
|
|
57
|
+
const newLink = addLeadingSlash(removeFileExtension(newFilePath));
|
|
58
|
+
const pagesInDirectory = getPagePaths(process.cwd());
|
|
59
|
+
const renameLinkPromises = [];
|
|
72
60
|
try {
|
|
73
|
-
|
|
61
|
+
for (var _d = true, pagesInDirectory_1 = __asyncValues(pagesInDirectory), pagesInDirectory_1_1; pagesInDirectory_1_1 = yield pagesInDirectory_1.next(), _a = pagesInDirectory_1_1.done, !_a; _d = true) {
|
|
62
|
+
_c = pagesInDirectory_1_1.value;
|
|
63
|
+
_d = false;
|
|
64
|
+
const filePath = _c;
|
|
65
|
+
renameLinkPromises.push((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const numRenamedLinks = yield renameInternalLinksInPage(path.resolve(process.cwd(), filePath), oldLink, newLink);
|
|
67
|
+
if (numRenamedLinks > 0) {
|
|
68
|
+
addLog(_jsx(SuccessLog, { message: `updated ${numRenamedLinks} link${numRenamedLinks === 1 ? '' : 's'} in ${filePath}` }));
|
|
69
|
+
}
|
|
70
|
+
}))());
|
|
71
|
+
}
|
|
74
72
|
}
|
|
75
|
-
|
|
73
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
74
|
+
finally {
|
|
75
|
+
try {
|
|
76
|
+
if (!_d && !_a && (_b = pagesInDirectory_1.return)) yield _b.call(pagesInDirectory_1);
|
|
77
|
+
}
|
|
78
|
+
finally { if (e_1) throw e_1.error; }
|
|
79
|
+
}
|
|
80
|
+
yield Promise.all(renameLinkPromises);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : 'an unknown error occurred' }));
|
|
76
85
|
}
|
|
77
|
-
yield Promise.all(renameLinkPromises);
|
|
78
|
-
return;
|
|
79
86
|
});
|
|
80
|
-
// renameFilesAndUpdateLinksInContent('/test/A.mdx', '/test/hello.mdx');
|