@dialekt/adapter-paraglide 0.1.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/TESTING.md +28 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +127 -0
- package/package.json +27 -0
- package/src/adapter.test.ts +155 -0
- package/src/adapter.ts +116 -0
- package/src/index.ts +2 -0
- package/src/message-file.test.ts +66 -0
- package/src/message-file.ts +68 -0
- package/src/unused-keys.test.ts +51 -0
- package/src/unused-keys.ts +59 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.ts +7 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FileSystem, Path } from '@effect/platform';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import type { AdapterReadError } from 'dialekt';
|
|
4
|
+
import { AdapterReadError as AdapterReadErrorClass } from 'dialekt';
|
|
5
|
+
|
|
6
|
+
export function findUnusedParaglideKeys(
|
|
7
|
+
scanPaths: readonly string[],
|
|
8
|
+
keys: readonly string[],
|
|
9
|
+
) {
|
|
10
|
+
return Effect.gen(function* () {
|
|
11
|
+
const fs = yield* FileSystem.FileSystem;
|
|
12
|
+
const path = yield* Path.Path;
|
|
13
|
+
|
|
14
|
+
const referenced = new Set<string>();
|
|
15
|
+
|
|
16
|
+
for (const scanPath of scanPaths) {
|
|
17
|
+
const exists = yield* fs.exists(scanPath).pipe(Effect.orElseSucceed(() => false));
|
|
18
|
+
if (!exists) continue;
|
|
19
|
+
|
|
20
|
+
const entries = yield* fs.readDirectory(scanPath, { recursive: true }).pipe(
|
|
21
|
+
Effect.orElseSucceed(() => [] as string[]),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
for (const relativePath of entries) {
|
|
25
|
+
if (
|
|
26
|
+
!relativePath.endsWith('.ts') &&
|
|
27
|
+
!relativePath.endsWith('.tsx') &&
|
|
28
|
+
!relativePath.endsWith('.js') &&
|
|
29
|
+
!relativePath.endsWith('.jsx') &&
|
|
30
|
+
!relativePath.endsWith('.svelte') &&
|
|
31
|
+
!relativePath.endsWith('.vue')
|
|
32
|
+
) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const filePath = path.join(scanPath, relativePath);
|
|
36
|
+
const content = yield* fs.readFileString(filePath).pipe(Effect.orElseSucceed(() => ''));
|
|
37
|
+
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
const pattern = new RegExp(`\\bm\\.${key}\\b`);
|
|
40
|
+
if (pattern.test(content)) {
|
|
41
|
+
referenced.add(key);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return keys.filter((key) => !referenced.has(key));
|
|
48
|
+
}).pipe(
|
|
49
|
+
Effect.mapError(
|
|
50
|
+
(cause) =>
|
|
51
|
+
new AdapterReadErrorClass({
|
|
52
|
+
adapter: 'paraglide',
|
|
53
|
+
locale: '',
|
|
54
|
+
resource: 'messages',
|
|
55
|
+
cause,
|
|
56
|
+
}) as AdapterReadError,
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
}
|