auto-lang 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
1
  # Auto Lang
2
2
 
3
- I'm too tired to write a README. See you tomorrow please.
3
+ Generate translation files for multiple languages
4
+ ## Installation
5
+ ### Using npm
6
+ ```$ npm install auto-lang```
7
+ ### Using yarn
8
+ ```$ yarn add auto-lang```
9
+
10
+ ## Usage
11
+ Run `auto-lang [options]`
12
+
13
+ ### Options
14
+
15
+ -V, --version output the version number
16
+ -f, --from <lang> language to translate from
17
+ -t, --to <lang...> Languages to translate to (Seperated by space)
18
+ -g, --gen-types generate typescript declaration file
19
+ -h, --help display help for command
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-lang",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "Automatically create language json files for internationalization",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -14,7 +14,9 @@
14
14
  "url": "https://github.com/lesleytech/auto-lang.git"
15
15
  },
16
16
  "license": "ISC",
17
- "bin": "./src/index.js",
17
+ "bin": {
18
+ "auto-lang": "./src/index.js"
19
+ },
18
20
  "type": "module",
19
21
  "dependencies": {
20
22
  "chalk": "^5.0.1",
package/src/index.js CHANGED
@@ -4,14 +4,14 @@ import path from 'path';
4
4
  import { promises as fs } from 'fs';
5
5
  import { existsSync } from 'fs';
6
6
  import { Command } from 'commander';
7
- import chalk from 'chalk';
8
7
  import { exit } from 'process';
9
8
  import { createSpinner } from 'nanospinner';
10
9
  import translate from 'translate';
11
- import { Logger } from './utils/Logger.mjs';
12
10
  import JsonToTS from 'json-to-ts';
13
11
  import prettier from 'prettier';
14
12
 
13
+ import { Logger } from './utils/Logger.mjs';
14
+
15
15
  const program = new Command();
16
16
  const nodeMajVer = parseInt(process.version.substring(1).split('.')[0]);
17
17
 
@@ -24,15 +24,16 @@ if (nodeMajVer < 14) {
24
24
  program
25
25
  .name('auto-lang')
26
26
  .description('Generate translation files for multiple languages')
27
- .version('1.0.0')
27
+ .version('1.0.3')
28
28
  .requiredOption('-f, --from <lang>', 'language to translate from')
29
29
  .requiredOption(
30
30
  '-t, --to <lang...>',
31
31
  'Languages to translate to (Seperated by space)'
32
32
  )
33
+ .option('-g, --gen-types', 'generate typescript declaration file')
33
34
  .parse();
34
35
 
35
- const { from, to } = program.opts();
36
+ const { from, to, genTypes } = program.opts();
36
37
 
37
38
  const inputFile = path.join(process.cwd(), 'translations', `${from}.json`);
38
39
 
@@ -97,7 +98,6 @@ async function translateFile(inputFile) {
97
98
  );
98
99
  let spinner, langFile, tranlatedJson;
99
100
 
100
- return inputJson;
101
101
  for (let lang of to) {
102
102
  langFile = path.join(process.cwd(), 'translations', `${lang}.json`);
103
103
  spinner = createSpinner(`Translating to ${lang}...`).start();
@@ -108,7 +108,12 @@ async function translateFile(inputFile) {
108
108
 
109
109
  spinner.success({ text: `Complete` });
110
110
  }
111
+
112
+ return inputJson;
111
113
  }
112
114
 
113
115
  const json = await translateFile(inputFile);
114
- await createDeclarationFile(json);
116
+
117
+ if (genTypes) {
118
+ await createDeclarationFile(json);
119
+ }