UNPKG

@zauberware/weblate-create-components

Version:

You need `curl` to be installed. It is installed per default on each unix-like machine.

163 lines (153 loc) 5.05 kB
#!/usr/bin/env node 'use strict' const { prompt, Toggle } = require('enquirer'); const createComponents = require('./create-components.js') const initialQuestions = [ { type: 'input', name: 'cwd', message: 'What is your local path of the git repository?', initial: process.cwd(), required: true, }, { type: 'select', name: 'isLanguageCodeInFilename', message: 'Does your translation files contain the language code? For example \'de.json\'?', initial: 'No', choices: [ { name: 'Yes', message: 'Yes', }, { name: 'No', message: 'No', } ] }, { type: 'input', name: 'token', message: 'Please enter the token of your weblate account or project?', required: true }, { type: 'input', name: 'projectName', message: 'What\'s the name/slug of the weblate project?', required: true }, { type: 'input', name: 'weblateUrl', message: 'What\'s the base url of your weblate server?', initial: 'https://translations.zauberware.dev', }, { type: 'input', name: 'branch', message: 'On which branch should weblate commit and get the current translations from?', initial: 'develop', }, { type: 'input', name: 'sourceLanguageCode', message: 'What\'s the source language of the project?', initial: 'de' }, { type: 'input', name: 'commitPendingAge', message: 'What\'s the duration in hours when weblate will create a commit to the repository?', initial: '1' }, { type: 'input', name: 'repoUrl', message: 'What\'s url of the git repository of your project?', required: true }, { type: 'select', name: 'fileFormat', message: 'What are the format of the translation files?', initial: 'i18next', choices: [ { name: "i18next", message: "i18next JSON file v3" }, { name: "ruby-yaml", message: "Ruby YAML file" }, { name: "laravel", message: "Laravel PHP strings" }, { name: "json", message: "JSON file" }, { name: "json-nested", message: "JSON nested structure file" }, { name: "arb", message: "ARB file" }, { name: "aresource", message: "Android String Resource" }, { name: "dtd", message: "DTD file" }, { name: "flatxml", message: "Flat XML file" }, { name: "go-i18n-json", message: "go-i18n JSON file" }, { name: "gwt", message: "GWT properties" }, { name: "ini", message: "INI file" }, { name: "islu", message: "Inno Setup INI file" }, { name: "joomla", message: "Joomla language file" }, { name: "mi18n-lang", message: "mi18n lang file" }, { name: "php", message: "PHP strings" }, { name: "po", message: "gettext PO file" }, { name: "properties", message: "Java Properties (ISO 8859-1)" }, { name: "properties-utf16", message: "Java Properties (UTF-16)" }, { name: "properties-utf8", message: "Java Properties (UTF-8)" }, { name: "resx", message: ".NET resource file" }, { name: "strings", message: "iOS strings (UTF-16)" }, { name: "strings-utf8", message: "iOS strings (UTF-8)" }, { name: "stringsdict", message: "Stringsdict file" }, { name: "yaml", message: "YAML file" }, { name: "tbx", message: "TermBase eXchange file" }, { name: "webextension", message: "WebExtension JSON file" }, { name: "xwiki-fullpage", message: "XWiki Full Page" }, { name: "xwiki-java-properties", message: "XWiki Java Properties" }, { name: "xwiki-page-properties", message: "XWiki Page Properties " }, ] }, { type: 'input', name: 'globFileMask', message: 'Enter a glob pattern to find all your different translation files in the source language.', hint: 'For example: `./public/locales/de/*.json`. This is only for local usage.', required: true, }, ] const questionsIfLanguageCodeNotInFilename = [ { type: 'input', name: 'fileMaskFolder', message: 'Enter a relative path to the directory where your translation files are located.', hint: 'For example: `public/locales`', required: true, }, ] const startQuestionaire = async () => { let response = await prompt(initialQuestions) if (response.isLanguageCodeInFilename !== 'Yes') { const moreResponses = await prompt(questionsIfLanguageCodeNotInFilename) response = { ...response, ...moreResponses } } return response } const askForStart = async (options, createComponentOptions) => { const start = await new Toggle({ message: 'Do you want to create your components?\n', enabled: 'Yes', disabled: 'Nope', }).run() if (start) { return await createComponents(options, createComponentOptions) } } const printOptions = (options, createComponentOptions) => { console.log('That are your entries: \n') console.log('options', { ...options, createComponentOptions }) console.log('========================================') } module.exports = { askForStart, printOptions, startQuestionaire, }