kerria 0.4.0 → 0.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.
- package/dist/{index.d.ts → index.d.mts} +1 -1
- package/dist/{index.js → index.mjs} +33 -32
- package/package.json +12 -11
|
@@ -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: () =>
|
|
49
|
+
watch: () => () => void;
|
|
50
50
|
};
|
|
51
51
|
//#endregion
|
|
52
52
|
export { KerriaContext, LoadInfo, SourceInfo, UseLoadOptions, UseSourceOptions, createKerria, useCurrentContext, useLoad, useSource };
|
|
@@ -22,13 +22,11 @@ function readJsonSync(path) {
|
|
|
22
22
|
}
|
|
23
23
|
function writeJson(path, data) {
|
|
24
24
|
mkdirSync(dirname(path), { recursive: true });
|
|
25
|
-
|
|
26
|
-
return writeFile(path, json);
|
|
25
|
+
return writeFile(path, JSON.stringify(data));
|
|
27
26
|
}
|
|
28
27
|
function writeJsonSync(path, data) {
|
|
29
28
|
mkdirSync(dirname(path), { recursive: true });
|
|
30
|
-
|
|
31
|
-
return writeFileSync(path, json);
|
|
29
|
+
return writeFileSync(path, JSON.stringify(data));
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
//#endregion
|
|
@@ -46,11 +44,8 @@ function createKerria(sign, setup) {
|
|
|
46
44
|
currentContext = ctx;
|
|
47
45
|
setup(ctx);
|
|
48
46
|
currentContext = null;
|
|
49
|
-
ctx.sourceInfos.sort((a, b) =>
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const cacheDir = pkg.cache("kerria", { create: true });
|
|
53
|
-
const cachePath = join(cacheDir, `${sign}.json`);
|
|
47
|
+
ctx.sourceInfos.sort((a, b) => a.kind - b.kind);
|
|
48
|
+
const cachePath = join(pkg.cache("kerria", { create: true }), `${sign}.json`);
|
|
54
49
|
const caches = existsSync(cachePath) && readJsonSync(cachePath) || {};
|
|
55
50
|
async function build() {
|
|
56
51
|
for (const info of ctx.sourceInfos) {
|
|
@@ -60,29 +55,39 @@ function createKerria(sign, setup) {
|
|
|
60
55
|
outputLoads();
|
|
61
56
|
consola.success(`[${sign}] Build`);
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
function watch() {
|
|
59
|
+
const watchers = [];
|
|
60
|
+
for (const info of ctx.sourceInfos) {
|
|
61
|
+
const watcher = chokidar.watch(info.folders, {
|
|
62
|
+
depth: info.deep ? Infinity : 0,
|
|
63
|
+
ignoreInitial: true
|
|
64
|
+
});
|
|
65
|
+
watchers.push(watcher);
|
|
66
|
+
watcher.on("all", async (event, filename) => {
|
|
67
|
+
const path = filename.replaceAll("\\", "/");
|
|
68
|
+
if (!path.endsWith(info.ext)) return false;
|
|
69
|
+
else if (!info.filter(path)) return false;
|
|
70
|
+
else if (event === "change" && !await parse(path, info)) return false;
|
|
71
|
+
else if (event === "add" && !await add(path, info)) return false;
|
|
72
|
+
else if (event === "unlink" && !unlink(path, info)) return false;
|
|
73
|
+
outputLoads();
|
|
74
|
+
consola.success(`[${sign}] ${capitalize(event)} "${path}"`);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
77
|
for (const info of ctx.loadInfos) {
|
|
78
78
|
if (!info.src) continue;
|
|
79
|
-
chokidar.watch(info.src, { ignoreInitial: true })
|
|
79
|
+
const watcher = chokidar.watch(info.src, { ignoreInitial: true });
|
|
80
|
+
watchers.push(watcher);
|
|
81
|
+
watcher.on("change", async () => {
|
|
80
82
|
const newVal = await readJson(info.src);
|
|
81
83
|
info.value = info.update?.(newVal, info.value) ?? newVal;
|
|
82
84
|
info.output();
|
|
83
85
|
consola.success(`[${sign}] Change "${info.src}"`);
|
|
84
86
|
});
|
|
85
87
|
}
|
|
88
|
+
return () => {
|
|
89
|
+
for (const watcher of watchers) watcher.close();
|
|
90
|
+
};
|
|
86
91
|
}
|
|
87
92
|
async function parse(path, info) {
|
|
88
93
|
const stats = await stat(path);
|
|
@@ -104,8 +109,7 @@ function createKerria(sign, setup) {
|
|
|
104
109
|
return true;
|
|
105
110
|
}
|
|
106
111
|
async function add(path, info) {
|
|
107
|
-
|
|
108
|
-
if (cache) return false;
|
|
112
|
+
if (caches[path]) return false;
|
|
109
113
|
return await parse(path, info);
|
|
110
114
|
}
|
|
111
115
|
function unlink(path, info) {
|
|
@@ -140,8 +144,7 @@ function useLoad(name, options) {
|
|
|
140
144
|
value: src ? readJsonSync(src) : defaultValue,
|
|
141
145
|
update,
|
|
142
146
|
output() {
|
|
143
|
-
|
|
144
|
-
writeJsonSync(out, data);
|
|
147
|
+
writeJsonSync(out, output?.(info.value) ?? info.value);
|
|
145
148
|
}
|
|
146
149
|
};
|
|
147
150
|
ctx.loadInfos.push(info);
|
|
@@ -168,12 +171,10 @@ function useSource(kind, options) {
|
|
|
168
171
|
deep,
|
|
169
172
|
skip,
|
|
170
173
|
filter(path) {
|
|
171
|
-
|
|
172
|
-
return skip < depth;
|
|
174
|
+
return skip < path.split("/").length - folders[0].split("/").length;
|
|
173
175
|
},
|
|
174
176
|
async output(path, data) {
|
|
175
|
-
|
|
176
|
-
await writeJson(outPath, data);
|
|
177
|
+
await writeJson(path.replace(base, dist).replace(info.ext, ".json"), data);
|
|
177
178
|
}
|
|
178
179
|
};
|
|
179
180
|
ctx.sourceInfos.push(info);
|
package/package.json
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kerria",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"description": "Composable source processor",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": "KazariEX/kerria",
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"exports": {
|
|
11
|
-
".": "./dist/index.
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
12
13
|
},
|
|
13
|
-
"main": "./dist/index.
|
|
14
|
-
"module": "./dist/index.
|
|
15
|
-
"types": "./dist/index.d.
|
|
14
|
+
"main": "./dist/index.mjs",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
16
17
|
"files": [
|
|
17
18
|
"dist"
|
|
18
19
|
],
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"chokidar": "^
|
|
21
|
+
"chokidar": "^5.0.0",
|
|
21
22
|
"consola": "^3.4.2",
|
|
22
23
|
"empathic": "^2.0.0",
|
|
23
24
|
"pathe": "^2.0.3",
|
|
24
|
-
"tinyglobby": "^0.2.
|
|
25
|
+
"tinyglobby": "^0.2.15"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@types/node": "^
|
|
28
|
+
"@types/node": "^25.0.3",
|
|
28
29
|
"@zinkawaii/eslint-config": "^0.4.1",
|
|
29
30
|
"@zinkawaii/tsconfig": "^0.0.2",
|
|
30
|
-
"bumpp": "^10.2
|
|
31
|
-
"eslint": "^9.
|
|
32
|
-
"tsdown": "^0.
|
|
31
|
+
"bumpp": "^10.3.2",
|
|
32
|
+
"eslint": "^9.39.2",
|
|
33
|
+
"tsdown": "^0.18.4"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "tsdown",
|