Skip to content

Commit

Permalink
🤔 save-file: 单纯地保存;
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-cat committed Oct 13, 2024
1 parent 67ca2fe commit 5b83ff8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 7 deletions.
82 changes: 78 additions & 4 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -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} */
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 写星号配置 是为了让其他工具可以读取该配置,实现匹配
# 一定要写成两个星号,否则会被 pnpm 识别为注释
packages:
- "packages/*"
- "demos/*"
- "packages/**"
- "demos/**"
- "utils"
- "learn-create-compoents-lib/*"
- "learn-create-compoents-lib/**"

catalog:
typescript: 5.4.5
Expand Down

0 comments on commit 5b83ff8

Please sign in to comment.