gtx-cli 2.0.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 +6 -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/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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 2.0.1
|
|
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 { 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,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',
|