gtx-cli 2.6.10 → 2.6.11
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 +6 -0
- package/dist/console/logging.d.ts +4 -0
- package/dist/console/logging.js +6 -0
- package/dist/functions.d.ts +6 -0
- package/dist/functions.js +5 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/translation/validate.d.ts +11 -0
- package/dist/translation/validate.js +57 -15
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.6.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#988](https://github.com/generaltranslation/gt/pull/988) [`efdf632`](https://github.com/generaltranslation/gt/commit/efdf632acab7cdd4d1819408d808bd4ac05bc7c8) Thanks [@pie575](https://github.com/pie575)! - Added function to export errors as json from running validate
|
|
8
|
+
|
|
3
9
|
## 2.6.10
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { FileToUpload } from 'generaltranslation/types';
|
|
2
|
+
/**
|
|
3
|
+
* Strip ANSI escape codes from a string (e.g., chalk color codes)
|
|
4
|
+
*/
|
|
5
|
+
export declare function stripAnsi(str: string): string;
|
|
2
6
|
export declare function logErrorAndExit(message: string): never;
|
|
3
7
|
export declare function exitSync(code: number): never;
|
|
4
8
|
export declare function displayHeader(introString?: string): void;
|
package/dist/console/logging.js
CHANGED
|
@@ -3,6 +3,12 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { getCLIVersion } from '../utils/packageJson.js';
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
5
|
import { TEMPLATE_FILE_NAME } from '../utils/constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Strip ANSI escape codes from a string (e.g., chalk color codes)
|
|
8
|
+
*/
|
|
9
|
+
export function stripAnsi(str) {
|
|
10
|
+
return str.replace(/\x1B\[[0-9;]*m/g, '');
|
|
11
|
+
}
|
|
6
12
|
export function logErrorAndExit(message) {
|
|
7
13
|
logger.error(message);
|
|
8
14
|
return exitSync(1);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file serves as an entrypoint for programmatically invoking CLI commands.
|
|
3
|
+
* Import from 'gtx-cli/functions' to access these APIs.
|
|
4
|
+
*/
|
|
5
|
+
export { getValidateJson } from './translation/validate.js';
|
|
6
|
+
export type { ValidationResult, ValidationMessage, ValidationLevel, } from './translation/validate.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.6.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.6.11";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const PACKAGE_VERSION = '2.6.
|
|
2
|
+
export const PACKAGE_VERSION = '2.6.11';
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import { Options, Settings } from '../types/index.js';
|
|
2
|
+
export type ValidationLevel = 'error' | 'warning';
|
|
3
|
+
export type ValidationMessage = {
|
|
4
|
+
level: ValidationLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type ValidationResult = Record<string, ValidationMessage[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Programmatic API for validation - returns structured results instead of logging/exiting.
|
|
10
|
+
* Equivalent to running `gtx-cli validate` but returns data.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getValidateJson(settings: Options & Settings, pkg: 'gt-react' | 'gt-next', files?: string[]): Promise<ValidationResult>;
|
|
2
13
|
export declare function validateProject(settings: Options & Settings, pkg: 'gt-react' | 'gt-next', files?: string[]): Promise<void>;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { logErrorAndExit } from '../console/logging.js';
|
|
1
|
+
import { logErrorAndExit, stripAnsi } from '../console/logging.js';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import findFilepath from '../fs/findFilepath.js';
|
|
4
4
|
import { logger } from '../console/logger.js';
|
|
5
5
|
import { createUpdates } from './parse.js';
|
|
6
6
|
import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Shared validation logic - returns raw results from createUpdates/createInlineUpdates
|
|
9
|
+
*/
|
|
10
|
+
async function runValidation(settings, pkg, files) {
|
|
8
11
|
if (files && files.length > 0) {
|
|
9
|
-
|
|
10
|
-
const { errors, updates } = await createInlineUpdates(pkg, true, files, settings.parsingOptions);
|
|
11
|
-
if (errors.length > 0) {
|
|
12
|
-
logErrorAndExit(chalk.red(`Error: CLI tool encountered ${errors.length} syntax errors:\n` +
|
|
13
|
-
errors
|
|
14
|
-
.map((error) => chalk.red('• ') + chalk.white(error) + '\n')
|
|
15
|
-
.join('')));
|
|
16
|
-
}
|
|
17
|
-
logger.success(chalk.green(`Success! Found ${updates.length} translatable entries.`));
|
|
18
|
-
return;
|
|
12
|
+
return createInlineUpdates(pkg, true, files, settings.parsingOptions);
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
// Full project validation
|
|
15
|
+
// Use local variable to avoid mutating caller's settings object
|
|
16
|
+
const dictionary = settings.dictionary ||
|
|
17
|
+
findFilepath([
|
|
22
18
|
'./dictionary.js',
|
|
23
19
|
'./src/dictionary.js',
|
|
24
20
|
'./dictionary.json',
|
|
@@ -26,8 +22,54 @@ export async function validateProject(settings, pkg, files) {
|
|
|
26
22
|
'./dictionary.ts',
|
|
27
23
|
'./src/dictionary.ts',
|
|
28
24
|
]);
|
|
25
|
+
return createUpdates(settings, settings.src, dictionary, pkg, true, settings.parsingOptions);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse file path from error/warning string in withLocation format: "filepath (line:col): message"
|
|
29
|
+
*/
|
|
30
|
+
function parseFileFromMessage(msg) {
|
|
31
|
+
// First try to match with location format: "filepath (line:col): message"
|
|
32
|
+
// Using [\s\S] instead of . with /s flag for ES5 compatibility
|
|
33
|
+
const withLocation = msg.match(/^(.+)\s+\(\d+:\d+\)\s*:\s*([\s\S]+)$/);
|
|
34
|
+
if (withLocation) {
|
|
35
|
+
return { file: withLocation[1].trim(), message: withLocation[2].trim() };
|
|
36
|
+
}
|
|
37
|
+
// Fallback: find the last ": " pattern (handles Windows paths like C:\...)
|
|
38
|
+
const lastColonSpace = msg.lastIndexOf(': ');
|
|
39
|
+
if (lastColonSpace > 0) {
|
|
40
|
+
return {
|
|
41
|
+
file: msg.substring(0, lastColonSpace).trim(),
|
|
42
|
+
message: msg.substring(lastColonSpace + 2).trim(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// No file found - use empty string as key for "global" messages
|
|
46
|
+
return { file: '', message: msg };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Programmatic API for validation - returns structured results instead of logging/exiting.
|
|
50
|
+
* Equivalent to running `gtx-cli validate` but returns data.
|
|
51
|
+
*/
|
|
52
|
+
export async function getValidateJson(settings, pkg, files) {
|
|
53
|
+
const { errors, warnings } = await runValidation(settings, pkg, files);
|
|
54
|
+
const result = {};
|
|
55
|
+
const addMessage = (file, level, message) => {
|
|
56
|
+
if (!result[file]) {
|
|
57
|
+
result[file] = [];
|
|
58
|
+
}
|
|
59
|
+
result[file].push({ level, message });
|
|
60
|
+
};
|
|
61
|
+
for (const error of errors) {
|
|
62
|
+
const { file, message } = parseFileFromMessage(stripAnsi(error));
|
|
63
|
+
addMessage(file, 'error', message);
|
|
64
|
+
}
|
|
65
|
+
for (const warning of warnings) {
|
|
66
|
+
const { file, message } = parseFileFromMessage(stripAnsi(warning));
|
|
67
|
+
addMessage(file, 'warning', message);
|
|
29
68
|
}
|
|
30
|
-
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
export async function validateProject(settings, pkg, files) {
|
|
72
|
+
const { updates, errors, warnings } = await runValidation(settings, pkg, files);
|
|
31
73
|
if (warnings.length > 0) {
|
|
32
74
|
logger.warn(chalk.yellow(`CLI tool encountered ${warnings.length} warnings while scanning for translatable content.`) +
|
|
33
75
|
'\n' +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.11",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"import": "./dist/types.js",
|
|
19
19
|
"types": "./dist/types.d.ts"
|
|
20
20
|
},
|
|
21
|
+
"./functions": {
|
|
22
|
+
"import": "./dist/functions.js",
|
|
23
|
+
"types": "./dist/functions.d.ts"
|
|
24
|
+
},
|
|
21
25
|
"./updates/*": {
|
|
22
26
|
"import": "./dist/updates/*.js",
|
|
23
27
|
"types": "./dist/updates/*.d.ts"
|