UNPKG

travelm-agency

Version:

Generate type-safe accessors and decoders for your i18n files

92 lines (88 loc) 3.34 kB
#!/usr/bin/env node "use strict"; import { run } from "./lib/main.js"; import yargs from "yargs"; import { hideBin } from "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, }) .option("custom_html_module", { description: "Which module the generated code should use instead of elm/html", type: "string", }) .option("custom_html_attributes_module", { description: "Which module the generated code should use instead of elm/html Html.Attributes. Defaults to the value of custom_html_module + '.Attributes'", type: "string", }) .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, customHtmlModule: args.custom_html_module, customHtmlAttributesModule: args.custom_html_attributes_module, }); })(); process.on("unhandledRejection", (err) => { throw err; });