gtx-cli 2.0.1-alpha.1 → 2.0.2
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 +15 -0
- package/dist/cli/base.js +2 -0
- package/dist/cli/react.d.ts +1 -1
- package/dist/cli/react.js +12 -5
- package/dist/react/jsx/utils/constants.d.ts +1 -0
- package/dist/react/jsx/utils/constants.js +2 -1
- package/dist/react/jsx/utils/parseJsx.js +2 -2
- package/dist/react/jsx/utils/parseStringFunction.js +2 -2
- package/dist/react/parse/createDictionaryUpdates.d.ts +1 -1
- package/dist/react/parse/createDictionaryUpdates.js +1 -1
- package/dist/react/parse/createInlineUpdates.d.ts +2 -2
- package/dist/react/parse/createInlineUpdates.js +2 -3
- package/dist/translation/parse.js +3 -3
- package/dist/translation/validate.d.ts +1 -1
- package/dist/translation/validate.js +13 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#458](https://github.com/generaltranslation/gt/pull/458) [`aff4b95`](https://github.com/generaltranslation/gt/commit/aff4b95f582ec9fcb28f1395d2eba907c93e4e31) Thanks [@brian-lou](https://github.com/brian-lou)! - Add individual file support to validate
|
|
8
|
+
|
|
9
|
+
## 2.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#440](https://github.com/generaltranslation/gt/pull/440) [`e6fdedf`](https://github.com/generaltranslation/gt/commit/e6fdedffcdfbac5d257ea35140cbb81de6aa2729) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fixes to breaking changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`e6fdedf`](https://github.com/generaltranslation/gt/commit/e6fdedffcdfbac5d257ea35140cbb81de6aa2729)]:
|
|
16
|
+
- generaltranslation@7.0.1
|
|
17
|
+
|
|
3
18
|
## 2.0.0
|
|
4
19
|
|
|
5
20
|
### Major 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 { getCLIVersion } from '../utils/packageJson.js';
|
|
17
18
|
export class BaseCLI {
|
|
18
19
|
library;
|
|
19
20
|
additionalModules;
|
|
@@ -21,6 +22,7 @@ export class BaseCLI {
|
|
|
21
22
|
// Constructor is shared amongst all CLI class types
|
|
22
23
|
constructor(program, library, additionalModules) {
|
|
23
24
|
this.program = program;
|
|
25
|
+
this.program.version(getCLIVersion());
|
|
24
26
|
this.library = library;
|
|
25
27
|
this.additionalModules = additionalModules || [];
|
|
26
28
|
this.setupInitCommand();
|
package/dist/cli/react.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ export declare class ReactCLI extends BaseCLI {
|
|
|
17
17
|
protected handleScanCommand(options: WrapOptions): Promise<void>;
|
|
18
18
|
protected handleStage(initOptions: Options): Promise<void>;
|
|
19
19
|
protected handleTranslate(initOptions: Options): Promise<void>;
|
|
20
|
-
protected handleValidate(initOptions: Options): Promise<void>;
|
|
20
|
+
protected handleValidate(initOptions: Options, files?: string[]): Promise<void>;
|
|
21
21
|
}
|
package/dist/cli/react.js
CHANGED
|
@@ -88,17 +88,17 @@ export class ReactCLI extends BaseCLI {
|
|
|
88
88
|
}
|
|
89
89
|
setupValidateCommand() {
|
|
90
90
|
this.program
|
|
91
|
-
.command('validate')
|
|
91
|
+
.command('validate [files...]')
|
|
92
92
|
.description('Scans the project for a dictionary and/or <T> tags, and validates the project for errors.')
|
|
93
93
|
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', findFilepath(['gt.config.json']))
|
|
94
94
|
.option('--tsconfig, --jsconfig <path>', 'Path to jsconfig or tsconfig file', findFilepath(['./tsconfig.json', './jsconfig.json']))
|
|
95
95
|
.option('--dictionary <path>', 'Path to dictionary file')
|
|
96
96
|
.option('--src <paths...>', "Space-separated list of glob patterns containing the app's source code, by default 'src/**/*.{js,jsx,ts,tsx}' 'app/**/*.{js,jsx,ts,tsx}' 'pages/**/*.{js,jsx,ts,tsx}' 'components/**/*.{js,jsx,ts,tsx}'")
|
|
97
97
|
.option('--inline', 'Include inline <T> tags in addition to dictionary file', true)
|
|
98
|
-
.action(async (options) => {
|
|
98
|
+
.action(async (files, options) => {
|
|
99
99
|
// intro here since we don't want to show the ascii title
|
|
100
100
|
intro(chalk.cyan('Validating project...'));
|
|
101
|
-
await this.handleValidate(options);
|
|
101
|
+
await this.handleValidate(options, files);
|
|
102
102
|
endCommand('Done!');
|
|
103
103
|
});
|
|
104
104
|
}
|
|
@@ -294,12 +294,19 @@ export class ReactCLI extends BaseCLI {
|
|
|
294
294
|
await flattenJsonFiles(options);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
async handleValidate(initOptions) {
|
|
297
|
+
async handleValidate(initOptions, files) {
|
|
298
298
|
validateConfigExists();
|
|
299
299
|
const settings = await generateSettings(initOptions);
|
|
300
300
|
// First run the base class's handleTranslate method
|
|
301
301
|
const options = { ...initOptions, ...settings };
|
|
302
302
|
const pkg = this.library === 'gt-next' ? 'gt-next' : 'gt-react';
|
|
303
|
-
|
|
303
|
+
if (files && files.length > 0) {
|
|
304
|
+
// Validate specific files using createInlineUpdates
|
|
305
|
+
await validateProject(options, pkg, files);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
// Validate whole project as before
|
|
309
|
+
await validateProject(options, pkg);
|
|
310
|
+
}
|
|
304
311
|
}
|
|
305
312
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const GT_TRANSLATION_FUNCS: string[];
|
|
2
2
|
export declare const VARIABLE_COMPONENTS: string[];
|
|
3
|
+
export declare const GT_ATTRIBUTES_WITH_SUGAR: string[];
|
|
3
4
|
export declare const GT_ATTRIBUTES: string[];
|
|
4
5
|
export declare function mapAttributeName(attrName: string): string;
|
|
@@ -12,7 +12,8 @@ export const GT_TRANSLATION_FUNCS = [
|
|
|
12
12
|
];
|
|
13
13
|
// Valid variable components
|
|
14
14
|
export const VARIABLE_COMPONENTS = ['Var', 'DateTime', 'Currency', 'Num'];
|
|
15
|
-
export const
|
|
15
|
+
export const GT_ATTRIBUTES_WITH_SUGAR = ['$id', '$context'];
|
|
16
|
+
export const GT_ATTRIBUTES = ['id', 'context', ...GT_ATTRIBUTES_WITH_SUGAR];
|
|
16
17
|
export function mapAttributeName(attrName) {
|
|
17
18
|
if (attrName === '$id')
|
|
18
19
|
return 'id';
|
|
@@ -7,7 +7,7 @@ import { warnHasUnwrappedExpressionSync, warnVariablePropSync, warnNestedTCompon
|
|
|
7
7
|
import { isAcceptedPluralForm } from 'generaltranslation/internal';
|
|
8
8
|
import { handleChildrenWhitespace } from '../trimJsxStringChildren.js';
|
|
9
9
|
import { isStaticExpression } from '../evaluateJsx.js';
|
|
10
|
-
import { GT_ATTRIBUTES, VARIABLE_COMPONENTS } from './constants.js';
|
|
10
|
+
import { GT_ATTRIBUTES, mapAttributeName, VARIABLE_COMPONENTS, } from './constants.js';
|
|
11
11
|
/**
|
|
12
12
|
* Builds a JSX tree from a given node, recursively handling children.
|
|
13
13
|
* @param node - The node to build the tree from
|
|
@@ -188,7 +188,7 @@ export function parseJSXElement(importAliases, node, updates, errors, file) {
|
|
|
188
188
|
}
|
|
189
189
|
// Use the static value if available
|
|
190
190
|
if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
|
|
191
|
-
metadata[attrName] = staticAnalysis.value;
|
|
191
|
+
metadata[mapAttributeName(attrName)] = staticAnalysis.value;
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
194
194
|
// Only store the code if we couldn't extract a static value
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { isStaticExpression } from '../evaluateJsx.js';
|
|
3
|
-
import {
|
|
3
|
+
import { GT_ATTRIBUTES_WITH_SUGAR, mapAttributeName } from './constants.js';
|
|
4
4
|
import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, } from '../../../console/index.js';
|
|
5
5
|
import generateModule from '@babel/generator';
|
|
6
6
|
import traverseModule from '@babel/traverse';
|
|
@@ -37,7 +37,7 @@ function processTranslationCall(tPath, updates, errors, file) {
|
|
|
37
37
|
if (prop.type === 'ObjectProperty' &&
|
|
38
38
|
prop.key.type === 'Identifier') {
|
|
39
39
|
const attribute = prop.key.name;
|
|
40
|
-
if (
|
|
40
|
+
if (GT_ATTRIBUTES_WITH_SUGAR.includes(attribute) &&
|
|
41
41
|
t.isExpression(prop.value)) {
|
|
42
42
|
const result = isStaticExpression(prop.value);
|
|
43
43
|
if (!result.isStatic) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BuildOptions } from 'esbuild';
|
|
2
2
|
import { Updates } from '../../types/index.js';
|
|
3
|
-
export
|
|
3
|
+
export declare function createDictionaryUpdates(dictionaryPath: string, esbuildConfig?: BuildOptions): Promise<Updates>;
|
|
@@ -7,7 +7,7 @@ import loadJSON from '../../fs/loadJSON.js';
|
|
|
7
7
|
import { hashSource } from 'generaltranslation/id';
|
|
8
8
|
import getEntryAndMetadata from '../utils/getEntryAndMetadata.js';
|
|
9
9
|
import { logError } from '../../console/logging.js';
|
|
10
|
-
export
|
|
10
|
+
export async function createDictionaryUpdates(dictionaryPath, esbuildConfig) {
|
|
11
11
|
let dictionary;
|
|
12
12
|
// ---- HANDLE JSON STRING DICTIONARY ----- //
|
|
13
13
|
if (dictionaryPath.endsWith('.json')) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { Updates } from '../../types/index.js';
|
|
2
|
+
export declare function createInlineUpdates(pkg: 'gt-react' | 'gt-next', validate: boolean, filePatterns: string[] | undefined): Promise<{
|
|
3
3
|
updates: Updates;
|
|
4
4
|
errors: string[];
|
|
5
5
|
}>;
|
|
@@ -12,12 +12,11 @@ import { validateStringFunction } from '../jsx/utils/validateStringFunction.js';
|
|
|
12
12
|
import { GT_TRANSLATION_FUNCS } from '../jsx/utils/constants.js';
|
|
13
13
|
import { matchFiles } from '../../fs/matchFiles.js';
|
|
14
14
|
import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
|
|
15
|
-
export
|
|
15
|
+
export async function createInlineUpdates(pkg, validate, filePatterns) {
|
|
16
16
|
const updates = [];
|
|
17
17
|
const errors = [];
|
|
18
18
|
// Use the provided app directory or default to the current directory
|
|
19
|
-
const
|
|
20
|
-
const files = matchFiles(process.cwd(), filePatterns);
|
|
19
|
+
const files = matchFiles(process.cwd(), filePatterns || DEFAULT_SRC_PATTERNS);
|
|
21
20
|
for (const file of files) {
|
|
22
21
|
const code = await fs.promises.readFile(file, 'utf8');
|
|
23
22
|
let ast;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { logError } from '../console/logging.js';
|
|
3
3
|
import loadJSON from '../fs/loadJSON.js';
|
|
4
|
-
import createDictionaryUpdates from '../react/parse/createDictionaryUpdates.js';
|
|
5
|
-
import createInlineUpdates from '../react/parse/createInlineUpdates.js';
|
|
4
|
+
import { createDictionaryUpdates } from '../react/parse/createDictionaryUpdates.js';
|
|
5
|
+
import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
|
|
6
6
|
import createESBuildConfig from '../react/config/createESBuildConfig.js';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
/**
|
|
@@ -48,7 +48,7 @@ export async function createUpdates(options, sourceDictionary, pkg, validate) {
|
|
|
48
48
|
}
|
|
49
49
|
// Scan through project for <T> tags
|
|
50
50
|
if (options.inline) {
|
|
51
|
-
const { updates: newUpdates, errors: newErrors } = await createInlineUpdates(
|
|
51
|
+
const { updates: newUpdates, errors: newErrors } = await createInlineUpdates(pkg, validate, options.src);
|
|
52
52
|
errors = [...errors, ...newErrors];
|
|
53
53
|
updates = [...updates, ...newUpdates];
|
|
54
54
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Options, Settings } from '../types/index.js';
|
|
2
|
-
export declare function validateProject(settings: Options & Settings, pkg: 'gt-react' | 'gt-next'): Promise<void>;
|
|
2
|
+
export declare function validateProject(settings: Options & Settings, pkg: 'gt-react' | 'gt-next', files?: string[]): Promise<void>;
|
|
@@ -3,7 +3,19 @@ import chalk from 'chalk';
|
|
|
3
3
|
import findFilepath from '../fs/findFilepath.js';
|
|
4
4
|
import { logError, logSuccess } from '../console/logging.js';
|
|
5
5
|
import { createUpdates } from './parse.js';
|
|
6
|
-
|
|
6
|
+
import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
|
|
7
|
+
export async function validateProject(settings, pkg, files) {
|
|
8
|
+
if (files && files.length > 0) {
|
|
9
|
+
// Validate specific files using createInlineUpdates
|
|
10
|
+
const { errors } = await createInlineUpdates(pkg, true, files);
|
|
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
|
+
return;
|
|
18
|
+
}
|
|
7
19
|
if (!settings.dictionary) {
|
|
8
20
|
settings.dictionary = findFilepath([
|
|
9
21
|
'./dictionary.js',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"esbuild": "^0.25.4",
|
|
88
88
|
"fast-glob": "^3.3.3",
|
|
89
89
|
"form-data": "^4.0.2",
|
|
90
|
-
"generaltranslation": "^7.0.
|
|
90
|
+
"generaltranslation": "^7.0.1",
|
|
91
91
|
"open": "^10.1.1",
|
|
92
92
|
"ora": "^8.2.0",
|
|
93
93
|
"resolve": "^1.22.10",
|