@dialexjs/cli 0.9.1 → 0.9.2
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/dist/api.d.mts +42 -39
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +1 -1
- package/dist/index.mjs +329 -395
- package/dist/index.mjs.map +1 -1
- package/dist/{project-B27699T2.mjs → project-BTpZGNjh.mjs} +232 -208
- package/dist/project-BTpZGNjh.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/project-B27699T2.mjs.map +0 -1
package/dist/api.d.mts
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { loadFile } from "magicast";
|
|
2
2
|
import { DialexConfig, LintRuleSetting } from "dialexjs";
|
|
3
|
-
//#region src/utils/
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* Magicast's proxy layer cannot represent every value (for example template-literal
|
|
8
|
-
* functions), so these helpers work on the underlying AST nodes and use Magicast only
|
|
9
|
-
* to parse and print, which preserves the rest of the file's formatting.
|
|
10
|
-
*
|
|
11
|
-
* Supported shapes:
|
|
12
|
-
* - `export default defineDictionary("name", { en: {...}, tr: {...} })`
|
|
13
|
-
* - `export default defineDictionary({ name: "name", dictionary: { ... } })`
|
|
14
|
-
* - `export default { name: "name", dictionary: { ... } }`
|
|
15
|
-
*/
|
|
16
|
-
type Node = {
|
|
3
|
+
//#region src/utils/ast.d.ts
|
|
4
|
+
/** A syntax-tree node as magicast (recast/babel) and oxc-style ESTree nodes both look. */
|
|
5
|
+
type AstNode = {
|
|
17
6
|
type: string;
|
|
18
7
|
[key: string]: any;
|
|
19
8
|
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/utils/dictionary/types.d.ts
|
|
20
11
|
export declare const TODO_PREFIX = "[TODO] ";
|
|
21
12
|
interface DictionaryFile {
|
|
22
13
|
file: string;
|
|
@@ -24,7 +15,7 @@ interface DictionaryFile {
|
|
|
24
15
|
name?: string;
|
|
25
16
|
mod: Awaited<ReturnType<typeof loadFile>>;
|
|
26
17
|
/** The object whose keys are locales. */
|
|
27
|
-
localesObj:
|
|
18
|
+
localesObj: AstNode;
|
|
28
19
|
/** Whether the file ended with a newline when loaded; restored on save. */
|
|
29
20
|
endsWithNewline: boolean;
|
|
30
21
|
/**
|
|
@@ -52,6 +43,8 @@ interface Leaf {
|
|
|
52
43
|
/** Present when `kind` is `"string"`. */
|
|
53
44
|
value?: string;
|
|
54
45
|
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/utils/dictionary/io.d.ts
|
|
55
48
|
/**
|
|
56
49
|
* Parses dictionary source text (for example an unsaved editor buffer). Returns `undefined` when
|
|
57
50
|
* the file does not have an editable shape; throws on syntax errors.
|
|
@@ -62,11 +55,15 @@ export declare function loadDictionaryFile(file: string): Promise<DictionaryFile
|
|
|
62
55
|
/** The source text with all edits applied, without writing anything. */
|
|
63
56
|
export declare function renderDictionaryFile(df: DictionaryFile): string;
|
|
64
57
|
export declare function saveDictionaryFile(df: DictionaryFile): Promise<void>;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/utils/dictionary/read.d.ts
|
|
65
60
|
export declare function listLocales(df: DictionaryFile): string[];
|
|
66
61
|
/** Lists every leaf (string, function, or other value) of a locale, in source order. */
|
|
67
62
|
export declare function listLeaves(df: DictionaryFile, locale: string): Leaf[];
|
|
68
63
|
export declare function hasPath(df: DictionaryFile, locale: string, path: string[]): boolean;
|
|
69
64
|
export declare function getString(df: DictionaryFile, locale: string, path: string[]): string | undefined;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/utils/dictionary/write.d.ts
|
|
70
67
|
type SetResult = "created" | "updated" | "skipped";
|
|
71
68
|
/**
|
|
72
69
|
* Sets a string value at `path`. Existing function or non-string values are left alone
|
|
@@ -79,6 +76,8 @@ export declare function setString(df: DictionaryFile, locale: string, path: stri
|
|
|
79
76
|
* Returns `false` when the source has no such leaf or the target already has one.
|
|
80
77
|
*/
|
|
81
78
|
export declare function copyLeaf(df: DictionaryFile, fromLocale: string, toLocale: string, path: string[], mapString?: (value: string) => string): boolean;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/utils/dictionary/locations.d.ts
|
|
82
81
|
/**
|
|
83
82
|
* Where a locale (no `path`) or a key within it is written. The range covers the property key, so
|
|
84
83
|
* it is a good place to attach a diagnostic or jump to.
|
|
@@ -89,15 +88,7 @@ export declare function dictionaryLocation(df: DictionaryFile): SourceRange | un
|
|
|
89
88
|
/** The source code of a leaf's value (a function's source, or a string with its quotes). */
|
|
90
89
|
export declare function getLeafSource(df: DictionaryFile, locale: string, path: string[]): string | undefined;
|
|
91
90
|
//#endregion
|
|
92
|
-
//#region src/analysis.d.ts
|
|
93
|
-
/**
|
|
94
|
-
* Project analysis shared by `dialex check` and the editor extension.
|
|
95
|
-
*
|
|
96
|
-
* It reads dictionaries from the syntax tree, so it never runs project code. Dictionaries that
|
|
97
|
-
* cannot be read that way (spreads, computed keys, imported values) are skipped with an `info`
|
|
98
|
-
* issue, unless `runtime: true` is passed, in which case they are imported and read from the
|
|
99
|
-
* evaluated module (the CLI does this; editors must not).
|
|
100
|
-
*/
|
|
91
|
+
//#region src/analysis/types.d.ts
|
|
101
92
|
type IssueLevel = "error" | "warning" | "info";
|
|
102
93
|
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
94
|
interface AnalysisIssue {
|
|
@@ -146,9 +137,6 @@ interface AnalysisCache {
|
|
|
146
137
|
/** The `.gitignore` filter, reused until {@link clearGitignore} is called. */
|
|
147
138
|
gitignore: Map<string, (absolutePath: string) => boolean>;
|
|
148
139
|
}
|
|
149
|
-
export declare function createAnalysisCache(): AnalysisCache;
|
|
150
|
-
/** Forget the cached `.gitignore` rules, for example after a `.gitignore` file changed. */
|
|
151
|
-
export declare function clearGitignore(cache: AnalysisCache): void;
|
|
152
140
|
interface SourceScan {
|
|
153
141
|
/** Distinct word-like tokens, for the unused-key heuristic. */
|
|
154
142
|
tokens: string[];
|
|
@@ -203,7 +191,6 @@ interface AnalysisResult {
|
|
|
203
191
|
/** Dictionary names registered in code with `dictionaries: { name: ... }`. Empty without `src`. */
|
|
204
192
|
inlineDictionaries: string[];
|
|
205
193
|
}
|
|
206
|
-
export declare const DEFAULT_SOURCE_GLOB = "**/*.{ts,tsx,js,jsx,mjs,cjs,vue,svelte,astro,mdx}";
|
|
207
194
|
interface Reference {
|
|
208
195
|
/** A dictionary name, or a full `dictionary.key.path`. */
|
|
209
196
|
kind: "dictionary" | "path";
|
|
@@ -212,16 +199,6 @@ interface Reference {
|
|
|
212
199
|
start: number;
|
|
213
200
|
end: number;
|
|
214
201
|
}
|
|
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
|
-
*/
|
|
224
|
-
export declare function scanReferences(text: string): Reference[];
|
|
225
202
|
interface DictionaryData {
|
|
226
203
|
name: string;
|
|
227
204
|
locales: string[];
|
|
@@ -237,6 +214,26 @@ type Loaded = {
|
|
|
237
214
|
code: IssueCode;
|
|
238
215
|
message: string;
|
|
239
216
|
};
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/analysis/cache.d.ts
|
|
219
|
+
export declare function createAnalysisCache(): AnalysisCache;
|
|
220
|
+
/** Forget the cached `.gitignore` rules, for example after a `.gitignore` file changed. */
|
|
221
|
+
export declare function clearGitignore(cache: AnalysisCache): void;
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/analysis/source-scan.d.ts
|
|
224
|
+
export declare const DEFAULT_SOURCE_GLOB = "**/*.{ts,tsx,js,jsx,mjs,cjs,vue,svelte,astro,mdx}";
|
|
225
|
+
/** References and inline dictionary names found in one source file. */
|
|
226
|
+
export declare function scanText(text: string): {
|
|
227
|
+
references: Reference[];
|
|
228
|
+
inline: string[];
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Finds `getDictionary("x")`-style and `t("x.y.z")` references in source text. References inside
|
|
232
|
+
* comments, and on lines a `dialex-ignore` comment covers, are skipped.
|
|
233
|
+
*/
|
|
234
|
+
export declare function scanReferences(text: string): Reference[];
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/analysis/index.d.ts
|
|
240
237
|
/** Analyzes a project. With `runtime: true`, dictionaries the syntax tree cannot describe are imported. */
|
|
241
238
|
export declare function analyzeProject(options: AnalysisOptions): Promise<AnalysisResult>;
|
|
242
239
|
/**
|
|
@@ -371,7 +368,7 @@ export declare function loadStaticProject(root: string, configFile?: string): Pr
|
|
|
371
368
|
/** `home` + `["nav", "about"]` -> `home.nav.about` */
|
|
372
369
|
export declare const toKey: (dictionary: string, keyPath: string[]) => string;
|
|
373
370
|
//#endregion
|
|
374
|
-
//#region src/commands/generate.d.ts
|
|
371
|
+
//#region src/commands/generate/types.d.ts
|
|
375
372
|
interface GenerateOptions {
|
|
376
373
|
cwd?: string;
|
|
377
374
|
watch?: boolean;
|
|
@@ -403,6 +400,8 @@ interface RenderedGenerate {
|
|
|
403
400
|
/** Things worth telling the user, such as a dictionary that could not be split by locale. */
|
|
404
401
|
notes: string[];
|
|
405
402
|
}
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/commands/generate/render.d.ts
|
|
406
405
|
/**
|
|
407
406
|
* Works out `dialex.generated.ts` and `dialex-env.d.ts` for a project without writing anything,
|
|
408
407
|
* so `check` can tell whether they are up to date.
|
|
@@ -411,6 +410,8 @@ interface RenderedGenerate {
|
|
|
411
410
|
* back to the locales the dictionaries define.
|
|
412
411
|
*/
|
|
413
412
|
export declare function renderGenerated(root: string, options?: GenerateOptions): RenderedGenerate;
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/commands/generate/write.d.ts
|
|
414
415
|
export declare function generateDictionaries(root: string, options?: GenerateOptions): {
|
|
415
416
|
files: string[];
|
|
416
417
|
outputPath: string;
|
|
@@ -418,6 +419,8 @@ export declare function generateDictionaries(root: string, options?: GenerateOpt
|
|
|
418
419
|
configFile?: string;
|
|
419
420
|
notes: string[];
|
|
420
421
|
};
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/commands/generate/watch.d.ts
|
|
421
424
|
/**
|
|
422
425
|
* Regenerates when a dictionary or config file is added, edited or removed. chokidar 4+ no longer
|
|
423
426
|
* understands globs, so this watches the project directory and decides for itself which events
|
package/dist/api.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-
|
|
1
|
+
{"version":3,"file":"api.d.mts","names":["Node"],"sources":["../src/utils/ast.ts","../src/utils/dictionary/types.ts","../src/utils/dictionary/io.ts","../src/utils/dictionary/read.ts","../src/utils/dictionary/write.ts","../src/utils/dictionary/locations.ts","../src/analysis/types.ts","../src/analysis/cache.ts","../src/analysis/source-scan.ts","../src/analysis/index.ts","../src/utils/files.ts","../src/utils/lockfile.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate/types.ts","../src/commands/generate/render.ts","../src/commands/generate/write.ts","../src/commands/generate/watch.ts"],"mappings":";;;;KACY;EAAY;GAAe;;;;qBCG1B;UAEI;EACf;;EAEA;EACA,KAAK,QAAQ,kBAAkB;;EAE/B,YAAYA;;EAEZ;;;;;;EAMA;;;UAIe;EACf;IAAS;IAAc;;EACvB;IAAO;IAAc;;;KAGX;UAEK;EACf;EACA,MAAM;;EAEN;;;;;;;;wBCvBc,oBAAoB,cAAc,eAAe;;wBAoB3C,mBAAmB,eAAe,QAAQ;;wBAKhD,qBAAqB,IAAI;wBA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S,kBAAkB,QAAQ;;;;;wBAkBxD,mBAAmB,SAAS,kBAAkB;;wBAe9C,aAAa,cAAc;;;;qBChE9B;;qBAQA;;;;;;wBA2CG,sBAAsB,gBAAgB;UAoCrC;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,mBAAmB;;;wBAIL,UACd,cACA,6BACA,UAAS;;;qBC3GE;;;;;;;;;;;;UAaI;EACf;EACA;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;;;UClEvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAGe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;;;wBCFc,gBAAgB,cAAc,UAAS,kBAAuB;;;wBCZ9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA;;;;;;;;;wBCHc,qBACd,cACA,SAAS,iBACT,wBACA,gBAEA;;AAAA,OAAM,8CAA4D"}
|
package/dist/api.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as scanFiles, B as listLeaves, D as BUILTIN_IGNORE, E as writeLock, F as locationOf, G as saveDictionaryFile, H as loadDictionaryFile, I as copyLeaf, K as TODO_PREFIX, L as setString, M as createAnalysisCache, N as dictionaryLocation, O as SOURCE_BUILTIN_IGNORE, P as getLeafSource, R as getString, U as parseDictionaryText, V as listLocales, W as renderDictionaryFile, _ as scanReferences, a as generateDictionaries, b as hashSource, c as DEFAULT_STATIC_CONFIG, g as DEFAULT_SOURCE_GLOB, h as relativeFile, j as clearGitignore, k as createGitignoreFilter, l as parseStaticConfig, m as analyzeProjectSync, n as loadStaticProject, o as startGenerateWatcher, p as analyzeProject, r as toKey, s as renderGenerated, t as loadProject, u as readStaticConfig, v as scanText, w as readLock, x as isStale, y as LOCK_FILE, z as hasPath } from "./project-BTpZGNjh.mjs";
|
|
2
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 };
|