gtx-cli 1.0.0 → 1.0.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.
package/dist/cli/base.js CHANGED
@@ -59,6 +59,7 @@ const yaml_1 = __importDefault(require("yaml"));
59
59
  const translate_1 = require("../formats/json/translate");
60
60
  const utils_1 = require("../fs/utils");
61
61
  const generateSettings_1 = require("../config/generateSettings");
62
+ const chalk_1 = __importDefault(require("chalk"));
62
63
  const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
63
64
  class BaseCLI {
64
65
  // Constructor is shared amongst all CLI class types
@@ -147,17 +148,14 @@ class BaseCLI {
147
148
  .action(() => __awaiter(this, void 0, void 0, function* () {
148
149
  (0, console_1.displayAsciiTitle)();
149
150
  (0, console_2.displayInitializingText)();
150
- // Ask where the translations are stored
151
- const translationsDir = yield (0, prompts_1.input)({
152
- message: 'Where is the directory containing your language files?',
153
- });
154
151
  // Ask for the default locale
155
152
  const defaultLocale = yield (0, prompts_1.input)({
156
153
  message: 'What is the default locale for your project?',
154
+ default: 'en',
157
155
  });
158
156
  // Ask for the locales
159
157
  const locales = yield (0, prompts_1.input)({
160
- message: 'What locales would you like to translate using General Translation? (space-separated list)',
158
+ message: `What locales would you like to translate using General Translation? ${chalk_1.default.gray('(space-separated list)')}`,
161
159
  validate: (input) => {
162
160
  const locales = input.split(' ');
163
161
  if (locales.length === 0) {
@@ -171,20 +169,63 @@ class BaseCLI {
171
169
  return true;
172
170
  },
173
171
  });
174
- const dataFormat = yield (0, prompts_1.select)({
175
- message: 'What is the format of your language files?',
176
- choices: ['.json', '.yaml'],
177
- default: '.json',
172
+ // Ask where the translations are stored
173
+ const location = yield (0, prompts_1.select)({
174
+ message: 'Where are your language files stored? (CDN or local)',
175
+ choices: [
176
+ { value: 'cdn', name: 'CDN' },
177
+ { value: 'local', name: 'Local' },
178
+ ],
179
+ default: 'cdn',
178
180
  });
179
- // combine translationsDir and dataFormat into something like
180
- // translationsDir/*[.json|.yaml]
181
- const translationsDirWithFormat = path_1.default.join(translationsDir, `*${dataFormat}`);
182
- // Create gt.config.json
183
- (0, setupConfig_1.default)('gt.config.json', {
184
- defaultLocale,
185
- locales: locales.split(' '),
186
- translationsDir: translationsDirWithFormat,
181
+ if (location === 'cdn') {
182
+ // Create gt.config.json
183
+ (0, setupConfig_1.default)('gt.config.json', {
184
+ defaultLocale,
185
+ locales: locales.split(' '),
186
+ });
187
+ return;
188
+ }
189
+ // Ask where the translations are stored
190
+ const translationsDir = yield (0, prompts_1.input)({
191
+ message: 'What is the path to the directory containing your language files?',
187
192
  });
193
+ const thirdPartyLibrary = this.library !== 'gt-next' && this.library !== 'gt-react';
194
+ // Ask if using another i18n library
195
+ const i18nLibrary = thirdPartyLibrary
196
+ ? yield (0, prompts_1.select)({
197
+ message: `Are you using a third-party i18n library? (${chalk_1.default.gray(`Auto-detected: ${this.library}`)})`,
198
+ choices: [
199
+ { value: true, name: 'Yes' },
200
+ { value: false, name: 'No' },
201
+ ],
202
+ default: true,
203
+ })
204
+ : false;
205
+ if (i18nLibrary) {
206
+ const dataFormat = yield (0, prompts_1.select)({
207
+ message: 'What is the format of your language files?',
208
+ choices: ['.json', '.yaml'],
209
+ default: '.json',
210
+ });
211
+ // combine translationsDir and dataFormat into something like
212
+ // translationsDir/*[.json|.yaml]
213
+ const translationsDirWithFormat = path_1.default.join(translationsDir, `*${dataFormat}`);
214
+ // Create gt.config.json
215
+ (0, setupConfig_1.default)('gt.config.json', {
216
+ defaultLocale,
217
+ locales: locales.split(' '),
218
+ translationsDir: translationsDirWithFormat,
219
+ });
220
+ }
221
+ else {
222
+ // Create gt.config.json
223
+ (0, setupConfig_1.default)('gt.config.json', {
224
+ defaultLocale,
225
+ locales: locales.split(' '),
226
+ translationsDir: translationsDir,
227
+ });
228
+ }
188
229
  }));
189
230
  }
190
231
  }
@@ -1,7 +1,7 @@
1
- import { WrapOptions, Options, Updates, SetupOptions, SupportedFrameworks } from '../types';
1
+ import { WrapOptions, Options, Updates, SetupOptions, SupportedFrameworks, SupportedLibraries } from '../types';
2
2
  import { ReactCLI } from './react';
3
3
  export declare class NextCLI extends ReactCLI {
4
- constructor();
4
+ constructor(library: SupportedLibraries);
5
5
  init(): void;
6
6
  execute(): void;
7
7
  protected scanForContent(options: WrapOptions, framework: SupportedFrameworks): Promise<{
package/dist/cli/next.js CHANGED
@@ -26,8 +26,8 @@ const react_1 = require("./react");
26
26
  const generateSettings_1 = require("../config/generateSettings");
27
27
  const pkg = 'gt-next';
28
28
  class NextCLI extends react_1.ReactCLI {
29
- constructor() {
30
- super();
29
+ constructor(library) {
30
+ super(library);
31
31
  }
32
32
  init() {
33
33
  this.setupTranslateCommand();
@@ -1,7 +1,7 @@
1
- import { Options, SetupOptions, SupportedFrameworks, Updates, WrapOptions, GenerateSourceOptions } from '../types';
1
+ import { Options, SetupOptions, SupportedFrameworks, Updates, WrapOptions, GenerateSourceOptions, SupportedLibraries } from '../types';
2
2
  import { BaseCLI } from './base';
3
3
  export declare class ReactCLI extends BaseCLI {
4
- constructor();
4
+ constructor(library: SupportedLibraries);
5
5
  init(): void;
6
6
  execute(): void;
7
7
  protected scanForContent(options: WrapOptions, framework: SupportedFrameworks): Promise<{
package/dist/cli/react.js CHANGED
@@ -70,8 +70,8 @@ const saveJSON_1 = require("../fs/saveJSON");
70
70
  const DEFAULT_TIMEOUT = 600;
71
71
  const pkg = 'gt-react';
72
72
  class ReactCLI extends base_1.BaseCLI {
73
- constructor() {
74
- super('gt-react');
73
+ constructor(library) {
74
+ super(library);
75
75
  }
76
76
  init() {
77
77
  this.setupTranslateCommand();
@@ -152,6 +152,10 @@ class ReactCLI extends base_1.BaseCLI {
152
152
  (0, console_1.displayInitializingText)();
153
153
  const settings = (0, generateSettings_1.generateSettings)(options);
154
154
  options = Object.assign(Object.assign({}, options), settings);
155
+ if (!settings.translationsDir) {
156
+ console.log(chalk_1.default.red('Error: the translationsDir path is required'));
157
+ process.exit(1);
158
+ }
155
159
  if (!options.dictionary) {
156
160
  options.dictionary = (0, findFilepath_1.default)([
157
161
  './dictionary.js',
@@ -192,7 +196,7 @@ class ReactCLI extends base_1.BaseCLI {
192
196
  for (const locale of settings.locales) {
193
197
  const existingTranslations = (0, loadJSON_1.default)(path_1.default.join(settings.translationsDir, `${locale}.json`));
194
198
  const mergedTranslations = Object.assign(Object.assign({}, newData), existingTranslations);
195
- // Filter out only keys that exist in newData
199
+ // Filter out keys that don't exist in newData
196
200
  const filteredTranslations = Object.fromEntries(Object.entries(mergedTranslations).filter(([key]) => newData[key]));
197
201
  (0, saveJSON_1.saveJSON)(path_1.default.join(settings.translationsDir, `${locale}.json`), filteredTranslations);
198
202
  }
package/dist/index.js CHANGED
@@ -11,10 +11,10 @@ function main() {
11
11
  const library = (0, determineFramework_1.determineLibrary)();
12
12
  let cli;
13
13
  if (library === 'gt-next') {
14
- cli = new next_1.NextCLI();
14
+ cli = new next_1.NextCLI('gt-next');
15
15
  }
16
16
  else if (library === 'gt-react') {
17
- cli = new react_1.ReactCLI();
17
+ cli = new react_1.ReactCLI('gt-react');
18
18
  }
19
19
  else {
20
20
  cli = new base_1.BaseCLI(library);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "scripts": {