@ruan-cat/utils 4.8.1 → 4.9.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.
package/README.md CHANGED
@@ -1 +1,9 @@
1
- 详情看[此文件](./src/index.md)。
1
+ ---
2
+ order: 10
3
+ dir:
4
+ order: 10
5
+ ---
6
+
7
+ # 工具包
8
+
9
+ 这是阮喵喵开发的工具包,提供了一些工具函数。
@@ -39,6 +39,19 @@ declare function hasChangelogMd(): boolean;
39
39
  */
40
40
  declare function copyChangelogMd(/** 目标文件夹 */ target: string): void;
41
41
 
42
+ /** 检查当前运行的根目录 是否存在文件名大写的 `README.md` 文件 */
43
+ declare function hasCapitalReadmeMd(): boolean;
44
+ /** 检查当前运行的根目录 是否存在文件名小写的 `readme.md` 文件 */
45
+ declare function hasLowerCaseReadmeMd(): boolean;
46
+ /** 检查当前运行的根目录 是否存在任意一个大小写命名的 README.md 文件 */
47
+ declare function hasReadmeMd(): boolean;
48
+ /**
49
+ * 将 README.md 文件移动到指定要求的位置内,并重命名为 index.md
50
+ * @description
51
+ * 该函数相当于实现 `cpx README.md docs` 命令
52
+ */
53
+ declare function copyReadmeMd(/** 目标文件夹 */ target: string): void;
54
+
42
55
  interface WriteYaml2mdParams<T = Record<string, any>> {
43
56
  /** 目标md文件地址 */
44
57
  mdPath: string;
@@ -59,4 +72,4 @@ interface AddChangelog2docOptions<T = Record<string, any>> {
59
72
  /** 将变更日志添加到指定的文档目录内 并提供参数 */
60
73
  declare function addChangelog2doc<T>(options: AddChangelog2docOptions<T>): void;
61
74
 
62
- export { type AddChangelog2docOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, defaultCleanTargets, getRuanCatPkgInfo, hasChangelogMd, writeYaml2md };
75
+ export { type AddChangelog2docOptions, type PackageInfo, type WriteYaml2mdParams, addChangelog2doc, clean, copyChangelogMd, copyReadmeMd, defaultCleanTargets, getRuanCatPkgInfo, hasCapitalReadmeMd, hasChangelogMd, hasLowerCaseReadmeMd, hasReadmeMd, writeYaml2md };
@@ -80,6 +80,11 @@ function generateSpawnSync(spawnSyncSimpleParams) {
80
80
  });
81
81
  }
82
82
 
83
+ // src/conditions.ts
84
+ function isConditionsSome(conditions) {
85
+ return conditions.some((condition) => condition());
86
+ }
87
+
83
88
  // src/print.ts
84
89
  import { isPlainObject, isArray } from "lodash-es";
85
90
 
@@ -131,9 +136,48 @@ function copyChangelogMd(target) {
131
136
  fs.copyFileSync(source, destination);
132
137
  }
133
138
 
139
+ // src/node-esm/scripts/copy-readme.ts
140
+ import fs2 from "fs";
141
+ import path2 from "path";
142
+ import consola3 from "consola";
143
+ var capitalReadmeMd = "README.md";
144
+ var lowerCaseReadmeMd = "readme.md";
145
+ function hasCapitalReadmeMd() {
146
+ const res = fs2.existsSync(path2.resolve(process.cwd(), capitalReadmeMd));
147
+ if (!res) {
148
+ consola3.warn(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${capitalReadmeMd} \u6587\u4EF6`);
149
+ }
150
+ return res;
151
+ }
152
+ function hasLowerCaseReadmeMd() {
153
+ const res = fs2.existsSync(path2.resolve(process.cwd(), lowerCaseReadmeMd));
154
+ if (!res) {
155
+ consola3.log(`\u5F53\u524D\u9879\u76EE\u6839\u76EE\u5F55\u4E0D\u5B58\u5728 ${lowerCaseReadmeMd} \u6587\u4EF6`);
156
+ }
157
+ return res;
158
+ }
159
+ function hasReadmeMd() {
160
+ const res = isConditionsSome([() => hasCapitalReadmeMd(), () => hasCapitalReadmeMd()]);
161
+ return res;
162
+ }
163
+ function copyReadmeMd(target) {
164
+ if (!hasReadmeMd()) {
165
+ return;
166
+ }
167
+ let readmeFileName = capitalReadmeMd;
168
+ if (hasCapitalReadmeMd()) {
169
+ readmeFileName = capitalReadmeMd;
170
+ } else if (hasLowerCaseReadmeMd()) {
171
+ readmeFileName = lowerCaseReadmeMd;
172
+ }
173
+ const source = path2.resolve(process.cwd(), readmeFileName);
174
+ const destination = path2.resolve(process.cwd(), target, "index.md");
175
+ fs2.copyFileSync(source, destination);
176
+ }
177
+
134
178
  // src/node-esm/scripts/yaml-to-md.ts
135
179
  import { readFileSync, writeFileSync } from "fs";
136
- import { consola as consola3 } from "consola";
180
+ import { consola as consola4 } from "consola";
137
181
  import { isUndefined } from "lodash-es";
138
182
 
139
183
  // ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/dist/js-yaml.mjs
@@ -2760,16 +2804,16 @@ var js_yaml_default = jsYaml;
2760
2804
 
2761
2805
  // src/node-esm/scripts/yaml-to-md.ts
2762
2806
  function writeYaml2md(params) {
2763
- consola3.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2807
+ consola4.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2764
2808
  const { mdPath, data } = params;
2765
2809
  if (isUndefined(mdPath)) {
2766
- consola3.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2810
+ consola4.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2767
2811
  process.exit(1);
2768
2812
  }
2769
2813
  try {
2770
2814
  readFileSync(mdPath, "utf-8");
2771
2815
  } catch (error) {
2772
- consola3.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2816
+ consola4.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2773
2817
  process.exit(1);
2774
2818
  }
2775
2819
  const mdContent = readFileSync(mdPath, "utf-8");
@@ -2779,18 +2823,18 @@ ${yamlContent}---
2779
2823
 
2780
2824
  ${mdContent}`;
2781
2825
  writeFileSync(mdPath, newContent, "utf-8");
2782
- consola3.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2826
+ consola4.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2783
2827
  }
2784
2828
 
2785
2829
  // src/node-esm/scripts/add-changelog-to-doc.ts
2786
- import path2 from "path";
2830
+ import path3 from "path";
2787
2831
  function addChangelog2doc(options) {
2788
2832
  const { data, target } = options;
2789
2833
  if (!hasChangelogMd()) {
2790
2834
  return;
2791
2835
  }
2792
2836
  copyChangelogMd(target);
2793
- const mdPath = path2.resolve(process.cwd(), target, "CHANGELOG.md");
2837
+ const mdPath = path3.resolve(process.cwd(), target, "CHANGELOG.md");
2794
2838
  writeYaml2md({
2795
2839
  mdPath,
2796
2840
  data
@@ -2800,9 +2844,13 @@ export {
2800
2844
  addChangelog2doc,
2801
2845
  clean,
2802
2846
  copyChangelogMd,
2847
+ copyReadmeMd,
2803
2848
  defaultCleanTargets,
2804
2849
  getRuanCatPkgInfo,
2850
+ hasCapitalReadmeMd,
2805
2851
  hasChangelogMd,
2852
+ hasLowerCaseReadmeMd,
2853
+ hasReadmeMd,
2806
2854
  writeYaml2md
2807
2855
  };
2808
2856
  /*! Bundled license information: