@scoutello/i18n-magic 0.16.0 → 0.19.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/README.md +207 -19
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +101 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/check-missing.d.ts +1 -0
- package/dist/commands/check-missing.d.ts.map +1 -0
- package/dist/commands/check-missing.js +13 -0
- package/dist/commands/check-missing.js.map +1 -0
- package/dist/commands/clean.d.ts +1 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +82 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/create-pruned-namespace-automated.d.ts +20 -0
- package/dist/commands/create-pruned-namespace-automated.d.ts.map +1 -0
- package/dist/commands/create-pruned-namespace-automated.js +98 -0
- package/dist/commands/create-pruned-namespace-automated.js.map +1 -0
- package/dist/commands/create-pruned-namespace.d.ts +3 -0
- package/dist/commands/create-pruned-namespace.d.ts.map +1 -0
- package/dist/commands/create-pruned-namespace.js +123 -0
- package/dist/commands/create-pruned-namespace.js.map +1 -0
- package/dist/commands/replace.d.ts +1 -0
- package/dist/commands/replace.d.ts.map +1 -0
- package/dist/commands/replace.js +58 -0
- package/dist/commands/replace.js.map +1 -0
- package/dist/commands/scan.d.ts +1 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +70 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/sync-locales.d.ts +1 -0
- package/dist/commands/sync-locales.d.ts.map +1 -0
- package/dist/commands/sync-locales.js +78 -0
- package/dist/commands/sync-locales.js.map +1 -0
- package/dist/i18n-magic.cjs.development.js +348 -130
- package/dist/i18n-magic.cjs.development.js.map +1 -1
- package/dist/i18n-magic.cjs.production.min.js +1 -1
- package/dist/i18n-magic.cjs.production.min.js.map +1 -1
- package/dist/i18n-magic.esm.js +339 -130
- package/dist/i18n-magic.esm.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -0
- package/dist/lib/languges.d.ts +1 -0
- package/dist/lib/languges.d.ts.map +1 -0
- package/dist/lib/languges.js +146 -0
- package/dist/lib/languges.js.map +1 -0
- package/dist/lib/types.d.ts +7 -1
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +20 -1
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +264 -0
- package/dist/lib/utils.js.map +1 -0
- package/package.json +38 -14
- package/src/cli.ts +117 -0
- package/src/commands/clean.ts +4 -1
- package/src/commands/create-pruned-namespace-automated.ts +165 -0
- package/src/commands/create-pruned-namespace.ts +168 -0
- package/src/commands/scan.ts +12 -0
- package/src/index.ts +23 -113
- package/src/lib/types.ts +7 -1
- package/src/lib/utils.ts +59 -2
package/src/lib/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import path from "node:path"
|
|
|
5
5
|
import type OpenAI from "openai"
|
|
6
6
|
import prompts from "prompts"
|
|
7
7
|
import { languages } from "./languges"
|
|
8
|
-
import type { Configuration } from "./types"
|
|
8
|
+
import type { GlobPatternConfig, Configuration } from "./types"
|
|
9
9
|
|
|
10
10
|
export const loadConfig = ({
|
|
11
11
|
configPath = "i18n-magic.js",
|
|
@@ -180,6 +180,62 @@ export const getPureKey = (
|
|
|
180
180
|
return null
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Extracts all glob patterns from the configuration, handling both string and object formats
|
|
185
|
+
*/
|
|
186
|
+
export const extractGlobPatterns = (
|
|
187
|
+
globPatterns: (string | GlobPatternConfig)[],
|
|
188
|
+
): string[] => {
|
|
189
|
+
return globPatterns.map((pattern) =>
|
|
190
|
+
typeof pattern === "string" ? pattern : pattern.pattern,
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Gets the namespaces associated with a specific file path based on glob pattern configuration
|
|
196
|
+
*/
|
|
197
|
+
export const getNamespacesForFile = (
|
|
198
|
+
filePath: string,
|
|
199
|
+
globPatterns: (string | { pattern: string; namespaces: string[] })[],
|
|
200
|
+
): string[] => {
|
|
201
|
+
const matchingNamespaces: string[] = []
|
|
202
|
+
|
|
203
|
+
for (const pattern of globPatterns) {
|
|
204
|
+
if (typeof pattern === "object") {
|
|
205
|
+
// Use minimatch or similar logic to check if file matches pattern
|
|
206
|
+
const globPattern = pattern.pattern
|
|
207
|
+
// For now, using a simple includes check - in production you'd want proper glob matching
|
|
208
|
+
if (filePath.includes(globPattern.replace("**/*", "").replace("*", ""))) {
|
|
209
|
+
matchingNamespaces.push(...pattern.namespaces)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return [...new Set(matchingNamespaces)] // Remove duplicates
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Gets all glob patterns that should be used for a specific namespace
|
|
219
|
+
*/
|
|
220
|
+
export const getGlobPatternsForNamespace = (
|
|
221
|
+
namespace: string,
|
|
222
|
+
globPatterns: (string | { pattern: string; namespaces: string[] })[],
|
|
223
|
+
): string[] => {
|
|
224
|
+
const patterns: string[] = []
|
|
225
|
+
|
|
226
|
+
for (const pattern of globPatterns) {
|
|
227
|
+
if (typeof pattern === "string") {
|
|
228
|
+
// String patterns apply to all namespaces
|
|
229
|
+
patterns.push(pattern)
|
|
230
|
+
} else if (pattern.namespaces.includes(namespace)) {
|
|
231
|
+
// Object patterns only apply to specified namespaces
|
|
232
|
+
patterns.push(pattern.pattern)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return patterns
|
|
237
|
+
}
|
|
238
|
+
|
|
183
239
|
export const getMissingKeys = async ({
|
|
184
240
|
globPatterns,
|
|
185
241
|
namespaces,
|
|
@@ -192,7 +248,8 @@ export const getMissingKeys = async ({
|
|
|
192
248
|
keySeparator: false,
|
|
193
249
|
})
|
|
194
250
|
|
|
195
|
-
const
|
|
251
|
+
const allPatterns = extractGlobPatterns(globPatterns)
|
|
252
|
+
const files = await glob([...allPatterns, "!**/node_modules/**"])
|
|
196
253
|
|
|
197
254
|
const keys = []
|
|
198
255
|
|