gtx-cli 1.2.31-alpha.1 → 1.2.31-alpha.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { displayProjectId, warnApiKeyInConfig } from '../console/logging.js';
|
|
2
|
-
import loadConfig from '../fs/config/loadConfig.js';
|
|
1
|
+
import { displayProjectId, logErrorAndExit, warnApiKeyInConfig, } from '../console/logging.js';
|
|
2
|
+
import { loadConfig } from '../fs/config/loadConfig.js';
|
|
3
3
|
import { defaultBaseUrl, libraryDefaultLocale, } from 'generaltranslation/internal';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import { createOrUpdateConfig } from '../fs/config/setupConfig.js';
|
|
@@ -9,6 +9,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
11
|
import path from 'node:path';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
import { resolveConfig } from './resolveConfig.js';
|
|
12
14
|
/**
|
|
13
15
|
* Generates settings from any
|
|
14
16
|
* @param options - The options to generate settings from
|
|
@@ -24,23 +26,33 @@ export async function generateSettings(options, cwd = process.cwd()) {
|
|
|
24
26
|
if (options.config) {
|
|
25
27
|
gtConfig = loadConfig(options.config);
|
|
26
28
|
}
|
|
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);
|
|
30
|
-
}
|
|
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);
|
|
34
|
-
}
|
|
35
29
|
else {
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const config = resolveConfig(cwd);
|
|
31
|
+
if (config) {
|
|
32
|
+
gtConfig = config.config;
|
|
33
|
+
options.config = config.path;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
gtConfig = {};
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
// Warn if apiKey is present in gt.config.json
|
|
40
40
|
if (gtConfig.apiKey) {
|
|
41
41
|
warnApiKeyInConfig(options.config);
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
|
+
const projectIdEnv = resolveProjectId();
|
|
45
|
+
// Resolve mismatched projectIds
|
|
46
|
+
if (gtConfig.projectId &&
|
|
47
|
+
options.projectId &&
|
|
48
|
+
gtConfig.projectId !== options.projectId) {
|
|
49
|
+
logErrorAndExit(`Project ID mismatch between ${chalk.green(gtConfig.projectId)} and ${chalk.green(options.projectId)}! Please use the same projectId in all configs.`);
|
|
50
|
+
}
|
|
51
|
+
else if (gtConfig.projectId &&
|
|
52
|
+
projectIdEnv &&
|
|
53
|
+
gtConfig.projectId !== projectIdEnv) {
|
|
54
|
+
logErrorAndExit(`Project ID mismatch between ${chalk.green(gtConfig.projectId)} and ${chalk.green(projectIdEnv)}! Please use the same projectId in all configs.`);
|
|
55
|
+
}
|
|
44
56
|
// merge options
|
|
45
57
|
const mergedOptions = { ...gtConfig, ...options };
|
|
46
58
|
// merge locales
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadConfig } from '../fs/config/loadConfig.js';
|
|
4
|
+
export function resolveConfig(cwd) {
|
|
5
|
+
const configFilepath = 'gt.config.json';
|
|
6
|
+
if (fs.existsSync(path.join(cwd, configFilepath))) {
|
|
7
|
+
return {
|
|
8
|
+
path: path.join(cwd, configFilepath),
|
|
9
|
+
config: loadConfig(path.join(cwd, configFilepath)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (fs.existsSync(path.join(cwd, 'src/gt.config.json'))) {
|
|
13
|
+
return {
|
|
14
|
+
path: path.join(cwd, 'src/gt.config.json'),
|
|
15
|
+
config: loadConfig(path.join(cwd, 'src/gt.config.json')),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function loadConfig(filepath: string): Record<string, any>;
|