@formatjs/cli-lib 8.5.1 → 8.5.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/gts_extractor-Dc-C_f4R.js +14 -0
- package/gts_extractor-Dc-C_f4R.js.map +1 -0
- package/{src/hbs_extractor.js → hbs_extractor-Eiqkz4d7.js} +9 -8
- package/hbs_extractor-Eiqkz4d7.js.map +1 -0
- package/index.d.ts +144 -7
- package/index.js +633 -2
- package/index.js.map +1 -0
- package/package.json +4 -4
- package/parse_script-EspfGgzZ.js +93 -0
- package/parse_script-EspfGgzZ.js.map +1 -0
- package/{src/svelte_extractor.js → svelte_extractor-Fr1Z3JHX.js} +16 -37
- package/svelte_extractor-Fr1Z3JHX.js.map +1 -0
- package/vue_extractor-Btw05cfG.js +41 -0
- package/vue_extractor-Btw05cfG.js.map +1 -0
- package/main.d.ts +0 -1
- package/main.js +0 -3
- package/src/cli.d.ts +0 -2
- package/src/cli.js +0 -145
- package/src/compile.d.ts +0 -63
- package/src/compile.js +0 -95
- package/src/compile_folder.d.ts +0 -2
- package/src/compile_folder.js +0 -8
- package/src/console_utils.d.ts +0 -7
- package/src/console_utils.js +0 -62
- package/src/extract.d.ts +0 -87
- package/src/extract.js +0 -212
- package/src/formatters/crowdin.d.ts +0 -7
- package/src/formatters/crowdin.js +0 -21
- package/src/formatters/default.d.ts +0 -6
- package/src/formatters/default.js +0 -9
- package/src/formatters/index.d.ts +0 -9
- package/src/formatters/index.js +0 -31
- package/src/formatters/lokalise.d.ts +0 -9
- package/src/formatters/lokalise.js +0 -18
- package/src/formatters/simple.d.ts +0 -4
- package/src/formatters/simple.js +0 -8
- package/src/formatters/smartling.d.ts +0 -21
- package/src/formatters/smartling.js +0 -39
- package/src/formatters/transifex.d.ts +0 -9
- package/src/formatters/transifex.js +0 -18
- package/src/gts_extractor.d.ts +0 -1
- package/src/gts_extractor.js +0 -14
- package/src/hbs_extractor.d.ts +0 -1
- package/src/parse_script.d.ts +0 -7
- package/src/parse_script.js +0 -43
- package/src/pseudo_locale.d.ts +0 -22
- package/src/pseudo_locale.js +0 -231
- package/src/svelte_extractor.d.ts +0 -2
- package/src/verify/checkExtraKeys.d.ts +0 -1
- package/src/verify/checkExtraKeys.js +0 -32
- package/src/verify/checkMissingKeys.d.ts +0 -1
- package/src/verify/checkMissingKeys.js +0 -33
- package/src/verify/checkStructuralEquality.d.ts +0 -1
- package/src/verify/checkStructuralEquality.js +0 -71
- package/src/verify/index.d.ts +0 -13
- package/src/verify/index.js +0 -26
- package/src/vue_extractor.d.ts +0 -2
- package/src/vue_extractor.js +0 -58
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as parseScript } from "./parse_script-EspfGgzZ.js";
|
|
2
|
+
import { parseFile as parseFile$1 } from "./hbs_extractor-Eiqkz4d7.js";
|
|
3
|
+
import { Preprocessor } from "content-tag";
|
|
4
|
+
//#region packages/cli-lib/gts_extractor.ts
|
|
5
|
+
let p = new Preprocessor();
|
|
6
|
+
function parseFile(source, fileName, options) {
|
|
7
|
+
parseScript(options, fileName)(p.process(source, { filename: fileName }).code);
|
|
8
|
+
const parseResult = p.parse(source, { filename: fileName });
|
|
9
|
+
for (let parsed of parseResult) parseFile$1(parsed.contents, fileName, options);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { parseFile };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=gts_extractor-Dc-C_f4R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gts_extractor-Dc-C_f4R.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const scriptParseFn = parseScript(options, fileName)\n const transformedSource = p.process(source, {filename: fileName})\n\n scriptParseFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;;AAGA,IAAI,IAAI,IAAI,cAAc;AAE1B,SAAgB,UACd,QACA,UACA,SACM;AACgB,aAAY,SAAS,SAAS,CAC1B,EAAE,QAAQ,QAAQ,EAAC,UAAU,UAAS,CAAC,CAEjC,KAAK;CAGrC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,UAAS,CAAC;AAEzD,MAAK,IAAI,UAAU,YACjB,aAAa,OAAO,UAAU,UAAU,QAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "@formatjs/ts-transformer";
|
|
2
1
|
import { preprocess, traverse } from "@glimmer/syntax";
|
|
2
|
+
//#region packages/cli-lib/hbs_extractor.ts
|
|
3
3
|
function extractText(node, fileName, options) {
|
|
4
4
|
if (!options.onMsgExtracted) return;
|
|
5
5
|
if (!options.overrideIdFn) return;
|
|
@@ -9,11 +9,9 @@ function extractText(node, fileName, options) {
|
|
|
9
9
|
if (first.type !== "StringLiteral") return;
|
|
10
10
|
let message = first?.value;
|
|
11
11
|
let desc;
|
|
12
|
-
if (second?.type === "StringLiteral")
|
|
13
|
-
desc = second.value?.trim().replace(/\s+/gm, " ");
|
|
14
|
-
}
|
|
12
|
+
if (second?.type === "StringLiteral") desc = second.value?.trim().replace(/\s+/gm, " ");
|
|
15
13
|
let defaultMessage = message?.trim().replace(/\s+/gm, " ");
|
|
16
|
-
let id = typeof options.overrideIdFn === "string" ? options.overrideIdFn : options.overrideIdFn(
|
|
14
|
+
let id = typeof options.overrideIdFn === "string" ? options.overrideIdFn : options.overrideIdFn(void 0, defaultMessage, desc, fileName);
|
|
17
15
|
options.onMsgExtracted(fileName, [{
|
|
18
16
|
id,
|
|
19
17
|
defaultMessage,
|
|
@@ -21,9 +19,8 @@ function extractText(node, fileName, options) {
|
|
|
21
19
|
}]);
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
traverse(ast, {
|
|
22
|
+
function parseFile(source, fileName, options) {
|
|
23
|
+
traverse(preprocess(source), {
|
|
27
24
|
MustacheStatement(node) {
|
|
28
25
|
extractText(node, fileName, options);
|
|
29
26
|
},
|
|
@@ -32,3 +29,7 @@ export function parseFile(source, fileName, options) {
|
|
|
32
29
|
}
|
|
33
30
|
});
|
|
34
31
|
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { parseFile };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=hbs_extractor-Eiqkz4d7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hbs_extractor-Eiqkz4d7.js","names":[],"sources":["../hbs_extractor.ts"],"sourcesContent":["import {type Opts} from '@formatjs/ts-transformer'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: Opts\n) {\n if (!options.onMsgExtracted) return\n if (!options.overrideIdFn) return\n\n if (node.path.type !== 'PathExpression') return\n\n if (['format-message', 'formatMessage'].includes(node.path.original)) {\n let [first, second] = node.params\n\n if (first.type !== 'StringLiteral') return\n\n let message = first?.value\n\n let desc: string | undefined\n if (second?.type === 'StringLiteral') {\n desc = second.value?.trim().replace(/\\s+/gm, ' ')\n }\n\n let defaultMessage = message?.trim().replace(/\\s+/gm, ' ')\n\n let id =\n typeof options.overrideIdFn === 'string'\n ? options.overrideIdFn\n : options.overrideIdFn(undefined, defaultMessage, desc, fileName)\n\n options.onMsgExtracted(fileName, [\n {\n id: id,\n defaultMessage: defaultMessage,\n description: desc,\n },\n ])\n }\n}\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const ast = preprocess(source)\n traverse(ast, {\n MustacheStatement(node: ASTv1.MustacheStatement) {\n extractText(node, fileName, options)\n },\n SubExpression(node: ASTv1.SubExpression) {\n extractText(node, fileName, options)\n },\n })\n}\n"],"mappings":";;AAGA,SAAS,YACP,MACA,UACA,SACA;AACA,KAAI,CAAC,QAAQ,eAAgB;AAC7B,KAAI,CAAC,QAAQ,aAAc;AAE3B,KAAI,KAAK,KAAK,SAAS,iBAAkB;AAEzC,KAAI,CAAC,kBAAkB,gBAAgB,CAAC,SAAS,KAAK,KAAK,SAAS,EAAE;EACpE,IAAI,CAAC,OAAO,UAAU,KAAK;AAE3B,MAAI,MAAM,SAAS,gBAAiB;EAEpC,IAAI,UAAU,OAAO;EAErB,IAAI;AACJ,MAAI,QAAQ,SAAS,gBACnB,QAAO,OAAO,OAAO,MAAM,CAAC,QAAQ,SAAS,IAAI;EAGnD,IAAI,iBAAiB,SAAS,MAAM,CAAC,QAAQ,SAAS,IAAI;EAE1D,IAAI,KACF,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,QAAQ,aAAa,KAAA,GAAW,gBAAgB,MAAM,SAAS;AAErE,UAAQ,eAAe,UAAU,CAC/B;GACM;GACY;GAChB,aAAa;GACd,CACF,CAAC;;;AAIN,SAAgB,UACd,QACA,UACA,SACM;AAEN,UADY,WAAW,OAAO,EAChB;EACZ,kBAAkB,MAA+B;AAC/C,eAAY,MAAM,UAAU,QAAQ;;EAEtC,cAAc,MAA2B;AACvC,eAAY,MAAM,UAAU,QAAQ;;EAEvC,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,144 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { MessageDescriptor, MessageDescriptor as MessageDescriptor$1, Opts as Opts$1 } from "@formatjs/ts-transformer";
|
|
2
|
+
import { Comparator, Comparator as Comparator$1 } from "json-stable-stringify";
|
|
3
|
+
|
|
4
|
+
//#region packages/cli-lib/formatters/default.d.ts
|
|
5
|
+
type FormatFn<T = Record<string, MessageDescriptor$1>> = (msgs: Record<string, MessageDescriptor$1>) => T;
|
|
6
|
+
type CompileFn<T = Record<string, MessageDescriptor$1>> = (msgs: T) => Record<string, string>;
|
|
7
|
+
type SerializeFn<T = Record<string, MessageDescriptor$1>> = (msgs: T) => string;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region packages/cli-lib/formatters/index.d.ts
|
|
10
|
+
interface Formatter<T> {
|
|
11
|
+
serialize?: SerializeFn<T>;
|
|
12
|
+
format: FormatFn<T>;
|
|
13
|
+
compile: CompileFn<T>;
|
|
14
|
+
compareMessages?: Comparator$1;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region packages/cli-lib/extract.d.ts
|
|
18
|
+
type ExtractCLIOptions = Omit<ExtractOpts, "overrideIdFn" | "onMsgExtracted" | "onMetaExtracted"> & {
|
|
19
|
+
/**
|
|
20
|
+
* Output File
|
|
21
|
+
*/
|
|
22
|
+
outFile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Input File
|
|
25
|
+
*/
|
|
26
|
+
inFile?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Ignore file glob pattern
|
|
29
|
+
*/
|
|
30
|
+
ignore?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Whether to follow symbolic links when traversing directories.
|
|
33
|
+
* Defaults to true for compatibility with pnpm symlinked node_modules.
|
|
34
|
+
*/
|
|
35
|
+
followLinks?: boolean;
|
|
36
|
+
};
|
|
37
|
+
type ExtractOpts = Opts$1 & {
|
|
38
|
+
/**
|
|
39
|
+
* Whether to throw an error if we had any issues with
|
|
40
|
+
* 1 of the source files
|
|
41
|
+
*/
|
|
42
|
+
throws?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Message ID interpolation pattern
|
|
45
|
+
*/
|
|
46
|
+
idInterpolationPattern?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether we read from stdin instead of a file
|
|
49
|
+
*/
|
|
50
|
+
readFromStdin?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Either path to a formatter file that controls the shape of JSON file from `outFile` or {@link Formatter} object.
|
|
53
|
+
*/
|
|
54
|
+
format?: string | Formatter<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Whether to hoist selectors & flatten sentences
|
|
57
|
+
*/
|
|
58
|
+
flatten?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* An AbortSignal to cancel the extraction
|
|
61
|
+
*/
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
} & Pick<Opts$1, "onMsgExtracted" | "onMetaExtracted">;
|
|
64
|
+
/**
|
|
65
|
+
* Extract strings from source files
|
|
66
|
+
* @param files list of files
|
|
67
|
+
* @param extractOpts extract options
|
|
68
|
+
* @returns messages serialized as JSON string since key order
|
|
69
|
+
* matters for some `format`
|
|
70
|
+
*/
|
|
71
|
+
declare function extract(files: readonly string[], extractOpts: ExtractOpts): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Extract strings from source files, also writes to a file.
|
|
74
|
+
* @param files list of files
|
|
75
|
+
* @param extractOpts extract options
|
|
76
|
+
* @returns A Promise that resolves if output file was written successfully
|
|
77
|
+
*/
|
|
78
|
+
declare function extractAndWrite(files: readonly string[], extractOpts: ExtractCLIOptions): Promise<void>;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region packages/cli-lib/compile.d.ts
|
|
81
|
+
type PseudoLocale = "xx-LS" | "xx-AC" | "xx-HA" | "en-XA" | "en-XB";
|
|
82
|
+
interface CompileCLIOpts extends Opts {
|
|
83
|
+
/**
|
|
84
|
+
* The target file that contains compiled messages.
|
|
85
|
+
*/
|
|
86
|
+
outFile?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to follow symbolic links when traversing directories.
|
|
89
|
+
* Defaults to true for compatibility with pnpm symlinked node_modules.
|
|
90
|
+
*/
|
|
91
|
+
followLinks?: boolean;
|
|
92
|
+
}
|
|
93
|
+
interface Opts {
|
|
94
|
+
/**
|
|
95
|
+
* Whether to compile message into AST instead of just string
|
|
96
|
+
*/
|
|
97
|
+
ast?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Whether to continue compiling messages after encountering an error.
|
|
100
|
+
* Any keys with errors will not be included in the output file.
|
|
101
|
+
*/
|
|
102
|
+
skipErrors?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Path to a formatter file that converts <translation_files> to
|
|
105
|
+
* `Record<string, string>` so we can compile.
|
|
106
|
+
*/
|
|
107
|
+
format?: string | Formatter<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* Whether to compile to pseudo locale
|
|
110
|
+
*/
|
|
111
|
+
pseudoLocale?: PseudoLocale;
|
|
112
|
+
/**
|
|
113
|
+
* Whether the parser to treat HTML/XML tags as string literal
|
|
114
|
+
* instead of parsing them as tag token.
|
|
115
|
+
* When this is false we only allow simple tags without
|
|
116
|
+
* any attributes
|
|
117
|
+
*/
|
|
118
|
+
ignoreTag?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* An AbortSignal to cancel the compilation
|
|
121
|
+
*/
|
|
122
|
+
signal?: AbortSignal;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Aggregate `inputFiles` into a single JSON blob and compile.
|
|
126
|
+
* Also checks for conflicting IDs.
|
|
127
|
+
* Then returns the serialized result as a `string` since key order
|
|
128
|
+
* makes a difference in some vendor.
|
|
129
|
+
* @param inputFiles Input files
|
|
130
|
+
* @param opts Options
|
|
131
|
+
* @returns serialized result in string format
|
|
132
|
+
*/
|
|
133
|
+
declare function compile(inputFiles: string[], opts?: Opts): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Aggregate `inputFiles` into a single JSON blob and compile.
|
|
136
|
+
* Also checks for conflicting IDs and write output to `outFile`.
|
|
137
|
+
* @param inputFiles Input files
|
|
138
|
+
* @param compileOpts options
|
|
139
|
+
* @returns A `Promise` that resolves if file was written successfully
|
|
140
|
+
*/
|
|
141
|
+
declare function compileAndWrite(inputFiles: string[], compileOpts?: CompileCLIOpts): Promise<void>;
|
|
142
|
+
//#endregion
|
|
143
|
+
export { type Comparator, type CompileCLIOpts, type CompileFn, type Opts as CompileOpts, type ExtractCLIOptions, type ExtractOpts, type FormatFn, type MessageDescriptor, compile, compileAndWrite, extract, extractAndWrite };
|
|
144
|
+
//# sourceMappingURL=index.d.ts.map
|