@gtkx/cli 1.6.0 → 2.0.0-beta.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/README.md +5 -5
- package/dist/codegen/freshness.d.ts.map +1 -1
- package/dist/codegen/freshness.js +45 -16
- package/dist/codegen/freshness.js.map +1 -1
- package/dist/codegen/reference.d.ts.map +1 -1
- package/dist/codegen/reference.js +1 -7
- package/dist/codegen/reference.js.map +1 -1
- package/dist/codegen/report.d.ts.map +1 -1
- package/dist/codegen/report.js +5 -16
- package/dist/codegen/report.js.map +1 -1
- package/dist/codegen/run-codegen.d.ts +3 -5
- package/dist/codegen/run-codegen.d.ts.map +1 -1
- package/dist/codegen/run-codegen.js +23 -100
- package/dist/codegen/run-codegen.js.map +1 -1
- package/dist/codegen/store-resolver.d.ts +0 -1
- package/dist/codegen/store-resolver.d.ts.map +1 -1
- package/dist/codegen/store-resolver.js +8 -17
- package/dist/codegen/store-resolver.js.map +1 -1
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +5 -15
- package/dist/commands/docs.js.map +1 -1
- package/dist/deploy/freedesktop/copyright.d.ts.map +1 -1
- package/dist/deploy/freedesktop/copyright.js +2 -13
- package/dist/deploy/freedesktop/copyright.js.map +1 -1
- package/dist/deploy/freedesktop/xml.d.ts.map +1 -1
- package/dist/deploy/freedesktop/xml.js +21 -25
- package/dist/deploy/freedesktop/xml.js.map +1 -1
- package/dist/deploy/node-runtime/license.d.ts.map +1 -1
- package/dist/deploy/node-runtime/license.js +2 -9
- package/dist/deploy/node-runtime/license.js.map +1 -1
- package/dist/deploy/notices/packages.d.ts.map +1 -1
- package/dist/deploy/notices/packages.js +3 -10
- package/dist/deploy/notices/packages.js.map +1 -1
- package/dist/deploy/payload/copy-tree.d.ts.map +1 -1
- package/dist/deploy/payload/copy-tree.js +3 -3
- package/dist/deploy/payload/copy-tree.js.map +1 -1
- package/dist/deploy/payload/stage.d.ts.map +1 -1
- package/dist/deploy/payload/stage.js +1 -3
- package/dist/deploy/payload/stage.js.map +1 -1
- package/dist/deploy/settings/build-manifest.d.ts.map +1 -1
- package/dist/deploy/settings/build-manifest.js +4 -15
- package/dist/deploy/settings/build-manifest.js.map +1 -1
- package/dist/deploy/settings/libraries.d.ts.map +1 -1
- package/dist/deploy/settings/libraries.js +2 -19
- package/dist/deploy/settings/libraries.js.map +1 -1
- package/dist/deploy/settings/paths.d.ts +1 -2
- package/dist/deploy/settings/paths.d.ts.map +1 -1
- package/dist/deploy/settings/paths.js +5 -15
- package/dist/deploy/settings/paths.js.map +1 -1
- package/dist/deploy/settings/screenshots.d.ts.map +1 -1
- package/dist/deploy/settings/screenshots.js +6 -31
- package/dist/deploy/settings/screenshots.js.map +1 -1
- package/dist/deploy/targets/flatpak-pnpm.js +4 -4
- package/dist/deploy/targets/flatpak-pnpm.js.map +1 -1
- package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak-source.js +4 -4
- package/dist/deploy/targets/flatpak-source.js.map +1 -1
- package/dist/deploy/targets/flatpak-sources.js +1 -1
- package/dist/deploy/targets/flatpak-sources.js.map +1 -1
- package/dist/dev/runner-main.d.ts.map +1 -1
- package/dist/dev/runner-main.js +1 -2
- package/dist/dev/runner-main.js.map +1 -1
- package/dist/dev/schema-dir.d.ts +1 -1
- package/dist/dev/schema-dir.d.ts.map +1 -1
- package/dist/dev/schema-dir.js +2 -4
- package/dist/dev/schema-dir.js.map +1 -1
- package/dist/i18n/catalogs.d.ts.map +1 -1
- package/dist/i18n/catalogs.js +2 -1
- package/dist/i18n/catalogs.js.map +1 -1
- package/dist/i18n/metadata-templates.d.ts.map +1 -1
- package/dist/i18n/metadata-templates.js +2 -1
- package/dist/i18n/metadata-templates.js.map +1 -1
- package/dist/i18n/source-messages.d.ts +3 -21
- package/dist/i18n/source-messages.d.ts.map +1 -1
- package/dist/i18n/source-messages.js +66 -85
- package/dist/i18n/source-messages.js.map +1 -1
- package/dist/i18n/types.d.ts +6 -7
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/i18n/types.js +83 -96
- package/dist/i18n/types.js.map +1 -1
- package/dist/internal/docs-elements.js +2 -2
- package/dist/internal/docs-elements.js.map +1 -1
- package/dist/internal/icon-path.d.ts.map +1 -1
- package/dist/internal/icon-path.js +5 -16
- package/dist/internal/icon-path.js.map +1 -1
- package/dist/internal/source-imports.d.ts.map +1 -1
- package/dist/internal/source-imports.js +10 -41
- package/dist/internal/source-imports.js.map +1 -1
- package/dist/settings/render.d.ts +0 -1
- package/dist/settings/render.d.ts.map +1 -1
- package/dist/settings/render.js +1 -11
- package/dist/settings/render.js.map +1 -1
- package/dist/settings/schema.d.ts +2 -2
- package/dist/settings/schema.d.ts.map +1 -1
- package/dist/settings/schema.js +21 -62
- package/dist/settings/schema.js.map +1 -1
- package/dist/vite-plugins/asset-imports.d.ts +1 -2
- package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
- package/dist/vite-plugins/asset-imports.js +19 -32
- package/dist/vite-plugins/asset-imports.js.map +1 -1
- package/dist/vite-plugins/asset-specifier.d.ts +1 -3
- package/dist/vite-plugins/asset-specifier.d.ts.map +1 -1
- package/dist/vite-plugins/asset-specifier.js +1 -4
- package/dist/vite-plugins/asset-specifier.js.map +1 -1
- package/dist/vite-plugins/i18n.d.ts.map +1 -1
- package/dist/vite-plugins/i18n.js +2 -1
- package/dist/vite-plugins/i18n.js.map +1 -1
- package/dist/vite-plugins/index.d.ts.map +1 -1
- package/dist/vite-plugins/index.js +2 -4
- package/dist/vite-plugins/index.js.map +1 -1
- package/dist/vite-plugins/resources.d.ts.map +1 -1
- package/dist/vite-plugins/resources.js +32 -97
- package/dist/vite-plugins/resources.js.map +1 -1
- package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
- package/dist/vite-plugins/settings-worker-env.js +2 -4
- package/dist/vite-plugins/settings-worker-env.js.map +1 -1
- package/dist/vite-plugins/settings.d.ts +1 -2
- package/dist/vite-plugins/settings.d.ts.map +1 -1
- package/dist/vite-plugins/settings.js +8 -14
- package/dist/vite-plugins/settings.js.map +1 -1
- package/dist/vite-plugins/undeclared-library.d.ts.map +1 -1
- package/dist/vite-plugins/undeclared-library.js +10 -13
- package/dist/vite-plugins/undeclared-library.js.map +1 -1
- package/dist/vite-plugins/worker.d.ts.map +1 -1
- package/dist/vite-plugins/worker.js +0 -1
- package/dist/vite-plugins/worker.js.map +1 -1
- package/package.json +21 -15
- package/src/codegen/freshness.ts +66 -17
- package/src/codegen/reference.ts +1 -8
- package/src/codegen/report.ts +5 -21
- package/src/codegen/run-codegen.ts +28 -145
- package/src/codegen/store-resolver.ts +8 -24
- package/src/commands/docs.ts +5 -17
- package/src/deploy/freedesktop/copyright.ts +2 -14
- package/src/deploy/freedesktop/xml.ts +24 -32
- package/src/deploy/node-runtime/license.ts +2 -8
- package/src/deploy/notices/packages.ts +3 -11
- package/src/deploy/payload/copy-tree.ts +3 -4
- package/src/deploy/payload/stage.ts +2 -6
- package/src/deploy/settings/build-manifest.ts +4 -16
- package/src/deploy/settings/libraries.ts +1 -22
- package/src/deploy/settings/paths.ts +6 -16
- package/src/deploy/settings/screenshots.ts +8 -46
- package/src/deploy/targets/flatpak-pnpm.ts +4 -4
- package/src/deploy/targets/flatpak-source.ts +4 -4
- package/src/deploy/targets/flatpak-sources.ts +1 -1
- package/src/dev/runner-main.ts +1 -2
- package/src/dev/schema-dir.ts +2 -4
- package/src/i18n/catalogs.ts +2 -1
- package/src/i18n/metadata-templates.ts +2 -1
- package/src/i18n/source-messages.ts +77 -115
- package/src/i18n/types.ts +97 -131
- package/src/internal/docs-elements.ts +2 -2
- package/src/internal/icon-path.ts +6 -19
- package/src/internal/source-imports.ts +14 -50
- package/src/settings/render.ts +1 -13
- package/src/settings/schema.ts +19 -81
- package/src/vite-plugins/asset-imports.ts +20 -44
- package/src/vite-plugins/asset-specifier.ts +0 -5
- package/src/vite-plugins/i18n.ts +2 -1
- package/src/vite-plugins/index.ts +2 -4
- package/src/vite-plugins/resources.ts +37 -140
- package/src/vite-plugins/settings-worker-env.ts +2 -4
- package/src/vite-plugins/settings.ts +11 -20
- package/src/vite-plugins/undeclared-library.ts +14 -20
- package/src/vite-plugins/worker.ts +0 -1
- package/dist/i18n/binding-extractor.d.ts +0 -30
- package/dist/i18n/binding-extractor.d.ts.map +0 -1
- package/dist/i18n/binding-extractor.js +0 -1324
- package/dist/i18n/binding-extractor.js.map +0 -1
- package/dist/i18n/extractor-plugin.d.ts +0 -8
- package/dist/i18n/extractor-plugin.d.ts.map +0 -1
- package/dist/i18n/extractor-plugin.js +0 -247
- package/dist/i18n/extractor-plugin.js.map +0 -1
- package/dist/internal/data-dir.d.ts +0 -4
- package/dist/internal/data-dir.d.ts.map +0 -1
- package/dist/internal/data-dir.js +0 -52
- package/dist/internal/data-dir.js.map +0 -1
- package/dist/vite-plugins/animated.d.ts +0 -5
- package/dist/vite-plugins/animated.d.ts.map +0 -1
- package/dist/vite-plugins/animated.js +0 -325
- package/dist/vite-plugins/animated.js.map +0 -1
- package/src/i18n/binding-extractor.ts +0 -1969
- package/src/i18n/extractor-plugin.ts +0 -413
- package/src/internal/data-dir.ts +0 -70
- package/src/vite-plugins/animated.ts +0 -486
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import type { Plugin, PluginContext } from "i18next-cli";
|
|
2
|
-
import {
|
|
3
|
-
type BindingExtraction,
|
|
4
|
-
extractBindings,
|
|
5
|
-
type ScopeInfo,
|
|
6
|
-
} from "./binding-extractor.js";
|
|
7
|
-
|
|
8
|
-
type GtkxExtractorPlugin = {
|
|
9
|
-
plugin: Plugin;
|
|
10
|
-
transComponents: string[];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type ExtractorState = {
|
|
14
|
-
extraction: BindingExtraction;
|
|
15
|
-
sentinel: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type ReconciledNodes = {
|
|
19
|
-
blocked: Set<string>;
|
|
20
|
-
calls: Set<string>;
|
|
21
|
-
trans: Set<string>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const emptyExtraction = (): BindingExtraction => ({
|
|
25
|
-
blockedGetFixedT: new Set(),
|
|
26
|
-
calls: new Map(),
|
|
27
|
-
errors: [],
|
|
28
|
-
messages: [],
|
|
29
|
-
trans: new Map(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
33
|
-
typeof value === "object" && value !== null;
|
|
34
|
-
|
|
35
|
-
const nodeSpanKey = (node: Record<string, unknown>): string | undefined => {
|
|
36
|
-
if (!isRecord(node.span)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return typeof node.span.start === "number" && typeof node.span.end === "number"
|
|
41
|
-
? `${String(node.span.start)}:${String(node.span.end)}`
|
|
42
|
-
: undefined;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const identifier = (value: string, source: unknown): Record<string, unknown> => {
|
|
46
|
-
const span = isRecord(source) && isRecord(source.span) ? source.span : { end: 0, start: 0 };
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
ctxt: 0,
|
|
50
|
-
optional: false,
|
|
51
|
-
span,
|
|
52
|
-
type: "Identifier",
|
|
53
|
-
value,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const sentinelFor = (code: string): string => {
|
|
58
|
-
let sentinel = "__gtkxI18nSentinel";
|
|
59
|
-
|
|
60
|
-
while (new RegExp(String.raw`\b${sentinel}\b`, "u").test(code)) {
|
|
61
|
-
sentinel += "_";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return sentinel;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const canonicalSource = (code: string): string => {
|
|
68
|
-
const hasBom = code.startsWith("\u{FEFF}");
|
|
69
|
-
let hashbangIndex = -1;
|
|
70
|
-
|
|
71
|
-
if (code.startsWith("#!")) {
|
|
72
|
-
hashbangIndex = 0;
|
|
73
|
-
} else if (hasBom && code.startsWith("#!", 1)) {
|
|
74
|
-
hashbangIndex = 1;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let canonical = hasBom ? ` ${code.slice(1)}` : code;
|
|
78
|
-
|
|
79
|
-
if (hashbangIndex !== -1) {
|
|
80
|
-
canonical = `${canonical.slice(0, hashbangIndex)}//${canonical.slice(hashbangIndex + 2)}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return `;${canonical}`;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const replaceCallCallee = (node: Record<string, unknown>, sentinel: string): void => {
|
|
87
|
-
node.callee = identifier(sentinel, node.callee);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const replaceJsxName = (element: unknown, sentinel: string): void => {
|
|
91
|
-
if (!isRecord(element)) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (isRecord(element.opening)) {
|
|
96
|
-
element.opening.name = identifier(sentinel, element.opening.name);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (isRecord(element.closing)) {
|
|
100
|
-
element.closing.name = identifier(sentinel, element.closing.name);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const isJsxAttribute = (value: unknown): value is Record<string, unknown> =>
|
|
105
|
-
isRecord(value) && value.type === "JSXAttribute";
|
|
106
|
-
|
|
107
|
-
const isTAttributeName = (value: unknown): boolean =>
|
|
108
|
-
isRecord(value) && value.value === "t";
|
|
109
|
-
|
|
110
|
-
const isExpressionContainer = (value: unknown): value is Record<string, unknown> =>
|
|
111
|
-
isRecord(value) && value.type === "JSXExpressionContainer";
|
|
112
|
-
|
|
113
|
-
const transTExpression = (attribute: unknown): Record<string, unknown> | undefined => {
|
|
114
|
-
if (!isJsxAttribute(attribute)) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!isTAttributeName(attribute.name)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!isExpressionContainer(attribute.value)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return attribute.value;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const replaceTransTProp = (
|
|
130
|
-
element: Record<string, unknown>,
|
|
131
|
-
sentinel: string,
|
|
132
|
-
info: ScopeInfo | null,
|
|
133
|
-
context: PluginContext,
|
|
134
|
-
): void => {
|
|
135
|
-
if (info === null || !isRecord(element.opening) || !Array.isArray(element.opening.attributes)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
for (const attribute of element.opening.attributes) {
|
|
140
|
-
const expression = transTExpression(attribute);
|
|
141
|
-
|
|
142
|
-
if (expression === undefined) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
context.setVarInScope(sentinel, info);
|
|
147
|
-
expression.expression = identifier(sentinel, expression.expression);
|
|
148
|
-
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const reconcileBlockedNode = (
|
|
154
|
-
value: Record<string, unknown>,
|
|
155
|
-
key: string,
|
|
156
|
-
extraction: BindingExtraction,
|
|
157
|
-
reconciled: ReconciledNodes,
|
|
158
|
-
): void => {
|
|
159
|
-
if (value.type !== "VariableDeclarator") {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (!extraction.blockedGetFixedT.has(key)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
blockUnrelatedGetFixedT(value);
|
|
168
|
-
reconciled.blocked.add(key);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const reconcileCallNode = (
|
|
172
|
-
value: Record<string, unknown>,
|
|
173
|
-
key: string,
|
|
174
|
-
extraction: BindingExtraction,
|
|
175
|
-
reconciled: ReconciledNodes,
|
|
176
|
-
): void => {
|
|
177
|
-
if (value.type === "CallExpression" && extraction.calls.has(key)) {
|
|
178
|
-
reconciled.calls.add(key);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const reconcileTransNode = (
|
|
183
|
-
value: Record<string, unknown>,
|
|
184
|
-
key: string,
|
|
185
|
-
extraction: BindingExtraction,
|
|
186
|
-
reconciled: ReconciledNodes,
|
|
187
|
-
): void => {
|
|
188
|
-
if (value.type === "JSXElement" && extraction.trans.has(key)) {
|
|
189
|
-
reconciled.trans.add(key);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const reconcileNode = (
|
|
194
|
-
value: Record<string, unknown>,
|
|
195
|
-
extraction: BindingExtraction,
|
|
196
|
-
reconciled: ReconciledNodes,
|
|
197
|
-
): void => {
|
|
198
|
-
const key = nodeSpanKey(value);
|
|
199
|
-
|
|
200
|
-
if (key === undefined) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
reconcileBlockedNode(value, key, extraction, reconciled);
|
|
205
|
-
reconcileCallNode(value, key, extraction, reconciled);
|
|
206
|
-
reconcileTransNode(value, key, extraction, reconciled);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const visitModuleChild = (
|
|
210
|
-
child: unknown,
|
|
211
|
-
extraction: BindingExtraction,
|
|
212
|
-
reconciled: ReconciledNodes,
|
|
213
|
-
): void => {
|
|
214
|
-
if (Array.isArray(child)) {
|
|
215
|
-
for (const item of child) {
|
|
216
|
-
visitModuleNode(item, extraction, reconciled);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
visitModuleNode(child, extraction, reconciled);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const visitModuleNode = (
|
|
226
|
-
value: unknown,
|
|
227
|
-
extraction: BindingExtraction,
|
|
228
|
-
reconciled: ReconciledNodes,
|
|
229
|
-
): void => {
|
|
230
|
-
if (!isRecord(value)) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
reconcileNode(value, extraction, reconciled);
|
|
235
|
-
|
|
236
|
-
for (const [name, child] of Object.entries(value)) {
|
|
237
|
-
if (name !== "span") {
|
|
238
|
-
visitModuleChild(child, extraction, reconciled);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const wasExtractionReconciled = (
|
|
244
|
-
extraction: BindingExtraction,
|
|
245
|
-
reconciled: ReconciledNodes,
|
|
246
|
-
): boolean =>
|
|
247
|
-
reconciled.blocked.size === extraction.blockedGetFixedT.size &&
|
|
248
|
-
reconciled.calls.size === extraction.calls.size &&
|
|
249
|
-
reconciled.trans.size === extraction.trans.size;
|
|
250
|
-
|
|
251
|
-
const blockUnrelatedGetFixedT = (declarator: Record<string, unknown>): void => {
|
|
252
|
-
if (!isRecord(declarator.init) || !isRecord(declarator.init.callee)) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const callee = declarator.init.callee;
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
callee.type === "MemberExpression" &&
|
|
260
|
-
isRecord(callee.property) &&
|
|
261
|
-
callee.property.value === "getFixedT"
|
|
262
|
-
) {
|
|
263
|
-
callee.property.value = "__gtkxIgnoredGetFixedT";
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const prepareModule = (
|
|
268
|
-
module: Record<string, unknown>,
|
|
269
|
-
extraction: BindingExtraction,
|
|
270
|
-
context: PluginContext,
|
|
271
|
-
): void => {
|
|
272
|
-
const reconciled: ReconciledNodes = {
|
|
273
|
-
blocked: new Set(),
|
|
274
|
-
calls: new Set(),
|
|
275
|
-
trans: new Set(),
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
visitModuleNode(module, extraction, reconciled);
|
|
279
|
-
|
|
280
|
-
if (!wasExtractionReconciled(extraction, reconciled)) {
|
|
281
|
-
context.logger.warn("GTKX could not reconcile the binding-aware and i18next syntax trees");
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
const submitMessages = (
|
|
286
|
-
extraction: BindingExtraction,
|
|
287
|
-
context: PluginContext,
|
|
288
|
-
): void => {
|
|
289
|
-
for (const error of extraction.errors) {
|
|
290
|
-
context.logger.warn(error);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
for (const message of extraction.messages) {
|
|
294
|
-
context.addKey({
|
|
295
|
-
key: message.key,
|
|
296
|
-
defaultValue: message.defaultValue,
|
|
297
|
-
explicitDefault: message.explicitDefault,
|
|
298
|
-
locations: [message.location],
|
|
299
|
-
...(message.ns !== undefined && { ns: message.ns }),
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const loadSource = async (
|
|
305
|
-
state: ExtractorState,
|
|
306
|
-
transComponents: string[],
|
|
307
|
-
code: string,
|
|
308
|
-
path: string,
|
|
309
|
-
): Promise<string> => {
|
|
310
|
-
const canonical = canonicalSource(code);
|
|
311
|
-
state.extraction = await extractBindings(canonical, path);
|
|
312
|
-
state.sentinel = sentinelFor(canonical);
|
|
313
|
-
transComponents.splice(0, transComponents.length, state.sentinel);
|
|
314
|
-
|
|
315
|
-
return canonical;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const visitCall = (
|
|
319
|
-
state: ExtractorState,
|
|
320
|
-
node: Record<string, unknown>,
|
|
321
|
-
key: string,
|
|
322
|
-
context: PluginContext,
|
|
323
|
-
): void => {
|
|
324
|
-
const call = state.extraction.calls.get(key);
|
|
325
|
-
|
|
326
|
-
if (call !== undefined) {
|
|
327
|
-
context.setVarInScope(state.sentinel, call.info);
|
|
328
|
-
replaceCallCallee(node, state.sentinel);
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const visitTrans = (
|
|
333
|
-
state: ExtractorState,
|
|
334
|
-
node: Record<string, unknown>,
|
|
335
|
-
key: string,
|
|
336
|
-
context: PluginContext,
|
|
337
|
-
): void => {
|
|
338
|
-
const transInfo = state.extraction.trans.get(key);
|
|
339
|
-
|
|
340
|
-
if (transInfo !== undefined) {
|
|
341
|
-
const tSentinel = `${state.sentinel}T`;
|
|
342
|
-
replaceJsxName(node, state.sentinel);
|
|
343
|
-
replaceTransTProp(node, tSentinel, transInfo, context);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const visitMatchedNode = (
|
|
348
|
-
state: ExtractorState,
|
|
349
|
-
node: Record<string, unknown>,
|
|
350
|
-
key: string,
|
|
351
|
-
context: PluginContext,
|
|
352
|
-
): void => {
|
|
353
|
-
if (node.type === "VariableDeclarator" && state.extraction.blockedGetFixedT.has(key)) {
|
|
354
|
-
blockUnrelatedGetFixedT(node);
|
|
355
|
-
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (node.type === "CallExpression") {
|
|
360
|
-
visitCall(state, node, key, context);
|
|
361
|
-
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (node.type === "JSXElement") {
|
|
366
|
-
visitTrans(state, node, key, context);
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const visitNode = (
|
|
371
|
-
state: ExtractorState,
|
|
372
|
-
node: unknown,
|
|
373
|
-
context: PluginContext,
|
|
374
|
-
): void => {
|
|
375
|
-
if (!isRecord(node)) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (node.type === "Module") {
|
|
380
|
-
prepareModule(node, state.extraction, context);
|
|
381
|
-
submitMessages(state.extraction, context);
|
|
382
|
-
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const key = nodeSpanKey(node);
|
|
387
|
-
|
|
388
|
-
if (key !== undefined) {
|
|
389
|
-
visitMatchedNode(state, node, key, context);
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
const gtkxExtractorPlugin = (): GtkxExtractorPlugin => {
|
|
394
|
-
const state: ExtractorState = {
|
|
395
|
-
extraction: emptyExtraction(),
|
|
396
|
-
sentinel: "__gtkxI18nSentinel",
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
const transComponents: string[] = [];
|
|
400
|
-
|
|
401
|
-
const plugin: Plugin = {
|
|
402
|
-
name: "gtkx-react-i18next",
|
|
403
|
-
onLoad: loadSource.bind(undefined, state, transComponents),
|
|
404
|
-
onVisitNode: visitNode.bind(undefined, state),
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
return {
|
|
408
|
-
plugin,
|
|
409
|
-
transComponents,
|
|
410
|
-
};
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
export { gtkxExtractorPlugin };
|
package/src/internal/data-dir.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
|
|
4
|
-
const DATA_IMPORT_PREFIX = "#data";
|
|
5
|
-
const DATA_IMPORT_KEY = `${DATA_IMPORT_PREFIX}/*`;
|
|
6
|
-
const CONDITION_PRIORITY = ["default", "import", "node"] as const;
|
|
7
|
-
const DATA_TARGET_PATTERN = /^\.?\/?(.+?)\/\*$/;
|
|
8
|
-
|
|
9
|
-
const isConditionMap = (entry: unknown): entry is Record<string, unknown> =>
|
|
10
|
-
entry !== null && typeof entry === "object" && !Array.isArray(entry);
|
|
11
|
-
|
|
12
|
-
const conditionTarget = (conditions: Record<string, unknown>): string | null => {
|
|
13
|
-
for (const condition of CONDITION_PRIORITY) {
|
|
14
|
-
const value = conditions[condition];
|
|
15
|
-
|
|
16
|
-
if (typeof value === "string") {
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const targetString = (entry: unknown): string | null => {
|
|
25
|
-
if (typeof entry === "string") {
|
|
26
|
-
return entry;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (isConditionMap(entry)) {
|
|
30
|
-
return conditionTarget(entry);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const directoryFromTarget = (target: string): string | null => {
|
|
37
|
-
const match = DATA_TARGET_PATTERN.exec(target);
|
|
38
|
-
|
|
39
|
-
return match?.[1] ?? null;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const resolveDataDir = (root: string): string | null => {
|
|
43
|
-
let manifest: unknown;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!isConditionMap(manifest)) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const imports = manifest.imports;
|
|
56
|
-
|
|
57
|
-
if (!isConditionMap(imports)) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const target = targetString(imports[DATA_IMPORT_KEY]);
|
|
62
|
-
|
|
63
|
-
if (target === null) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return directoryFromTarget(target);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export { DATA_IMPORT_PREFIX, resolveDataDir };
|