From 5b83ff879d3acbe41198ba255055e33f4ab40125 Mon Sep 17 00:00:00 2001 From: ruan-cat <1219043956@qq.com> Date: Sun, 13 Oct 2024 22:49:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=94=20save-file:=20=E5=8D=95=E7=BA=AF?= =?UTF-8?q?=E5=9C=B0=E4=BF=9D=E5=AD=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commitlint.config.cjs | 82 ++++++++++++++++++++++++++++++++++++++++--- package.json | 2 ++ pnpm-workspace.yaml | 8 +++-- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/commitlint.config.cjs b/commitlint.config.cjs index 4e68f14..1739862 100644 --- a/commitlint.config.cjs +++ b/commitlint.config.cjs @@ -1,13 +1,87 @@ -// https://cz-git.qbb.sh/zh/config/#中英文对照模板 +/** + * @description + * 这个配置文件不能使用ts格式 ts不被支持 + * + * @see https://cz-git.qbb.sh/zh/config/#中英文对照模板 + */ /** * TODO: 实现索引全部的包名和包描述 * @see https://cz-git.qbb.sh/zh/recipes/# */ -const fs = require("node:fs"); -const path = require("node:path"); +const fs = require("fs"); +const path = require("path"); +const glob = require("glob"); +const yaml = require("js-yaml"); + const packages = fs.readdirSync(path.resolve(__dirname, "packages")); -console.log(" in c ", packages); +// console.log(" in c ", packages); + +/** + * 根据 pnpm-workspace.yaml 配置的monorepo有意义的包名,获取包名和包描述 + * @description + * 根据 pnpm-workspace.yaml 配置的monorepo有意义的包名,获取包名和包描述 + * + * @return { Array<{name: string, description: string}>} + */ +function getPackagesNameAndDescription() { + // 读取 pnpm-workspace.yaml 文件 文件路径 + const workspaceConfigPath = path.join(__dirname, "pnpm-workspace.yaml"); + // 文件 + const workspaceFile = fs.readFileSync(workspaceConfigPath, "utf8"); + // 配置 + const workspaceConfig = yaml.load(workspaceFile); + + console.log("workspaceConfig :>> ", workspaceConfig); + + // 获取 packages 配置 + const pkgPatterns = workspaceConfig.packages; + console.log("pkgPatterns :>> ", pkgPatterns); + + // // 存储匹配的 package.json 文件路径 + // let pkgPaths = []; + // // 根据每个模式匹配相应的目录 + // pkgPatterns.forEach((pattern) => { + // const matchedPath = path.join(__dirname, pattern, "package.json").replace(/\\/g, "/"); + // console.log("matchedPath :>> ", matchedPath); + // const matchedPaths = glob.sync(matchedPath, { + // ignore: "**/node_modules/**", + // }); + // pkgPaths = pkgPaths.concat(matchedPaths); + // }); + // // 输出匹配的 package.json 文件路径 + // console.log(pkgPaths); + + const packagesInfo = pkgPatterns.forEach((pkgPattern) => { + const matchedPath = path.join(__dirname, pkgPattern, "package.json").replace(/\\/g, "/"); + console.log("matchedPath :>> ", matchedPath); + const matchedPaths = glob.sync(matchedPath, { + ignore: "**/node_modules/**", + }); + }); + + // const packagesInfo = workspaceConfig.packages.flatMap((pkgPattern) => { + // // console.log("pkgPattern :>> ", pkgPattern); + // const pkgPaths = glob.sync(path.join(__dirname, pkgPattern, "**/package.json")); + // console.log("pkgPaths :>> ", pkgPaths); + // return pkgPaths.map((pkgJsonPath) => { + // console.log("pkgJsonPath :>> ", pkgJsonPath); + // if (fs.existsSync(pkgJsonPath)) { + // const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")); + // return { + // name: pkgJson.name, + // description: pkgJson.description || "没查询到description", + // }; + // } + // return null; + // }); + // }); + + // return packagesInfo.filter(Boolean); +} + +getPackagesNameAndDescription(); +// console.log(" in c ", ); // .commitlintrc.js /** @type {import("cz-git").UserConfig} */ diff --git a/package.json b/package.json index 98f9690..1bbc1ed 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,8 @@ "eslint-plugin-jsdoc": "^48.11.0", "eslint-plugin-prettier": "^5.2.1", "execa": "^9.4.0", + "glob": "^11.0.0", + "js-yaml": "^4.1.0", "markdown-it": "^14.1.0", "mkdirp": "^3.0.1", "pkg-types": "^1.2.1", diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e5b530f..c2e7087 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,8 +1,10 @@ +# 写星号配置 是为了让其他工具可以读取该配置,实现匹配 +# 一定要写成两个星号,否则会被 pnpm 识别为注释 packages: - - "packages/*" - - "demos/*" + - "packages/**" + - "demos/**" - "utils" - - "learn-create-compoents-lib/*" + - "learn-create-compoents-lib/**" catalog: typescript: 5.4.5