-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
next: replace contentlayer with velite (#733)
- Loading branch information
Showing
19 changed files
with
728 additions
and
1,769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,5 @@ web_modules/ | |
.env.test.local | ||
.env.production.local | ||
.env.local | ||
.contentlayer | ||
.contentlayer | ||
sites/docs/.velite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ yarn.lock | |
package.json | ||
.vercel | ||
.contentlayer | ||
.velite | ||
**/dist | ||
|
||
CHANGELOG.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ yarn.lock | |
package.json | ||
.vercel | ||
.contentlayer | ||
.velite | ||
dist | ||
|
||
vite.config.js.timestamp-* | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { readFile, writeFile } from "node:fs/promises"; | ||
import { join } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
const __dirname = fileURLToPath(new URL(".", import.meta.url)); | ||
const dtsPath = join(__dirname, "../.velite/index.d.ts"); | ||
const indexPath = join(__dirname, "../.velite/index.js"); | ||
|
||
async function replaceContents() { | ||
const data = await readFile(dtsPath, "utf8").catch((err) => { | ||
console.error("Error reading file:", err); | ||
}); | ||
if (!data) return; | ||
|
||
const updatedContent = data.replace("'../velite.config'", "'../velite.config.js'"); | ||
if (updatedContent === data) return; | ||
|
||
await writeFile(dtsPath, updatedContent, "utf8").catch((err) => { | ||
console.error("Error writing file:", err); | ||
}); | ||
} | ||
|
||
async function replaceIndexContents() { | ||
const data = await readFile(indexPath, "utf8").catch((err) => { | ||
console.error("Error reading file:", err); | ||
}); | ||
if (!data) return; | ||
|
||
const updatedContent = data.replaceAll(".json'", ".json' with { type: 'json' }"); | ||
if (updatedContent === data) return; | ||
|
||
await writeFile(indexPath, updatedContent, "utf8").catch((err) => { | ||
console.error("Error writing file:", err); | ||
}); | ||
} | ||
|
||
await replaceContents(); | ||
await replaceIndexContents(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { watch } from "node:fs"; | ||
import { readFile, writeFile } from "node:fs/promises"; | ||
import { join } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
// Configuration | ||
const __dirname = fileURLToPath(new URL(".", import.meta.url)); | ||
const dtsPath = join(__dirname, "../.velite/index.d.ts"); | ||
const indexPath = join(__dirname, "../.velite/index.js"); | ||
let isUpdatingDts = false; | ||
let isUpdatingIndex = false; | ||
|
||
async function replaceIndexDtsContents() { | ||
isUpdatingDts = true; | ||
|
||
const data = await readFile(dtsPath, "utf8").catch((err) => { | ||
console.error("Error reading file:", err); | ||
isUpdatingDts = false; | ||
}); | ||
if (!data) return; | ||
|
||
const updatedContent = data.replace("'../velite.config'", "'../velite.config.js'"); | ||
if (updatedContent === data) { | ||
isUpdatingDts = false; | ||
return; | ||
} | ||
|
||
await writeFile(dtsPath, updatedContent, "utf8").catch((err) => { | ||
console.error("Error writing file:", err); | ||
}); | ||
isUpdatingDts = false; | ||
} | ||
|
||
async function replaceIndexContents() { | ||
isUpdatingIndex = true; | ||
|
||
const data = await readFile(indexPath, "utf8").catch((err) => { | ||
console.error("Error reading file:", err); | ||
isUpdatingIndex = false; | ||
}); | ||
if (!data) return; | ||
|
||
const updatedContent = data.replaceAll(".json'", ".json' with { type: 'json' }"); | ||
if (updatedContent === data) { | ||
isUpdatingIndex = false; | ||
return; | ||
} | ||
|
||
await writeFile(indexPath, updatedContent, "utf8").catch((err) => { | ||
console.error("Error writing file:", err); | ||
}); | ||
isUpdatingIndex = false; | ||
} | ||
|
||
watch(dtsPath, async (eventType, filename) => { | ||
if (eventType === "change" && !isUpdatingDts) { | ||
console.info(`File ${filename} has been modified`); | ||
replaceIndexDtsContents(); | ||
} | ||
}); | ||
|
||
watch(indexPath, async (eventType, filename) => { | ||
if (eventType === "change" && !isUpdatingIndex) { | ||
console.info(`File ${filename} has been modified`); | ||
replaceIndexContents(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.