@tolgee/cli 2.1.6 → 2.1.7

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.
@@ -47,17 +47,15 @@ export function createApiClient({ baseUrl, apiKey, projectId, autoThrow = false,
47
47
  },
48
48
  });
49
49
  apiClient.use({
50
- onRequest: (req, options) => {
51
- debug(`[HTTP] Requesting: ${req.method} ${req.url}`);
52
- return undefined;
50
+ onRequest: ({ request }) => {
51
+ debug(`[HTTP] Requesting: ${request.method} ${request.url}`);
53
52
  },
54
- onResponse: async (res, options) => {
55
- debug(`[HTTP] Response: ${res.url} [${res.status}]`);
56
- if (autoThrow && !res.ok) {
57
- const loadable = await parseResponse(res, options.parseAs);
58
- throw new Error(`Tolgee request error ${res.url} ${errorFromLoadable(loadable)}`);
53
+ onResponse: async ({ response, options }) => {
54
+ debug(`[HTTP] Response: ${response.url} [${response.status}]`);
55
+ if (autoThrow && !response.ok) {
56
+ const loadable = await parseResponse(response, options.parseAs);
57
+ throw new Error(`Tolgee request error ${response.url} ${errorFromLoadable(loadable)}`);
59
58
  }
60
- return undefined;
61
59
  },
62
60
  });
63
61
  return {
@@ -1,28 +1,22 @@
1
- import FormData from 'form-data';
2
- import { pathToPossix } from '../utils/pathToPossix.js';
1
+ import { pathToPosix } from '../utils/pathToPosix.js';
3
2
  export const createImportClient = ({ apiClient }) => {
4
3
  return {
5
4
  async import(data) {
6
5
  const body = new FormData();
7
6
  for (const file of data.files) {
8
- // converting paths to possix style, so it's correctly matched on the server
9
- body.append('files', file.data, { filepath: pathToPossix(file.name) });
7
+ // converting paths to posix style, so it's correctly matched on the server
8
+ body.append('files', new Blob([file.data]), pathToPosix(file.name));
10
9
  }
11
10
  data.params.fileMappings = data.params.fileMappings.map((i) => ({
12
11
  ...i,
13
- // converting paths to possix style, so it's correctly matched on the server
14
- fileName: pathToPossix(i.fileName),
12
+ // converting paths to posix style, so it's correctly matched on the server
13
+ fileName: pathToPosix(i.fileName),
15
14
  }));
16
15
  body.append('params', JSON.stringify(data.params));
17
16
  return apiClient.POST('/v2/projects/{projectId}/single-step-import', {
18
17
  params: { path: { projectId: apiClient.getProjectId() } },
19
18
  body: body,
20
- bodySerializer: (r) => {
21
- return r.getBuffer();
22
- },
23
- headers: {
24
- 'content-type': `multipart/form-data; boundary=${body.getBoundary()}`,
25
- },
19
+ bodySerializer: (r) => r,
26
20
  });
27
21
  },
28
22
  };
@@ -9,14 +9,15 @@ const lintHandler = (config) => async function () {
9
9
  let warningCount = 0;
10
10
  let filesCount = 0;
11
11
  for (const [file, { warnings }] of extracted) {
12
- if (warnings.length) {
12
+ if (warnings?.length) {
13
13
  warningCount += warnings.length;
14
14
  filesCount++;
15
15
  const relFile = relative(process.cwd(), file);
16
16
  console.log('%s:', relFile);
17
17
  for (const warning of warnings) {
18
18
  if (warning.warning in WarningMessages) {
19
- const { name } = WarningMessages[warning.warning];
19
+ const warn = warning.warning;
20
+ const { name } = WarningMessages[warn];
20
21
  console.log('\tline %d: %s', warning.line, name);
21
22
  }
22
23
  else {
@@ -23,12 +23,13 @@ const printHandler = (config) => async function () {
23
23
  }
24
24
  }
25
25
  }
26
- if (warnings.length) {
26
+ if (warnings?.length) {
27
27
  warningCount += warnings.length;
28
28
  console.log('%d warning%s %s emitted during extraction:', warnings.length, warnings.length !== 1 ? 's' : '', warnings.length !== 1 ? 'were' : 'was');
29
29
  for (const warning of warnings) {
30
30
  if (warning.warning in WarningMessages) {
31
- const { name } = WarningMessages[warning.warning];
31
+ const warn = warning.warning;
32
+ const { name } = WarningMessages[warn];
32
33
  console.log('\tline %d: %s', warning.line, name);
33
34
  }
34
35
  else {
@@ -36,7 +37,7 @@ const printHandler = (config) => async function () {
36
37
  }
37
38
  }
38
39
  }
39
- if (keys.length || warnings.length) {
40
+ if (keys.length || warnings?.length) {
40
41
  console.log();
41
42
  }
42
43
  }
@@ -1,7 +1,7 @@
1
1
  import { extname, join } from 'path';
2
2
  import { readdir, readFile, stat } from 'fs/promises';
3
3
  import { Command, Option } from 'commander';
4
- import { glob } from 'glob';
4
+ import glob from 'fast-glob';
5
5
  import { loading, success, error, warn, exitWithError, } from '../utils/logger.js';
6
6
  import { askString } from '../utils/ask.js';
7
7
  import { mapImportFormat } from '../utils/mapImportFormat.js';
@@ -91,6 +91,7 @@ const pushHandler = (config) => async function () {
91
91
  return;
92
92
  }
93
93
  const params = {
94
+ createNewKeys: true,
94
95
  forceMode: opts.forceMode,
95
96
  overrideKeyDescriptions: opts.overrideKeyDescriptions,
96
97
  convertPlaceholdersToIcu: opts.convertPlaceholdersToIcu,
@@ -16,7 +16,7 @@ function parseConfig(input, configDir) {
16
16
  try {
17
17
  new URL(rc.apiUrl);
18
18
  }
19
- catch (e) {
19
+ catch {
20
20
  throw new Error('Invalid config: apiUrl is an invalid URL');
21
21
  }
22
22
  }
@@ -20,7 +20,7 @@ export const reactMergers = pipeMachines([
20
20
  ]);
21
21
  export const ParserReact = () => {
22
22
  return Parser({
23
- mappers: [generalMapper, reactMapper],
23
+ mappers: reactMappers,
24
24
  blocks: {
25
25
  ...DEFAULT_BLOCKS,
26
26
  },
@@ -1,4 +1,4 @@
1
- import { glob } from 'glob';
1
+ import glob from 'fast-glob';
2
2
  import { extname } from 'path';
3
3
  import { callWorker } from './worker.js';
4
4
  import { exitWithError } from '../utils/logger.js';
@@ -44,7 +44,7 @@ export async function extractKeysOfFiles(opts) {
44
44
  if (!opts.patterns?.length) {
45
45
  exitWithError("Missing '--patterns' or 'config.patterns' option");
46
46
  }
47
- const files = await glob(opts.patterns, { nodir: true });
47
+ const files = await glob(opts.patterns, { onlyFiles: true });
48
48
  if (files.length === 0) {
49
49
  exitWithError('No files were matched for extraction');
50
50
  }
@@ -50,14 +50,15 @@ export const WarningMessages = {
50
50
  export function dumpWarnings(extractionResult) {
51
51
  let warningCount = 0;
52
52
  for (const [file, { warnings }] of extractionResult.entries()) {
53
- if (warnings.length) {
53
+ if (warnings?.length) {
54
54
  if (!warningCount) {
55
55
  console.error('Warnings were emitted during extraction.');
56
56
  }
57
57
  console.error(file);
58
58
  for (const warning of warnings) {
59
59
  const warnText = warning.warning in WarningMessages
60
- ? WarningMessages[warning.warning].name
60
+ ? WarningMessages[warning.warning]
61
+ .name
61
62
  : warning.warning;
62
63
  console.error('\tline %d: %s', warning.line, warnText);
63
64
  emitGitHubWarning(warning.warning, file, warning.line);
@@ -75,7 +76,8 @@ export function emitGitHubWarning(warning, file, line) {
75
76
  return;
76
77
  file = relative(process.env.GITHUB_WORKSPACE ?? process.cwd(), file);
77
78
  if (warning in WarningMessages) {
78
- const { name, description } = WarningMessages[warning];
79
+ const warn = warning;
80
+ const { name, description } = WarningMessages[warn];
79
81
  const encodedDescription = description
80
82
  .replaceAll('%', '%25')
81
83
  .replaceAll('\r', '%0D')
@@ -2,16 +2,15 @@ import { extname } from 'path';
2
2
  let tsService;
3
3
  async function registerTsNode() {
4
4
  if (!tsService) {
5
- try {
6
- const tsNode = await import('ts-node');
7
- tsService = tsNode.register({ compilerOptions: { module: 'CommonJS' } });
8
- }
9
- catch (e) {
10
- if (e.code === 'ERR_MODULE_NOT_FOUND') {
11
- throw new Error('ts-node is required to load TypeScript files.');
12
- }
13
- throw e;
14
- }
5
+ // try {
6
+ // const tsNode = await import('ts-node');
7
+ // tsService = tsNode.register({ compilerOptions: { module: 'CommonJS' } });
8
+ // } catch (e: any) {
9
+ // if (e.code === 'ERR_MODULE_NOT_FOUND') {
10
+ // throw new Error('ts-node is required to load TypeScript files.');
11
+ // }
12
+ // throw e;
13
+ // }
15
14
  }
16
15
  }
17
16
  async function importTypeScript(file) {
@@ -1,4 +1,4 @@
1
1
  import path from 'path';
2
- export function pathToPossix(input) {
2
+ export function pathToPosix(input) {
3
3
  return input.replaceAll(path.sep, path.posix.sep);
4
4
  }
package/extractor.d.ts CHANGED
@@ -22,9 +22,6 @@ export type ParserType = 'react' | 'vue' | 'svelte';
22
22
  export type Extractor = (fileContents: string, fileName: string, options: ExtractOptions) => ExtractionResult;
23
23
  export type ExtractionResult = {
24
24
  keys: ExtractedKey[];
25
- warnings: Warning[];
25
+ warnings?: Warning[];
26
26
  };
27
- export type ExtractionResults = Map<string, {
28
- keys: ExtractedKey[];
29
- warnings: Warning[];
30
- }>;
27
+ export type ExtractionResults = Map<string, ExtractionResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolgee/cli",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "type": "module",
5
5
  "description": "A tool to interact with the Tolgee Platform through CLI",
6
6
  "repository": {
@@ -11,57 +11,63 @@
11
11
  "tolgee": "./dist/cli.js"
12
12
  },
13
13
  "scripts": {
14
- "build": "rimraf dist dist-types && tsc -p tsconfig.prod.json && node scripts/copyExtractorTypes.mjs",
14
+ "prepack": "npm run build",
15
+ "build": "premove dist dist-types && tsc -p tsconfig.prod.json && tsx scripts/copyExtractorTypes.ts",
15
16
  "test": "vitest run",
16
- "test:unit": "vitest run -c unit.vitest.config.ts --dir ./src/test/unit",
17
- "test:e2e": "vitest run --dir ./src/test/e2e",
18
- "test:package": "node scripts/validatePackage.js",
19
- "tolgee:start": "node scripts/startDocker.js",
17
+ "test:unit": "vitest run -c unit.vitest.config.ts --dir ./test/unit",
18
+ "test:e2e": "vitest run --dir ./test/e2e",
19
+ "test:package": "tsx ./scripts/validatePackage.ts",
20
+ "test:types": "tsc --noEmit",
21
+ "tolgee:start": "tsx ./scripts/startDocker.ts",
20
22
  "tolgee:stop": "docker stop tolgee_cli_e2e",
21
- "eslint": "eslint --max-warnings 0 --ext .ts --ext .js --ext .cjs ./src ./scripts vitest.config.ts",
22
- "prettier": "prettier --write ./src ./scripts vitest.config.ts",
23
- "run-dev": "cross-env NODE_OPTIONS=\"--import=./scripts/registerTsNode.js\" node ./src/cli.ts",
23
+ "eslint": "eslint --max-warnings 0",
24
+ "format": "eslint --fix",
25
+ "run-dev": "tsx ./src/cli.ts",
24
26
  "schema": "openapi-typescript http://localhost:22222/v3/api-docs/All%20Internal%20-%20for%20Tolgee%20Web%20application --output src/client/internal/schema.generated.ts",
25
27
  "release": "semantic-release",
26
- "config:type": "node scripts/configType.mjs"
28
+ "config:type": "tsx scripts/configType.ts"
27
29
  },
28
30
  "author": "Jan Cizmar",
29
31
  "license": "MIT",
30
32
  "dependencies": {
31
33
  "ansi-colors": "^4.1.3",
32
34
  "base32-decode": "^1.0.0",
33
- "commander": "^12.0.0",
34
- "cosmiconfig": "^8.2.0",
35
- "form-data": "^4.0.0",
36
- "glob": "^10.3.3",
35
+ "commander": "^12.1.0",
36
+ "cosmiconfig": "^9.0.0",
37
+ "fast-glob": "^3.3.2",
37
38
  "json5": "^2.2.3",
38
39
  "jsonschema": "^1.4.1",
39
- "openapi-fetch": "^0.9.7",
40
+ "openapi-fetch": "^0.10.6",
40
41
  "unescape-js": "^1.1.4",
41
- "vscode-oniguruma": "^1.7.0",
42
- "vscode-textmate": "^9.0.0",
43
- "yauzl": "^2.10.0"
42
+ "vscode-oniguruma": "^2.0.1",
43
+ "vscode-textmate": "^9.1.0",
44
+ "yauzl": "^3.1.3"
44
45
  },
45
46
  "devDependencies": {
47
+ "@eslint/js": "^9.8.0",
46
48
  "@semantic-release/changelog": "^6.0.3",
47
49
  "@semantic-release/git": "^10.0.1",
48
- "@types/node": "^20.4.5",
49
- "@types/yauzl": "^2.10.0",
50
- "@typescript-eslint/eslint-plugin": "^6.2.0",
51
- "@typescript-eslint/parser": "^6.2.0",
50
+ "@tsconfig/node18": "^18.2.4",
51
+ "@tsconfig/recommended": "^1.0.7",
52
+ "@types/eslint__js": "^8.42.3",
53
+ "@types/js-yaml": "^4.0.9",
54
+ "@types/node": "^22.1.0",
55
+ "@types/yauzl": "^2.10.3",
52
56
  "cross-env": "^7.0.3",
53
- "eslint": "^8.45.0",
54
- "eslint-plugin-prettier": "^5.0.0",
57
+ "eslint": "^9.8.0",
58
+ "eslint-config-prettier": "^9.1.0",
59
+ "eslint-plugin-prettier": "^5.2.1",
55
60
  "js-yaml": "^4.1.0",
56
- "json-schema-to-typescript": "^13.1.2",
57
- "openapi-typescript": "^6.7.6",
58
- "prettier": "^3.0.0",
59
- "rimraf": "^5.0.1",
60
- "semantic-release": "^21.0.7",
61
+ "json-schema-to-typescript": "^15.0.0",
62
+ "openapi-typescript": "^7.3.0",
63
+ "premove": "^4.0.0",
64
+ "prettier": "^3.3.3",
65
+ "semantic-release": "^24.0.0",
61
66
  "tree-cli": "^0.6.7",
62
- "ts-node": "^10.9.2",
63
- "typescript": "^5.4.5",
64
- "vitest": "^1.6.0"
67
+ "tsx": "^4.17.0",
68
+ "typescript": "^5.5.4",
69
+ "typescript-eslint": "^8.0.1",
70
+ "vitest": "^2.0.5"
65
71
  },
66
72
  "engines": {
67
73
  "node": ">= 18"
@@ -102,5 +108,10 @@
102
108
  "@semantic-release/npm",
103
109
  "@semantic-release/github"
104
110
  ]
111
+ },
112
+ "imports": {
113
+ "#cli/*.js": "./src/*.js",
114
+ "#tests/*.js": "./test/*.js",
115
+ "#tests/*.json": "./test/*.json"
105
116
  }
106
117
  }