@translated/lara-cli 0.2.1

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.
Files changed (68) hide show
  1. package/README.md +212 -0
  2. package/build/cli/cmd/glossary/glossary.js +55 -0
  3. package/build/cli/cmd/glossary/glossary.js.map +1 -0
  4. package/build/cli/cmd/init/init.input.js +177 -0
  5. package/build/cli/cmd/init/init.input.js.map +1 -0
  6. package/build/cli/cmd/init/init.js +158 -0
  7. package/build/cli/cmd/init/init.js.map +1 -0
  8. package/build/cli/cmd/init/init.types.js +2 -0
  9. package/build/cli/cmd/init/init.types.js.map +1 -0
  10. package/build/cli/cmd/init/init.utils.js +99 -0
  11. package/build/cli/cmd/init/init.utils.js.map +1 -0
  12. package/build/cli/cmd/memory/memory.js +55 -0
  13. package/build/cli/cmd/memory/memory.js.map +1 -0
  14. package/build/cli/cmd/translate/translate.js +149 -0
  15. package/build/cli/cmd/translate/translate.js.map +1 -0
  16. package/build/index.js +25 -0
  17. package/build/index.js.map +1 -0
  18. package/build/interface/parser.js +2 -0
  19. package/build/interface/parser.js.map +1 -0
  20. package/build/messages/messages.js +120 -0
  21. package/build/messages/messages.js.map +1 -0
  22. package/build/modules/common/common.const.js +424 -0
  23. package/build/modules/common/common.const.js.map +1 -0
  24. package/build/modules/common/common.types.js +15 -0
  25. package/build/modules/common/common.types.js.map +1 -0
  26. package/build/modules/config/config.provider.js +47 -0
  27. package/build/modules/config/config.provider.js.map +1 -0
  28. package/build/modules/config/config.types.js +95 -0
  29. package/build/modules/config/config.types.js.map +1 -0
  30. package/build/modules/translation/translation.engine.js +165 -0
  31. package/build/modules/translation/translation.engine.js.map +1 -0
  32. package/build/modules/translation/translation.service.js +45 -0
  33. package/build/modules/translation/translation.service.js.map +1 -0
  34. package/build/parsers/android-xml.parser.js +308 -0
  35. package/build/parsers/android-xml.parser.js.map +1 -0
  36. package/build/parsers/json.parser.js +18 -0
  37. package/build/parsers/json.parser.js.map +1 -0
  38. package/build/parsers/markdown.parser.js +74 -0
  39. package/build/parsers/markdown.parser.js.map +1 -0
  40. package/build/parsers/parser.factory.js +52 -0
  41. package/build/parsers/parser.factory.js.map +1 -0
  42. package/build/parsers/parser.types.js +2 -0
  43. package/build/parsers/parser.types.js.map +1 -0
  44. package/build/parsers/po.parser.js +175 -0
  45. package/build/parsers/po.parser.js.map +1 -0
  46. package/build/parsers/ts.parser.js +176 -0
  47. package/build/parsers/ts.parser.js.map +1 -0
  48. package/build/parsers/vue.parser.js +156 -0
  49. package/build/parsers/vue.parser.js.map +1 -0
  50. package/build/utils/checksum.js +80 -0
  51. package/build/utils/checksum.js.map +1 -0
  52. package/build/utils/cli.js +4 -0
  53. package/build/utils/cli.js.map +1 -0
  54. package/build/utils/display.js +60 -0
  55. package/build/utils/display.js.map +1 -0
  56. package/build/utils/error.js +18 -0
  57. package/build/utils/error.js.map +1 -0
  58. package/build/utils/locale.js +108 -0
  59. package/build/utils/locale.js.map +1 -0
  60. package/build/utils/parser.js +25 -0
  61. package/build/utils/parser.js.map +1 -0
  62. package/build/utils/path.js +173 -0
  63. package/build/utils/path.js.map +1 -0
  64. package/build/utils/progressWithOra.js +72 -0
  65. package/build/utils/progressWithOra.js.map +1 -0
  66. package/build/utils/prompt.js +205 -0
  67. package/build/utils/prompt.js.map +1 -0
  68. package/package.json +89 -0
