kerria 0.4.1 → 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 +3 -3
- package/dist/index.mjs +14 -14
- 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;
|
|
@@ -46,7 +46,7 @@ interface KerriaContext {
|
|
|
46
46
|
declare function useCurrentContext(): KerriaContext;
|
|
47
47
|
declare function createKerria(sign: string, setup: (ctx: KerriaContext) => void): {
|
|
48
48
|
build: () => Promise<void>;
|
|
49
|
-
watch: () => () => void
|
|
49
|
+
watch: () => () => Promise<void[]>;
|
|
50
50
|
};
|
|
51
51
|
//#endregion
|
|
52
52
|
export { KerriaContext, LoadInfo, SourceInfo, UseLoadOptions, UseSourceOptions, createKerria, useCurrentContext, useLoad, useSource };
|
package/dist/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ function createKerria(sign, setup) {
|
|
|
46
46
|
currentContext = null;
|
|
47
47
|
ctx.sourceInfos.sort((a, b) => a.kind - b.kind);
|
|
48
48
|
const cachePath = join(pkg.cache("kerria", { create: true }), `${sign}.json`);
|
|
49
|
-
const caches = existsSync(cachePath)
|
|
49
|
+
const caches = existsSync(cachePath) ? readJsonSync(cachePath) : {};
|
|
50
50
|
async function build() {
|
|
51
51
|
for (const info of ctx.sourceInfos) {
|
|
52
52
|
const paths = await glob(info.patterns, { absolute: true });
|
|
@@ -85,9 +85,7 @@ function createKerria(sign, setup) {
|
|
|
85
85
|
consola.success(`[${sign}] Change "${info.src}"`);
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
return () =>
|
|
89
|
-
for (const watcher of watchers) watcher.close();
|
|
90
|
-
};
|
|
88
|
+
return () => Promise.all(watchers.map((watcher) => watcher.close()));
|
|
91
89
|
}
|
|
92
90
|
async function parse(path, info) {
|
|
93
91
|
const stats = await stat(path);
|
|
@@ -108,9 +106,9 @@ function createKerria(sign, setup) {
|
|
|
108
106
|
} else unlink(path, info);
|
|
109
107
|
return true;
|
|
110
108
|
}
|
|
111
|
-
|
|
112
|
-
if (caches
|
|
113
|
-
return
|
|
109
|
+
function add(path, info) {
|
|
110
|
+
if (path in caches) return false;
|
|
111
|
+
return parse(path, info);
|
|
114
112
|
}
|
|
115
113
|
function unlink(path, info) {
|
|
116
114
|
const cache = caches[path];
|
|
@@ -135,16 +133,17 @@ function createKerria(sign, setup) {
|
|
|
135
133
|
function useLoad(name, options) {
|
|
136
134
|
const ctx = useCurrentContext();
|
|
137
135
|
const { defaultValue = {}, update, output } = options;
|
|
138
|
-
const src = options.src
|
|
139
|
-
const
|
|
136
|
+
const src = options.src && resolve(options.src);
|
|
137
|
+
const dist = options.dist && resolve(options.dist);
|
|
140
138
|
const info = {
|
|
141
139
|
name,
|
|
142
140
|
src,
|
|
143
|
-
|
|
141
|
+
dist,
|
|
144
142
|
value: src ? readJsonSync(src) : defaultValue,
|
|
145
143
|
update,
|
|
146
144
|
output() {
|
|
147
|
-
|
|
145
|
+
if (dist === void 0) return;
|
|
146
|
+
writeJsonSync(dist, output?.(info.value) ?? info.value);
|
|
148
147
|
}
|
|
149
148
|
};
|
|
150
149
|
ctx.loadInfos.push(info);
|
|
@@ -158,7 +157,7 @@ function useSource(kind, options) {
|
|
|
158
157
|
const ctx = useCurrentContext();
|
|
159
158
|
const { deep = true, skip = 0 } = options;
|
|
160
159
|
const base = resolve(options.base);
|
|
161
|
-
const dist = options.dist
|
|
160
|
+
const dist = options.dist && resolve(options.dist);
|
|
162
161
|
const folders = options.folders?.map((folder) => resolve(base, folder)) ?? [base];
|
|
163
162
|
const patterns = folders.map((path) => resolve(path, (deep ? "**/*" : "*") + options.ext));
|
|
164
163
|
const info = {
|
|
@@ -173,8 +172,9 @@ function useSource(kind, options) {
|
|
|
173
172
|
filter(path) {
|
|
174
173
|
return skip < path.split("/").length - folders[0].split("/").length;
|
|
175
174
|
},
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
output(path, data) {
|
|
176
|
+
if (dist === void 0) return;
|
|
177
|
+
return writeJson(path.replace(base, dist).replace(info.ext, ".json"), data);
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
ctx.sourceInfos.push(info);
|
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",
|