@dialexjs/cli 0.2.3 → 0.5.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 CHANGED
@@ -29,7 +29,7 @@ Binaries installed: `dialex` and the shorter alias `dx` (handy in package.json s
29
29
  Initialize or configure Dialex in any project:
30
30
 
31
31
  - **Automatic Framework Detection**: Identifies Next.js, Fastify, Koa, Hono, Express, NestJS, Elysia, SvelteKit, Astro, Vue, Nuxt, and React/Vite.
32
- - **Magicast AST Injection**: Manipulates `dialex.config.ts` and injects Vite plugins into `vite.config.ts` (React, Vue) and the module into `nuxt.config.ts` (Nuxt) cleanly.
32
+ - **Magicast AST Injection**: Manipulates `dialex.config.ts` and registers the module in `nuxt.config.ts` (Nuxt) cleanly.
33
33
  - **Starter Dictionaries**: Emits typed starter dictionary and TypeScript declaration file.
34
34
 
35
35
  ```bash
package/dist/api.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { loadFile } from "magicast";
2
- import { I18nConfig } from "dialexjs";
2
+ import { DialexConfig } from "dialexjs";
3
3
  //#region src/utils/dictionary-edit.d.ts
4
4
  /**
5
5
  * AST-level helpers for reading and editing `.content.ts` dictionary files.
@@ -99,7 +99,7 @@ export declare function getLeafSource(df: DictionaryFile, locale: string, path:
99
99
  * evaluated module (the CLI does this; editors must not).
100
100
  */
101
101
  type IssueLevel = "error" | "warning" | "info";
102
- type IssueCode = "invalid-dictionary" | "unanalyzable" | "missing-locale" | "missing-key" | "invalid-locale" | "todo-placeholder" | "invalid-icu" | "icu-args-mismatch" | "icu-plural-categories" | "unknown-dictionary" | "unknown-path" | "unused-key" | "unused-dictionary";
102
+ type IssueCode = "invalid-dictionary" | "unanalyzable" | "missing-locale" | "missing-key" | "invalid-locale" | "todo-placeholder" | "stale-translation" | "invalid-icu" | "icu-args-mismatch" | "icu-plural-categories" | "unknown-dictionary" | "unknown-path" | "unused-key" | "unused-dictionary";
103
103
  interface AnalysisIssue {
104
104
  /** Absolute path of the file the issue is in. */
105
105
  file: string;
@@ -132,6 +132,8 @@ interface AnalysisOptions {
132
132
  ignore?: string[];
133
133
  /** Report possibly unused keys and dictionaries. @default true */
134
134
  unused?: boolean;
135
+ /** Report translations whose source text changed since `dialex.lock.json` recorded them. @default true */
136
+ lock?: boolean;
135
137
  }
136
138
  interface LeafInfo {
137
139
  kind: "string" | "function" | "other";
@@ -172,6 +174,36 @@ export declare function analyzeProject(options: AnalysisOptions): Promise<Analys
172
174
  /** Project root-relative path with forward slashes, for display. */
173
175
  export declare function relativeFile(root: string, file: string): string;
174
176
  //#endregion
177
+ //#region src/utils/lockfile.d.ts
178
+ export declare const LOCK_FILE = "dialex.lock.json";
179
+ /**
180
+ * Records which version of the source text each translation was made from, so a later edit of the
181
+ * source can be noticed. A translation whose source changed afterwards is *stale*.
182
+ *
183
+ * ```json
184
+ * { "version": 1, "sourceLocale": "en", "locales": { "tr": { "home.title": "a1b2c3d4" } } }
185
+ * ```
186
+ *
187
+ * The value is a short hash of the source locale's text at the time. Translations without a
188
+ * record are untracked (for example hand-written ones) and are never reported as stale.
189
+ */
190
+ interface Lockfile {
191
+ version: 1;
192
+ sourceLocale?: string;
193
+ locales: Record<string, Record<string, string>>;
194
+ }
195
+ /** A short, stable fingerprint of a source string. */
196
+ export declare function hashSource(text: string): string;
197
+ /** The lock file, or `undefined` when there is none (or it cannot be read). */
198
+ export declare function readLock(root: string): Lockfile | undefined;
199
+ /** Writes the lock with sorted keys, so it produces small, stable diffs. */
200
+ export declare function writeLock(root: string, lock: Lockfile): void;
201
+ /**
202
+ * True when `key` was recorded for `locale` from different source text than `sourceText`. A key
203
+ * with no record is not stale.
204
+ */
205
+ export declare function isStale(lock: Lockfile, locale: string, key: string, sourceText: string): boolean;
206
+ //#endregion
175
207
  //#region src/utils/static-config.d.ts
176
208
  /**
177
209
  * The parts of `dialex.config` that tooling needs, read **without running the file**. Editors must
@@ -184,7 +216,7 @@ interface StaticConfig {
184
216
  include: string | string[];
185
217
  fallbacks: Record<string, string[]>;
186
218
  prefixDefault: boolean;
187
- lazy: boolean;
219
+ lazy: boolean | "locale";
188
220
  }
189
221
  interface StaticConfigResult {
190
222
  config: StaticConfig;
@@ -208,7 +240,7 @@ interface ProjectDictionary {
208
240
  }
209
241
  interface Project {
210
242
  root: string;
211
- config: I18nConfig;
243
+ config: DialexConfig;
212
244
  dictionaries: ProjectDictionary[];
213
245
  /** Dictionary files that could not be parsed into an editable shape. */
214
246
  unsupported: string[];
@@ -235,12 +267,46 @@ interface GenerateOptions {
235
267
  output?: string;
236
268
  config?: string;
237
269
  json?: boolean;
270
+ /**
271
+ * Read `dialex.config.*` from its syntax tree instead of running it, so no project code
272
+ * executes (used by the editor extension). Settings that are not literals fall back to defaults.
273
+ */
274
+ static?: boolean;
275
+ }
276
+ interface RenderedGenerate {
277
+ /** Absolute paths of the dictionary files, sorted. */
278
+ files: string[];
279
+ /** Where `dialex.generated.ts` goes, and what it should contain. */
280
+ outputPath: string;
281
+ content: string;
282
+ /** Where `dialex-env.d.ts` goes, and what it should contain (absent without dictionaries). */
283
+ dtsPath: string;
284
+ dtsContent?: string;
285
+ /** The config file that was read, if there is one. Without it every default applies. */
286
+ configFile?: string;
287
+ /** Per-locale modules for `lazy: "locale"`, written next to the generated file. */
288
+ extraFiles: {
289
+ path: string;
290
+ content: string;
291
+ }[];
292
+ /** Things worth telling the user, such as a dictionary that could not be split by locale. */
293
+ notes: string[];
238
294
  }
295
+ /**
296
+ * Works out `dialex.generated.ts` and `dialex-env.d.ts` for a project without writing anything,
297
+ * so `check` can tell whether they are up to date.
298
+ *
299
+ * Settings come from `dialex.config.*` and fall back to {@link DEFAULT_CONFIG}; `locales` falls
300
+ * back to the locales the dictionaries define.
301
+ */
302
+ export declare function renderGenerated(root: string, options?: GenerateOptions): RenderedGenerate;
239
303
  export declare function generateDictionaries(root: string, options?: GenerateOptions): {
240
304
  files: string[];
241
305
  outputPath: string;
242
306
  dtsPath: string;
307
+ configFile?: string;
308
+ notes: string[];
243
309
  };
244
310
  //#endregion
245
- export type { AnalysisConfig, AnalysisIssue, AnalysisOptions, AnalysisResult, AnalyzedDictionary, DictionaryFile, GenerateOptions, IssueCode, IssueLevel, Leaf, LeafInfo, LeafKind, Project, ProjectDictionary, Reference, SourceRange, StaticConfig, StaticConfigResult };
311
+ export type { AnalysisConfig, AnalysisIssue, AnalysisOptions, AnalysisResult, AnalyzedDictionary, DictionaryFile, GenerateOptions, IssueCode, IssueLevel, Leaf, LeafInfo, LeafKind, Lockfile, Project, ProjectDictionary, Reference, RenderedGenerate, SourceRange, StaticConfig, StaticConfigResult };
246
312
  //# sourceMappingURL=api.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate.ts"],"mappings":";;;;;;;;;;;;;;;KAgBK;EAAS;GAAe;;qBAEhB;UAII;EACf;;EAEA;EACA,KAAK,QAAQ,kBAAkB;;EAE/B,YAAY;;EAEZ;;;;;;EAMA;;;UAIe;EACf;IAAS;IAAc;;EACvB;IAAO;IAAc;;;KAGX;UAEK;EACf;EACA,MAAM;;EAEN;;;;;;wBAgIc,oBAAoB,cAAc,eAAe;;wBAoB3C,mBAAmB,eAAe,QAAQ;;wBAKhD,qBAAqB,IAAI;wBAKnB,mBAAmB,IAAI,iBAAiB;wBAQ9C,YAAY,IAAI;;wBAahB,WAAW,IAAI,gBAAgB,iBAAiB;wBAoChD,QAAQ,IAAI,gBAAgB,gBAAgB;wBAI5C,UAAU,IAAI,gBAAgB,gBAAgB;KA+BlD;;;;;wBAMI,UACd,IAAI,gBACJ,gBACA,gBACA,gBACC;;;;;;wBAsBa,SACd,IAAI,gBACJ,oBACA,kBACA,gBACA,aAAa;;;;;wBAwCC,WACd,IAAI,gBACJ,gBACA,kBACC;;wBAMa,mBAAmB,IAAI,iBAAiB;;wBAKxC,cACd,IAAI,gBACJ,gBACA;;;;;;;;;;;KCnXU;KAEA;UAeK;;EAEf;EACA,OAAO;EACP,MAAM;EACN;;EAEA,QAAQ;;EAER;EACA;;EAEA;;EAEA;;UAGe;EACf;EACA;EACA;;UAGe;EACf;EACA,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;UAGe;EACf;EACA;;UAGe;EACf;;EAEA;;EAEA;;EAEA,QAAQ,YAAY,YAAY;;EAEhC;;EAEA,KAAK;;UAGU;EACf,QAAQ;EACR,cAAc;;EAEd;EACA;;qBAKW;UAqBI;;EAEf;EACA;;EAEA;EACA;;;wBAIc,eAAe,eAAe;wBA4IxB,eAAe,SAAS,kBAAkB,QAAQ;;wBA+NxD,aAAa,cAAc;;;;;;;;UCte1B;EACf;EACA;EACA;EACA,WAAW;EACX;EACA;;UAGe;EACf,QAAQ;;EAER;;EAEA;;qBAMW,uBAAuB;;wBAiFpB,kBAAkB,cAAc,gBAA4B;;wBA8C5D,iBAAiB,cAAc,sBAAsB;;;UC5JpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBAgCoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UC7DvB;EACf;EACA;EACA;EACA;EACA;;wBAGc,qBACd,cACA,UAAS;EAET;EACA;EACA"}
1
+ {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/lockfile.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate.ts"],"mappings":";;;;;;;;;;;;;;;KAiBK;EAAS;GAAe;;qBAEhB;UAII;EACf;;EAEA;EACA,KAAK,QAAQ,kBAAkB;;EAE/B,YAAY;;EAEZ;;;;;;EAMA;;;UAIe;EACf;IAAS;IAAc;;EACvB;IAAO;IAAc;;;KAGX;UAEK;EACf;EACA,MAAM;;EAEN;;;;;;wBAgIc,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AAc,sBAAsB;;;UC5JpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBAgCoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UCvDvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAUe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;wBAcc,gBAAgB,cAAc,UAAS,kBAAuB;wBA8J9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA"}
package/dist/api.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { C as saveDictionaryFile, S as renderDictionaryFile, T as generateDictionaries, _ as listLeaves, a as parseStaticConfig, b as locationOf, c as analyzeProject, d as TODO_PREFIX, f as copyLeaf, g as hasPath, h as getString, i as DEFAULT_STATIC_CONFIG, l as relativeFile, m as getLeafSource, n as loadStaticProject, o as readStaticConfig, p as dictionaryLocation, r as toKey, s as DEFAULT_SOURCE_GLOB, t as loadProject, u as scanReferences, v as listLocales, w as setString, x as parseDictionaryText, y as loadDictionaryFile } from "./project-BnG6V2I0.mjs";
2
- export { DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, TODO_PREFIX, analyzeProject, copyLeaf, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readStaticConfig, relativeFile, renderDictionaryFile, saveDictionaryFile, scanReferences, setString, toKey };
1
+ import { A as listLocales, C as TODO_PREFIX, D as getString, E as getLeafSource, F as saveDictionaryFile, I as setString, M as locationOf, N as parseDictionaryText, O as hasPath, P as renderDictionaryFile, S as writeLock, T as dictionaryLocation, _ as isStale, a as renderGenerated, b as readLock, c as parseStaticConfig, d as DEFAULT_SOURCE_GLOB, f as analyzeProject, g as hashSource, h as LOCK_FILE, i as generateDictionaries, j as loadDictionaryFile, k as listLeaves, l as readStaticConfig, m as scanReferences, n as loadStaticProject, p as relativeFile, r as toKey, s as DEFAULT_STATIC_CONFIG, t as loadProject, w as copyLeaf } from "./project-BJYmnKiU.mjs";
2
+ export { DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, LOCK_FILE, TODO_PREFIX, analyzeProject, copyLeaf, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, hashSource, isStale, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readLock, readStaticConfig, relativeFile, renderDictionaryFile, renderGenerated, saveDictionaryFile, scanReferences, setString, toKey, writeLock };