Skip to content

Commit a0b31a8

Browse files
committed
✨ [nodekit] 提供了writeText、mergeConfig
1 parent 2fb7a1b commit a0b31a8

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

deno.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodekit/deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "@gaubee/nodekit",
3-
"version": "0.10.2",
3+
"version": "0.11.2",
44
"exports": {
55
"./colors": "./src/colors.ts",
66
"./config_file": "./src/config_file.ts",
7+
"./config": "./src/config.ts",
78
"./markdown_file": "./src/markdown_file.ts",
89
"./fs": "./src/fs.ts",
910
"./git": "./src/git/index.ts",

nodekit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@inquirer/prompts": "^7.5.3",
77
"dax-sh": "^0.43.2",
8+
"defu": "^6.1.4",
89
"gray-matter": "^4.0.3",
910
"ignore": "^7.0.5",
1011
"minimatch": "^10.0.3",

nodekit/src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {obj_assign_props} from "@gaubee/util/object";
2+
import * as defu from "defu";
3+
export type {Defu as MergeConfig} from "defu";
4+
5+
export const mergeConfig = obj_assign_props(defu.default, {
6+
create: defu.createDefu,
7+
fn: defu.defuFn,
8+
arrayFn: defu.defuArrayFn,
9+
});

nodekit/src/config_file.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import * as YAML from "@std/yaml";
99
import fs from "node:fs";
1010
export {JSONC, TOML, YAML};
1111

12+
type ReadText = {
13+
<S extends string = string>(path: string, defaultValue?: undefined): S;
14+
<S extends string = string, T extends unknown = unknown>(path: string, defaultValue: () => T): S | T;
15+
};
16+
export const readText: ReadText = (path: string, defaultValue?: () => any) => {
17+
try {
18+
return fs.readFileSync(normalizeFilePath(path), "utf8");
19+
} catch (e) {
20+
if (defaultValue) {
21+
return defaultValue();
22+
}
23+
throw e;
24+
}
25+
};
26+
1227
export const writeText = (path: string, content: string): void => {
1328
path = normalizeFilePath(path);
1429
try {

nodekit/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./colors.ts";
22
export * from "./config_file.ts";
3+
export * from './config.ts'
34
export * from "./fs.ts";
45
export * from "./git/index.ts";
56
export * from "./ignore.ts";

0 commit comments

Comments
 (0)