gtx-cli 1.2.27 → 1.2.28

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.28
4
+
5
+ ### Patch Changes
6
+
7
+ - [#397](https://github.com/generaltranslation/gt/pull/397) [`80a1395`](https://github.com/generaltranslation/gt/commit/80a13955db9ff46e5883ac8b0909ab294c63d001) Thanks [@brian-lou](https://github.com/brian-lou)! - Run translate after i18n
8
+
3
9
  ## 1.2.27
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { createOraSpinner } from '../console/logging.js';
2
+ import { createOraSpinner, logErrorAndExit, } from '../console/logging.js';
3
3
  import { getLocaleProperties } from 'generaltranslation';
4
4
  /**
5
5
  * Waits for translations to be deployed to the General Translation API
@@ -28,8 +28,13 @@ export const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, time
28
28
  const data = await response.json();
29
29
  const { availableLocales, locales, localesWaitingForApproval } = data;
30
30
  if (localesWaitingForApproval.length > 0) {
31
- spinner.text = `Waiting for approval for ${localesWaitingForApproval.length} locales`;
32
- return false;
31
+ spinner.stop();
32
+ logErrorAndExit(`Error! ${localesWaitingForApproval.length} translations are waiting for approval:\n${localesWaitingForApproval
33
+ .map((locale) => {
34
+ const localeProperties = getLocaleProperties(locale);
35
+ return `${localeProperties.name} (${localeProperties.code})`;
36
+ })
37
+ .join('\n')}\nPlease approve these locales in the General Translation dashboard, then re-run the command.`);
33
38
  }
34
39
  if (availableLocales) {
35
40
  availableLocales.forEach((locale) => {
@@ -2,6 +2,7 @@ import { Settings } from '../types/index.js';
2
2
  /**
3
3
  * Generates settings from any
4
4
  * @param options - The options to generate settings from
5
+ * @param cwd - The current working directory
5
6
  * @returns The generated settings
6
7
  */
7
- export declare function generateSettings(options: any): Promise<Settings>;
8
+ export declare function generateSettings(options: any, cwd?: string): Promise<Settings>;
@@ -8,12 +8,14 @@ import { findFilepaths } from '../fs/findFilepath.js';
8
8
  import { validateSettings } from './validateSettings.js';
9
9
  import { GT_DASHBOARD_URL } from '../utils/constants.js';
10
10
  import { resolveProjectId } from '../fs/utils.js';
11
+ import path from 'node:path';
11
12
  /**
12
13
  * Generates settings from any
13
14
  * @param options - The options to generate settings from
15
+ * @param cwd - The current working directory
14
16
  * @returns The generated settings
15
17
  */
16
- export async function generateSettings(options) {
18
+ export async function generateSettings(options, cwd = process.cwd()) {
17
19
  // Load config file
18
20
  let gtConfig = {};
19
21
  if (options.config && !options.config.endsWith('.json')) {
@@ -22,13 +24,13 @@ export async function generateSettings(options) {
22
24
  if (options.config) {
23
25
  gtConfig = loadConfig(options.config);
24
26
  }
25
- else if (fs.existsSync('gt.config.json')) {
26
- options.config = 'gt.config.json';
27
- gtConfig = loadConfig('gt.config.json');
27
+ else if (fs.existsSync(path.join(cwd, 'gt.config.json'))) {
28
+ options.config = path.join(cwd, 'gt.config.json');
29
+ gtConfig = loadConfig(options.config);
28
30
  }
29
- else if (fs.existsSync('src/gt.config.json')) {
30
- options.config = 'src/gt.config.json';
31
- gtConfig = loadConfig('src/gt.config.json');
31
+ else if (fs.existsSync(path.join(cwd, 'src/gt.config.json'))) {
32
+ options.config = path.join(cwd, 'src/gt.config.json');
33
+ gtConfig = loadConfig(options.config);
32
34
  }
33
35
  else {
34
36
  // If neither config exists, use empty config
@@ -57,7 +59,8 @@ export async function generateSettings(options) {
57
59
  // Add locales if not provided
58
60
  mergedOptions.locales = mergedOptions.locales || [];
59
61
  // Add default config file name if not provided
60
- mergedOptions.config = mergedOptions.config || 'gt.config.json';
62
+ mergedOptions.config =
63
+ mergedOptions.config || path.join(cwd, 'gt.config.json');
61
64
  // Display projectId if present
62
65
  if (mergedOptions.projectId)
63
66
  displayProjectId(mergedOptions.projectId);
@@ -67,10 +70,15 @@ export async function generateSettings(options) {
67
70
  // Populate src if not provided
68
71
  mergedOptions.src =
69
72
  mergedOptions.src ||
70
- findFilepaths(['./src', './app', './pages', './components']);
73
+ findFilepaths([
74
+ path.join(cwd, './src'),
75
+ path.join(cwd, './app'),
76
+ path.join(cwd, './pages'),
77
+ path.join(cwd, './components'),
78
+ ]);
71
79
  // Resolve all glob patterns in the files object
72
80
  mergedOptions.files = mergedOptions.files
73
- ? resolveFiles(mergedOptions.files, mergedOptions.defaultLocale)
81
+ ? resolveFiles(mergedOptions.files, mergedOptions.defaultLocale, cwd)
74
82
  : undefined;
75
83
  // if there's no existing config file, creates one
76
84
  // does not include the API key to avoid exposing it
@@ -16,7 +16,7 @@ export declare function resolveLocaleFiles(files: ResolvedFiles, locale: string)
16
16
  * @param files - The files object
17
17
  * @returns The resolved files
18
18
  */
19
- export declare function resolveFiles(files: FilesOptions, locale: string): {
19
+ export declare function resolveFiles(files: FilesOptions, locale: string, cwd: string): {
20
20
  resolvedPaths: ResolvedFiles;
21
21
  placeholderPaths: ResolvedFiles;
22
22
  transformPaths: TransformFiles;
@@ -28,7 +28,7 @@ export function resolveLocaleFiles(files, locale) {
28
28
  * @param files - The files object
29
29
  * @returns The resolved files
30
30
  */
31
- export function resolveFiles(files, locale) {
31
+ export function resolveFiles(files, locale, cwd) {
32
32
  // Initialize result object with empty arrays for each file type
33
33
  const result = {};
34
34
  const placeholderResult = {};
@@ -45,7 +45,7 @@ export function resolveFiles(files, locale) {
45
45
  }
46
46
  // ==== PLACEHOLDERS ==== //
47
47
  if (files[fileType]?.include) {
48
- const filePaths = expandGlobPatterns(files[fileType].include, files[fileType]?.exclude || [], locale, transformPaths[fileType] || undefined);
48
+ const filePaths = expandGlobPatterns(cwd, files[fileType].include, files[fileType]?.exclude || [], locale, transformPaths[fileType] || undefined);
49
49
  result[fileType] = filePaths.resolvedPaths;
50
50
  placeholderResult[fileType] = filePaths.placeholderPaths;
51
51
  }
@@ -57,7 +57,7 @@ export function resolveFiles(files, locale) {
57
57
  };
58
58
  }
59
59
  // Helper function to expand glob patterns
60
- function expandGlobPatterns(includePatterns, excludePatterns, locale, transformPatterns) {
60
+ function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, transformPatterns) {
61
61
  // Expand glob patterns to include all matching files
62
62
  const resolvedPaths = [];
63
63
  const placeholderPaths = [];
@@ -81,9 +81,9 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
81
81
  }
82
82
  const expandedPattern = pattern.replace(/\[locale\]/g, locale);
83
83
  // Resolve the absolute pattern path
84
- const absolutePattern = path.resolve(process.cwd(), expandedPattern);
84
+ const absolutePattern = path.resolve(cwd, expandedPattern);
85
85
  // Prepare exclude patterns with locale replaced
86
- const expandedExcludePatterns = excludePatterns.map((p) => path.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
86
+ const expandedExcludePatterns = excludePatterns.map((p) => path.resolve(cwd, p.replace(/\[locale\]/g, locale)));
87
87
  // Use fast-glob to find all matching files, excluding the patterns
88
88
  const matches = fg.sync(absolutePattern, {
89
89
  absolute: true,
@@ -93,7 +93,7 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
93
93
  // For each match, create a version with [locale] in the correct positions
94
94
  matches.forEach((match) => {
95
95
  // Convert to relative path to make replacement easier
96
- const relativePath = path.relative(process.cwd(), match);
96
+ const relativePath = path.relative(cwd, match);
97
97
  let originalRelativePath = relativePath;
98
98
  // Replace locale with [locale] at each tracked position
99
99
  if (localePositions.length > 0) {
@@ -113,7 +113,7 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
113
113
  originalRelativePath = pathParts.join(path.sep);
114
114
  }
115
115
  // Convert back to absolute path
116
- const originalPath = path.resolve(process.cwd(), originalRelativePath);
116
+ const originalPath = path.resolve(cwd, originalRelativePath);
117
117
  placeholderPaths.push(originalPath);
118
118
  });
119
119
  }
@@ -3,6 +3,7 @@ export interface PackageManager {
3
3
  name: string;
4
4
  label: string;
5
5
  installCommand: string;
6
+ installAllCommand: string;
6
7
  buildCommand: string;
7
8
  runScriptCommand: string;
8
9
  flags: string;
@@ -12,6 +13,9 @@ export interface PackageManager {
12
13
  detect: (cwd: string) => boolean;
13
14
  addOverride: (pkgName: string, pkgVersion: string) => Promise<void>;
14
15
  }
16
+ export declare class NoPackageManagerError extends Error {
17
+ constructor(message: string);
18
+ }
15
19
  export declare const BUN: PackageManager;
16
20
  export declare const DENO: PackageManager;
17
21
  export declare const YARN_V1: PackageManager;
@@ -21,4 +25,4 @@ export declare const PNPM: PackageManager;
21
25
  export declare const NPM: PackageManager;
22
26
  export declare const packageManagers: PackageManager[];
23
27
  export declare function _detectPackageManger(cwd: string): PackageManager | null;
24
- export declare function getPackageManager(cwd?: string, specifiedPackageManager?: string): Promise<PackageManager>;
28
+ export declare function getPackageManager(cwd?: string, specifiedPackageManager?: string, errorIfNotFound?: boolean): Promise<PackageManager>;
@@ -3,11 +3,18 @@ import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { getPackageJson, updatePackageJson } from './packageJson.js';
5
5
  import { promptSelect } from '../console/logging.js';
6
+ export class NoPackageManagerError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = 'NoPackageManagerError';
10
+ }
11
+ }
6
12
  export const BUN = {
7
13
  id: 'bun',
8
14
  name: 'bun',
9
15
  label: 'Bun',
10
16
  installCommand: 'add',
17
+ installAllCommand: 'bun install',
11
18
  buildCommand: 'bun run build',
12
19
  runScriptCommand: 'bun run',
13
20
  flags: '',
@@ -41,6 +48,7 @@ export const DENO = {
41
48
  name: 'deno',
42
49
  label: 'Deno',
43
50
  installCommand: 'install',
51
+ installAllCommand: 'deno install',
44
52
  buildCommand: 'deno task build',
45
53
  runScriptCommand: 'deno task',
46
54
  flags: '',
@@ -75,6 +83,7 @@ export const YARN_V1 = {
75
83
  name: 'yarn',
76
84
  label: 'Yarn V1',
77
85
  installCommand: 'add',
86
+ installAllCommand: 'yarn install',
78
87
  buildCommand: 'yarn build',
79
88
  runScriptCommand: 'yarn',
80
89
  flags: '--ignore-workspace-root-check',
@@ -112,6 +121,7 @@ export const YARN_V2 = {
112
121
  name: 'yarn',
113
122
  label: 'Yarn V2/3/4',
114
123
  installCommand: 'add',
124
+ installAllCommand: 'yarn install',
115
125
  buildCommand: 'yarn build',
116
126
  runScriptCommand: 'yarn',
117
127
  flags: '',
@@ -148,6 +158,7 @@ export const PNPM = {
148
158
  name: 'pnpm',
149
159
  label: 'PNPM',
150
160
  installCommand: 'add',
161
+ installAllCommand: 'pnpm install',
151
162
  buildCommand: 'pnpm build',
152
163
  runScriptCommand: 'pnpm',
153
164
  flags: '--ignore-workspace-root-check',
@@ -185,6 +196,7 @@ export const NPM = {
185
196
  name: 'npm',
186
197
  label: 'NPM',
187
198
  installCommand: 'install',
199
+ installAllCommand: 'npm ci',
188
200
  buildCommand: 'npm run build',
189
201
  runScriptCommand: 'npm run',
190
202
  flags: '',
@@ -225,7 +237,7 @@ export function _detectPackageManger(cwd) {
225
237
  }
226
238
  // Get the package manager for the current project
227
239
  // Uses a global cache to avoid prompting the user multiple times
228
- export async function getPackageManager(cwd = process.cwd(), specifiedPackageManager) {
240
+ export async function getPackageManager(cwd = process.cwd(), specifiedPackageManager, errorIfNotFound = false) {
229
241
  const globalWizard = global;
230
242
  if (globalWizard._gt_wizard_cached_package_manager) {
231
243
  return globalWizard._gt_wizard_cached_package_manager;
@@ -242,6 +254,9 @@ export async function getPackageManager(cwd = process.cwd(), specifiedPackageMan
242
254
  globalWizard._gt_wizard_cached_package_manager = detectedPackageManager;
243
255
  return detectedPackageManager;
244
256
  }
257
+ if (errorIfNotFound) {
258
+ throw new NoPackageManagerError('No package manager found');
259
+ }
245
260
  const selectedPackageManager = await promptSelect({
246
261
  message: 'Please select your package manager.',
247
262
  options: packageManagers.map((packageManager) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.2.27",
3
+ "version": "1.2.28",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [