@ruan-cat/utils 1.3.5 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ import { spawnSync } from "node:child_process";
2
+
3
+ /** 包的信息 */
4
+ export interface PackageInfo {
5
+ /** 包名 */
6
+ name: string;
7
+ /** 包的描述 */
8
+ description: string;
9
+ /** 带有包名的官方镜像源地址 */
10
+ url: `https://npm.im/${string}`;
11
+ }
12
+
13
+ /**
14
+ * 获得阮喵喵全部的包信息
15
+ * @description
16
+ * 这是一个node环境下的函数,用于获取阮喵喵的所有包的信息。
17
+ *
18
+ * 使用的是node的child_process模块,调用pnpm命令获取包信息。
19
+ *
20
+ * - 默认仅考虑pnpm包
21
+ * - 在node环境下运行
22
+ */
23
+ export async function getRuanCatPkgInfo() {
24
+ return new Promise<PackageInfo[]>((resolve, reject) => {
25
+ /**
26
+ * pnpm s @ruan-cat/* --registry https://registry.npmmirror.com/ --json
27
+ * 仅查询淘宝源的数据
28
+ */
29
+ const result = spawnSync("pnpm", ["s", "@ruan-cat/*", "--registry", "https://registry.npmmirror.com/", "--json"], {
30
+ encoding: "utf-8",
31
+ });
32
+
33
+ if (result.error) {
34
+ console.error(`Error executing command: ${result.error.message}`);
35
+ reject(result.error);
36
+ return;
37
+ }
38
+ if (result.stderr) {
39
+ console.error(`Error in output: ${result.stderr}`);
40
+ reject(new Error(result.stderr));
41
+ return;
42
+ }
43
+
44
+ const packages = <unknown[]>JSON.parse(result.stdout);
45
+ const res = packages.map(
46
+ (pkg: any) =>
47
+ ({
48
+ name: pkg.name,
49
+ description: pkg.description,
50
+ url: `https://npm.im/${pkg.name}`,
51
+ }) satisfies PackageInfo,
52
+ );
53
+ // const res = packages;
54
+ resolve(res);
55
+ });
56
+ }