Avoid loop rebuild in watch mode
This commit is contained in:
@ -3,6 +3,7 @@ import type { BuildContext } from "./buildContext";
|
|||||||
import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
|
import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
|
import { existsAsync } from "../tools/fs.existsAsync";
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
projectDirPath: string;
|
projectDirPath: string;
|
||||||
@ -21,9 +22,13 @@ export async function generateKcGenTs(params: {
|
|||||||
projectDirPath: buildContext.projectDirPath
|
projectDirPath: buildContext.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
await fs.writeFile(
|
const filePath = pathJoin(themeSrcDirPath, "kc.gen.ts");
|
||||||
pathJoin(themeSrcDirPath, "kc.gen.ts"),
|
|
||||||
Buffer.from(
|
const currentContent = (await existsAsync(filePath))
|
||||||
|
? await fs.readFile(filePath)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const newContent = Buffer.from(
|
||||||
[
|
[
|
||||||
`/* prettier-ignore-start */`,
|
`/* prettier-ignore-start */`,
|
||||||
``,
|
``,
|
||||||
@ -56,6 +61,11 @@ export async function generateKcGenTs(params: {
|
|||||||
`/* prettier-ignore-end */`
|
`/* prettier-ignore-end */`
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
"utf8"
|
"utf8"
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (currentContent !== undefined && currentContent.equals(newContent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(filePath, newContent);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user