@dialexjs/cli 0.7.1 → 0.9.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 CHANGED
@@ -32,7 +32,7 @@ Binaries installed: `dialex` and the shorter alias `dx` (handy in package.json s
32
32
 
33
33
  Initialize or configure Dialex in any project:
34
34
 
35
- - **Automatic Framework Detection**: Identifies Next.js, Fastify, Koa, Hono, Express, NestJS, Elysia, SvelteKit, Astro, Vue, Nuxt, and React/Vite.
35
+ - **Automatic Framework Detection**: Identifies Next.js, React Router, React/Vite, Preact, Solid, Svelte, SvelteKit, Vue, Nuxt, Qwik, Lit, React Native, Astro, Hono, Express, Fastify, Koa, NestJS, Elysia, Hapi, AdonisJS and tRPC from `package.json`.
36
36
  - **Magicast AST Injection**: Manipulates `dialex.config.ts` and registers the module in `nuxt.config.ts` (Nuxt) cleanly.
37
37
  - **Starter Dictionaries**: Emits typed starter dictionary and TypeScript declaration file.
38
38
 
@@ -70,6 +70,15 @@ dialex import translations/tr.xlf
70
70
 
71
71
  Fills missing (or `[TODO]`) strings with a provider you configure in `dialex.config.ts`. Built-in providers for Claude, OpenAI (ChatGPT), Gemini and DeepL are exported from `@dialexjs/cli/translate`. `--dry-run` lists what would be sent without calling anything.
72
72
 
73
+ ### `dialex lock`
74
+
75
+ Records the translations you have as up to date with their current source text (`dialex.lock.json`), so a later edit of the source is noticed. `dialex translate` and `dialex import` record what they write; `dialex check` warns about translations whose source changed, and `--fail-on-stale` makes that an error.
76
+
77
+ ```bash
78
+ dialex lock
79
+ dialex lock --all # also accept translations that are already out of date
80
+ ```
81
+
73
82
  ### `dialex check` (alias: `lint`)
74
83
 
75
84
  CI verification command:
@@ -86,6 +95,16 @@ dialex check
86
95
 
87
96
  ---
88
97
 
98
+ ## Exit codes
99
+
100
+ `0` on success; `1` when the command fails. `dialex check` exits with `1` when it finds errors (warnings never fail it). `dialex import` exits with `0` even when it rejected values; read `success` in its `--json` output. Every command except `init` accepts `--json`.
101
+
102
+ ## Documentation
103
+
104
+ [Commands and options](https://dialex.awaiden.com/cli/) and the [diagnostics reference](https://dialex.awaiden.com/guide/diagnostics.html).
105
+
106
+ ---
107
+
89
108
  ## 📝 Changelog
90
109
 
91
110
  See what changed in each release in the [changelog](https://github.com/awaiden/dialex/blob/main/CHANGELOG.md), or on [GitHub Releases](https://github.com/awaiden/dialex/releases).
package/dist/api.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { loadFile } from "magicast";
2
- import { DialexConfig } from "dialexjs";
2
+ import { DialexConfig, LintRuleSetting } 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.
@@ -121,7 +121,14 @@ interface AnalysisConfig {
121
121
  locales?: string[];
122
122
  include?: string | string[];
123
123
  exclude?: string[];
124
+ /** `lint.rules` of the config: `"off"` drops an issue, `"warn"` and `"error"` set its level. */
125
+ lint?: {
126
+ rules?: Record<string, LintSetting>;
127
+ };
124
128
  }
129
+ type LintLevel = "off" | "warn" | "error";
130
+ /** A rule as written in the config: `"warn"` or `["warn", { ...options }]`. */
131
+ type LintSetting = LintLevel | readonly [LintLevel, unknown?];
125
132
  /**
126
133
  * Remembers parsed dictionaries and scanned source files between `analyzeProject` calls, keyed by
127
134
  * modification time and size, so a long-lived caller (the editor extension) only re-reads what
@@ -149,6 +156,8 @@ interface SourceScan {
149
156
  ref: Reference;
150
157
  range: SourceRange;
151
158
  }[];
159
+ /** Dictionary names registered inline with `dictionaries: { name: ... }`. */
160
+ inline: string[];
152
161
  }
153
162
  interface AnalysisOptions {
154
163
  root: string;
@@ -165,6 +174,8 @@ interface AnalysisOptions {
165
174
  lock?: boolean;
166
175
  /** Reuse work between calls. Ignored when `runtime` is set, because that evaluates code. */
167
176
  cache?: AnalysisCache;
177
+ /** Unsaved text of files, by absolute path, used instead of reading them from disk. */
178
+ contents?: ReadonlyMap<string, string>;
168
179
  }
169
180
  interface LeafInfo {
170
181
  kind: "string" | "function" | "other";
@@ -189,6 +200,8 @@ interface AnalysisResult {
189
200
  /** Absolute paths of every dictionary file that matched. */
190
201
  files: string[];
191
202
  sourceFilesScanned: number;
203
+ /** Dictionary names registered in code with `dictionaries: { name: ... }`. Empty without `src`. */
204
+ inlineDictionaries: string[];
192
205
  }
193
206
  export declare const DEFAULT_SOURCE_GLOB = "**/*.{ts,tsx,js,jsx,mjs,cjs,vue,svelte,astro,mdx}";
194
207
  interface Reference {
@@ -199,7 +212,15 @@ interface Reference {
199
212
  start: number;
200
213
  end: number;
201
214
  }
202
- /** Finds `getDictionary("x")`-style and `t("x.y.z")` references in source text. */
215
+ /** References and inline dictionary names found in one source file. */
216
+ export declare function scanText(text: string): {
217
+ references: Reference[];
218
+ inline: string[];
219
+ };
220
+ /**
221
+ * Finds `getDictionary("x")`-style and `t("x.y.z")` references in source text. References inside
222
+ * comments, and on lines a `dialex-ignore` comment covers, are skipped.
223
+ */
203
224
  export declare function scanReferences(text: string): Reference[];
204
225
  interface DictionaryData {
205
226
  name: string;
@@ -216,7 +237,13 @@ type Loaded = {
216
237
  code: IssueCode;
217
238
  message: string;
218
239
  };
240
+ /** Analyzes a project. With `runtime: true`, dictionaries the syntax tree cannot describe are imported. */
219
241
  export declare function analyzeProject(options: AnalysisOptions): Promise<AnalysisResult>;
242
+ /**
243
+ * `analyzeProject` for callers that cannot await, such as lint rules. Reads dictionaries from the
244
+ * syntax tree only: `runtime` is ignored, so project code is never executed.
245
+ */
246
+ export declare function analyzeProjectSync(options: AnalysisOptions): AnalysisResult;
220
247
  /** Project root-relative path with forward slashes, for display. */
221
248
  export declare function relativeFile(root: string, file: string): string;
222
249
  //#endregion
@@ -287,9 +314,15 @@ interface StaticConfig {
287
314
  locales: string[];
288
315
  include: string | string[];
289
316
  exclude: string[];
317
+ /** Where the generated file goes, when the config sets it. */
318
+ output?: string;
290
319
  fallbacks: Record<string, string[]>;
291
320
  prefixDefault: boolean;
292
321
  lazy: boolean | "locale";
322
+ /** Severity and options of each check, by diagnostic code. */
323
+ lint: {
324
+ rules: Record<string, LintRuleSetting>;
325
+ };
293
326
  }
294
327
  interface StaticConfigResult {
295
328
  config: StaticConfig;
@@ -297,6 +330,11 @@ interface StaticConfigResult {
297
330
  file?: string;
298
331
  /** Things that could not be read statically, for example `locales: getLocales()`. */
299
332
  notes: string[];
333
+ /**
334
+ * The config object has a spread or a computed key, so it may set things this reader cannot
335
+ * see. Only running the file gives a trustworthy answer.
336
+ */
337
+ opaque: boolean;
300
338
  }
301
339
  export declare const DEFAULT_STATIC_CONFIG: StaticConfig;
302
340
  /** Reads a config file's source text. Exposed for tests and for unsaved buffers. */
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/files.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,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,i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Ac,gBAA4B;;wBA+C5D,iBAAiB,cAAc,sBAAsB;;;UChKpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBA4BoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UCnDvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAGe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;wBAcc,gBAAgB,cAAc,UAAS,kBAAuB;wBA8J9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA;;;;;;;wBAmGc,qBACd,cACA,SAAS,iBACT,wBACA,gBAEA;;AAAA,OAAM,8CAA4D"}
1
+ {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/files.ts","../src/utils/lockfile.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate.ts"],"mappings":";;;;;;;;;;;;;;;KAwBK;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;;;;;;wBAmGc,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,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EACA,SAAS,eAAe;;;wBAYV,WAAW;;wBAKX,SAAS,eAAe;;wBAiBxB,UAAU,cAAc,MAAM;;;;;wBA2B9B,QAAQ,MAAM,UAAU,gBAAgB,aAAa;;;;;;;;UCpEpD;EACf;EACA;EACA;EACA;;EAEA;EACA,WAAW;EACX;EACA;;EAEA;IAAQ,OAAO,eAAe;;;UAGf;EACf,QAAQ;;EAER;;EAEA;;;;;EAKA;;qBA8BW,uBAAuB;;wBA2HpB,kBAAkB,cAAc,gBAA4B;;wBA4C5D,iBAAiB,cAAc,sBAAsB;;;UCjOpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBA4BoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UCnDvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAGe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;wBAcc,gBAAgB,cAAc,UAAS,kBAAuB;wBAqK9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA;;;;;;;wBAmGc,qBACd,cACA,SAAS,iBACT,wBACA,gBAEA;;AAAA,OAAM,8CAA4D"}
package/dist/api.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as scanFiles, B as locationOf, D as BUILTIN_IGNORE, E as writeLock, F as getString, H as renderDictionaryFile, I as hasPath, L as listLeaves, M as copyLeaf, N as dictionaryLocation, O as SOURCE_BUILTIN_IGNORE, P as getLeafSource, R as listLocales, U as saveDictionaryFile, V as parseDictionaryText, W as setString, _ as relativeFile, a as renderGenerated, b as hashSource, c as DEFAULT_STATIC_CONFIG, g as createAnalysisCache, h as clearGitignore, i as generateDictionaries, j as TODO_PREFIX, k as createGitignoreFilter, l as parseStaticConfig, m as analyzeProject, n as loadStaticProject, p as DEFAULT_SOURCE_GLOB, r as toKey, s as startGenerateWatcher, t as loadProject, u as readStaticConfig, v as scanReferences, w as readLock, x as isStale, y as LOCK_FILE, z as loadDictionaryFile } from "./project-Dz0FbydQ.mjs";
2
- export { BUILTIN_IGNORE, DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, LOCK_FILE, SOURCE_BUILTIN_IGNORE, TODO_PREFIX, analyzeProject, clearGitignore, copyLeaf, createAnalysisCache, createGitignoreFilter, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, hashSource, isStale, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readLock, readStaticConfig, relativeFile, renderDictionaryFile, renderGenerated, saveDictionaryFile, scanFiles, scanReferences, setString, startGenerateWatcher, toKey, writeLock };
1
+ import { A as SOURCE_BUILTIN_IGNORE, B as listLocales, C as isStale, E as readLock, F as dictionaryLocation, G as saveDictionaryFile, H as locationOf, I as getLeafSource, K as setString, L as getString, M as scanFiles, N as TODO_PREFIX, O as writeLock, P as copyLeaf, R as hasPath, S as hashSource, U as parseDictionaryText, V as loadDictionaryFile, W as renderDictionaryFile, _ as createAnalysisCache, a as renderGenerated, b as scanText, c as DEFAULT_STATIC_CONFIG, g as clearGitignore, h as analyzeProjectSync, i as generateDictionaries, j as createGitignoreFilter, k as BUILTIN_IGNORE, l as parseStaticConfig, m as analyzeProject, n as loadStaticProject, p as DEFAULT_SOURCE_GLOB, r as toKey, s as startGenerateWatcher, t as loadProject, u as readStaticConfig, v as relativeFile, x as LOCK_FILE, y as scanReferences, z as listLeaves } from "./project-B27699T2.mjs";
2
+ export { BUILTIN_IGNORE, DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, LOCK_FILE, SOURCE_BUILTIN_IGNORE, TODO_PREFIX, analyzeProject, analyzeProjectSync, clearGitignore, copyLeaf, createAnalysisCache, createGitignoreFilter, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, hashSource, isStale, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readLock, readStaticConfig, relativeFile, renderDictionaryFile, renderGenerated, saveDictionaryFile, scanFiles, scanReferences, scanText, setString, startGenerateWatcher, toKey, writeLock };