@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.
Files changed (64) hide show
  1. package/README.md +207 -19
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +101 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/check-missing.d.ts +1 -0
  7. package/dist/commands/check-missing.d.ts.map +1 -0
  8. package/dist/commands/check-missing.js +13 -0
  9. package/dist/commands/check-missing.js.map +1 -0
  10. package/dist/commands/clean.d.ts +1 -0
  11. package/dist/commands/clean.d.ts.map +1 -0
  12. package/dist/commands/clean.js +82 -0
  13. package/dist/commands/clean.js.map +1 -0
  14. package/dist/commands/create-pruned-namespace-automated.d.ts +20 -0
  15. package/dist/commands/create-pruned-namespace-automated.d.ts.map +1 -0
  16. package/dist/commands/create-pruned-namespace-automated.js +98 -0
  17. package/dist/commands/create-pruned-namespace-automated.js.map +1 -0
  18. package/dist/commands/create-pruned-namespace.d.ts +3 -0
  19. package/dist/commands/create-pruned-namespace.d.ts.map +1 -0
  20. package/dist/commands/create-pruned-namespace.js +123 -0
  21. package/dist/commands/create-pruned-namespace.js.map +1 -0
  22. package/dist/commands/replace.d.ts +1 -0
  23. package/dist/commands/replace.d.ts.map +1 -0
  24. package/dist/commands/replace.js +58 -0
  25. package/dist/commands/replace.js.map +1 -0
  26. package/dist/commands/scan.d.ts +1 -0
  27. package/dist/commands/scan.d.ts.map +1 -0
  28. package/dist/commands/scan.js +70 -0
  29. package/dist/commands/scan.js.map +1 -0
  30. package/dist/commands/sync-locales.d.ts +1 -0
  31. package/dist/commands/sync-locales.d.ts.map +1 -0
  32. package/dist/commands/sync-locales.js +78 -0
  33. package/dist/commands/sync-locales.js.map +1 -0
  34. package/dist/i18n-magic.cjs.development.js +348 -130
  35. package/dist/i18n-magic.cjs.development.js.map +1 -1
  36. package/dist/i18n-magic.cjs.production.min.js +1 -1
  37. package/dist/i18n-magic.cjs.production.min.js.map +1 -1
  38. package/dist/i18n-magic.esm.js +339 -130
  39. package/dist/i18n-magic.esm.js.map +1 -1
  40. package/dist/index.d.ts +11 -1
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +22 -9
  43. package/dist/index.js.map +1 -0
  44. package/dist/lib/languges.d.ts +1 -0
  45. package/dist/lib/languges.d.ts.map +1 -0
  46. package/dist/lib/languges.js +146 -0
  47. package/dist/lib/languges.js.map +1 -0
  48. package/dist/lib/types.d.ts +7 -1
  49. package/dist/lib/types.d.ts.map +1 -0
  50. package/dist/lib/types.js +3 -0
  51. package/dist/lib/types.js.map +1 -0
  52. package/dist/lib/utils.d.ts +20 -1
  53. package/dist/lib/utils.d.ts.map +1 -0
  54. package/dist/lib/utils.js +264 -0
  55. package/dist/lib/utils.js.map +1 -0
  56. package/package.json +38 -14
  57. package/src/cli.ts +117 -0
  58. package/src/commands/clean.ts +4 -1
  59. package/src/commands/create-pruned-namespace-automated.ts +165 -0
  60. package/src/commands/create-pruned-namespace.ts +168 -0
  61. package/src/commands/scan.ts +12 -0
  62. package/src/index.ts +23 -113
  63. package/src/lib/types.ts +7 -1
  64. 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 files = await glob([...globPatterns, "!**/node_modules/**"])
251
+ const allPatterns = extractGlobPatterns(globPatterns)
252
+ const files = await glob([...allPatterns, "!**/node_modules/**"])
196
253
 
197
254
  const keys = []
198
255