kerria 0.4.2 → 0.5.0
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/dist/index.d.mts +2 -2
- package/dist/index.mjs +7 -5
- package/package.json +4 -6
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ interface LoadInfo extends Omit<UseLoadOptions, "defaultValue" | "output"> {
|
|
|
6
6
|
}
|
|
7
7
|
interface UseLoadOptions {
|
|
8
8
|
src?: string;
|
|
9
|
-
|
|
9
|
+
dist?: string;
|
|
10
10
|
defaultValue?: unknown;
|
|
11
11
|
update?: (newVal: any, oldVal: any) => any;
|
|
12
12
|
output?: (val: any) => any;
|
|
@@ -22,7 +22,7 @@ interface SourceInfo extends Omit<UseSourceOptions, "folders"> {
|
|
|
22
22
|
folders: string[];
|
|
23
23
|
patterns: string[];
|
|
24
24
|
filter: (path: string) => boolean;
|
|
25
|
-
output: (path: string, data: any) =>
|
|
25
|
+
output: (path: string, data: any) => MaybePromise<void>;
|
|
26
26
|
}
|
|
27
27
|
interface UseSourceOptions<T = any> {
|
|
28
28
|
base: string;
|
package/dist/index.mjs
CHANGED
|
@@ -133,16 +133,17 @@ function createKerria(sign, setup) {
|
|
|
133
133
|
function useLoad(name, options) {
|
|
134
134
|
const ctx = useCurrentContext();
|
|
135
135
|
const { defaultValue = {}, update, output } = options;
|
|
136
|
-
const src = options.src
|
|
137
|
-
const
|
|
136
|
+
const src = options.src && resolve(options.src);
|
|
137
|
+
const dist = options.dist && resolve(options.dist);
|
|
138
138
|
const info = {
|
|
139
139
|
name,
|
|
140
140
|
src,
|
|
141
|
-
|
|
141
|
+
dist,
|
|
142
142
|
value: src ? readJsonSync(src) : defaultValue,
|
|
143
143
|
update,
|
|
144
144
|
output() {
|
|
145
|
-
|
|
145
|
+
if (dist === void 0) return;
|
|
146
|
+
writeJsonSync(dist, output?.(info.value) ?? info.value);
|
|
146
147
|
}
|
|
147
148
|
};
|
|
148
149
|
ctx.loadInfos.push(info);
|
|
@@ -156,7 +157,7 @@ function useSource(kind, options) {
|
|
|
156
157
|
const ctx = useCurrentContext();
|
|
157
158
|
const { deep = true, skip = 0 } = options;
|
|
158
159
|
const base = resolve(options.base);
|
|
159
|
-
const dist = options.dist
|
|
160
|
+
const dist = options.dist && resolve(options.dist);
|
|
160
161
|
const folders = options.folders?.map((folder) => resolve(base, folder)) ?? [base];
|
|
161
162
|
const patterns = folders.map((path) => resolve(path, (deep ? "**/*" : "*") + options.ext));
|
|
162
163
|
const info = {
|
|
@@ -172,6 +173,7 @@ function useSource(kind, options) {
|
|
|
172
173
|
return skip < path.split("/").length - folders[0].split("/").length;
|
|
173
174
|
},
|
|
174
175
|
output(path, data) {
|
|
176
|
+
if (dist === void 0) return;
|
|
175
177
|
return writeJson(path.replace(base, dist).replace(info.ext, ".json"), data);
|
|
176
178
|
}
|
|
177
179
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kerria",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "Composable source processor",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
".": "./dist/index.mjs",
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
|
-
"main": "./dist/index.mjs",
|
|
15
|
-
"module": "./dist/index.mjs",
|
|
16
14
|
"types": "./dist/index.d.mts",
|
|
17
15
|
"files": [
|
|
18
16
|
"dist"
|
|
@@ -25,12 +23,12 @@
|
|
|
25
23
|
"tinyglobby": "^0.2.15"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^25.0.
|
|
26
|
+
"@types/node": "^25.0.10",
|
|
29
27
|
"@zinkawaii/eslint-config": "^0.4.1",
|
|
30
28
|
"@zinkawaii/tsconfig": "^0.0.2",
|
|
31
|
-
"bumpp": "^10.
|
|
29
|
+
"bumpp": "^10.4.0",
|
|
32
30
|
"eslint": "^9.39.2",
|
|
33
|
-
"tsdown": "^0.
|
|
31
|
+
"tsdown": "^0.20.1"
|
|
34
32
|
},
|
|
35
33
|
"scripts": {
|
|
36
34
|
"build": "tsdown",
|