-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
80 lines (76 loc) · 2.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
"use strict";
const { run } = require("./lib/main.js");
const yargs = require("yargs");
const { hideBin } = require("yargs/helpers");
(async () => {
const args = await yargs(hideBin(process.argv))
.command(
"$0 <translation_directory>",
"Generate Elm code for your translation files",
(builder) =>
builder
.option("elm_path", {
description:
"Where to put the generated Elm file. There needs to be an elm.json file in some parent folder for this script to work.",
type: "string",
default: "src/Translations.elm",
})
.option("json_path", {
description:
"The directory to generate the optimized translation files into. This will not be used if --inline is specified.",
type: "string",
default: "dist/i18n",
})
.option("inline", {
description:
"Generate an Elm module that contains all of the translations inline (no resource loading necessary at runtime).",
type: "boolean",
default: false,
})
.option("hash", {
description:
"Add content hashes to generated json files. This helps with caching. This will not be used if --inline is specified.",
type: "boolean",
default: false,
})
.option("i18n_arg_first", {
description:
"Pass the i18n instance as the last parameter to the generated function (opposed to it being the first).",
type: "boolean",
default: false,
})
.option("prefix_file_identifier", {
description:
"Prefix the identifier of the files containing the translation keys to the generated translation functions.",
type: "boolean",
default: false,
})
.option("devMode", {
description: "Disable completeness check for i18n keys",
type: "boolean",
default: false,
})
.positional("translation_directory", {
description:
"The directory containing translation files (.json/.properties).",
type: "string",
demandOption: true,
})
)
.parse();
run({
translationDir: args.translation_directory,
elmPath: args.elm_path,
jsonPath: args.json_path,
elmJson: args.elm_json,
generatorMode: args.inline ? "inline" : "dynamic",
addContentHash: args.hash,
devMode: args.devMode,
i18nArgFirst: args.i18n_arg_first,
prefixFileIdentifier: args.prefix_file_identifier,
});
})();
process.on("unhandledRejection", (err) => {
throw err;
});