gt 2.16.4 → 2.17.0-iris.0
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 +27 -0
- package/LICENSE.md +18 -102
- package/dist/api/downloadFileBatch.d.ts +6 -3
- package/dist/api/downloadFileBatch.js +10 -7
- package/dist/api/downloadFileBatch.js.map +1 -1
- package/dist/cli/base.d.ts +24 -2
- package/dist/cli/base.js +67 -20
- package/dist/cli/base.js.map +1 -1
- package/dist/cli/commands/download.js +9 -4
- package/dist/cli/commands/download.js.map +1 -1
- package/dist/cli/commands/enqueue.js +3 -2
- package/dist/cli/commands/enqueue.js.map +1 -1
- package/dist/cli/commands/setupProject.js +3 -3
- package/dist/cli/commands/setupProject.js.map +1 -1
- package/dist/cli/commands/stage.d.ts +2 -0
- package/dist/cli/commands/stage.js +6 -4
- package/dist/cli/commands/stage.js.map +1 -1
- package/dist/cli/commands/translate.d.ts +2 -1
- package/dist/cli/commands/translate.js +2 -1
- package/dist/cli/commands/translate.js.map +1 -1
- package/dist/cli/flags.d.ts +2 -2
- package/dist/cli/flags.js +6 -6
- package/dist/cli/flags.js.map +1 -1
- package/dist/cli/inline.d.ts +5 -1
- package/dist/cli/inline.js +15 -8
- package/dist/cli/inline.js.map +1 -1
- package/dist/cli/react.js +1 -1
- package/dist/cli/vue.d.ts +17 -0
- package/dist/cli/vue.js +42 -0
- package/dist/cli/vue.js.map +1 -0
- package/dist/console/logging.d.ts +2 -1
- package/dist/console/logging.js +4 -2
- package/dist/console/logging.js.map +1 -1
- package/dist/formats/files/collectFiles.d.ts +4 -0
- package/dist/formats/files/collectFiles.js +16 -4
- package/dist/formats/files/collectFiles.js.map +1 -1
- package/dist/fs/config/setupConfig.d.ts +3 -0
- package/dist/fs/config/setupConfig.js +2 -0
- package/dist/fs/config/setupConfig.js.map +1 -1
- package/dist/fs/determineFramework/index.d.ts +9 -1
- package/dist/fs/determineFramework/index.js +15 -3
- package/dist/fs/determineFramework/index.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/generated/version.js.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/next/parse/wrapContent.js +1 -1
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -1
- package/dist/react/jsx/utils/parseString.js +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.d.ts +0 -1
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +1 -1
- package/dist/react/parse/createInlineUpdates.js +1 -1
- package/dist/react/parse/wrapContent.js +1 -1
- package/dist/setup/wizard.js +1 -1
- package/dist/translation/extractInline.d.ts +12 -0
- package/dist/translation/extractInline.js +37 -0
- package/dist/translation/extractInline.js.map +1 -0
- package/dist/translation/parse.js +3 -2
- package/dist/translation/parse.js.map +1 -1
- package/dist/translation/validate.d.ts +1 -1
- package/dist/translation/validate.js +7 -3
- package/dist/translation/validate.js.map +1 -1
- package/dist/types/libraries.d.ts +4 -1
- package/dist/types/libraries.js +7 -1
- package/dist/types/libraries.js.map +1 -1
- package/dist/types/parsing.d.ts +5 -0
- package/dist/types/parsing.js.map +1 -1
- package/dist/workflows/download.d.ts +3 -1
- package/dist/workflows/download.js +3 -3
- package/dist/workflows/download.js.map +1 -1
- package/dist/workflows/enqueue.d.ts +3 -1
- package/dist/workflows/enqueue.js +2 -2
- package/dist/workflows/enqueue.js.map +1 -1
- package/dist/workflows/setupProject.d.ts +2 -1
- package/dist/workflows/setupProject.js +2 -2
- package/dist/workflows/setupProject.js.map +1 -1
- package/dist/workflows/stage.d.ts +3 -1
- package/dist/workflows/stage.js +2 -2
- package/dist/workflows/stage.js.map +1 -1
- package/dist/workflows/steps/DownloadStep.d.ts +3 -1
- package/dist/workflows/steps/DownloadStep.js +3 -2
- package/dist/workflows/steps/DownloadStep.js.map +1 -1
- package/dist/workflows/steps/PollJobsStep.d.ts +3 -1
- package/dist/workflows/steps/PollJobsStep.js +4 -2
- package/dist/workflows/steps/PollJobsStep.js.map +1 -1
- package/package.json +10 -8
package/dist/types/libraries.js
CHANGED
|
@@ -10,6 +10,7 @@ let Libraries = /* @__PURE__ */ function(Libraries) {
|
|
|
10
10
|
Libraries["GT_I18N"] = "gt-i18n";
|
|
11
11
|
Libraries["GT_REACT_CORE"] = "@generaltranslation/react-core";
|
|
12
12
|
Libraries["GT_TANSTACK_START"] = "gt-tanstack-start";
|
|
13
|
+
Libraries["GT_VUE"] = "gt-vue";
|
|
13
14
|
Libraries["GT_FLASK"] = "gt-flask";
|
|
14
15
|
Libraries["GT_FASTAPI"] = "gt-fastapi";
|
|
15
16
|
return Libraries;
|
|
@@ -38,6 +39,7 @@ const INLINE_LIBRARIES = [
|
|
|
38
39
|
"gt-react-native",
|
|
39
40
|
"@generaltranslation/react-core",
|
|
40
41
|
"gt-tanstack-start",
|
|
42
|
+
"gt-vue",
|
|
41
43
|
"gt-i18n",
|
|
42
44
|
"gt-flask",
|
|
43
45
|
"gt-fastapi"
|
|
@@ -45,6 +47,10 @@ const INLINE_LIBRARIES = [
|
|
|
45
47
|
function isInlineLibrary(lib) {
|
|
46
48
|
return INLINE_LIBRARIES.includes(lib);
|
|
47
49
|
}
|
|
50
|
+
/** Returns the framework-specific label for the shared inline GTJSON file. */
|
|
51
|
+
function getInlineElementsLabel(inlineLibrary) {
|
|
52
|
+
return inlineLibrary === "gt-vue" ? "Vue Elements" : "React Elements";
|
|
53
|
+
}
|
|
48
54
|
/**
|
|
49
55
|
* Libraries that support react primitives
|
|
50
56
|
*/
|
|
@@ -101,6 +107,6 @@ const GT_LIBRARIES_UPSTREAM = {
|
|
|
101
107
|
["gt-fastapi"]: ["gt-fastapi"]
|
|
102
108
|
};
|
|
103
109
|
//#endregion
|
|
104
|
-
export { GT_LIBRARIES, GT_LIBRARIES_UPSTREAM, INLINE_LIBRARIES, Libraries, NODE_LIBRARIES, PYTHON_LIBRARIES, REACT_LIBRARIES, isInlineLibrary, isPythonLibrary };
|
|
110
|
+
export { GT_LIBRARIES, GT_LIBRARIES_UPSTREAM, INLINE_LIBRARIES, Libraries, NODE_LIBRARIES, PYTHON_LIBRARIES, REACT_LIBRARIES, getInlineElementsLabel, isInlineLibrary, isPythonLibrary };
|
|
105
111
|
|
|
106
112
|
//# sourceMappingURL=libraries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libraries.js","names":[],"sources":["../../src/types/libraries.ts"],"sourcesContent":["/**\n * A list of all the libraries names supported by the CLI\n */\nexport enum Libraries {\n GT_REACT = 'gt-react',\n GT_NEXT = 'gt-next',\n GT_REACT_NATIVE = 'gt-react-native',\n GT_NODE = 'gt-node',\n GT_I18N = 'gt-i18n',\n GT_REACT_CORE = '@generaltranslation/react-core',\n GT_TANSTACK_START = 'gt-tanstack-start',\n GT_FLASK = 'gt-flask',\n GT_FASTAPI = 'gt-fastapi',\n}\n\n/**\n * A list of all the libraries that support the CLI\n */\nexport const GT_LIBRARIES = [\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_NODE,\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type GTLibrary = (typeof GT_LIBRARIES)[number];\n\n/**\n * Libraries that support inline translation\n */\nexport const INLINE_LIBRARIES = [\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n Libraries.GT_NODE,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n Libraries.GT_I18N,\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type InlineLibrary = (typeof INLINE_LIBRARIES)[number];\n\nexport function isInlineLibrary(lib: string): lib is InlineLibrary {\n return (INLINE_LIBRARIES as readonly string[]).includes(lib);\n}\n\n/**\n * Libraries that support react primitives\n */\nexport const REACT_LIBRARIES = [\n Libraries.GT_NEXT,\n Libraries.GT_REACT,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n] as const;\nexport type ReactLibrary = (typeof REACT_LIBRARIES)[number];\n\n/**\n * Node/server-side libraries\n */\nexport const NODE_LIBRARIES = [Libraries.GT_NODE, Libraries.GT_I18N] as const;\nexport type NodeLibrary = (typeof NODE_LIBRARIES)[number];\n\n/**\n * Python libraries\n */\nexport const PYTHON_LIBRARIES = [\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type PythonLibrary = (typeof PYTHON_LIBRARIES)[number];\n\nexport function isPythonLibrary(lib: string): lib is PythonLibrary {\n return (PYTHON_LIBRARIES as readonly string[]).includes(lib);\n}\n\n/**\n * A mapping of each library to their upstream dependencies for filtering imports\n */\nexport const GT_LIBRARIES_UPSTREAM: Record<GTLibrary, GTLibrary[]> = {\n [Libraries.GT_NEXT]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n ],\n [Libraries.GT_REACT]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_REACT_NATIVE, // allow for cross-library compatibility (gt-react/gt-react-native only)\n ],\n [Libraries.GT_REACT_NATIVE]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT, // allow for cross-library compatibility (gt-react/gt-react-native only)\n ],\n [Libraries.GT_NODE]: [Libraries.GT_I18N, Libraries.GT_NODE],\n [Libraries.GT_REACT_CORE]: [Libraries.GT_I18N, Libraries.GT_REACT_CORE],\n [Libraries.GT_TANSTACK_START]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_TANSTACK_START,\n ],\n [Libraries.GT_I18N]: [Libraries.GT_I18N],\n [Libraries.GT_FLASK]: [Libraries.GT_FLASK],\n [Libraries.GT_FASTAPI]: [Libraries.GT_FASTAPI],\n} as const;\n"],"mappings":";;;;AAGA,IAAY,YAAL,yBAAA,WAAA;AACL,WAAA,cAAA;AACA,WAAA,aAAA;AACA,WAAA,qBAAA;AACA,WAAA,aAAA;AACA,WAAA,aAAA;AACA,WAAA,mBAAA;AACA,WAAA,uBAAA;AACA,WAAA,cAAA;AACA,WAAA,gBAAA;;KACD;;;;AAKD,MAAa,eAAe;;;;;;;;;;CAU3B;;;;AAMD,MAAa,mBAAmB
|
|
1
|
+
{"version":3,"file":"libraries.js","names":[],"sources":["../../src/types/libraries.ts"],"sourcesContent":["/**\n * A list of all the libraries names supported by the CLI\n */\nexport enum Libraries {\n GT_REACT = 'gt-react',\n GT_NEXT = 'gt-next',\n GT_REACT_NATIVE = 'gt-react-native',\n GT_NODE = 'gt-node',\n GT_I18N = 'gt-i18n',\n GT_REACT_CORE = '@generaltranslation/react-core',\n GT_TANSTACK_START = 'gt-tanstack-start',\n GT_VUE = 'gt-vue',\n GT_FLASK = 'gt-flask',\n GT_FASTAPI = 'gt-fastapi',\n}\n\n/**\n * A list of all the libraries that support the CLI\n */\nexport const GT_LIBRARIES = [\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_NODE,\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type GTLibrary = (typeof GT_LIBRARIES)[number];\n\n/**\n * Libraries that support inline translation\n */\nexport const INLINE_LIBRARIES = [\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n Libraries.GT_NODE,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n Libraries.GT_VUE,\n Libraries.GT_I18N,\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type InlineLibrary = (typeof INLINE_LIBRARIES)[number];\n\nexport function isInlineLibrary(lib: string): lib is InlineLibrary {\n return (INLINE_LIBRARIES as readonly string[]).includes(lib);\n}\n\n/** Returns the framework-specific label for the shared inline GTJSON file. */\nexport function getInlineElementsLabel(\n inlineLibrary?: InlineLibrary\n): 'Vue Elements' | 'React Elements' {\n return inlineLibrary === Libraries.GT_VUE ? 'Vue Elements' : 'React Elements';\n}\n\n/**\n * Libraries that support react primitives\n */\nexport const REACT_LIBRARIES = [\n Libraries.GT_NEXT,\n Libraries.GT_REACT,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT_CORE,\n Libraries.GT_TANSTACK_START,\n] as const;\nexport type ReactLibrary = (typeof REACT_LIBRARIES)[number];\n\n/**\n * Node/server-side libraries\n */\nexport const NODE_LIBRARIES = [Libraries.GT_NODE, Libraries.GT_I18N] as const;\nexport type NodeLibrary = (typeof NODE_LIBRARIES)[number];\n\n/**\n * Python libraries\n */\nexport const PYTHON_LIBRARIES = [\n Libraries.GT_FLASK,\n Libraries.GT_FASTAPI,\n] as const;\nexport type PythonLibrary = (typeof PYTHON_LIBRARIES)[number];\n\nexport function isPythonLibrary(lib: string): lib is PythonLibrary {\n return (PYTHON_LIBRARIES as readonly string[]).includes(lib);\n}\n\n/**\n * A mapping of each library to their upstream dependencies for filtering imports\n */\nexport const GT_LIBRARIES_UPSTREAM: Record<GTLibrary, GTLibrary[]> = {\n [Libraries.GT_NEXT]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_NEXT,\n ],\n [Libraries.GT_REACT]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_REACT_NATIVE, // allow for cross-library compatibility (gt-react/gt-react-native only)\n ],\n [Libraries.GT_REACT_NATIVE]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT_NATIVE,\n Libraries.GT_REACT, // allow for cross-library compatibility (gt-react/gt-react-native only)\n ],\n [Libraries.GT_NODE]: [Libraries.GT_I18N, Libraries.GT_NODE],\n [Libraries.GT_REACT_CORE]: [Libraries.GT_I18N, Libraries.GT_REACT_CORE],\n [Libraries.GT_TANSTACK_START]: [\n Libraries.GT_I18N,\n Libraries.GT_REACT_CORE,\n Libraries.GT_REACT,\n Libraries.GT_TANSTACK_START,\n ],\n [Libraries.GT_I18N]: [Libraries.GT_I18N],\n [Libraries.GT_FLASK]: [Libraries.GT_FLASK],\n [Libraries.GT_FASTAPI]: [Libraries.GT_FASTAPI],\n} as const;\n"],"mappings":";;;;AAGA,IAAY,YAAL,yBAAA,WAAA;AACL,WAAA,cAAA;AACA,WAAA,aAAA;AACA,WAAA,qBAAA;AACA,WAAA,aAAA;AACA,WAAA,aAAA;AACA,WAAA,mBAAA;AACA,WAAA,uBAAA;AACA,WAAA,YAAA;AACA,WAAA,cAAA;AACA,WAAA,gBAAA;;KACD;;;;AAKD,MAAa,eAAe;;;;;;;;;;CAU3B;;;;AAMD,MAAa,mBAAmB;;;;;;;;;;;CAW/B;AAGD,SAAgB,gBAAgB,KAAmC;AACjE,QAAQ,iBAAuC,SAAS,IAAI;;;AAI9D,SAAgB,uBACd,eACmC;AACnC,QAAO,kBAAA,WAAqC,iBAAiB;;;;;AAM/D,MAAa,kBAAkB;;;;;;CAM9B;;;;AAMD,MAAa,iBAAiB,CAAA,WAAA,UAAsC;;;;AAMpE,MAAa,mBAAmB,CAAA,YAAA,aAG/B;AAGD,SAAgB,gBAAgB,KAAmC;AACjE,QAAQ,iBAAuC,SAAS,IAAI;;;;;AAM9D,MAAa,wBAAwD;cAC9C;;;;;EAKpB;eACqB;;;;;EAKrB;sBAC4B;;;;;EAK5B;cACoB,CAAA,WAAA,UAAsC;qCAChC,CAAA,WAAA,iCAA4C;wBACxC;;;;;EAK9B;cACoB,CAAA,UAAmB;eAClB,CAAA,WAAoB;iBAClB,CAAA,aAAsB;CAC/C"}
|
package/dist/types/parsing.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VueCompilerOptions } from '@generaltranslation/vue-extractor/types';
|
|
1
2
|
import type { SupportedFileExtension } from './index.js';
|
|
2
3
|
/**
|
|
3
4
|
* For monorepo projects, checking for extra exports fields in resolved internal packages.
|
|
@@ -34,6 +35,8 @@ export type BaseParsingFlags = Record<string, unknown>;
|
|
|
34
35
|
* @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.
|
|
35
36
|
* @property {boolean} enableAutoJsxInjection - Whether to enable auto-jsx injection for the internal <_T> and <_Var> components.
|
|
36
37
|
* @property {boolean} legacyGtReactImportSource - Whether compiler-injected gt-react imports should use gt-react/browser.
|
|
38
|
+
* @property {string} viteConfigPath - Vite config used to resolve hash-affecting Vue compiler behavior.
|
|
39
|
+
* @property {VueCompilerOptions} vueCompilerOptions - Hash-affecting Vue template compiler options.
|
|
37
40
|
*/
|
|
38
41
|
export type GTParsingFlags = BaseParsingFlags & {
|
|
39
42
|
autoderive: boolean | {
|
|
@@ -43,6 +46,8 @@ export type GTParsingFlags = BaseParsingFlags & {
|
|
|
43
46
|
includeSourceCodeContext: boolean;
|
|
44
47
|
enableAutoJsxInjection: boolean;
|
|
45
48
|
legacyGtReactImportSource: boolean;
|
|
49
|
+
viteConfigPath?: string;
|
|
50
|
+
vueCompilerOptions?: VueCompilerOptions;
|
|
46
51
|
};
|
|
47
52
|
/**
|
|
48
53
|
* Resolves the autoderive config value into separate jsx and strings flags.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.js","names":[],"sources":["../../src/types/parsing.ts"],"sourcesContent":["import type { SupportedFileExtension } from './index.js';\n\n/**\n * For monorepo projects, checking for extra exports fields in resolved internal packages.\n * For instance, an exported path may be labeled as 'browser' or 'module' or 'default'.\n * These can resolve to different files in the compiled package. This helps us know\n * which files to check when we do resolution.\n *\n * @property conditionNames - The condition names to check for in the resolved package.\n *\n * @example\n * {\n * conditionNames: ['development', 'browser', 'module', 'import', 'require', 'default']\n * }\n */\nexport type ParsingConfigOptions = {\n conditionNames: string[];\n};\n\n/**\n * Base parsing flags for all files.\n * Currently no supported properties\n *\n * Future ideas for flags:\n * - flag for extraction of file name\n * - flag for extraction of last modified timestamp\n * - flag for extraction of git history\n */\nexport type BaseParsingFlags = Record<string, unknown>;\n\n/**\n * Flags for parsing content. Not to be confused with ParsingConfig which helps us enable/disable\n * parsing features depending on the function being parsed. Parsing flags is for users to override\n * some of these defaults or enable/disable other features.\n *\n * @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both JSX and strings. An object enables selectively.\n * @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.\n * @property {boolean} enableAutoJsxInjection - Whether to enable auto-jsx injection for the internal <_T> and <_Var> components.\n * @property {boolean} legacyGtReactImportSource - Whether compiler-injected gt-react imports should use gt-react/browser.\n */\nexport type GTParsingFlags = BaseParsingFlags & {\n autoderive: boolean | { jsx?: boolean; strings?: boolean };\n includeSourceCodeContext: boolean;\n enableAutoJsxInjection: boolean;\n legacyGtReactImportSource: boolean;\n};\n\n/**\n * Resolves the autoderive config value into separate jsx and strings flags.\n * - `true` enables both (backward compatible)\n * - `false` disables both (backward compatible)\n * - `{ jsx?: boolean; strings?: boolean }` enables selectively (missing keys default to false)\n */\nexport function resolveAutoderive(\n value: boolean | { jsx?: boolean; strings?: boolean } | undefined\n): { jsx: boolean; strings: boolean } {\n if (value === undefined || typeof value === 'boolean') {\n return { jsx: !!value, strings: !!value };\n }\n return { jsx: value.jsx ?? false, strings: value.strings ?? false };\n}\n\n/**\n * Flags for parsing content with each filetype having its own flags\n * This is really a helper type that helps us map across filetypes\n */\nexport type ParseFlagsByFileType = {\n [K in SupportedFileExtension]?: BaseParsingFlags;\n};\n"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"parsing.js","names":[],"sources":["../../src/types/parsing.ts"],"sourcesContent":["import type { VueCompilerOptions } from '@generaltranslation/vue-extractor/types';\nimport type { SupportedFileExtension } from './index.js';\n\n/**\n * For monorepo projects, checking for extra exports fields in resolved internal packages.\n * For instance, an exported path may be labeled as 'browser' or 'module' or 'default'.\n * These can resolve to different files in the compiled package. This helps us know\n * which files to check when we do resolution.\n *\n * @property conditionNames - The condition names to check for in the resolved package.\n *\n * @example\n * {\n * conditionNames: ['development', 'browser', 'module', 'import', 'require', 'default']\n * }\n */\nexport type ParsingConfigOptions = {\n conditionNames: string[];\n};\n\n/**\n * Base parsing flags for all files.\n * Currently no supported properties\n *\n * Future ideas for flags:\n * - flag for extraction of file name\n * - flag for extraction of last modified timestamp\n * - flag for extraction of git history\n */\nexport type BaseParsingFlags = Record<string, unknown>;\n\n/**\n * Flags for parsing content. Not to be confused with ParsingConfig which helps us enable/disable\n * parsing features depending on the function being parsed. Parsing flags is for users to override\n * some of these defaults or enable/disable other features.\n *\n * @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both JSX and strings. An object enables selectively.\n * @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.\n * @property {boolean} enableAutoJsxInjection - Whether to enable auto-jsx injection for the internal <_T> and <_Var> components.\n * @property {boolean} legacyGtReactImportSource - Whether compiler-injected gt-react imports should use gt-react/browser.\n * @property {string} viteConfigPath - Vite config used to resolve hash-affecting Vue compiler behavior.\n * @property {VueCompilerOptions} vueCompilerOptions - Hash-affecting Vue template compiler options.\n */\nexport type GTParsingFlags = BaseParsingFlags & {\n autoderive: boolean | { jsx?: boolean; strings?: boolean };\n includeSourceCodeContext: boolean;\n enableAutoJsxInjection: boolean;\n legacyGtReactImportSource: boolean;\n viteConfigPath?: string;\n vueCompilerOptions?: VueCompilerOptions;\n};\n\n/**\n * Resolves the autoderive config value into separate jsx and strings flags.\n * - `true` enables both (backward compatible)\n * - `false` disables both (backward compatible)\n * - `{ jsx?: boolean; strings?: boolean }` enables selectively (missing keys default to false)\n */\nexport function resolveAutoderive(\n value: boolean | { jsx?: boolean; strings?: boolean } | undefined\n): { jsx: boolean; strings: boolean } {\n if (value === undefined || typeof value === 'boolean') {\n return { jsx: !!value, strings: !!value };\n }\n return { jsx: value.jsx ?? false, strings: value.strings ?? false };\n}\n\n/**\n * Flags for parsing content with each filetype having its own flags\n * This is really a helper type that helps us map across filetypes\n */\nexport type ParseFlagsByFileType = {\n [K in SupportedFileExtension]?: BaseParsingFlags;\n};\n"],"mappings":";;;;;;;AA0DA,SAAgB,kBACd,OACoC;AACpC,KAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAC1C,QAAO;EAAE,KAAK,CAAC,CAAC;EAAO,SAAS,CAAC,CAAC;EAAO;AAE3C,QAAO;EAAE,KAAK,MAAM,OAAO;EAAO,SAAS,MAAM,WAAW;EAAO"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Settings } from '../types/index.js';
|
|
2
2
|
import { EnqueueFilesResult } from 'generaltranslation/types';
|
|
3
3
|
import { BranchData } from '../types/branch.js';
|
|
4
|
+
import type { InlineLibrary } from '../types/libraries.js';
|
|
4
5
|
export type FileTranslationData = {
|
|
5
6
|
[fileId: string]: {
|
|
6
7
|
versionId: string;
|
|
@@ -21,7 +22,7 @@ export type FileTranslationData = {
|
|
|
21
22
|
* @param forceDownload - Whether to force download even if file exists
|
|
22
23
|
* @returns True if all translations are downloaded successfully, false otherwise
|
|
23
24
|
*/
|
|
24
|
-
export declare function runDownloadWorkflow({ fileVersionData, jobData, branchData, locales, timeoutDuration, resolveOutputPath, options, forceRetranslation, forceDownload, }: {
|
|
25
|
+
export declare function runDownloadWorkflow({ fileVersionData, jobData, branchData, locales, timeoutDuration, resolveOutputPath, options, inlineLibrary, forceRetranslation, forceDownload, }: {
|
|
25
26
|
fileVersionData: FileTranslationData;
|
|
26
27
|
jobData: EnqueueFilesResult | undefined;
|
|
27
28
|
branchData: BranchData | undefined;
|
|
@@ -29,6 +30,7 @@ export declare function runDownloadWorkflow({ fileVersionData, jobData, branchDa
|
|
|
29
30
|
timeoutDuration: number;
|
|
30
31
|
resolveOutputPath: (sourcePath: string, locale: string) => string | null;
|
|
31
32
|
options: Settings;
|
|
33
|
+
inlineLibrary?: InlineLibrary;
|
|
32
34
|
forceRetranslation?: boolean;
|
|
33
35
|
forceDownload?: boolean;
|
|
34
36
|
}): Promise<boolean>;
|
|
@@ -22,7 +22,7 @@ import path from "node:path";
|
|
|
22
22
|
* @param forceDownload - Whether to force download even if file exists
|
|
23
23
|
* @returns True if all translations are downloaded successfully, false otherwise
|
|
24
24
|
*/
|
|
25
|
-
async function runDownloadWorkflow({ fileVersionData, jobData, branchData, locales, timeoutDuration, resolveOutputPath, options, forceRetranslation, forceDownload }) {
|
|
25
|
+
async function runDownloadWorkflow({ fileVersionData, jobData, branchData, locales, timeoutDuration, resolveOutputPath, options, inlineLibrary, forceRetranslation, forceDownload }) {
|
|
26
26
|
if (!branchData) {
|
|
27
27
|
const branchResult = await new BranchStep(gt, options).run();
|
|
28
28
|
if (!branchResult) return logErrorAndExit(branchResolutionError);
|
|
@@ -41,7 +41,7 @@ async function runDownloadWorkflow({ fileVersionData, jobData, branchData, local
|
|
|
41
41
|
};
|
|
42
42
|
let pollTimedOut = false;
|
|
43
43
|
if (jobData) {
|
|
44
|
-
const pollResult = await new PollTranslationJobsStep(gt).run({
|
|
44
|
+
const pollResult = await new PollTranslationJobsStep(gt, inlineLibrary).run({
|
|
45
45
|
fileTracker,
|
|
46
46
|
fileQueryData,
|
|
47
47
|
jobData,
|
|
@@ -65,7 +65,7 @@ async function runDownloadWorkflow({ fileVersionData, jobData, branchData, local
|
|
|
65
65
|
resolveOutputPath,
|
|
66
66
|
options
|
|
67
67
|
});
|
|
68
|
-
const downloadResult = await new DownloadTranslationsStep(gt, settingsForBranch).run({
|
|
68
|
+
const downloadResult = await new DownloadTranslationsStep(gt, settingsForBranch, inlineLibrary).run({
|
|
69
69
|
fileTracker,
|
|
70
70
|
resolveOutputPath,
|
|
71
71
|
forceDownload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","names":[],"sources":["../../src/workflows/download.ts"],"sourcesContent":["import path from 'node:path';\nimport { Settings } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult } from 'generaltranslation/types';\nimport { clearLocaleDirs } from '../fs/clearLocaleDirs.js';\nimport {\n FileStatusTracker,\n PollTranslationJobsStep,\n} from './steps/PollJobsStep.js';\nimport { DownloadTranslationsStep } from './steps/DownloadStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { branchResolutionError } from '../console/index.js';\nimport { logErrorAndExit } from '../console/logging.js';\nimport { logger } from '../console/logger.js';\nimport { recordWarning } from '../state/translateWarnings.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { FileProperties } from '../types/files.js';\nimport chalk from 'chalk';\n\nexport type FileTranslationData = {\n [fileId: string]: {\n versionId: string;\n fileName: string;\n /** Source component count for GTJSON files */\n componentCount?: number;\n };\n};\n\n/**\n * Checks the status of translations and downloads them using a workflow pattern\n * @param fileVersionData - Mapping of file IDs to their version and name information\n * @param jobData - Optional job data from enqueue operation\n * @param locales - The locales to wait for\n * @param timeoutDuration - The timeout duration for the wait in seconds\n * @param resolveOutputPath - Function to resolve the output path for a given source path and locale\n * @param options - Settings configuration\n * @param forceRetranslation - Whether to force retranslation\n * @param forceDownload - Whether to force download even if file exists\n * @returns True if all translations are downloaded successfully, false otherwise\n */\nexport async function runDownloadWorkflow({\n fileVersionData,\n jobData,\n branchData,\n locales,\n timeoutDuration,\n resolveOutputPath,\n options,\n forceRetranslation,\n forceDownload,\n}: {\n fileVersionData: FileTranslationData;\n jobData: EnqueueFilesResult | undefined;\n branchData: BranchData | undefined;\n locales: string[];\n timeoutDuration: number;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n options: Settings;\n forceRetranslation?: boolean;\n forceDownload?: boolean;\n}): Promise<boolean> {\n if (!branchData) {\n // Run the branch step\n const branchStep = new BranchStep(gt, options);\n const branchResult = await branchStep.run();\n if (!branchResult) {\n return logErrorAndExit(branchResolutionError);\n }\n branchData = branchResult;\n }\n // readLockfile uses _branchId to select branch-specific lockfile entries.\n // Keep it on a scoped copy so the caller's settings object is not mutated.\n const settingsForBranch: Settings = {\n ...options,\n _branchId: branchData.currentBranch.id,\n };\n // Prepare the query data\n const fileQueryData = prepareFileQueryData(\n fileVersionData,\n locales,\n branchData\n );\n\n // Initialize download status\n const fileTracker: FileStatusTracker = {\n completed: new Map<string, FileProperties>(),\n inProgress: new Map<string, FileProperties>(),\n failed: new Map<string, FileProperties>(),\n skipped: new Map<string, FileProperties>(),\n };\n\n // Step 1: Poll translation jobs if jobData exists\n let pollTimedOut = false;\n if (jobData) {\n const pollStep = new PollTranslationJobsStep(gt);\n const pollResult = await pollStep.run({\n fileTracker,\n fileQueryData,\n jobData,\n timeoutDuration,\n forceRetranslation,\n });\n\n if (pollResult.fileTracker.failed.size > 0) {\n logger.error(\n `${chalk.red(`${pollResult.fileTracker.failed.size} file(s) failed to translate:`)}\\n${Array.from(\n pollResult.fileTracker.failed.entries()\n )\n .map(([, value]) => `- ${value.fileName}`)\n .join('\\n')}`\n );\n for (const [, value] of pollResult.fileTracker.failed) {\n recordWarning(\n 'failed_translation',\n value.fileName,\n `Failed to translate for locale ${value.locale}`\n );\n }\n\n // If all files failed translation, exit early\n if (pollResult.fileTracker.completed.size === 0) {\n return false;\n }\n }\n\n // Even if polling timed out, still download whatever completed successfully\n if (!pollResult.success) {\n pollTimedOut = true;\n if (pollResult.fileTracker.completed.size > 0) {\n logger.warn(\n chalk.yellow(\n `Timed out, but ${pollResult.fileTracker.completed.size} translation(s) completed successfully. Downloading completed files...`\n )\n );\n } else {\n return false;\n }\n }\n } else {\n for (const file of fileQueryData) {\n // Staging - assume all files are completed\n fileTracker.completed.set(\n `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`,\n file\n );\n }\n }\n\n await clearCompletedLocaleDirs({\n fileTracker,\n locales,\n resolveOutputPath,\n options,\n });\n\n // Step 2: Download translations\n const downloadStep = new DownloadTranslationsStep(gt
|
|
1
|
+
{"version":3,"file":"download.js","names":[],"sources":["../../src/workflows/download.ts"],"sourcesContent":["import path from 'node:path';\nimport { Settings } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult } from 'generaltranslation/types';\nimport { clearLocaleDirs } from '../fs/clearLocaleDirs.js';\nimport {\n FileStatusTracker,\n PollTranslationJobsStep,\n} from './steps/PollJobsStep.js';\nimport { DownloadTranslationsStep } from './steps/DownloadStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { branchResolutionError } from '../console/index.js';\nimport { logErrorAndExit } from '../console/logging.js';\nimport { logger } from '../console/logger.js';\nimport { recordWarning } from '../state/translateWarnings.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { FileProperties } from '../types/files.js';\nimport chalk from 'chalk';\nimport type { InlineLibrary } from '../types/libraries.js';\n\nexport type FileTranslationData = {\n [fileId: string]: {\n versionId: string;\n fileName: string;\n /** Source component count for GTJSON files */\n componentCount?: number;\n };\n};\n\n/**\n * Checks the status of translations and downloads them using a workflow pattern\n * @param fileVersionData - Mapping of file IDs to their version and name information\n * @param jobData - Optional job data from enqueue operation\n * @param locales - The locales to wait for\n * @param timeoutDuration - The timeout duration for the wait in seconds\n * @param resolveOutputPath - Function to resolve the output path for a given source path and locale\n * @param options - Settings configuration\n * @param forceRetranslation - Whether to force retranslation\n * @param forceDownload - Whether to force download even if file exists\n * @returns True if all translations are downloaded successfully, false otherwise\n */\nexport async function runDownloadWorkflow({\n fileVersionData,\n jobData,\n branchData,\n locales,\n timeoutDuration,\n resolveOutputPath,\n options,\n inlineLibrary,\n forceRetranslation,\n forceDownload,\n}: {\n fileVersionData: FileTranslationData;\n jobData: EnqueueFilesResult | undefined;\n branchData: BranchData | undefined;\n locales: string[];\n timeoutDuration: number;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n options: Settings;\n inlineLibrary?: InlineLibrary;\n forceRetranslation?: boolean;\n forceDownload?: boolean;\n}): Promise<boolean> {\n if (!branchData) {\n // Run the branch step\n const branchStep = new BranchStep(gt, options);\n const branchResult = await branchStep.run();\n if (!branchResult) {\n return logErrorAndExit(branchResolutionError);\n }\n branchData = branchResult;\n }\n // readLockfile uses _branchId to select branch-specific lockfile entries.\n // Keep it on a scoped copy so the caller's settings object is not mutated.\n const settingsForBranch: Settings = {\n ...options,\n _branchId: branchData.currentBranch.id,\n };\n // Prepare the query data\n const fileQueryData = prepareFileQueryData(\n fileVersionData,\n locales,\n branchData\n );\n\n // Initialize download status\n const fileTracker: FileStatusTracker = {\n completed: new Map<string, FileProperties>(),\n inProgress: new Map<string, FileProperties>(),\n failed: new Map<string, FileProperties>(),\n skipped: new Map<string, FileProperties>(),\n };\n\n // Step 1: Poll translation jobs if jobData exists\n let pollTimedOut = false;\n if (jobData) {\n const pollStep = new PollTranslationJobsStep(gt, inlineLibrary);\n const pollResult = await pollStep.run({\n fileTracker,\n fileQueryData,\n jobData,\n timeoutDuration,\n forceRetranslation,\n });\n\n if (pollResult.fileTracker.failed.size > 0) {\n logger.error(\n `${chalk.red(`${pollResult.fileTracker.failed.size} file(s) failed to translate:`)}\\n${Array.from(\n pollResult.fileTracker.failed.entries()\n )\n .map(([, value]) => `- ${value.fileName}`)\n .join('\\n')}`\n );\n for (const [, value] of pollResult.fileTracker.failed) {\n recordWarning(\n 'failed_translation',\n value.fileName,\n `Failed to translate for locale ${value.locale}`\n );\n }\n\n // If all files failed translation, exit early\n if (pollResult.fileTracker.completed.size === 0) {\n return false;\n }\n }\n\n // Even if polling timed out, still download whatever completed successfully\n if (!pollResult.success) {\n pollTimedOut = true;\n if (pollResult.fileTracker.completed.size > 0) {\n logger.warn(\n chalk.yellow(\n `Timed out, but ${pollResult.fileTracker.completed.size} translation(s) completed successfully. Downloading completed files...`\n )\n );\n } else {\n return false;\n }\n }\n } else {\n for (const file of fileQueryData) {\n // Staging - assume all files are completed\n fileTracker.completed.set(\n `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`,\n file\n );\n }\n }\n\n await clearCompletedLocaleDirs({\n fileTracker,\n locales,\n resolveOutputPath,\n options,\n });\n\n // Step 2: Download translations\n const downloadStep = new DownloadTranslationsStep(\n gt,\n settingsForBranch,\n inlineLibrary\n );\n const downloadResult = await downloadStep.run({\n fileTracker,\n resolveOutputPath,\n forceDownload,\n });\n\n // If polling timed out, report failure even though we downloaded what we could\n if (pollTimedOut) {\n return false;\n }\n\n return downloadResult;\n}\n\nasync function clearCompletedLocaleDirs({\n fileTracker,\n locales,\n resolveOutputPath,\n options,\n}: {\n fileTracker: FileStatusTracker;\n locales: string[];\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n options: Settings;\n}): Promise<void> {\n if (\n options.options?.experimentalClearLocaleDirs !== true ||\n fileTracker.completed.size === 0\n ) {\n return;\n }\n\n const translatedFiles = new Set(\n Array.from(fileTracker.completed.values())\n .map((file) => {\n const outputPath = resolveOutputPath(file.fileName, file.locale);\n // Only clear if the output path is different from the source.\n return outputPath !== null && outputPath !== file.fileName\n ? outputPath\n : null;\n })\n .filter((filePath): filePath is string => filePath !== null)\n );\n\n if (translatedFiles.size === 0) return;\n\n const cwd = path.dirname(options.config);\n\n await clearLocaleDirs(\n translatedFiles,\n locales,\n options.options?.clearLocaleDirsExclude,\n cwd\n );\n}\n\n/**\n * Prepares the file query data from input data and locales\n */\nfunction prepareFileQueryData(\n fileVersionData: FileTranslationData,\n locales: string[],\n branchData: BranchData\n): FileProperties[] {\n const fileQueryData: FileProperties[] = [];\n\n for (const fileId in fileVersionData) {\n for (const locale of locales) {\n fileQueryData.push({\n versionId: fileVersionData[fileId].versionId,\n fileName: fileVersionData[fileId].fileName,\n fileId,\n locale,\n branchId: branchData.currentBranch.id,\n componentCount: fileVersionData[fileId].componentCount,\n });\n }\n }\n\n return fileQueryData;\n}\n"],"mappings":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AAK,SAAS,GAAG,KAAK,OAAO,GAAG,KAAK,UAAU,GAAG,KAAK,UAC1D,KACD;AAIL,OAAM,yBAAyB;EAC7B;EACA;EACA;EACA;EACD,CAAC;CAQF,MAAM,iBAAiB,MAAM,IALJ,yBACvB,IACA,mBACA,cAEuC,CAAC,IAAI;EAC5C;EACA;EACA;EACD,CAAC;AAGF,KAAI,aACF,QAAO;AAGT,QAAO;;AAGT,eAAe,yBAAyB,EACtC,aACA,SACA,mBACA,WAMgB;AAChB,KACE,QAAQ,SAAS,gCAAgC,QACjD,YAAY,UAAU,SAAS,EAE/B;CAGF,MAAM,kBAAkB,IAAI,IAC1B,MAAM,KAAK,YAAY,UAAU,QAAQ,CAAC,CACvC,KAAK,SAAS;EACb,MAAM,aAAa,kBAAkB,KAAK,UAAU,KAAK,OAAO;AAEhE,SAAO,eAAe,QAAQ,eAAe,KAAK,WAC9C,aACA;GACJ,CACD,QAAQ,aAAiC,aAAa,KAAK,CAC/D;AAED,KAAI,gBAAgB,SAAS,EAAG;CAEhC,MAAM,MAAM,KAAK,QAAQ,QAAQ,OAAO;AAExC,OAAM,gBACJ,iBACA,SACA,QAAQ,SAAS,wBACjB,IACD;;;;;AAMH,SAAS,qBACP,iBACA,SACA,YACkB;CAClB,MAAM,gBAAkC,EAAE;AAE1C,MAAK,MAAM,UAAU,gBACnB,MAAK,MAAM,UAAU,QACnB,eAAc,KAAK;EACjB,WAAW,gBAAgB,QAAQ;EACnC,UAAU,gBAAgB,QAAQ;EAClC;EACA;EACA,UAAU,WAAW,cAAc;EACnC,gBAAgB,gBAAgB,QAAQ;EACzC,CAAC;AAIN,QAAO"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Settings, TranslateFlags } from '../types/index.js';
|
|
2
2
|
import { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';
|
|
3
|
+
import type { InlineLibrary } from '../types/libraries.js';
|
|
3
4
|
/**
|
|
4
5
|
* Enqueues translations for a given set of files
|
|
5
6
|
* - Only enqueues uploaded files
|
|
@@ -10,8 +11,9 @@ import { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';
|
|
|
10
11
|
* @param {Settings} settings - The settings for the enqueue operation
|
|
11
12
|
* @returns {Promise<EnqueueFilesResult>} The enqueue result
|
|
12
13
|
*/
|
|
13
|
-
export declare function runEnqueueWorkflow({ files, options, settings, }: {
|
|
14
|
+
export declare function runEnqueueWorkflow({ files, options, settings, inlineLibrary, }: {
|
|
14
15
|
files: FileToUpload[];
|
|
15
16
|
options: TranslateFlags;
|
|
16
17
|
settings: Settings;
|
|
18
|
+
inlineLibrary?: InlineLibrary;
|
|
17
19
|
}): Promise<EnqueueFilesResult>;
|
|
@@ -17,9 +17,9 @@ import { filterFilesForEnqueue } from "./utils/filterFilesForEnqueue.js";
|
|
|
17
17
|
* @param {Settings} settings - The settings for the enqueue operation
|
|
18
18
|
* @returns {Promise<EnqueueFilesResult>} The enqueue result
|
|
19
19
|
*/
|
|
20
|
-
async function runEnqueueWorkflow({ files, options, settings }) {
|
|
20
|
+
async function runEnqueueWorkflow({ files, options, settings, inlineLibrary }) {
|
|
21
21
|
try {
|
|
22
|
-
logCollectedFiles(files);
|
|
22
|
+
logCollectedFiles(files, void 0, inlineLibrary);
|
|
23
23
|
logger.debug("Files: " + JSON.stringify(files, null, 2));
|
|
24
24
|
await syncFonts(settings);
|
|
25
25
|
const branchStep = new BranchStep(gt, settings);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enqueue.js","names":[],"sources":["../../src/workflows/enqueue.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { logger } from '../console/logger.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\nimport { syncFonts } from './utils/syncFonts.js';\n\n/**\n * Enqueues translations for a given set of files\n * - Only enqueues uploaded files\n * - Don't have to worry about double enqueuing files because dedupe on API side\n *\n * @param {FileTranslationData} fileVersionData - The file version data\n * @param {TranslateFlags} options - The options for the enqueue operation\n * @param {Settings} settings - The settings for the enqueue operation\n * @returns {Promise<EnqueueFilesResult>} The enqueue result\n */\nexport async function runEnqueueWorkflow({\n files,\n options,\n settings,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n}): Promise<EnqueueFilesResult> {\n try {\n // Log files to be enqueued\n logCollectedFiles(files);\n\n logger.debug('Files: ' + JSON.stringify(files, null, 2));\n\n // Sync fonts before enqueueing so the translation jobs (e.g. Lottie\n // layout refinement) can use them instead of fallback fonts.\n await syncFonts(settings);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n // const queryFileDataStep = new QueryFileDataStep(gt);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // (1) run the branch step\n const branchData = await branchStep.run();\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n logger.debug('Branch data: ' + JSON.stringify(branchData, null, 2));\n\n // (2) Enqueue the files\n const filesWithBranch = files.map((files) => ({\n branchId: branchData.currentBranch.id,\n ...files,\n }));\n const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({\n gt,\n files: filesWithBranch,\n locales: settings.locales,\n force: options.force,\n });\n if (skippedFiles.length > 0) {\n logger.info(\n `Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? '' : 's'}`\n );\n }\n\n const enqueueResult = await enqueueStep.run(filesToEnqueue);\n\n logger.debug('Enqueue result: ' + JSON.stringify(enqueueResult, null, 2));\n\n logEnqueueResult(\n enqueueResult,\n filesToEnqueue.length === 0 ? files.length : filesToEnqueue.length\n );\n return enqueueResult;\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Translations could not be enqueued. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n\n// ----- Helper functions ----- //\n\n/**\n * Logs the enqueue result\n * @param enqueueResult - The enqueue result\n * @returns void\n */\nfunction logEnqueueResult(\n enqueueResult: EnqueueFilesResult,\n fileCount: number\n): void {\n if (Object.keys(enqueueResult.jobData).length === 0) {\n logger.success(\n `All ${fileCount} ${fileCount === 1 ? 'file' : 'files'} already translated. 0 files enqueued.`\n );\n } else {\n logger.success(enqueueResult.message);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"enqueue.js","names":[],"sources":["../../src/workflows/enqueue.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { logger } from '../console/logger.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\nimport { syncFonts } from './utils/syncFonts.js';\nimport type { InlineLibrary } from '../types/libraries.js';\n\n/**\n * Enqueues translations for a given set of files\n * - Only enqueues uploaded files\n * - Don't have to worry about double enqueuing files because dedupe on API side\n *\n * @param {FileTranslationData} fileVersionData - The file version data\n * @param {TranslateFlags} options - The options for the enqueue operation\n * @param {Settings} settings - The settings for the enqueue operation\n * @returns {Promise<EnqueueFilesResult>} The enqueue result\n */\nexport async function runEnqueueWorkflow({\n files,\n options,\n settings,\n inlineLibrary,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n inlineLibrary?: InlineLibrary;\n}): Promise<EnqueueFilesResult> {\n try {\n // Log files to be enqueued\n logCollectedFiles(files, undefined, inlineLibrary);\n\n logger.debug('Files: ' + JSON.stringify(files, null, 2));\n\n // Sync fonts before enqueueing so the translation jobs (e.g. Lottie\n // layout refinement) can use them instead of fallback fonts.\n await syncFonts(settings);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n // const queryFileDataStep = new QueryFileDataStep(gt);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // (1) run the branch step\n const branchData = await branchStep.run();\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n logger.debug('Branch data: ' + JSON.stringify(branchData, null, 2));\n\n // (2) Enqueue the files\n const filesWithBranch = files.map((files) => ({\n branchId: branchData.currentBranch.id,\n ...files,\n }));\n const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({\n gt,\n files: filesWithBranch,\n locales: settings.locales,\n force: options.force,\n });\n if (skippedFiles.length > 0) {\n logger.info(\n `Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? '' : 's'}`\n );\n }\n\n const enqueueResult = await enqueueStep.run(filesToEnqueue);\n\n logger.debug('Enqueue result: ' + JSON.stringify(enqueueResult, null, 2));\n\n logEnqueueResult(\n enqueueResult,\n filesToEnqueue.length === 0 ? files.length : filesToEnqueue.length\n );\n return enqueueResult;\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Translations could not be enqueued. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n\n// ----- Helper functions ----- //\n\n/**\n * Logs the enqueue result\n * @param enqueueResult - The enqueue result\n * @returns void\n */\nfunction logEnqueueResult(\n enqueueResult: EnqueueFilesResult,\n fileCount: number\n): void {\n if (Object.keys(enqueueResult.jobData).length === 0) {\n logger.success(\n `All ${fileCount} ${fileCount === 1 ? 'file' : 'files'} already translated. 0 files enqueued.`\n );\n } else {\n logger.success(enqueueResult.message);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,eAAsB,mBAAmB,EACvC,OACA,SACA,UACA,iBAM8B;AAC9B,KAAI;AAEF,oBAAkB,OAAO,KAAA,GAAW,cAAc;AAElD,SAAO,MAAM,YAAY,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC;AAIxD,QAAM,UAAU,SAAS;EAGzB,MAAM,aAAa,IAAI,WAAW,IAAI,SAAS;EAE/C,MAAM,cAAc,IAAI,YAAY,IAAI,UAAU,QAAQ,MAAM;EAGhE,MAAM,aAAa,MAAM,WAAW,KAAK;AACzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;AAE/C,SAAO,MAAM,kBAAkB,KAAK,UAAU,YAAY,MAAM,EAAE,CAAC;EAOnE,MAAM,EAAE,gBAAgB,iBAAiB,MAAM,sBAAsB;GACnE;GACA,OANsB,MAAM,KAAK,WAAW;IAC5C,UAAU,WAAW,cAAc;IACnC,GAAG;IACJ,EAGuB;GACtB,SAAS,SAAS;GAClB,OAAO,QAAQ;GAChB,CAAC;AACF,MAAI,aAAa,SAAS,EACxB,QAAO,KACL,uBAAuB,aAAa,OAAO,0BAA0B,aAAa,WAAW,IAAI,KAAK,MACvG;EAGH,MAAM,gBAAgB,MAAM,YAAY,IAAI,eAAe;AAE3D,SAAO,MAAM,qBAAqB,KAAK,UAAU,eAAe,MAAM,EAAE,CAAC;AAEzE,mBACE,eACA,eAAe,WAAW,IAAI,MAAM,SAAS,eAAe,OAC7D;AACD,SAAO;UACA,OAAO;AACd,SAAO,gBACL,kBACE,mHACA,MACD,CACF;;;;;;;;AAWL,SAAS,iBACP,eACA,WACM;AACN,KAAI,OAAO,KAAK,cAAc,QAAQ,CAAC,WAAW,EAChD,QAAO,QACL,OAAO,UAAU,GAAG,cAAc,IAAI,SAAS,QAAQ,wCACxD;KAED,QAAO,QAAQ,cAAc,QAAQ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Settings, TranslateFlags } from '../types/index.js';
|
|
2
2
|
import { FileToUpload } from 'generaltranslation/types';
|
|
3
3
|
import { BranchData } from '../types/branch.js';
|
|
4
|
+
import type { InlineLibrary } from '../types/libraries.js';
|
|
4
5
|
/**
|
|
5
6
|
* Sets up a project by uploading files running the setup step
|
|
6
7
|
* @param files - Array of file objects to upload
|
|
@@ -8,6 +9,6 @@ import { BranchData } from '../types/branch.js';
|
|
|
8
9
|
* @param settings - Settings configuration
|
|
9
10
|
* @returns The branch data
|
|
10
11
|
*/
|
|
11
|
-
export declare function runSetupProjectWorkflow(files: FileToUpload[], options: TranslateFlags, settings: Settings): Promise<{
|
|
12
|
+
export declare function runSetupProjectWorkflow(files: FileToUpload[], options: TranslateFlags, settings: Settings, inlineLibrary?: InlineLibrary): Promise<{
|
|
12
13
|
branchData: BranchData;
|
|
13
14
|
}>;
|
|
@@ -13,9 +13,9 @@ import { calculateTimeoutMs } from "../utils/calculateTimeoutMs.js";
|
|
|
13
13
|
* @param settings - Settings configuration
|
|
14
14
|
* @returns The branch data
|
|
15
15
|
*/
|
|
16
|
-
async function runSetupProjectWorkflow(files, options, settings) {
|
|
16
|
+
async function runSetupProjectWorkflow(files, options, settings, inlineLibrary) {
|
|
17
17
|
try {
|
|
18
|
-
logCollectedFiles(files);
|
|
18
|
+
logCollectedFiles(files, void 0, inlineLibrary);
|
|
19
19
|
const timeoutMs = calculateTimeoutMs(options.timeout);
|
|
20
20
|
const branchStep = new BranchStep(gt, settings);
|
|
21
21
|
const uploadStep = new UploadSourcesStep(gt, settings);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupProject.js","names":[],"sources":["../../src/workflows/setupProject.ts"],"sourcesContent":["import { logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { logCollectedFiles } from '../console/logging.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\n\n/**\n * Sets up a project by uploading files running the setup step\n * @param files - Array of file objects to upload\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The branch data\n */\nexport async function runSetupProjectWorkflow(\n files: FileToUpload[],\n options: TranslateFlags,\n settings: Settings\n): Promise<{\n branchData: BranchData;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n\n // first run the branch step\n const branchData = await branchStep.run();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // then run the setup step\n await setupStep.run(uploadedFiles, options.force ?? false);\n\n return { branchData };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Project setup could not be completed. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"setupProject.js","names":[],"sources":["../../src/workflows/setupProject.ts"],"sourcesContent":["import { logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { logCollectedFiles } from '../console/logging.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\nimport type { InlineLibrary } from '../types/libraries.js';\n\n/**\n * Sets up a project by uploading files running the setup step\n * @param files - Array of file objects to upload\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The branch data\n */\nexport async function runSetupProjectWorkflow(\n files: FileToUpload[],\n options: TranslateFlags,\n settings: Settings,\n inlineLibrary?: InlineLibrary\n): Promise<{\n branchData: BranchData;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files, undefined, inlineLibrary);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n\n // first run the branch step\n const branchData = await branchStep.run();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // then run the setup step\n await setupStep.run(uploadedFiles, options.force ?? false);\n\n return { branchData };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Project setup could not be completed. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,eAAsB,wBACpB,OACA,SACA,UACA,eAGC;AACD,KAAI;AAEF,oBAAkB,OAAO,KAAA,GAAW,cAAc;EAGlD,MAAM,YAAY,mBAAmB,QAAQ,QAAQ;EAGrD,MAAM,aAAa,IAAI,WAAW,IAAI,SAAS;EAC/C,MAAM,aAAa,IAAI,kBAAkB,IAAI,SAAS;EACtD,MAAM,YAAY,IAAI,UAAU,IAAI,UAAU,UAAU;EAGxD,MAAM,aAAa,MAAM,WAAW,KAAK;AAEzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;EAI/C,MAAM,gBAAgB,MAAM,WAAW,IAAI;GAAE;GAAO;GAAY,CAAC;AAGjE,QAAM,UAAU,IAAI,eAAe,QAAQ,SAAS,MAAM;AAE1D,SAAO,EAAE,YAAY;UACd,OAAO;AACd,SAAO,gBACL,kBACE,qHACA,MACD,CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Settings, TranslateFlags } from '../types/index.js';
|
|
2
2
|
import { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';
|
|
3
3
|
import { BranchData } from '../types/branch.js';
|
|
4
|
+
import type { InlineLibrary } from '../types/libraries.js';
|
|
4
5
|
/**
|
|
5
6
|
* Sends multiple files for translation to the API using a workflow pattern
|
|
6
7
|
* @param files - Array of file objects to translate
|
|
@@ -8,10 +9,11 @@ import { BranchData } from '../types/branch.js';
|
|
|
8
9
|
* @param settings - Settings configuration
|
|
9
10
|
* @returns The translated content or version ID
|
|
10
11
|
*/
|
|
11
|
-
export declare function runStageFilesWorkflow({ files, options, settings, }: {
|
|
12
|
+
export declare function runStageFilesWorkflow({ files, options, settings, inlineLibrary, }: {
|
|
12
13
|
files: FileToUpload[];
|
|
13
14
|
options: TranslateFlags;
|
|
14
15
|
settings: Settings;
|
|
16
|
+
inlineLibrary?: InlineLibrary;
|
|
15
17
|
}): Promise<{
|
|
16
18
|
branchData: BranchData;
|
|
17
19
|
enqueueResult: EnqueueFilesResult;
|
package/dist/workflows/stage.js
CHANGED
|
@@ -19,9 +19,9 @@ import { filterFilesForEnqueue } from "./utils/filterFilesForEnqueue.js";
|
|
|
19
19
|
* @param settings - Settings configuration
|
|
20
20
|
* @returns The translated content or version ID
|
|
21
21
|
*/
|
|
22
|
-
async function runStageFilesWorkflow({ files, options, settings }) {
|
|
22
|
+
async function runStageFilesWorkflow({ files, options, settings, inlineLibrary }) {
|
|
23
23
|
try {
|
|
24
|
-
logCollectedFiles(files);
|
|
24
|
+
logCollectedFiles(files, void 0, inlineLibrary);
|
|
25
25
|
await syncFonts(settings);
|
|
26
26
|
const timeoutMs = calculateTimeoutMs(options.timeout);
|
|
27
27
|
const branchStep = new BranchStep(gt, settings);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage.js","names":[],"sources":["../../src/workflows/stage.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { TagStep } from './steps/TagStep.js';\nimport { UserEditDiffsStep } from './steps/UserEditDiffsStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\nimport { syncFonts } from './utils/syncFonts.js';\n\n/**\n * Sends multiple files for translation to the API using a workflow pattern\n * @param files - Array of file objects to translate\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The translated content or version ID\n */\nexport async function runStageFilesWorkflow({\n files,\n options,\n settings,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n}): Promise<{\n branchData: BranchData;\n enqueueResult: EnqueueFilesResult;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Sync fonts before enqueueing so the translation jobs (e.g. Lottie\n // layout refinement) can use them instead of fallback fonts.\n await syncFonts(settings);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const userEditDiffsStep = new UserEditDiffsStep(settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // first run the branch step\n const branchData = await branchStep.run();\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // optionally run the user edit diffs step\n if (options?.saveLocal) {\n await userEditDiffsStep.run(uploadedFiles);\n }\n\n // then run the tag step (non-fatal — tagging failure should not block translations)\n if (settings.tag) {\n try {\n const userProvidedTag = !!options.tag;\n const tagStep = new TagStep(gt, settings, userProvidedTag);\n await tagStep.run(uploadedFiles);\n } catch {\n logger.warn('Failed to create translation tag. Continuing...');\n }\n }\n\n // then run the setup step\n await setupStep.run(uploadedFiles);\n\n // then run the enqueue step\n const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({\n gt,\n files: uploadedFiles,\n locales: settings.locales,\n force: options.force,\n });\n if (skippedFiles.length > 0) {\n logger.info(\n `Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? '' : 's'}`\n );\n }\n\n const enqueueResult = await enqueueStep.run(filesToEnqueue);\n\n return { branchData, enqueueResult };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Files could not be sent for translation. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"stage.js","names":[],"sources":["../../src/workflows/stage.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { TagStep } from './steps/TagStep.js';\nimport { UserEditDiffsStep } from './steps/UserEditDiffsStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\nimport { syncFonts } from './utils/syncFonts.js';\nimport type { InlineLibrary } from '../types/libraries.js';\n\n/**\n * Sends multiple files for translation to the API using a workflow pattern\n * @param files - Array of file objects to translate\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The translated content or version ID\n */\nexport async function runStageFilesWorkflow({\n files,\n options,\n settings,\n inlineLibrary,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n inlineLibrary?: InlineLibrary;\n}): Promise<{\n branchData: BranchData;\n enqueueResult: EnqueueFilesResult;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files, undefined, inlineLibrary);\n\n // Sync fonts before enqueueing so the translation jobs (e.g. Lottie\n // layout refinement) can use them instead of fallback fonts.\n await syncFonts(settings);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const userEditDiffsStep = new UserEditDiffsStep(settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // first run the branch step\n const branchData = await branchStep.run();\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // optionally run the user edit diffs step\n if (options?.saveLocal) {\n await userEditDiffsStep.run(uploadedFiles);\n }\n\n // then run the tag step (non-fatal — tagging failure should not block translations)\n if (settings.tag) {\n try {\n const userProvidedTag = !!options.tag;\n const tagStep = new TagStep(gt, settings, userProvidedTag);\n await tagStep.run(uploadedFiles);\n } catch {\n logger.warn('Failed to create translation tag. Continuing...');\n }\n }\n\n // then run the setup step\n await setupStep.run(uploadedFiles);\n\n // then run the enqueue step\n const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({\n gt,\n files: uploadedFiles,\n locales: settings.locales,\n force: options.force,\n });\n if (skippedFiles.length > 0) {\n logger.info(\n `Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? '' : 's'}`\n );\n }\n\n const enqueueResult = await enqueueStep.run(filesToEnqueue);\n\n return { branchData, enqueueResult };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Files could not be sent for translation. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyBA,eAAsB,sBAAsB,EAC1C,OACA,SACA,UACA,iBASC;AACD,KAAI;AAEF,oBAAkB,OAAO,KAAA,GAAW,cAAc;AAIlD,QAAM,UAAU,SAAS;EAGzB,MAAM,YAAY,mBAAmB,QAAQ,QAAQ;EAGrD,MAAM,aAAa,IAAI,WAAW,IAAI,SAAS;EAC/C,MAAM,aAAa,IAAI,kBAAkB,IAAI,SAAS;EACtD,MAAM,oBAAoB,IAAI,kBAAkB,SAAS;EACzD,MAAM,YAAY,IAAI,UAAU,IAAI,UAAU,UAAU;EACxD,MAAM,cAAc,IAAI,YAAY,IAAI,UAAU,QAAQ,MAAM;EAGhE,MAAM,aAAa,MAAM,WAAW,KAAK;AACzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;EAI/C,MAAM,gBAAgB,MAAM,WAAW,IAAI;GAAE;GAAO;GAAY,CAAC;AAGjE,MAAI,SAAS,UACX,OAAM,kBAAkB,IAAI,cAAc;AAI5C,MAAI,SAAS,IACX,KAAI;AAGF,SAAM,IADc,QAAQ,IAAI,UAAU,CADjB,CAAC,QAAQ,IAErB,CAAC,IAAI,cAAc;UAC1B;AACN,UAAO,KAAK,kDAAkD;;AAKlE,QAAM,UAAU,IAAI,cAAc;EAGlC,MAAM,EAAE,gBAAgB,iBAAiB,MAAM,sBAAsB;GACnE;GACA,OAAO;GACP,SAAS,SAAS;GAClB,OAAO,QAAQ;GAChB,CAAC;AACF,MAAI,aAAa,SAAS,EACxB,QAAO,KACL,uBAAuB,aAAa,OAAO,0BAA0B,aAAa,WAAW,IAAI,KAAK,MACvG;AAKH,SAAO;GAAE;GAAY,eAAA,MAFO,YAAY,IAAI,eAAe;GAEvB;UAC7B,OAAO;AACd,SAAO,gBACL,kBACE,wHACA,MACD,CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GT } from 'generaltranslation';
|
|
2
2
|
import { Settings } from '../../types/index.js';
|
|
3
3
|
import { FileStatusTracker } from './PollJobsStep.js';
|
|
4
|
+
import type { InlineLibrary } from '../../types/libraries.js';
|
|
4
5
|
export type DownloadTranslationsInput = {
|
|
5
6
|
fileTracker: FileStatusTracker;
|
|
6
7
|
resolveOutputPath: (sourcePath: string, locale: string) => string | null;
|
|
@@ -9,8 +10,9 @@ export type DownloadTranslationsInput = {
|
|
|
9
10
|
export declare class DownloadTranslationsStep {
|
|
10
11
|
private gt;
|
|
11
12
|
private settings;
|
|
13
|
+
private inlineLibrary?;
|
|
12
14
|
private spinner;
|
|
13
|
-
constructor(gt: GT, settings: Settings);
|
|
15
|
+
constructor(gt: GT, settings: Settings, inlineLibrary?: InlineLibrary | undefined);
|
|
14
16
|
run({ fileTracker, resolveOutputPath, forceDownload, }: DownloadTranslationsInput): Promise<boolean>;
|
|
15
17
|
private downloadFiles;
|
|
16
18
|
private downloadFilesWithRetry;
|
|
@@ -7,9 +7,10 @@ import path from "node:path";
|
|
|
7
7
|
//#region src/workflows/steps/DownloadStep.ts
|
|
8
8
|
var DownloadTranslationsStep = class {
|
|
9
9
|
spinner = null;
|
|
10
|
-
constructor(gt, settings) {
|
|
10
|
+
constructor(gt, settings, inlineLibrary) {
|
|
11
11
|
this.gt = gt;
|
|
12
12
|
this.settings = settings;
|
|
13
|
+
this.inlineLibrary = inlineLibrary;
|
|
13
14
|
}
|
|
14
15
|
async run({ fileTracker, resolveOutputPath, forceDownload }) {
|
|
15
16
|
this.spinner = logger.createProgressBar(fileTracker.completed.size);
|
|
@@ -96,7 +97,7 @@ var DownloadTranslationsStep = class {
|
|
|
96
97
|
let retryCount = 0;
|
|
97
98
|
let allSkipped = [];
|
|
98
99
|
while (remainingFiles.length > 0 && retryCount <= maxRetries) {
|
|
99
|
-
const batchResult = await downloadFileBatch(fileTracker, remainingFiles, this.settings, forceDownload);
|
|
100
|
+
const batchResult = await downloadFileBatch(fileTracker, remainingFiles, this.settings, forceDownload, this.inlineLibrary);
|
|
100
101
|
allSuccessful = [...allSuccessful, ...batchResult.successful];
|
|
101
102
|
allSkipped = [...allSkipped, ...batchResult.skipped];
|
|
102
103
|
this.spinner?.advance(batchResult.successful.length + batchResult.skipped.length + batchResult.failed.length);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DownloadStep.js","names":[],"sources":["../../../src/workflows/steps/DownloadStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport path from 'node:path';\nimport { logger } from '../../console/logger.js';\nimport {\n BatchedFiles,\n downloadFileBatch,\n DownloadFileBatchResult,\n} from '../../api/downloadFileBatch.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport { FileStatusTracker } from './PollJobsStep.js';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\n\nexport type DownloadTranslationsInput = {\n fileTracker: FileStatusTracker;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n forceDownload?: boolean;\n};\n\nexport class DownloadTranslationsStep {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n\n constructor(\n private gt: GT,\n private settings: Settings\n ) {}\n\n async run({\n fileTracker,\n resolveOutputPath,\n forceDownload,\n }: DownloadTranslationsInput): Promise<boolean> {\n this.spinner = logger.createProgressBar(fileTracker.completed.size);\n this.spinner.start('Downloading files...');\n\n return this.downloadFiles(fileTracker, resolveOutputPath, forceDownload);\n }\n\n private async downloadFiles(\n fileTracker: FileStatusTracker,\n resolveOutputPath: (sourcePath: string, locale: string) => string | null,\n forceDownload?: boolean\n ): Promise<boolean> {\n try {\n // Only download files that are marked as completed\n const currentQueryData = Array.from(fileTracker.completed.values());\n\n // If no files to download, we're done\n if (currentQueryData.length === 0) {\n this.spinner?.stop(chalk.green('No files to download'));\n return true;\n }\n\n // Check for translations\n const responseData = await this.gt.queryFileData({\n translatedFiles: currentQueryData.map((item) => ({\n fileId: item.fileId,\n versionId: item.versionId,\n branchId: item.branchId,\n locale: item.locale,\n })),\n });\n const translatedFiles = responseData.translatedFiles || [];\n\n // Filter for ready translations\n const readyTranslations = translatedFiles.filter(\n (file) => file.completedAt !== null\n );\n let missingCount = 0;\n\n if (readyTranslations.length < currentQueryData.length) {\n const readyKeys = new Set(\n readyTranslations.map(\n (t) => `${t.branchId}:${t.fileId}:${t.versionId}:${t.locale}`\n )\n );\n const missing = currentQueryData.filter(\n (item) =>\n !readyKeys.has(\n `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`\n )\n );\n missingCount = missing.length;\n logger.warn(\n `Failed to download ${missing.length} file(s):\\n${missing.map((f) => `- ${f.fileName} (${f.locale})`).join('\\n')}`\n );\n for (const f of missing) {\n recordWarning(\n 'failed_download',\n f.fileName,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n\n // Review gating: skip completed translations for normal files whose\n // effective requiresReview policy is true but that are not approved\n // yet. Skips are intentional, not failures — a review-gated file is\n // simply absent locally and falls back to source behavior.\n // GTJSON is exempt: it is always requested, and the platform filters\n // unapproved components out of the served content itself.\n const requiresReviewPaths =\n this.settings.files?.requiresReviewPaths ?? new Set<string>();\n const reviewGatedKeys = new Set<string>();\n if (requiresReviewPaths.size > 0) {\n for (const translation of readyTranslations) {\n if (translation.approvedAt !== null) continue;\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) continue;\n if (fileProperties.fileName === TEMPLATE_FILE_NAME) continue;\n const absolutePath = path.resolve(\n process.cwd(),\n fileProperties.fileName\n );\n if (!requiresReviewPaths.has(absolutePath)) continue;\n reviewGatedKeys.add(fileKey);\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n recordWarning(\n 'pending_review',\n fileProperties.fileName,\n `Translation for locale ${translation.locale} requires review and is not approved yet`\n );\n }\n if (reviewGatedKeys.size > 0) {\n logger.info(\n `Skipped ${reviewGatedKeys.size} file(s) awaiting review approval. They will download once approved.`\n );\n }\n }\n\n // Prepare batch download data\n const batchFiles: BatchedFiles = readyTranslations\n .map((translation) => {\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) {\n return null;\n }\n const outputPath = resolveOutputPath(\n fileProperties.fileName,\n translation.locale\n );\n\n // Skip downloading GTJSON files that are not in the files configuration\n if (outputPath === null) {\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n return null;\n }\n return {\n branchId: translation.branchId,\n fileId: translation.fileId,\n versionId: translation.versionId,\n locale: translation.locale,\n inputPath: fileProperties.fileName,\n outputPath,\n };\n })\n .filter((file) => file !== null) as BatchedFiles;\n\n if (batchFiles.length > 0) {\n const batchResult = await this.downloadFilesWithRetry(\n fileTracker,\n batchFiles,\n forceDownload\n );\n this.spinner?.stop(\n chalk.green(\n `Downloaded ${batchResult.successful.length} files${batchResult.skipped.length > 0 ? `, skipped ${batchResult.skipped.length} files` : ''}`\n )\n );\n if (batchResult.failed.length > 0) {\n logger.warn(\n `Failed to download ${batchResult.failed.length} files: ${batchResult.failed.map((f) => f.inputPath).join('\\n')}`\n );\n for (const f of batchResult.failed) {\n recordWarning(\n 'failed_download',\n f.inputPath,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n } else if (missingCount > 0) {\n this.spinner?.stop(\n chalk.yellow('No files downloaded - see warnings above')\n );\n } else {\n this.spinner?.stop(chalk.green('No files to download'));\n }\n\n return true;\n } catch (error) {\n this.spinner?.stop(\n chalk.red('An error occurred while downloading translations')\n );\n logger.error(chalk.red('Error: ') + error);\n return false;\n }\n }\n\n private async downloadFilesWithRetry(\n fileTracker: FileStatusTracker,\n files: BatchedFiles,\n forceDownload?: boolean,\n maxRetries: number = 3,\n initialDelay: number = 1000\n ): Promise<DownloadFileBatchResult> {\n let remainingFiles = files;\n let allSuccessful: BatchedFiles = [];\n let retryCount = 0;\n let allSkipped: BatchedFiles = [];\n while (remainingFiles.length > 0 && retryCount <= maxRetries) {\n const batchResult = await downloadFileBatch(\n fileTracker,\n remainingFiles,\n this.settings,\n forceDownload\n );\n\n allSuccessful = [...allSuccessful, ...batchResult.successful];\n allSkipped = [...allSkipped, ...batchResult.skipped];\n\n this.spinner?.advance(\n batchResult.successful.length +\n batchResult.skipped.length +\n batchResult.failed.length\n );\n\n // If no failures or we've exhausted retries, we're done\n if (batchResult.failed.length === 0 || retryCount === maxRetries) {\n return {\n successful: allSuccessful,\n failed: batchResult.failed,\n skipped: allSkipped,\n };\n }\n\n // Calculate exponential backoff delay\n const delay = initialDelay * Math.pow(2, retryCount);\n logger.error(\n chalk.yellow(\n `Retrying ${batchResult.failed.length} failed file(s) in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`\n )\n );\n\n // Wait before retrying\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n remainingFiles = batchResult.failed;\n retryCount++;\n }\n\n return {\n successful: allSuccessful,\n failed: remainingFiles,\n skipped: allSkipped,\n };\n }\n}\n"],"mappings":";;;;;;;AAoBA,IAAa,2BAAb,MAAsC;CACpC,UAAsE;CAEtE,YACE,IACA,UACA;AAFQ,OAAA,KAAA;AACA,OAAA,WAAA;;CAGV,MAAM,IAAI,EACR,aACA,mBACA,iBAC8C;AAC9C,OAAK,UAAU,OAAO,kBAAkB,YAAY,UAAU,KAAK;AACnE,OAAK,QAAQ,MAAM,uBAAuB;AAE1C,SAAO,KAAK,cAAc,aAAa,mBAAmB,cAAc;;CAG1E,MAAc,cACZ,aACA,mBACA,eACkB;AAClB,MAAI;GAEF,MAAM,mBAAmB,MAAM,KAAK,YAAY,UAAU,QAAQ,CAAC;AAGnE,OAAI,iBAAiB,WAAW,GAAG;AACjC,SAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AACvD,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SAAS,KACZ,MAAM,OAAO,2CAA2C,CACzD;OAED,MAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAGzD,UAAO;WACA,OAAO;AACd,QAAK,SAAS,KACZ,MAAM,IAAI,mDAAmD,CAC9D;AACD,UAAO,MAAM,MAAM,IAAI,UAAU,GAAG,MAAM;AAC1C,UAAO;;;CAIX,MAAc,uBACZ,aACA,OACA,eACA,aAAqB,GACrB,eAAuB,KACW;EAClC,IAAI,iBAAiB;EACrB,IAAI,gBAA8B,EAAE;EACpC,IAAI,aAAa;EACjB,IAAI,aAA2B,EAAE;AACjC,SAAO,eAAe,SAAS,KAAK,cAAc,YAAY;GAC5D,MAAM,cAAc,MAAM,kBACxB,aACA,gBACA,KAAK,UACL,cACD;AAED,mBAAgB,CAAC,GAAG,eAAe,GAAG,YAAY,WAAW;AAC7D,gBAAa,CAAC,GAAG,YAAY,GAAG,YAAY,QAAQ;AAEpD,QAAK,SAAS,QACZ,YAAY,WAAW,SACrB,YAAY,QAAQ,SACpB,YAAY,OAAO,OACtB;AAGD,OAAI,YAAY,OAAO,WAAW,KAAK,eAAe,WACpD,QAAO;IACL,YAAY;IACZ,QAAQ,YAAY;IACpB,SAAS;IACV;GAIH,MAAM,QAAQ,eAAe,KAAK,IAAI,GAAG,WAAW;AACpD,UAAO,MACL,MAAM,OACJ,YAAY,YAAY,OAAO,OAAO,qBAAqB,MAAM,cAAc,aAAa,EAAE,GAAG,WAAW,MAC7G,CACF;AAGD,SAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;AAE1D,oBAAiB,YAAY;AAC7B;;AAGF,SAAO;GACL,YAAY;GACZ,QAAQ;GACR,SAAS;GACV"}
|
|
1
|
+
{"version":3,"file":"DownloadStep.js","names":[],"sources":["../../../src/workflows/steps/DownloadStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport path from 'node:path';\nimport { logger } from '../../console/logger.js';\nimport {\n BatchedFiles,\n downloadFileBatch,\n DownloadFileBatchResult,\n} from '../../api/downloadFileBatch.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport { FileStatusTracker } from './PollJobsStep.js';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\nimport type { InlineLibrary } from '../../types/libraries.js';\n\nexport type DownloadTranslationsInput = {\n fileTracker: FileStatusTracker;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n forceDownload?: boolean;\n};\n\nexport class DownloadTranslationsStep {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n\n constructor(\n private gt: GT,\n private settings: Settings,\n private inlineLibrary?: InlineLibrary\n ) {}\n\n async run({\n fileTracker,\n resolveOutputPath,\n forceDownload,\n }: DownloadTranslationsInput): Promise<boolean> {\n this.spinner = logger.createProgressBar(fileTracker.completed.size);\n this.spinner.start('Downloading files...');\n\n return this.downloadFiles(fileTracker, resolveOutputPath, forceDownload);\n }\n\n private async downloadFiles(\n fileTracker: FileStatusTracker,\n resolveOutputPath: (sourcePath: string, locale: string) => string | null,\n forceDownload?: boolean\n ): Promise<boolean> {\n try {\n // Only download files that are marked as completed\n const currentQueryData = Array.from(fileTracker.completed.values());\n\n // If no files to download, we're done\n if (currentQueryData.length === 0) {\n this.spinner?.stop(chalk.green('No files to download'));\n return true;\n }\n\n // Check for translations\n const responseData = await this.gt.queryFileData({\n translatedFiles: currentQueryData.map((item) => ({\n fileId: item.fileId,\n versionId: item.versionId,\n branchId: item.branchId,\n locale: item.locale,\n })),\n });\n const translatedFiles = responseData.translatedFiles || [];\n\n // Filter for ready translations\n const readyTranslations = translatedFiles.filter(\n (file) => file.completedAt !== null\n );\n let missingCount = 0;\n\n if (readyTranslations.length < currentQueryData.length) {\n const readyKeys = new Set(\n readyTranslations.map(\n (t) => `${t.branchId}:${t.fileId}:${t.versionId}:${t.locale}`\n )\n );\n const missing = currentQueryData.filter(\n (item) =>\n !readyKeys.has(\n `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`\n )\n );\n missingCount = missing.length;\n logger.warn(\n `Failed to download ${missing.length} file(s):\\n${missing.map((f) => `- ${f.fileName} (${f.locale})`).join('\\n')}`\n );\n for (const f of missing) {\n recordWarning(\n 'failed_download',\n f.fileName,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n\n // Review gating: skip completed translations for normal files whose\n // effective requiresReview policy is true but that are not approved\n // yet. Skips are intentional, not failures — a review-gated file is\n // simply absent locally and falls back to source behavior.\n // GTJSON is exempt: it is always requested, and the platform filters\n // unapproved components out of the served content itself.\n const requiresReviewPaths =\n this.settings.files?.requiresReviewPaths ?? new Set<string>();\n const reviewGatedKeys = new Set<string>();\n if (requiresReviewPaths.size > 0) {\n for (const translation of readyTranslations) {\n if (translation.approvedAt !== null) continue;\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) continue;\n if (fileProperties.fileName === TEMPLATE_FILE_NAME) continue;\n const absolutePath = path.resolve(\n process.cwd(),\n fileProperties.fileName\n );\n if (!requiresReviewPaths.has(absolutePath)) continue;\n reviewGatedKeys.add(fileKey);\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n recordWarning(\n 'pending_review',\n fileProperties.fileName,\n `Translation for locale ${translation.locale} requires review and is not approved yet`\n );\n }\n if (reviewGatedKeys.size > 0) {\n logger.info(\n `Skipped ${reviewGatedKeys.size} file(s) awaiting review approval. They will download once approved.`\n );\n }\n }\n\n // Prepare batch download data\n const batchFiles: BatchedFiles = readyTranslations\n .map((translation) => {\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) {\n return null;\n }\n const outputPath = resolveOutputPath(\n fileProperties.fileName,\n translation.locale\n );\n\n // Skip downloading GTJSON files that are not in the files configuration\n if (outputPath === null) {\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n return null;\n }\n return {\n branchId: translation.branchId,\n fileId: translation.fileId,\n versionId: translation.versionId,\n locale: translation.locale,\n inputPath: fileProperties.fileName,\n outputPath,\n };\n })\n .filter((file) => file !== null) as BatchedFiles;\n\n if (batchFiles.length > 0) {\n const batchResult = await this.downloadFilesWithRetry(\n fileTracker,\n batchFiles,\n forceDownload\n );\n this.spinner?.stop(\n chalk.green(\n `Downloaded ${batchResult.successful.length} files${batchResult.skipped.length > 0 ? `, skipped ${batchResult.skipped.length} files` : ''}`\n )\n );\n if (batchResult.failed.length > 0) {\n logger.warn(\n `Failed to download ${batchResult.failed.length} files: ${batchResult.failed.map((f) => f.inputPath).join('\\n')}`\n );\n for (const f of batchResult.failed) {\n recordWarning(\n 'failed_download',\n f.inputPath,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n } else if (missingCount > 0) {\n this.spinner?.stop(\n chalk.yellow('No files downloaded - see warnings above')\n );\n } else {\n this.spinner?.stop(chalk.green('No files to download'));\n }\n\n return true;\n } catch (error) {\n this.spinner?.stop(\n chalk.red('An error occurred while downloading translations')\n );\n logger.error(chalk.red('Error: ') + error);\n return false;\n }\n }\n\n private async downloadFilesWithRetry(\n fileTracker: FileStatusTracker,\n files: BatchedFiles,\n forceDownload?: boolean,\n maxRetries: number = 3,\n initialDelay: number = 1000\n ): Promise<DownloadFileBatchResult> {\n let remainingFiles = files;\n let allSuccessful: BatchedFiles = [];\n let retryCount = 0;\n let allSkipped: BatchedFiles = [];\n while (remainingFiles.length > 0 && retryCount <= maxRetries) {\n const batchResult = await downloadFileBatch(\n fileTracker,\n remainingFiles,\n this.settings,\n forceDownload,\n this.inlineLibrary\n );\n\n allSuccessful = [...allSuccessful, ...batchResult.successful];\n allSkipped = [...allSkipped, ...batchResult.skipped];\n\n this.spinner?.advance(\n batchResult.successful.length +\n batchResult.skipped.length +\n batchResult.failed.length\n );\n\n // If no failures or we've exhausted retries, we're done\n if (batchResult.failed.length === 0 || retryCount === maxRetries) {\n return {\n successful: allSuccessful,\n failed: batchResult.failed,\n skipped: allSkipped,\n };\n }\n\n // Calculate exponential backoff delay\n const delay = initialDelay * Math.pow(2, retryCount);\n logger.error(\n chalk.yellow(\n `Retrying ${batchResult.failed.length} failed file(s) in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`\n )\n );\n\n // Wait before retrying\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n remainingFiles = batchResult.failed;\n retryCount++;\n }\n\n return {\n successful: allSuccessful,\n failed: remainingFiles,\n skipped: allSkipped,\n };\n }\n}\n"],"mappings":";;;;;;;AAqBA,IAAa,2BAAb,MAAsC;CACpC,UAAsE;CAEtE,YACE,IACA,UACA,eACA;AAHQ,OAAA,KAAA;AACA,OAAA,WAAA;AACA,OAAA,gBAAA;;CAGV,MAAM,IAAI,EACR,aACA,mBACA,iBAC8C;AAC9C,OAAK,UAAU,OAAO,kBAAkB,YAAY,UAAU,KAAK;AACnE,OAAK,QAAQ,MAAM,uBAAuB;AAE1C,SAAO,KAAK,cAAc,aAAa,mBAAmB,cAAc;;CAG1E,MAAc,cACZ,aACA,mBACA,eACkB;AAClB,MAAI;GAEF,MAAM,mBAAmB,MAAM,KAAK,YAAY,UAAU,QAAQ,CAAC;AAGnE,OAAI,iBAAiB,WAAW,GAAG;AACjC,SAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AACvD,WAAO;;GAeT,MAAM,sBAHkB,MARG,KAAK,GAAG,cAAc,EAC/C,iBAAiB,iBAAiB,KAAK,UAAU;IAC/C,QAAQ,KAAK;IACb,WAAW,KAAK;IAChB,UAAU,KAAK;IACf,QAAQ,KAAK;IACd,EAAE,EACJ,CAAC,EACmC,mBAAmB,EAAE,EAGhB,QACvC,SAAS,KAAK,gBAAgB,KAChC;GACD,IAAI,eAAe;AAEnB,OAAI,kBAAkB,SAAS,iBAAiB,QAAQ;IACtD,MAAM,YAAY,IAAI,IACpB,kBAAkB,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,aAAa;EACjB,IAAI,aAA2B,EAAE;AACjC,SAAO,eAAe,SAAS,KAAK,cAAc,YAAY;GAC5D,MAAM,cAAc,MAAM,kBACxB,aACA,gBACA,KAAK,UACL,eACA,KAAK,cACN;AAED,mBAAgB,CAAC,GAAG,eAAe,GAAG,YAAY,WAAW;AAC7D,gBAAa,CAAC,GAAG,YAAY,GAAG,YAAY,QAAQ;AAEpD,QAAK,SAAS,QACZ,YAAY,WAAW,SACrB,YAAY,QAAQ,SACpB,YAAY,OAAO,OACtB;AAGD,OAAI,YAAY,OAAO,WAAW,KAAK,eAAe,WACpD,QAAO;IACL,YAAY;IACZ,QAAQ,YAAY;IACpB,SAAS;IACV;GAIH,MAAM,QAAQ,eAAe,KAAK,IAAI,GAAG,WAAW;AACpD,UAAO,MACL,MAAM,OACJ,YAAY,YAAY,OAAO,OAAO,qBAAqB,MAAM,cAAc,aAAa,EAAE,GAAG,WAAW,MAC7G,CACF;AAGD,SAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;AAE1D,oBAAiB,YAAY;AAC7B;;AAGF,SAAO;GACL,YAAY;GACZ,QAAQ;GACR,SAAS;GACV"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GT } from 'generaltranslation';
|
|
2
2
|
import { EnqueueFilesResult } from 'generaltranslation/types';
|
|
3
3
|
import type { FileProperties } from '../../types/files.js';
|
|
4
|
+
import { type InlineLibrary } from '../../types/libraries.js';
|
|
4
5
|
export type PollJobsInput = {
|
|
5
6
|
fileTracker: FileStatusTracker;
|
|
6
7
|
fileQueryData: FileProperties[];
|
|
@@ -20,9 +21,10 @@ export type PollJobsOutput = {
|
|
|
20
21
|
};
|
|
21
22
|
export declare class PollTranslationJobsStep {
|
|
22
23
|
private gt;
|
|
24
|
+
private inlineLibrary?;
|
|
23
25
|
private spinner;
|
|
24
26
|
private previousProgress;
|
|
25
|
-
constructor(gt: GT);
|
|
27
|
+
constructor(gt: GT, inlineLibrary?: InlineLibrary | undefined);
|
|
26
28
|
run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation, }: PollJobsInput): Promise<PollJobsOutput>;
|
|
27
29
|
private updateSpinner;
|
|
28
30
|
private generateStatusSuffixText;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import "../../utils/constants.js";
|
|
3
|
+
import { getInlineElementsLabel } from "../../types/libraries.js";
|
|
3
4
|
import { getFileTranslationKey, queryCompletedTranslationKeys } from "../utils/queryCompletedTranslations.js";
|
|
4
5
|
import chalk from "chalk";
|
|
5
6
|
//#region src/workflows/steps/PollJobsStep.ts
|
|
6
7
|
var PollTranslationJobsStep = class {
|
|
7
8
|
spinner = null;
|
|
8
9
|
previousProgress = 0;
|
|
9
|
-
constructor(gt) {
|
|
10
|
+
constructor(gt, inlineLibrary) {
|
|
10
11
|
this.gt = gt;
|
|
12
|
+
this.inlineLibrary = inlineLibrary;
|
|
11
13
|
}
|
|
12
14
|
async run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation }) {
|
|
13
15
|
const startTime = Date.now();
|
|
@@ -186,7 +188,7 @@ var PollTranslationJobsStep = class {
|
|
|
186
188
|
else if (locale.status === "failed") return chalk.red(locale.locale);
|
|
187
189
|
else if (locale.status === "pending") return chalk.yellow(locale.locale);
|
|
188
190
|
}).join(", ");
|
|
189
|
-
const prettyFileName = fileName === "__INTERNAL_GT_TEMPLATE_NAME__" ?
|
|
191
|
+
const prettyFileName = fileName === "__INTERNAL_GT_TEMPLATE_NAME__" ? `<${getInlineElementsLabel(this.inlineLibrary)}>` : fileName;
|
|
190
192
|
newSuffixText.push(`${chalk.bold(prettyFileName)} [${localeString}]`);
|
|
191
193
|
}
|
|
192
194
|
if (filesArray.length > maxFilesToShow) newSuffixText.push(`... and ${filesArray.length - maxFilesToShow} more files`);
|