package/README.md ADDED
@@ -0,0 +1,212 @@
1
+ <div align="center">
2
+
3
+ # 🚀 Lara Cli – A Powerful CLI Tool for Instant i18n Localization
4
+
5
+ Lara Cli automates translation of your i18n files with a single command, preserving structure and formatting while integrating with a professional translation API. Given a source language, it translates your content to selected target languages based on your source i18n files.
6
+
7
+ Supports multiple file formats including JSON, PO (gettext), TypeScript, Vue I18n single-file components, Markdown and MDX files, and Android XML string resource files. See [Supported Formats](docs/config/formats.md) for details.
8
+
9
+ [![Version](https://img.shields.io/badge/version-0.2.1-blue.svg)](https://github.com/translated/lara-cli)
10
+
11
+ </div>
12
+
13
+ > **⚠️ Development Mode Only:** This tool is currently available in Development mode. The full release is coming soon! 🚀
14
+
15
+ ## 📑 Table of Contents
16
+
17
+ - [Requirements](#requirements)
18
+ - [Local Development Setup](#local-development-setup)
19
+ - [Setting Up Your Project](#setting-up-your-project)
20
+ - [Technology Stack](#technology-stack)
21
+ - [Supported Locales](#supported-locales)
22
+ - [Documentation](#documentation)
23
+
24
+ ## Requirements
25
+
26
+ - Node.js v18 or higher
27
+ - pnpm v8 or higher
28
+
29
+ ## Local Development Setup
30
+
31
+ 1. **Clone the repository**
32
+
33
+ ```bash
34
+ git clone https://github.com/translated/lara-cli.git
35
+ ```
36
+
37
+ 2. **Navigate to the cloned repository**
38
+
39
+ ```bash
40
+ cd lara-cli
41
+ ```
42
+
43
+ 3. **Install dependencies and build**
44
+
45
+ > **Note:** This project uses pnpm. If you don't have it installed, run: `npm install -g pnpm`. Verify the installation with `pnpm -v` before proceeding with the following commands.
46
+
47
+ ```bash
48
+ pnpm install
49
+ pnpm run build
50
+ ```
51
+
52
+ 4. **Setup pnpm global bin directory (first time only)**
53
+
54
+ ```bash
55
+ pnpm setup
56
+ ```
57
+
58
+ This command configures your shell to add the pnpm global bin directory to your PATH. After running it, you'll see output similar to:
59
+
60
+ ```bash
61
+ Appended new lines to /Users/<username>/.zshrc
62
+
63
+ Next configuration changes were made:
64
+ export PNPM_HOME="/Users/<username>/Library/pnpm"
65
+ case ":$PATH:" in
66
+ *":$PNPM_HOME:"*) ;;
67
+ *) export PATH="$PNPM_HOME:$PATH" ;;
68
+ esac
69
+ ```
70
+
71
+ Add these lines to your shell profile (`.zshrc`, `.bashrc`, etc.) or restart your terminal to apply the changes. This ensures you can run globally installed pnpm packages.
72
+
73
+ 5. **Link globally**
74
+
75
+ ```bash
76
+ pnpm link --global
77
+ ```
78
+
79
+ > **Note:** If you experience an error like `ERR_PNPM_NO_GLOBAL_BIN_DIR`, you may need to manually copy and paste the lines added by `pnpm setup` into your shell profile. After doing so, restart your terminal or source your profile file, and you should be able to proceed.
80
+
81
+ After running this command, the project will be successfully linked to the pnpm global library. You should see a response similar to:
82
+
83
+ ```bash
84
+ /Users/username/Library/pnpm/global/5:
85
+ + lara-cli version <- ../../../../Projects/translated/lara-cli
86
+ ```
87
+
88
+ 6. **Installation Complete - Use anywhere**
89
+
90
+ Now that Lara CLI is installed globally, you can use it from any directory on your system:
91
+
92
+ ```bash
93
+ # Get help with available commands
94
+ lara-cli --help
95
+
96
+ # Initialize a new Lara project
97
+ lara-cli init --help
98
+
99
+ # Translate your localization files
100
+ lara-cli translate --help
101
+ ```
102
+
103
+ **Note:** After making changes to the source code, run `pnpm run build` to update the global command.
104
+
105
+ ## Setting Up Your Project
106
+
107
+ ### Add Your Credentials to `.env`
108
+
109
+ Create a `.env` file (or add the following lines to an existing `.env`) in the project where you want to run translations.
110
+
111
+ 💡 **Tip:** If you don't have API keys yet, visit [Lara's API key documentation](https://support.laratranslate.com/en/api-key-for-laras-api).
112
+
113
+ ```bash
114
+ LARA_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID>
115
+ LARA_ACCESS_KEY_SECRET=<YOUR_ACCESS_KEY_SECRET>
116
+ ```
117
+
118
+ Replace the placeholders with your **actual credentials**.
119
+
120
+ > **🔑 Need to update credentials?** If your API keys expire or need updating, run `lara-cli init --reset-credentials` to safely update them in your `.env` file.
121
+
122
+ ### Initialize Your Project
123
+
124
+ In your project directory, run:
125
+
126
+ ```bash
127
+ lara-cli init
128
+ ```
129
+
130
+ This will start the interactive initialization process.
131
+
132
+ The CLI will **automatically detect your localization directories and target locales** from your existing project files, then guide you through a few questions. These will be used to generate the configuration file: `lara.yaml`.
133
+
134
+ **Key features:**
135
+
136
+ - 🔍 **Auto-detection**: Scans your project for existing locale files and automatically suggests target locales
137
+ - 📊 **Smart display**: For enterprise projects with many locales, uses formatted tables for better readability
138
+ - ⚙️ **Flexible configuration**: Choose detected locales or manually add/remove as needed
139
+ - 🎯 **Project instructions**: Optionally provide instructions to improve translation quality (e.g., tone, style, terminology)
140
+
141
+ **Providing project instructions** (optional but recommended):
142
+
143
+ During initialization, you can provide instructions to help improve translation quality. Instructions guide the translation service on tone, style, and terminology. This is especially useful for:
144
+
145
+ - Tone requirements (formal, casual, professional, friendly)
146
+ - Domain-specific terminology (medical, legal, technical, etc.)
147
+ - Style preferences (concise, creative, detailed)
148
+
149
+ **Providing glossaries** (optional but recommended):
150
+
151
+ Lara's glossary system lets you define exactly how specific terms should be translated, across any text or document. Whether you work with technical terms, product names, or recurring brand phrases, glossaries are your best tool to ensure consistency and precision.
152
+
153
+ 💡 **Tip:** For more information about glossaries, visit [Lara's Glossary documentation](https://support.laratranslate.com/en/how-glossaries-work-in-lara).
154
+
155
+ ### Translate Your Files
156
+
157
+ To translate your files into the target locales, run:
158
+
159
+ ```bash
160
+ lara-cli translate
161
+ ```
162
+
163
+ That's it – you're ready to go!
164
+
165
+ > **📖 Documentation:** For detailed information about commands, see [Init Command](docs/commands/init.md) and [Translate Command](docs/commands/translate.md).
166
+
167
+ ## Technology Stack
168
+
169
+ Lara CLI is built with modern technologies to ensure reliability, performance, and maintainability:
170
+
171
+ - **TypeScript** - For type safety and developer experience
172
+ - **Commander.js** - For CLI argument parsing and command structure
173
+ - **Zod** - For robust schema validation
174
+ - **Inquirer.js** - For interactive command-line user interfaces
175
+ - **Lara Translation API** - For high-quality, context-aware translations
176
+
177
+ The codebase follows a modular architecture with clear separation of concerns, making it easy to extend and maintain.
178
+
179
+ ## Supported Locales
180
+
181
+ Lara CLI supports translations using different locale codes, following two main standards:
182
+
183
+ See the [full list of supported locales](docs/config/locales.md#supported-locales).
184
+
185
+ ## Documentation
186
+
187
+ For detailed documentation on using Lara CLI:
188
+
189
+ ### Commands
190
+
191
+ - [Init Command](docs/commands/init.md) - Initialize your project
192
+ - [Translate Command](docs/commands/translate.md) - Translate your files
193
+ - [Memory Command](docs/commands/memory.md) - List available Translation Memories
194
+ - [Glossary Command](docs/commands/glossary.md) - List available Glossaries
195
+
196
+ ### Configuration
197
+
198
+ - [Configuration Overview](docs/config/README.md) - Configuration system overview
199
+ - [Supported Formats](docs/config/formats.md) - Supported file formats (JSON, PO, etc.)
200
+ - [Locales Configuration](docs/config/locales.md) - Configure source and target languages
201
+ - [Files Configuration](docs/config/files.md) - Configure file paths and patterns
202
+ - [Instructions](docs/config/instructions.md) - Configure translation instructions
203
+ - [Translation Memories](docs/config/memories.md) - Configure Translation Memories
204
+ - [Glossaries](docs/config/glossaries.md) - Configure Glossaries
205
+
206
+ ### Format-Specific Guides
207
+
208
+ - [TS Files Guide](docs/config/files/ts-files.md) - Complete guide for TypeScript files
209
+ - [PO Files Guide](docs/config/files/po-files.md) - Complete guide for gettext PO files
210
+ - [Vue Files Guide](docs/config/files/vue-files.md) - Complete guide for Vue I18n single-file components
211
+ - [Markdown Files Guide](docs/config/files/md-files.md) - Complete guide for Markdown and MDX files
212
+ - [Android XML Files Guide](docs/config/files/android-xml-files.md) - Complete guide for Android XML string resource files
@@ -0,0 +1,55 @@
1
+ import { Command } from 'commander';
2
+ import Ora from 'ora';
3
+ import { TranslationService } from '#modules/translation/translation.service.js';
4
+ import { LARA_WEB_URL } from '#modules/common/common.const.js';
5
+ import { handleLaraApiError } from '#utils/error.js';
6
+ import { LaraApiError } from '@translated/lara';
7
+ import { Messages } from '#messages/messages.js';
8
+ export default new Command()
9
+ .command('glossary')
10
+ .description('Manage glossaries')
11
+ .helpOption('-h, --help', 'Show help')
12
+ .action(async () => {
13
+ if (!process.env.LARA_ACCESS_KEY_ID || !process.env.LARA_ACCESS_KEY_SECRET) {
14
+ Ora({
15
+ text: Messages.errors.noApiCredentials,
16
+ color: 'red',
17
+ }).fail();
18
+ process.exit(1);
19
+ }
20
+ await handleGlossary();
21
+ });
22
+ async function handleGlossary() {
23
+ try {
24
+ await listGlossaries();
25
+ }
26
+ catch (error) {
27
+ const message = error instanceof Error ? error.message : String(error);
28
+ Ora({ text: message, color: 'red' }).fail();
29
+ process.exit(1);
30
+ }
31
+ }
32
+ async function listGlossaries() {
33
+ const spinner = Ora().start(Messages.info.fetchingGlossaries);
34
+ try {
35
+ const translationService = TranslationService.getInstance();
36
+ const clientGlossaries = await translationService.getGlossaries();
37
+ if (clientGlossaries.length === 0) {
38
+ spinner.warn(Messages.warnings.noGlossariesLinked(LARA_WEB_URL));
39
+ return;
40
+ }
41
+ spinner.succeed(Messages.success.foundGlossaries(clientGlossaries.length));
42
+ for (const glossary of clientGlossaries) {
43
+ console.log(Messages.ui.itemId(glossary.id));
44
+ console.log(Messages.ui.itemName(glossary.name) + '\n');
45
+ }
46
+ }
47
+ catch (error) {
48
+ if (error instanceof LaraApiError) {
49
+ handleLaraApiError(error, Messages.errors.gettingGlossaries, spinner);
50
+ return;
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+ //# sourceMappingURL=glossary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glossary.js","sourceRoot":"/","sources":["cli/cmd/glossary/glossary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,eAAe,IAAI,OAAO,EAAE;KACzB,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,mBAAmB,CAAC;KAChC,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC;KACrC,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC;QAC3E,GAAG,CA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CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;YACtE,OAAO;QACT,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,177 @@
1
+ import { confirm, input } from '@inquirer/prompts';
2
+ import Ora from 'ora';
3
+ import { searchLocalePaths } from '#utils/path.js';
4
+ import { AVAILABLE_LOCALES, COMMA_AND_SPACE_REGEX } from '#modules/common/common.const.js';
5
+ import { FilePath } from '#modules/config/config.types.js';
6
+ import { extractLocaleFromPath, extractAllLocalesFromProject } from '#utils/locale.js';
7
+ import { displayLocaleTable, formatLocaleList } from '#utils/display.js';
8
+ import customSearchableSelect from '#utils/prompt.js';
9
+ import { Messages } from '#messages/messages.js';
10
+ export async function sourceInput(options) {
11
+ const spinner = Ora({ text: Messages.info.searchingLocales, color: 'yellow' }).start();
12
+ const foundLocales = await extractAllLocalesFromProject();
13
+ if (foundLocales.length === 0) {
14
+ spinner.fail(Messages.errors.noLocalesFound);
15
+ Ora({
16
+ text: Messages.errors.noLocalesFoundHint,
17
+ color: 'red',
18
+ }).fail();
19
+ process.exit(1);
20
+ }
21
+ spinner.succeed(Messages.success.foundLocales(foundLocales.length));
22
+ const choices = foundLocales.map((locale) => ({
23
+ label: locale,
24
+ value: locale,
25
+ }));
26
+ const result = await customSearchableSelect({
27
+ message: Messages.prompts.sourceLocale,
28
+ multiple: false,
29
+ default: options.source && foundLocales.includes(options.source) ? options.source : undefined,
30
+ choices: choices,
31
+ });
32
+ if (!result || result.length === 0 || !result[0]) {
33
+ throw new Error(Messages.errors.sourceLocaleRequired);
34
+ }
35
+ return result[0];
36
+ }
37
+ export async function autoTargetInput(source) {
38
+ const shouldAutoTarget = await confirm({
39
+ message: Messages.prompts.autoDetectTarget,
40
+ });
41
+ if (shouldAutoTarget) {
42
+ const spinner = Ora({ text: Messages.info.searchingTargetLocales, color: 'yellow' }).start();
43
+ const locales = await extractLocaleFromPath(source);
44
+ if (locales.length === 0) {
45
+ spinner.warn(Messages.info.noTargetLocalesFound);
46
+ return [];
47
+ }
48
+ if (locales.length > 10) {
49
+ displayLocaleTable({
50
+ locales,
51
+ title: Messages.success.foundTargetLocales(locales.length),
52
+ spinner,
53
+ type: 'succeed',
54
+ });
55
+ }
56
+ else {
57
+ spinner.succeed(Messages.success.foundTargetLocales(locales.length, formatLocaleList(locales, 10)));
58
+ }
59
+ return locales;
60
+ }
61
+ Ora({ text: Messages.info.autoDetectionSkipped, color: 'blue' }).info();
62
+ return [];
63
+ }
64
+ export async function targetInput(source, defaults = []) {
65
+ const autoDetectedLocales = await autoTargetInput(source);
66
+ const autoDetectedLocalesSet = new Set(autoDetectedLocales);
67
+ const choices = AVAILABLE_LOCALES.filter((locale) => locale !== source && !autoDetectedLocalesSet.has(locale)).map((locale) => ({
68
+ label: locale,
69
+ value: locale,
70
+ }));
71
+ let addMoreTargetLocales = true;
72
+ if (autoDetectedLocales.length > 0) {
73
+ const alreadyAddedMessage = autoDetectedLocales.length <= 5
74
+ ? Messages.info.alreadyAdded(formatLocaleList(autoDetectedLocales))
75
+ : Messages.info.localesAlreadyAdded(autoDetectedLocales.length);
76
+ addMoreTargetLocales = await confirm({
77
+ message: Messages.prompts.addMoreTargetLocales(alreadyAddedMessage),
78
+ });
79
+ }
80
+ if (!addMoreTargetLocales) {
81
+ return Array.from(new Set([...defaults, ...autoDetectedLocales]));
82
+ }
83
+ const additionalLocalesMessage = autoDetectedLocales.length > 0
84
+ ? Messages.prompts.selectAdditionalTargetLocales
85
+ : Messages.prompts.selectTargetLocales;
86
+ const additionalLocales = await customSearchableSelect({
87
+ message: additionalLocalesMessage,
88
+ choices: choices,
89
+ multiple: true,
90
+ default: defaults,
91
+ theme: {
92
+ icon: {
93
+ checked: '◉',
94
+ unchecked: '◯',
95
+ cursor: '›',
96
+ },
97
+ },
98
+ validate: (value) => {
99
+ if (autoDetectedLocales.length === 0 && value.length === 0) {
100
+ return Messages.errors.selectAtLeastOneLocale;
101
+ }
102
+ return true;
103
+ },
104
+ });
105
+ const allTargetLocales = [...autoDetectedLocales, ...additionalLocales];
106
+ if (allTargetLocales.length > 0) {
107
+ const autoCount = autoDetectedLocales.length;
108
+ const manualCount = additionalLocales.length;
109
+ const summaryParts = [];
110
+ if (autoCount > 0) {
111
+ summaryParts.push(Messages.info.autoDetected(autoCount));
112
+ }
113
+ if (manualCount > 0) {
114
+ summaryParts.push(Messages.info.manuallyAdded(manualCount));
115
+ }
116
+ const summaryText = summaryParts.length > 0 ? ` (${summaryParts.join(', ')})` : '';
117
+ if (allTargetLocales.length > 10) {
118
+ displayLocaleTable({
119
+ locales: allTargetLocales,
120
+ title: Messages.success.totalTargetLocalesSelected(allTargetLocales.length, summaryText),
121
+ type: 'succeed',
122
+ });
123
+ }
124
+ else {
125
+ Ora().succeed(Messages.success.targetLocalesSelected(formatLocaleList(allTargetLocales, 10), summaryText));
126
+ }
127
+ }
128
+ return allTargetLocales;
129
+ }
130
+ export async function pathsInput(options) {
131
+ const spinner = Ora({ text: Messages.info.searchingPaths, color: 'yellow' }).start();
132
+ const paths = await searchLocalePaths({ source: options.source });
133
+ if (paths.length === 0) {
134
+ spinner.warn(Messages.info.noPathsFound);
135
+ const inputPath = await input({
136
+ message: Messages.prompts.enterPaths,
137
+ default: options.paths.join(', '),
138
+ validate: (value) => {
139
+ const paths = value.split(COMMA_AND_SPACE_REGEX);
140
+ for (const path of paths) {
141
+ const parsedPath = FilePath.safeParse(path);
142
+ if (!parsedPath.success) {
143
+ return parsedPath.error.issues[0]?.message || Messages.errors.invalidPath;
144
+ }
145
+ }
146
+ return true;
147
+ },
148
+ });
149
+ return inputPath.split(COMMA_AND_SPACE_REGEX);
150
+ }
151
+ spinner.succeed(Messages.success.pathsFound);
152
+ const optionPaths = paths.map((path) => ({
153
+ name: path,
154
+ value: path,
155
+ checked: options.paths.includes(path),
156
+ }));
157
+ return await customSearchableSelect({
158
+ message: Messages.prompts.selectPaths,
159
+ choices: optionPaths.map((path) => ({
160
+ value: path.value,
161
+ label: path.name,
162
+ })),
163
+ multiple: true,
164
+ default: options.paths,
165
+ theme: {
166
+ icon: {
167
+ checked: '◉',
168
+ unchecked: '◯',
169
+ cursor: '›',
170
+ },
171
+ },
172
+ validate: (value) => {
173
+ return value.length > 0 || Messages.errors.selectAtLeastOnePath;
174
+ },
175
+ });
176
+ }
177
+ //# sourceMappingURL=init.input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.input.js","sourceRoot":"/","sources":["cli/cmd/init/init.input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,sBAAsB,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,WA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aACZ;SACF;QACD,QAAQ,EAAE,CAAC,KAAe,EAAE,EAAE;YAC5B,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,158 @@
1
+ import { Command, Option } from 'commander';
2
+ import Ora from 'ora';
3
+ import { confirm } from '@inquirer/prompts';
4
+ import { LocalesEnum } from '#modules/common/common.types.js';
5
+ import { ConfigProvider } from '#modules/config/config.provider.js';
6
+ import { isRunningInInteractiveMode } from '#utils/cli.js';
7
+ import { COMMA_AND_SPACE_REGEX } from '#modules/common/common.const.js';
8
+ import { pathsInput, sourceInput, targetInput } from './init.input.js';
9
+ import { Messages } from '#messages/messages.js';
10
+ import { setCredentials, resolveProjectInstruction } from './init.utils.js';
11
+ import { getFileExtension } from '#utils/path.js';
12
+ export default new Command()
13
+ .command('init')
14
+ .description('Initialize a new Lara project')
15
+ .helpOption('-h, --help', 'Show help')
16
+ .addOption(new Option('-f --force', 'Overwrite existing config file').default(false))
17
+ .addOption(new Option('-s --source <locale>', 'Source locale')
18
+ .argParser((value) => {
19
+ const locale = LocalesEnum.safeParse(value);
20
+ if (!locale.success) {
21
+ Ora({ text: Messages.errors.invalidLocale(value), color: 'red' }).fail();
22
+ return process.exit(1);
23
+ }
24
+ return locale.data;
25
+ })
26
+ .default('en'))
27
+ .addOption(new Option('-t --target <locales>', 'Target locales, separated by a comma, a space or a combination of both').argParser((value) => {
28
+ const locales = value.split(COMMA_AND_SPACE_REGEX);
29
+ for (const locale of locales) {
30
+ const parsed = LocalesEnum.safeParse(locale);
31
+ if (!parsed.success) {
32
+ Ora({ text: Messages.errors.invalidLocale(locale), color: 'red' }).fail();
33
+ process.exit(1);
34
+ }
35
+ }
36
+ return locales.map((locale) => LocalesEnum.parse(locale));
37
+ }))
38
+ .addOption(new Option('-p --paths <paths>', 'Paths to watch, separated by a comma, a space or a combination of both')
39
+ .argParser((value) => {
40
+ const paths = value.split(COMMA_AND_SPACE_REGEX);
41
+ return paths.map((path) => {
42
+ return path.toString();
43
+ });
44
+ })
45
+ .default(['src/i18n/[locale].json']))
46
+ .addOption(new Option('-r --reset-credentials', 'Reset credentials').default(false))
47
+ .addOption(new Option('-i --instruction <instruction>', 'Project instruction to help with translations'))
48
+ .addOption(new Option('-m --translation-memories <translation-memories>', 'Translation memories to use for translations')
49
+ .argParser((value) => {
50
+ return value.split(COMMA_AND_SPACE_REGEX);
51
+ })
52
+ .default([]))
53
+ .addOption(new Option('-g --glossaries <glossaries>', 'Glossaries to use for translations')
54
+ .argParser((value) => {
55
+ return value.split(COMMA_AND_SPACE_REGEX);
56
+ })
57
+ .default([]))
58
+ .action(async (options, command) => {
59
+ const config = isRunningInInteractiveMode(command)
60
+ ? await handleInteractiveMode(options)
61
+ : handleNonInteractiveMode(options);
62
+ const spinner = Ora({ text: Messages.info.creatingConfig, color: 'yellow' }).start();
63
+ ConfigProvider.getInstance().saveConfig(config);
64
+ spinner.succeed(Messages.success.configCreated);
65
+ });
66
+ function groupPathsByExtension(paths) {
67
+ const filesByExtension = {};
68
+ for (const path of paths) {
69
+ const extension = getFileExtension(path);
70
+ if (!filesByExtension[extension]) {
71
+ filesByExtension[extension] = {
72
+ include: [],
73
+ exclude: [],
74
+ fileInstructions: [],
75
+ keyInstructions: [],
76
+ lockedKeys: [],
77
+ ignoredKeys: [],
78
+ };
79
+ }
80
+ filesByExtension[extension].include.push(path);
81
+ }
82
+ return filesByExtension;
83
+ }
84
+ function handleNonInteractiveMode(options) {
85
+ if (!process.env.LARA_ACCESS_KEY_ID || !process.env.LARA_ACCESS_KEY_SECRET) {
86
+ Ora({
87
+ text: Messages.warnings.noApiCredentials,
88
+ color: 'yellow',
89
+ }).warn();
90
+ return process.exit(1);
91
+ }
92
+ const instruction = resolveProjectInstruction(options.instruction);
93
+ return {
94
+ version: '1.0.0',
95
+ project: {
96
+ instruction,
97
+ },
98
+ locales: {
99
+ source: options.source,
100
+ target: options.target,
101
+ },
102
+ memories: options.translationMemories,
103
+ glossaries: options.glossaries,
104
+ files: groupPathsByExtension(options.paths),
105
+ };
106
+ }
107
+ async function handleInteractiveMode(options) {
108
+ if (options.resetCredentials) {
109
+ const shouldOverwrite = await confirm({
110
+ message: Messages.prompts.resetCredentials,
111
+ });
112
+ if (shouldOverwrite) {
113
+ await setCredentials();
114
+ }
115
+ }
116
+ const configProvider = ConfigProvider.getInstance();
117
+ if (configProvider.doesConfigExists() && !options.force) {
118
+ const shouldOverwrite = await confirm({
119
+ message: Messages.prompts.overwriteConfig,
120
+ });
121
+ if (!shouldOverwrite) {
122
+ Ora({
123
+ text: Messages.errors.configOverwriteDeclined,
124
+ color: 'red',
125
+ }).fail();
126
+ return process.exit(1);
127
+ }
128
+ }
129
+ const inputSource = await sourceInput(options);
130
+ const inputTarget = await targetInput(inputSource, options.target);
131
+ options.source = inputSource;
132
+ const inputPaths = await pathsInput(options);
133
+ if (!process.env.LARA_ACCESS_KEY_ID || !process.env.LARA_ACCESS_KEY_SECRET) {
134
+ const shouldInsertCredentials = await confirm({
135
+ message: Messages.prompts.insertCredentials,
136
+ });
137
+ if (shouldInsertCredentials) {
138
+ await setCredentials();
139
+ }
140
+ else {
141
+ Ora({
142
+ text: Messages.warnings.noApiCredentials,
143
+ color: 'yellow',
144
+ }).warn();
145
+ }
146
+ }
147
+ return {
148
+ version: '1.0.0',
149
+ locales: {
150
+ source: inputSource,
151
+ target: inputTarget,
152
+ },
153
+ memories: [],
154
+ glossaries: [],
155
+ files: groupPathsByExtension(inputPaths),
156
+ };
157
+ }
158
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"/","sources":["cli/cmd/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,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