@tolgee/cli 2.9.0 → 2.10.1
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/dist/cli.js +116 -94
- package/dist/client/ApiClient.js +40 -32
- package/dist/client/ExportClient.js +24 -11
- package/dist/client/ImportClient.js +25 -16
- package/dist/client/TolgeeClient.js +1 -5
- package/dist/client/errorFromLoadable.js +3 -2
- package/dist/client/getApiKeyInformation.js +16 -6
- package/dist/commands/extract/check.js +38 -27
- package/dist/commands/extract/print.js +46 -35
- package/dist/commands/login.js +39 -26
- package/dist/commands/pull.js +60 -43
- package/dist/commands/push.js +162 -123
- package/dist/commands/sync/compare.js +43 -31
- package/dist/commands/sync/sync.js +118 -99
- package/dist/commands/sync/syncUtils.js +2 -1
- package/dist/commands/tag.js +52 -38
- package/dist/config/credentials.js +110 -93
- package/dist/config/tolgeerc.js +51 -35
- package/dist/extractor/extractor.js +45 -31
- package/dist/extractor/parser/extractComment.js +1 -1
- package/dist/extractor/parser/generateReport.js +8 -6
- package/dist/extractor/parser/iterator.js +2 -1
- package/dist/extractor/parser/mergerMachine.js +2 -11
- package/dist/extractor/parser/nodeUtils.js +1 -1
- package/dist/extractor/parser/parser.js +4 -2
- package/dist/extractor/parser/rules/tNsSourceGeneral.js +1 -1
- package/dist/extractor/parser/tree/getTranslateProps.js +21 -16
- package/dist/extractor/parser/tree/getValue.js +1 -1
- package/dist/extractor/parser/tree/parseTag.js +1 -1
- package/dist/extractor/parserNgx/ParserNgx.js +1 -3
- package/dist/extractor/parserNgx/ngxMapper.js +2 -1
- package/dist/extractor/parserNgx/ngxTreeTransform.js +3 -2
- package/dist/extractor/parserNgx/rules/translatePipe.js +1 -1
- package/dist/extractor/parserReact/ParserReact.js +1 -3
- package/dist/extractor/parserSvelte/ParserSvelte.js +1 -3
- package/dist/extractor/parserVue/ParserVue.js +1 -3
- package/dist/extractor/parserVue/tokenMergers/hyphenPropsMerger.js +1 -4
- package/dist/extractor/parserVue/vueTreeTransform.js +13 -2
- package/dist/extractor/runner.js +53 -39
- package/dist/extractor/tokenizer.js +50 -35
- package/dist/extractor/visualizers/printTokens.js +2 -1
- package/dist/extractor/visualizers/visualizeRules.js +4 -7
- package/dist/extractor/warnings.js +3 -2
- package/dist/extractor/worker.js +29 -16
- package/dist/options.js +1 -1
- package/dist/utils/apiKeyList.js +31 -19
- package/dist/utils/ask.js +35 -21
- package/dist/utils/checkPathNotAFile.js +22 -11
- package/dist/utils/filesTemplate.js +147 -0
- package/dist/utils/mapImportFormat.js +1 -1
- package/dist/utils/moduleLoader.js +37 -23
- package/dist/utils/prepareDir.js +20 -9
- package/dist/utils/valueToArray.js +8 -0
- package/package.json +2 -2
- package/schema.json +14 -2
package/dist/cli.js
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
2
11
|
import { Command } from 'commander';
|
3
12
|
import ansi from 'ansi-colors';
|
4
13
|
import { getApiKey, savePak, savePat } from './config/credentials.js';
|
@@ -24,30 +33,33 @@ function topLevelName(command) {
|
|
24
33
|
? topLevelName(command.parent)
|
25
34
|
: command.name();
|
26
35
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
function loadApiKey(cmd) {
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
38
|
+
const opts = cmd.optsWithGlobals();
|
39
|
+
// API Key is already loaded
|
40
|
+
if (opts.apiKey)
|
41
|
+
return;
|
42
|
+
// Attempt to load --api-key from config store if not specified
|
43
|
+
// This is not done as part of the init routine or via the mandatory flag, as this is dependent on the API URL.
|
44
|
+
const key = yield getApiKey(opts.apiUrl, opts.projectId);
|
45
|
+
// No key in store, stop here.
|
46
|
+
if (!key)
|
47
|
+
return;
|
48
|
+
cmd.setOptionValue('apiKey', key);
|
49
|
+
program.setOptionValue('_removeApiKeyFromStore', () => {
|
50
|
+
if (key.startsWith(API_KEY_PAT_PREFIX)) {
|
51
|
+
savePat(opts.apiUrl);
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
savePak(opts.apiUrl, opts.projectId);
|
55
|
+
}
|
56
|
+
});
|
46
57
|
});
|
47
58
|
}
|
48
59
|
function loadProjectId(cmd) {
|
60
|
+
var _a;
|
49
61
|
const opts = cmd.optsWithGlobals();
|
50
|
-
if (opts.apiKey
|
62
|
+
if ((_a = opts.apiKey) === null || _a === void 0 ? void 0 : _a.startsWith(API_KEY_PAK_PREFIX)) {
|
51
63
|
// Parse the key and ensure we can access the specified Project ID
|
52
64
|
const projectId = projectIdFromKey(opts.apiKey);
|
53
65
|
program.setOptionValue('projectId', projectId);
|
@@ -59,41 +71,46 @@ function loadProjectId(cmd) {
|
|
59
71
|
}
|
60
72
|
}
|
61
73
|
}
|
62
|
-
|
63
|
-
|
64
|
-
if (opts.projectId === -1) {
|
65
|
-
error('No Project ID have been specified. You must either provide one via --project-id, or by setting up a `.tolgeerc` file.');
|
66
|
-
info('If you provide Project Api Key (PAK) via `--api-key`, Project ID is derived automatically.');
|
67
|
-
info('Learn more about configuring the CLI here: https://tolgee.io/tolgee-cli/project-configuration');
|
68
|
-
process.exit(1);
|
69
|
-
}
|
70
|
-
if (!opts.apiKey) {
|
71
|
-
error(`Not authenticated for host ${ansi.blue(opts.apiUrl.hostname)} and project ${ansi.blue(opts.projectId)}.`);
|
72
|
-
info(`You must either provide api key via --api-key or login via \`tolgee login\` (for correct api url and project)`);
|
73
|
-
console.log('\nYou are logged into these projects:');
|
74
|
-
await printApiKeyLists();
|
75
|
-
process.exit(1);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
const preHandler = (config) => async function (prog, cmd) {
|
79
|
-
if (!NO_KEY_COMMANDS.includes(topLevelName(cmd))) {
|
80
|
-
await loadApiKey(cmd);
|
81
|
-
loadProjectId(cmd);
|
82
|
-
validateOptions(cmd);
|
74
|
+
function validateOptions(cmd) {
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
83
76
|
const opts = cmd.optsWithGlobals();
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
77
|
+
if (opts.projectId === -1) {
|
78
|
+
error('No Project ID have been specified. You must either provide one via --project-id, or by setting up a `.tolgeerc` file.');
|
79
|
+
info('If you provide Project Api Key (PAK) via `--api-key`, Project ID is derived automatically.');
|
80
|
+
info('Learn more about configuring the CLI here: https://tolgee.io/tolgee-cli/project-configuration');
|
81
|
+
process.exit(1);
|
82
|
+
}
|
83
|
+
if (!opts.apiKey) {
|
84
|
+
error(`Not authenticated for host ${ansi.blue(opts.apiUrl.hostname)} and project ${ansi.blue(opts.projectId)}.`);
|
85
|
+
info(`You must either provide api key via --api-key or login via \`tolgee login\` (for correct api url and project)`);
|
86
|
+
console.log('\nYou are logged into these projects:');
|
87
|
+
yield printApiKeyLists();
|
88
|
+
process.exit(1);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
}
|
92
|
+
const preHandler = (config) => function (prog, cmd) {
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
94
|
+
var _a, _b, _c;
|
95
|
+
if (!NO_KEY_COMMANDS.includes(topLevelName(cmd))) {
|
96
|
+
yield loadApiKey(cmd);
|
97
|
+
loadProjectId(cmd);
|
98
|
+
validateOptions(cmd);
|
99
|
+
const opts = cmd.optsWithGlobals();
|
100
|
+
const client = createTolgeeClient({
|
101
|
+
baseUrl: (_b = (_a = opts.apiUrl) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : (_c = config.apiUrl) === null || _c === void 0 ? void 0 : _c.toString(),
|
102
|
+
apiKey: opts.apiKey,
|
103
|
+
projectId: opts.projectId !== undefined
|
104
|
+
? Number(opts.projectId)
|
105
|
+
: config.projectId !== undefined
|
106
|
+
? Number(config.projectId)
|
107
|
+
: undefined,
|
108
|
+
});
|
109
|
+
cmd.setOptionValue('client', client);
|
110
|
+
}
|
111
|
+
// Apply verbosity
|
112
|
+
setDebug(Boolean(prog.opts().verbose));
|
113
|
+
});
|
97
114
|
};
|
98
115
|
const program = new Command('tolgee')
|
99
116
|
.version(VERSION)
|
@@ -101,46 +118,51 @@ const program = new Command('tolgee')
|
|
101
118
|
.description('Command Line Interface to interact with the Tolgee Platform');
|
102
119
|
// get config path to update defaults
|
103
120
|
const configPath = getSingleOption(CONFIG_OPT, process.argv);
|
104
|
-
|
105
|
-
|
106
|
-
|
121
|
+
function loadConfig(program) {
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
123
|
+
const tgConfig = yield loadTolgeeRc(configPath);
|
124
|
+
return tgConfig !== null && tgConfig !== void 0 ? tgConfig : {};
|
125
|
+
});
|
107
126
|
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
127
|
+
function run() {
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
129
|
+
var _a, _b, _c, _d;
|
130
|
+
try {
|
131
|
+
const config = yield loadConfig(program);
|
132
|
+
program.hook('preAction', preHandler(config));
|
133
|
+
// Global options
|
134
|
+
program.addOption(VERBOSE);
|
135
|
+
program.addOption(CONFIG_OPT);
|
136
|
+
program.addOption(API_URL_OPT.default((_a = config.apiUrl) !== null && _a !== void 0 ? _a : DEFAULT_API_URL));
|
137
|
+
program.addOption(API_KEY_OPT.default(config.apiKey));
|
138
|
+
program.addOption(PROJECT_ID_OPT.default((_b = config.projectId) !== null && _b !== void 0 ? _b : -1));
|
139
|
+
program.addOption(FORMAT_OPT.default((_c = config.format) !== null && _c !== void 0 ? _c : 'JSON_TOLGEE'));
|
140
|
+
program.addOption(EXTRACTOR.default(config.extractor));
|
141
|
+
program.addOption(FILE_PATTERNS.default(config.patterns));
|
142
|
+
program.addOption(PARSER.default(config.parser));
|
143
|
+
program.addOption(STRICT_NAMESPACE.default((_d = config.strictNamespace) !== null && _d !== void 0 ? _d : true));
|
144
|
+
program.addOption(STRICT_NAMESPACE_NEGATION);
|
145
|
+
program.addOption(DEFAULT_NAMESPACE.default(config.defaultNamespace));
|
146
|
+
// Register commands
|
147
|
+
program.addCommand(Login);
|
148
|
+
program.addCommand(Logout);
|
149
|
+
program.addCommand(PushCommand(config).configureHelp({ showGlobalOptions: true }));
|
150
|
+
program.addCommand(PullCommand(config).configureHelp({ showGlobalOptions: true }));
|
151
|
+
program.addCommand(ExtractCommand(config).configureHelp({ showGlobalOptions: true }));
|
152
|
+
program.addCommand(CompareCommand(config).configureHelp({ showGlobalOptions: true }));
|
153
|
+
program.addCommand(SyncCommand(config).configureHelp({ showGlobalOptions: true }));
|
154
|
+
program.addCommand(TagCommand(config).configureHelp({ showGlobalOptions: true }));
|
155
|
+
yield program.parseAsync();
|
156
|
+
}
|
157
|
+
catch (e) {
|
158
|
+
// If the error is uncaught, huge chance that either:
|
159
|
+
// - The error should be handled here but isn't
|
160
|
+
// - The error should be handled in the command but isn't
|
161
|
+
// - Something went wrong with the code
|
162
|
+
error('An unexpected error occurred while running the command.');
|
163
|
+
error('Please report this to our issue tracker: https://github.com/tolgee/tolgee-cli/issues');
|
164
|
+
exitWithError(e);
|
165
|
+
}
|
166
|
+
});
|
145
167
|
}
|
146
168
|
run();
|
package/dist/client/ApiClient.js
CHANGED
@@ -1,33 +1,44 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import createClient from 'openapi-fetch';
|
2
11
|
import base32Decode from 'base32-decode';
|
3
12
|
import { API_KEY_PAK_PREFIX, USER_AGENT } from '../constants.js';
|
4
13
|
import { getApiKeyInformation } from './getApiKeyInformation.js';
|
5
14
|
import { debug } from '../utils/logger.js';
|
6
15
|
import { errorFromLoadable } from './errorFromLoadable.js';
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
response.
|
12
|
-
|
13
|
-
|
14
|
-
// parse response (falling back to .text() when necessary)
|
15
|
-
if (response.ok) {
|
16
|
-
// if "stream", skip parsing entirely
|
17
|
-
if (parseAs === 'stream') {
|
18
|
-
return { data: response.body, response };
|
16
|
+
function parseResponse(response, parseAs) {
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
18
|
+
// handle empty content
|
19
|
+
// note: we return `{}` because we want user truthy checks for `.data` or `.error` to succeed
|
20
|
+
if (response.status === 204 ||
|
21
|
+
response.headers.get('Content-Length') === '0') {
|
22
|
+
return response.ok ? { data: {}, response } : { error: {}, response };
|
19
23
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
//
|
29
|
-
|
30
|
-
|
24
|
+
// parse response (falling back to .text() when necessary)
|
25
|
+
if (response.ok) {
|
26
|
+
// if "stream", skip parsing entirely
|
27
|
+
if (parseAs === 'stream') {
|
28
|
+
return { data: response.body, response };
|
29
|
+
}
|
30
|
+
return { data: yield response[parseAs](), response };
|
31
|
+
}
|
32
|
+
// handle errors
|
33
|
+
let error = yield response.text();
|
34
|
+
try {
|
35
|
+
error = JSON.parse(error); // attempt to parse as JSON
|
36
|
+
}
|
37
|
+
catch (_a) {
|
38
|
+
// noop
|
39
|
+
}
|
40
|
+
return { error, response };
|
41
|
+
});
|
31
42
|
}
|
32
43
|
export function projectIdFromKey(key) {
|
33
44
|
if (!key.startsWith(API_KEY_PAK_PREFIX)) {
|
@@ -38,7 +49,7 @@ export function projectIdFromKey(key) {
|
|
38
49
|
return Number(decoded.split('_')[0]);
|
39
50
|
}
|
40
51
|
export function createApiClient({ baseUrl, apiKey, projectId, autoThrow = false, }) {
|
41
|
-
const computedProjectId = projectId
|
52
|
+
const computedProjectId = projectId !== null && projectId !== void 0 ? projectId : (apiKey ? projectIdFromKey(apiKey) : undefined);
|
42
53
|
const apiClient = createClient({
|
43
54
|
baseUrl,
|
44
55
|
headers: {
|
@@ -50,17 +61,15 @@ export function createApiClient({ baseUrl, apiKey, projectId, autoThrow = false,
|
|
50
61
|
onRequest: ({ request }) => {
|
51
62
|
debug(`[HTTP] Requesting: ${request.method} ${request.url}`);
|
52
63
|
},
|
53
|
-
onResponse:
|
64
|
+
onResponse: (_a) => __awaiter(this, [_a], void 0, function* ({ response, options }) {
|
54
65
|
debug(`[HTTP] Response: ${response.url} [${response.status}]`);
|
55
66
|
if (autoThrow && !response.ok) {
|
56
|
-
const loadable =
|
67
|
+
const loadable = yield parseResponse(response, options.parseAs);
|
57
68
|
throw new Error(`Tolgee request error ${response.url} ${errorFromLoadable(loadable)}`);
|
58
69
|
}
|
59
|
-
},
|
70
|
+
}),
|
60
71
|
});
|
61
|
-
return {
|
62
|
-
...apiClient,
|
63
|
-
getProjectId() {
|
72
|
+
return Object.assign(Object.assign({}, apiClient), { getProjectId() {
|
64
73
|
return computedProjectId;
|
65
74
|
},
|
66
75
|
getApiKeyInfo() {
|
@@ -68,6 +77,5 @@ export function createApiClient({ baseUrl, apiKey, projectId, autoThrow = false,
|
|
68
77
|
},
|
69
78
|
getSettings() {
|
70
79
|
return { baseUrl, apiKey, projectId, autoThrow };
|
71
|
-
}
|
72
|
-
};
|
80
|
+
} });
|
73
81
|
}
|
@@ -1,18 +1,31 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
export const createExportClient = ({ apiClient }) => {
|
2
11
|
return {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
12
|
+
export(req) {
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
14
|
+
const body = Object.assign(Object.assign({}, req), { zip: true });
|
15
|
+
const loadable = yield apiClient.POST('/v2/projects/{projectId}/export', {
|
16
|
+
params: { path: { projectId: apiClient.getProjectId() } },
|
17
|
+
body: body,
|
18
|
+
parseAs: 'blob',
|
19
|
+
});
|
20
|
+
return Object.assign(Object.assign({}, loadable), { data: loadable.data });
|
9
21
|
});
|
10
|
-
return { ...loadable, data: loadable.data };
|
11
22
|
},
|
12
|
-
|
13
|
-
return
|
14
|
-
|
15
|
-
|
23
|
+
exportSingle(req) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
return apiClient.POST('/v2/projects/{projectId}/export', {
|
26
|
+
params: { path: { projectId: apiClient.getProjectId() } },
|
27
|
+
body: Object.assign(Object.assign({}, req), { zip: false }),
|
28
|
+
});
|
16
29
|
});
|
17
30
|
},
|
18
31
|
};
|
@@ -1,22 +1,31 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import { pathToPosix } from '../utils/pathToPosix.js';
|
2
11
|
export const createImportClient = ({ apiClient }) => {
|
3
12
|
return {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
import(data) {
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
15
|
+
const body = new FormData();
|
16
|
+
for (const file of data.files) {
|
17
|
+
// converting paths to posix style, so it's correctly matched on the server
|
18
|
+
body.append('files', new Blob([file.data]), pathToPosix(file.name));
|
19
|
+
}
|
20
|
+
data.params.fileMappings = data.params.fileMappings.map((i) => (Object.assign(Object.assign({}, i), {
|
21
|
+
// converting paths to posix style, so it's correctly matched on the server
|
22
|
+
fileName: pathToPosix(i.fileName) })));
|
23
|
+
body.append('params', JSON.stringify(data.params));
|
24
|
+
return apiClient.POST('/v2/projects/{projectId}/single-step-import', {
|
25
|
+
params: { path: { projectId: apiClient.getProjectId() } },
|
26
|
+
body: body,
|
27
|
+
bodySerializer: (r) => r,
|
28
|
+
});
|
20
29
|
});
|
21
30
|
},
|
22
31
|
};
|
@@ -5,11 +5,7 @@ import { createImportClient } from './ImportClient.js';
|
|
5
5
|
import { errorFromLoadable } from './errorFromLoadable.js';
|
6
6
|
export function createTolgeeClient(props) {
|
7
7
|
const apiClient = createApiClient(props);
|
8
|
-
return {
|
9
|
-
...apiClient,
|
10
|
-
import: createImportClient({ apiClient }),
|
11
|
-
export: createExportClient({ apiClient }),
|
12
|
-
};
|
8
|
+
return Object.assign(Object.assign({}, apiClient), { import: createImportClient({ apiClient }), export: createExportClient({ apiClient }) });
|
13
9
|
}
|
14
10
|
export const handleLoadableError = (loadable) => {
|
15
11
|
if (loadable.error) {
|
@@ -1,10 +1,11 @@
|
|
1
1
|
export const addErrorDetails = (loadable, showBeError = true) => {
|
2
|
+
var _a, _b, _c;
|
2
3
|
const items = [];
|
3
4
|
items.push(`status: ${loadable.response.status}`);
|
4
|
-
if (showBeError && loadable.error
|
5
|
+
if (showBeError && ((_a = loadable.error) === null || _a === void 0 ? void 0 : _a.code)) {
|
5
6
|
items.push(`code: ${loadable.error.code}`);
|
6
7
|
}
|
7
|
-
if (loadable.response.status === 403 && loadable.error
|
8
|
+
if (loadable.response.status === 403 && ((_c = (_b = loadable.error) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c[0])) {
|
8
9
|
items.push(`missing scope: ${loadable.error.params[0]}`);
|
9
10
|
}
|
10
11
|
return `[${items.join(', ')}]`;
|
@@ -1,9 +1,19 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import { API_KEY_PAK_PREFIX } from './../constants.js';
|
2
11
|
import { handleLoadableError } from './TolgeeClient.js';
|
3
12
|
import { exitWithError } from './../utils/logger.js';
|
4
|
-
export const getApiKeyInformation =
|
13
|
+
export const getApiKeyInformation = (client, key) => __awaiter(void 0, void 0, void 0, function* () {
|
14
|
+
var _a, _b;
|
5
15
|
if (key.startsWith(API_KEY_PAK_PREFIX)) {
|
6
|
-
const loadable =
|
16
|
+
const loadable = yield client.GET('/v2/api-keys/current');
|
7
17
|
if (loadable.response.status === 401) {
|
8
18
|
exitWithError(`Couldn't log in: the API key you provided is invalid (${new URL(loadable.response.url).host}).`);
|
9
19
|
}
|
@@ -18,11 +28,11 @@ export const getApiKeyInformation = async (client, key) => {
|
|
18
28
|
id: info.projectId,
|
19
29
|
name: info.projectName,
|
20
30
|
},
|
21
|
-
expires: info.expiresAt
|
31
|
+
expires: (_a = info.expiresAt) !== null && _a !== void 0 ? _a : 0,
|
22
32
|
};
|
23
33
|
}
|
24
34
|
else {
|
25
|
-
const loadable =
|
35
|
+
const loadable = yield client.GET('/v2/pats/current');
|
26
36
|
if (loadable.response.status === 401) {
|
27
37
|
exitWithError(`Couldn't log in: the API key you provided is invalid (${new URL(loadable.response.url).host}).`);
|
28
38
|
}
|
@@ -33,7 +43,7 @@ export const getApiKeyInformation = async (client, key) => {
|
|
33
43
|
type: 'PAT',
|
34
44
|
key: key,
|
35
45
|
username: username,
|
36
|
-
expires: info.expiresAt
|
46
|
+
expires: (_b = info.expiresAt) !== null && _b !== void 0 ? _b : 0,
|
37
47
|
};
|
38
48
|
}
|
39
|
-
};
|
49
|
+
});
|
@@ -1,38 +1,49 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import { relative } from 'path';
|
2
11
|
import { Command } from 'commander';
|
3
12
|
import { extractKeysOfFiles } from '../../extractor/runner.js';
|
4
13
|
import { WarningMessages, emitGitHubWarning, } from '../../extractor/warnings.js';
|
5
14
|
import { loading } from '../../utils/logger.js';
|
6
|
-
const lintHandler = (config) =>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
const lintHandler = (config) => function () {
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
17
|
+
const opts = this.optsWithGlobals();
|
18
|
+
const extracted = yield loading('Analyzing code...', extractKeysOfFiles(opts));
|
19
|
+
let warningCount = 0;
|
20
|
+
let filesCount = 0;
|
21
|
+
for (const [file, { warnings }] of extracted) {
|
22
|
+
if (warnings === null || warnings === void 0 ? void 0 : warnings.length) {
|
23
|
+
warningCount += warnings.length;
|
24
|
+
filesCount++;
|
25
|
+
const relFile = relative(process.cwd(), file);
|
26
|
+
console.log('%s:', relFile);
|
27
|
+
for (const warning of warnings) {
|
28
|
+
if (warning.warning in WarningMessages) {
|
29
|
+
const warn = warning.warning;
|
30
|
+
const { name } = WarningMessages[warn];
|
31
|
+
console.log('\tline %d: %s', warning.line, name);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
console.log('\tline %d: %s', warning.line, warning.warning);
|
35
|
+
}
|
36
|
+
emitGitHubWarning(warning.warning, file, warning.line);
|
25
37
|
}
|
26
|
-
emitGitHubWarning(warning.warning, file, warning.line);
|
27
38
|
}
|
28
39
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
if (warningCount !== 0) {
|
41
|
+
console.log();
|
42
|
+
console.log('Total: %d warning%s in %d file%s', warningCount, warningCount !== 1 ? 's' : '', filesCount, filesCount !== 1 ? 's' : '');
|
43
|
+
process.exit(1);
|
44
|
+
}
|
45
|
+
console.log('No issues found.');
|
46
|
+
});
|
36
47
|
};
|
37
48
|
export default (config) => new Command('check')
|
38
49
|
.description('Checks if the keys can be extracted automatically, and reports problems if any')
|