mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-08-16 04:31:22 +08:00
chore: use pnpm CLI to get versions
This commit is contained in:
@ -119,8 +119,8 @@ Drop `<script>` inside your HTML file and access the component via `window.VueEC
|
||||
<!-- vue3Scripts:start -->
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.5.18"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.5.18"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@8.0.0-beta.1"></script>
|
||||
```
|
||||
|
||||
|
@ -119,8 +119,8 @@ import "echarts";
|
||||
<!-- vue3Scripts:start -->
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.5.18"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.5.18"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@8.0.0-beta.1"></script>
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
"dev:build": "vite build",
|
||||
"dev:preview": "vite preview",
|
||||
"dev:typecheck": "vue-tsc -p ./demo",
|
||||
"docs": "node ./scripts/docs.js",
|
||||
"docs": "jiti ./scripts/docs.ts",
|
||||
"prepublishOnly": "pnpm run typecheck && pnpm run dev:typecheck && pnpm run build && publint"
|
||||
},
|
||||
"packageManager": "pnpm@10.14.0",
|
||||
|
@ -1,13 +1,21 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { commentMark } from "comment-mark";
|
||||
import { getPackageMeta, resolvePath, getVersions } from "./utils.js";
|
||||
import { getPackageVersions, resolvePath } from "./utils";
|
||||
|
||||
const { name, version, devDependencies } = getPackageMeta();
|
||||
const { name, version, devDependencies } = getPackageVersions([
|
||||
"echarts",
|
||||
"vue",
|
||||
]);
|
||||
|
||||
const CDN_PREFIX = "https://cdn.jsdelivr.net/npm/";
|
||||
|
||||
const DEP_VERSIONS = {
|
||||
...getVersions(["vue", "echarts"], devDependencies),
|
||||
...Object.fromEntries(
|
||||
Object.entries(devDependencies).map(([name, { version }]) => [
|
||||
name,
|
||||
version,
|
||||
]),
|
||||
),
|
||||
[name]: version,
|
||||
};
|
||||
|
||||
@ -20,7 +28,7 @@ function getScripts() {
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function getCodeBlock(code) {
|
||||
function getCodeBlock(code: string) {
|
||||
return "\n```html\n" + code + "\n```\n";
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function resolvePath(url, ...parts) {
|
||||
return resolve(dirname(fileURLToPath(url)), ...parts);
|
||||
}
|
||||
|
||||
export function getPackageMeta() {
|
||||
return JSON.parse(
|
||||
readFileSync(resolvePath(import.meta.url, "../package.json"), "utf8"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package versions from version record object (like dependencies or devDependencies)
|
||||
* @param {string|string[]} packageNames - Package name or array of package names
|
||||
* @param {Object} versionRecord - Version record object (e.g., dependencies, devDependencies)
|
||||
* @returns {Object|string} - Returns version string for single package, or {packageName: version} object for array
|
||||
*/
|
||||
export function getVersions(packageNames, versionRecord) {
|
||||
if (!versionRecord || typeof versionRecord !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Helper function to extract clean version number
|
||||
const extractVersion = (versionString) => {
|
||||
if (!versionString) return null;
|
||||
// Remove prefixes like ^, ~, >=, etc. and return clean version
|
||||
return versionString.replace(/^[\^~>=<]+/, "");
|
||||
};
|
||||
|
||||
// If single string, return single version
|
||||
if (typeof packageNames === "string") {
|
||||
const version = extractVersion(versionRecord[packageNames]);
|
||||
return version || null;
|
||||
}
|
||||
|
||||
// If array, return object with package names as keys
|
||||
if (Array.isArray(packageNames)) {
|
||||
const result = {};
|
||||
for (const pkg of packageNames) {
|
||||
const version = extractVersion(versionRecord[pkg]);
|
||||
if (version) {
|
||||
result[pkg] = version;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
20
scripts/utils.ts
Normal file
20
scripts/utils.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function resolvePath(url: string, ...parts: string[]) {
|
||||
return resolve(dirname(fileURLToPath(url)), ...parts);
|
||||
}
|
||||
|
||||
type PackageVersions = {
|
||||
name: string;
|
||||
version: string;
|
||||
devDependencies: Record<string, { version: string }>;
|
||||
};
|
||||
|
||||
export function getPackageVersions(devDeps?: string[]): PackageVersions {
|
||||
const stdOut = execSync(`pnpm ls ${devDeps?.join(" ") || ""} --json`, {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
return JSON.parse(stdOut)[0];
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"include": ["*.config.*"],
|
||||
"include": ["*.config.*", "scripts/**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"lib": ["ESNext"],
|
||||
|
Reference in New Issue
Block a user