gtx-cli 1.2.24-alpha.6 → 1.2.24

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 1.2.24
4
+
5
+ ### Patch Changes
6
+
7
+ - [#358](https://github.com/generaltranslation/gt/pull/358) [`b0ea226`](https://github.com/generaltranslation/gt/commit/b0ea226310abb04ef5aa9ef1af23ee37b9e18cd1) Thanks [@brian-lou](https://github.com/brian-lou)! - Release Locadex (Beta) version
8
+
3
9
  ## 1.2.23
4
10
 
5
11
  ### Patch Changes
package/dist/cli/base.js CHANGED
@@ -14,6 +14,7 @@ import { installPackage } from '../utils/installPackage.js';
14
14
  import { getPackageManager } from '../utils/packageManager.js';
15
15
  import { retrieveCredentials, setCredentials } from '../utils/credentials.js';
16
16
  import { areCredentialsSet } from '../utils/credentials.js';
17
+ import { validateConfigExists } from '../config/validateSettings.js';
17
18
  export class BaseCLI {
18
19
  library;
19
20
  additionalModules;
@@ -51,6 +52,7 @@ export class BaseCLI {
51
52
  .option('--dry-run', 'Dry run, does not send updates to General Translation API', false)
52
53
  .action(async (initOptions) => {
53
54
  displayHeader('Starting translation...');
55
+ validateConfigExists();
54
56
  const settings = await generateSettings(initOptions);
55
57
  const options = { ...initOptions, ...settings };
56
58
  await this.handleGenericTranslate(options);
package/dist/cli/react.js CHANGED
@@ -13,6 +13,7 @@ import { stageProject } from '../translation/stage.js';
13
13
  import { createUpdates } from '../translation/parse.js';
14
14
  import { translate } from '../translation/translate.js';
15
15
  import updateConfig from '../fs/config/updateConfig.js';
16
+ import { validateConfigExists } from '../config/validateSettings.js';
16
17
  const DEFAULT_TIMEOUT = 600;
17
18
  const pkg = 'gt-react';
18
19
  export class ReactCLI extends BaseCLI {
@@ -235,6 +236,7 @@ export class ReactCLI extends BaseCLI {
235
236
  await stageProject(options, pkg);
236
237
  }
237
238
  async handleTranslate(initOptions) {
239
+ validateConfigExists();
238
240
  const settings = await generateSettings(initOptions);
239
241
  // First run the base class's handleTranslate method
240
242
  const options = { ...initOptions, ...settings };
@@ -1,2 +1,3 @@
1
1
  import { Settings } from '../types/index.js';
2
2
  export declare function validateSettings(settings: Settings): void;
3
+ export declare function validateConfigExists(): string | undefined;
@@ -1,5 +1,6 @@
1
1
  import { isValidLocale, isSupersetLocale } from 'generaltranslation';
2
2
  import { logErrorAndExit } from '../console/logging.js';
3
+ import fs from 'node:fs';
3
4
  export function validateSettings(settings) {
4
5
  // Validate locales
5
6
  for (const locale of settings.locales) {
@@ -18,3 +19,12 @@ export function validateSettings(settings) {
18
19
  logErrorAndExit(`defaultLocale: ${settings.defaultLocale} is a superset of another locale (${locale})! Please change the defaultLocale to a more specific locale.`);
19
20
  }
20
21
  }
22
+ export function validateConfigExists() {
23
+ const possibleConfigPaths = ['gt.config.json', 'src/gt.config.json'];
24
+ for (const possibleConfigPath of possibleConfigPaths) {
25
+ if (fs.existsSync(possibleConfigPath)) {
26
+ return possibleConfigPath;
27
+ }
28
+ }
29
+ logErrorAndExit('No gt.config.json file found. Are you in the correct directory?');
30
+ }
@@ -49,6 +49,10 @@ Please let us know what you would like to see supported at https://github.com/ge
49
49
  framework: frameworkType,
50
50
  });
51
51
  const packageJson = await getPackageJson();
52
+ if (!packageJson) {
53
+ logError(chalk.red('No package.json found in the current directory. Please run this command from the root of your project.'));
54
+ process.exit(1);
55
+ }
52
56
  // Check if gt-next or gt-react is installed
53
57
  if (frameworkType === 'next-app' &&
54
58
  !isPackageInstalled('gt-next', packageJson)) {
@@ -1,5 +1,5 @@
1
1
  export declare function searchForPackageJson(cwd?: string): Promise<Record<string, any> | null>;
2
- export declare function getPackageJson(cwd?: string): Promise<Record<string, any>>;
2
+ export declare function getPackageJson(cwd?: string): Promise<Record<string, any> | null>;
3
3
  export declare function getCLIVersion(): string;
4
4
  export declare function updatePackageJson(packageJson: Record<string, any>, cwd?: string): Promise<void>;
5
5
  export declare function isPackageInstalled(packageName: string, packageJson: Record<string, any>, asDevDependency?: boolean, checkBoth?: boolean): boolean;
@@ -2,7 +2,6 @@ import { logError } from '../console/logging.js';
2
2
  import chalk from 'chalk';
3
3
  import path from 'node:path';
4
4
  import fs from 'node:fs';
5
- import { logErrorAndExit } from '../console/logging.js';
6
5
  import { fromPackageRoot } from '../fs/getPackageResource.js';
7
6
  // search for package.json such that we can run init in non-js projects
8
7
  export async function searchForPackageJson(cwd = process.cwd()) {
@@ -23,14 +22,13 @@ export async function getPackageJson(cwd = process.cwd()) {
23
22
  const packageJsonPath = path.join(cwd, 'package.json');
24
23
  // Check if package.json exists
25
24
  if (!fs.existsSync(packageJsonPath)) {
26
- logErrorAndExit(chalk.red('No package.json found in the current directory. Please run this command from the root of your project.'));
25
+ return null;
27
26
  }
28
27
  try {
29
28
  return JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
30
29
  }
31
30
  catch (error) {
32
- logError(chalk.red('Error parsing package.json: ' + String(error)));
33
- process.exit(1);
31
+ return null;
34
32
  }
35
33
  }
36
34
  export function getCLIVersion() {
@@ -23,6 +23,9 @@ export const BUN = {
23
23
  }),
24
24
  addOverride: async (pkgName, pkgVersion) => {
25
25
  const packageDotJson = await getPackageJson();
26
+ if (!packageDotJson) {
27
+ return;
28
+ }
26
29
  const overrides = packageDotJson.overrides || {};
27
30
  await updatePackageJson({
28
31
  ...packageDotJson,
@@ -54,6 +57,9 @@ export const DENO = {
54
57
  },
55
58
  addOverride: async (pkgName, pkgVersion) => {
56
59
  const packageDotJson = await getPackageJson();
60
+ if (!packageDotJson) {
61
+ return;
62
+ }
57
63
  const overrides = packageDotJson.overrides || {};
58
64
  await updatePackageJson({
59
65
  ...packageDotJson,
@@ -87,6 +93,9 @@ export const YARN_V1 = {
87
93
  },
88
94
  addOverride: async (pkgName, pkgVersion) => {
89
95
  const packageDotJson = await getPackageJson();
96
+ if (!packageDotJson) {
97
+ return;
98
+ }
90
99
  const resolutions = packageDotJson.resolutions || {};
91
100
  await updatePackageJson({
92
101
  ...packageDotJson,
@@ -121,6 +130,9 @@ export const YARN_V2 = {
121
130
  },
122
131
  addOverride: async (pkgName, pkgVersion) => {
123
132
  const packageDotJson = await getPackageJson();
133
+ if (!packageDotJson) {
134
+ return;
135
+ }
124
136
  const resolutions = packageDotJson.resolutions || {};
125
137
  await updatePackageJson({
126
138
  ...packageDotJson,
@@ -151,6 +163,9 @@ export const PNPM = {
151
163
  },
152
164
  addOverride: async (pkgName, pkgVersion) => {
153
165
  const packageDotJson = await getPackageJson();
166
+ if (!packageDotJson) {
167
+ return;
168
+ }
154
169
  const pnpm = packageDotJson.pnpm || {};
155
170
  const overrides = pnpm.overrides || {};
156
171
  await updatePackageJson({
@@ -185,6 +200,9 @@ export const NPM = {
185
200
  },
186
201
  addOverride: async (pkgName, pkgVersion) => {
187
202
  const packageDotJson = await getPackageJson();
203
+ if (!packageDotJson) {
204
+ return;
205
+ }
188
206
  const overrides = packageDotJson.overrides || {};
189
207
  await updatePackageJson({
190
208
  ...packageDotJson,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.2.24-alpha.6",
3
+ "version": "1.2.24",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [