Files
vueecharts/scripts/docs.mjs
Yue JIN 30e7934aab feat: dynamically update the theme (#841)
Co-authored-by: GU Yiling <justice360@gmail.com>
2025-08-10 23:26:12 +08:00

46 lines
1.0 KiB
JavaScript

import { readFileSync, writeFileSync } from "node:fs";
import { commentMark } from "comment-mark";
import { getPackageMeta, resolvePath } from "./utils.mjs";
const { name, version } = getPackageMeta();
const CDN_PREFIX = "https://cdn.jsdelivr.net/npm/";
const DEP_VERSIONS = {
vue: "3.5.13",
echarts: "6.0.0-beta.1",
[name]: version,
};
function getScripts() {
const deps = ["vue", "echarts", name];
return deps
.map((dep) => {
const [, name] = dep.match(/^(.+?)(?:@.+)?$/) || [];
return `<script src="${CDN_PREFIX}${name}@${DEP_VERSIONS[dep]}"></script>`;
})
.join("\n");
}
function getCodeBlock(code) {
return "\n```html\n" + code + "\n```\n";
}
const README_FILES = ["README.md", "README.zh-Hans.md"].map((name) =>
resolvePath(import.meta.url, "..", name),
);
README_FILES.forEach((file) => {
const content = readFileSync(file, "utf8");
writeFileSync(
file,
commentMark(content, {
vue3Scripts: getCodeBlock(getScripts()),
}),
"utf8",
);
});
console.log("README files updated.");