gt 2.14.51-odysseus.0 → 2.14.52
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 +10 -8
- package/dist/api/downloadFileBatch.js +1 -1
- package/dist/api/saveLocalEdits.js +1 -1
- package/dist/cli/base.js +1 -7
- package/dist/cli/base.js.map +1 -1
- package/dist/cli/commands/setupProject.js +1 -0
- package/dist/cli/commands/setupProject.js.map +1 -1
- package/dist/cli/commands/stage.js +1 -0
- package/dist/cli/commands/stage.js.map +1 -1
- package/dist/cli/commands/upload.d.ts +2 -7
- package/dist/cli/commands/upload.js +13 -108
- package/dist/cli/commands/upload.js.map +1 -1
- package/dist/config/defaults.js +1 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/console/index.js +3 -3
- package/dist/console/index.js.map +1 -1
- package/dist/formats/files/aggregateFiles.js +3 -4
- package/dist/formats/files/aggregateFiles.js.map +1 -1
- package/dist/formats/files/preprocessContent.js +1 -1
- package/dist/fs/config/parseFilesConfig.js +4 -0
- package/dist/fs/config/parseFilesConfig.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/react/jsx/utils/constants.d.ts +9 -3
- package/dist/react/jsx/utils/constants.js +14 -7
- package/dist/react/jsx/utils/constants.js.map +1 -1
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.d.ts +2 -2
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +7 -7
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -1
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +2 -2
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.d.ts +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -1
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -1
- package/dist/react/parse/createInlineUpdates.js +1 -1
- package/dist/react/parse/createInlineUpdates.js.map +1 -1
- package/dist/types/parsing.d.ts +0 -2
- package/dist/types/parsing.js.map +1 -1
- package/dist/workflows/publish.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
-
## 2.14.
|
|
3
|
+
## 2.14.52
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Updated dependencies [[`3197028`](https://github.com/generaltranslation/gt/commit/319702855a7b129f95217d41be9f2402680a2f01)]:
|
|
8
|
+
- generaltranslation@8.2.17
|
|
9
|
+
- @generaltranslation/python-extractor@0.2.23
|
|
10
|
+
- @generaltranslation/supported-locales@2.1.2
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- gt-remark@1.0.11-odysseus.0
|
|
12
|
+
## 2.14.51
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#1605](https://github.com/generaltranslation/gt/pull/1605) [`69172dc`](https://github.com/generaltranslation/gt/commit/69172dc72e3fe22b6072b4c60e26c3de2cd68494) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Aggregate files on `upload` command. Ensures consistency with `stage` and `translate`
|
|
15
17
|
|
|
16
18
|
## 2.14.50
|
|
17
19
|
|
|
@@ -5,8 +5,8 @@ import { SUPPORTED_FILE_EXTENSIONS } from "../formats/files/supportedFiles.js";
|
|
|
5
5
|
import { hasNonIdentityFileFormatTransformForType } from "../formats/files/transformFormat.js";
|
|
6
6
|
import { validateJsonSchema } from "../formats/json/utils.js";
|
|
7
7
|
import { extractJson } from "../formats/json/extractJson.js";
|
|
8
|
-
import { resolveMintlifyRefs, shouldResolveRefs } from "../utils/resolveMintlifyRefs.js";
|
|
9
8
|
import { recordWarning } from "../state/translateWarnings.js";
|
|
9
|
+
import { resolveMintlifyRefs, shouldResolveRefs } from "../utils/resolveMintlifyRefs.js";
|
|
10
10
|
import { validateYamlSchema } from "../formats/yaml/utils.js";
|
|
11
11
|
import { findOrCreateEntry, readLockfile, writeLockfile } from "../fs/config/downloadedVersions.js";
|
|
12
12
|
import { extractYaml } from "../formats/yaml/extractYaml.js";
|
|
@@ -4,8 +4,8 @@ import { logErrorAndExit } from "../console/logging.js";
|
|
|
4
4
|
import { branchResolutionError } from "../console/index.js";
|
|
5
5
|
import { BranchStep } from "../workflows/steps/BranchStep.js";
|
|
6
6
|
import { runPublishWorkflow } from "../workflows/publish.js";
|
|
7
|
-
import { collectAndSendUserEditDiffs } from "./collectUserEditDiffs.js";
|
|
8
7
|
import { aggregateFiles } from "../formats/files/aggregateFiles.js";
|
|
8
|
+
import { collectAndSendUserEditDiffs } from "./collectUserEditDiffs.js";
|
|
9
9
|
import chalk from "chalk";
|
|
10
10
|
//#region src/api/saveLocalEdits.ts
|
|
11
11
|
/**
|
package/dist/cli/base.js
CHANGED
|
@@ -250,14 +250,8 @@ var BaseCLI = class {
|
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
async handleUploadCommand(settings) {
|
|
253
|
-
let dataFormat;
|
|
254
|
-
if (this.library === "next-intl") dataFormat = "ICU";
|
|
255
|
-
else if (this.library === "i18next") if (this.additionalModules.includes("i18next-icu")) dataFormat = "ICU";
|
|
256
|
-
else dataFormat = "I18NEXT";
|
|
257
|
-
else dataFormat = "JSX";
|
|
258
253
|
if (!settings.files) return;
|
|
259
|
-
|
|
260
|
-
await upload(sourceFiles, placeholderPaths, transformPaths, dataFormat, settings);
|
|
254
|
+
await upload(settings);
|
|
261
255
|
}
|
|
262
256
|
async handleInitCommand(ranReactSetup, useDefaults = false, isVite = false) {
|
|
263
257
|
const { defaultLocale, locales } = await getDesiredLocales();
|
package/dist/cli/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../src/cli/base.ts"],"sourcesContent":["import { Command } from 'commander';\nimport {\n DEFAULT_TRANSLATIONS_DIR,\n DEFAULT_VITE_TRANSLATIONS_DIR,\n} from '../utils/constants.js';\nimport { createOrUpdateConfig } from '../fs/config/setupConfig.js';\nimport findFilepath from '../fs/findFilepath.js';\nimport {\n displayHeader,\n promptText,\n logErrorAndExit,\n promptConfirm,\n promptMultiSelect,\n promptSelect,\n promptGlobPatterns,\n} from '../console/logging.js';\nimport { logger } from '../console/logger.js';\nimport { parseGlobPatterns } from '../console/promptParsing.js';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport {\n FilesOptions,\n Settings,\n SupportedLibraries,\n SetupOptions,\n TranslateFlags,\n SharedFlags,\n} from '../types/index.js';\nimport { DataFormat } from '../types/data.js';\nimport { generateSettings } from '../config/generateSettings.js';\nimport chalk from 'chalk';\nimport { FILE_EXT_TO_EXT_LABEL } from '../formats/files/supportedFiles.js';\nimport { handleSetupReactCommand } from '../setup/wizard.js';\nimport {\n isPackageInstalled,\n searchForPackageJson,\n} from '../utils/packageJson.js';\nimport { getDesiredLocales } from '../setup/userInput.js';\nimport { installPackage } from '../utils/installPackage.js';\nimport { getPackageManager } from '../utils/packageManager.js';\nimport { retrieveCredentials, setCredentials } from '../utils/credentials.js';\nimport { areCredentialsSet } from '../utils/credentials.js';\nimport { upload } from './commands/upload.js';\nimport { attachSharedFlags, attachTranslateFlags } from './flags.js';\nimport { handleStage } from './commands/stage.js';\nimport { handleSetupProject } from './commands/setupProject.js';\nimport { handleDownload } from './commands/download.js';\nimport {\n handleTranslate,\n postProcessTranslations,\n} from './commands/translate.js';\nimport {\n getNeedsPostprocessing,\n clearDownloaded,\n} from '../state/recentDownloads.js';\nimport { clearWarnings } from '../state/translateWarnings.js';\nimport { displayTranslateSummary } from '../console/displayTranslateSummary.js';\nimport updateConfig from '../fs/config/updateConfig.js';\nimport { createLoadTranslationsFile } from '../fs/createLoadTranslationsFile.js';\nimport { saveLocalEdits } from '../api/saveLocalEdits.js';\nimport processSharedStaticAssets, {\n mirrorAssetsToLocales,\n} from '../utils/sharedStaticAssets.js';\nimport { setupLocadex } from '../locadex/setupFlow.js';\nimport { detectFramework } from '../setup/detectFramework.js';\nimport {\n getFrameworkDisplayName,\n getReactFrameworkLibrary,\n} from '../setup/frameworkUtils.js';\nimport { INLINE_LIBRARIES } from '../types/libraries.js';\nimport { handleEnqueue } from './commands/enqueue.js';\nimport { splitMintlifyLanguageRefs } from '../utils/splitMintlifyLanguageRefs.js';\n\nexport type UploadOptions = {\n config?: string;\n apiKey?: string;\n projectId?: string;\n defaultLocale?: string;\n};\n\nexport type LoginOptions = {\n config?: string;\n keyType?: 'development' | 'production' | 'all';\n};\n\nexport class BaseCLI {\n protected library: SupportedLibraries;\n protected additionalModules: SupportedLibraries[];\n protected program: Command;\n // Constructor is shared amongst all CLI class types\n public constructor(\n program: Command,\n library: SupportedLibraries,\n additionalModules?: SupportedLibraries[]\n ) {\n this.program = program;\n this.library = library;\n this.additionalModules = additionalModules || [];\n\n this.program.option(\n '--skip-version-check',\n 'Skip the monorepo GT package version consistency check'\n );\n\n this.setupInitCommand();\n this.setupConfigureCommand();\n this.setupUploadCommand();\n this.setupLoginCommand();\n this.setupSendDiffsCommand();\n }\n // Init is never called in a child class\n public init() {\n this.setupSetupProjectCommand();\n this.setupStageCommand();\n this.setupTranslateCommand();\n this.setupDownloadCommand();\n this.setupEnqueueCommand();\n }\n // Execute is called by the main program\n public execute() {\n // If no command is specified, run 'init'\n if (process.argv.length <= 2) {\n process.argv.push('init');\n }\n }\n\n protected setupSetupProjectCommand(): void {\n attachTranslateFlags(\n this.program\n .command('setup')\n .description(\n 'Upload source files and setup the project for translation'\n )\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Uploading source files and setting up project...');\n await this.handleSetupProject(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupStageCommand(): void {\n attachTranslateFlags(\n this.program\n .command('stage')\n .description(\n 'Submits the project to the General Translation API for translation. Translations created using this command will require human approval.'\n )\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader(\n 'Staging project for translation with approval required...'\n );\n await this.handleStage(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n /**\n * Enqueues translations for a given set of files\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected setupEnqueueCommand(): void {\n attachTranslateFlags(\n this.program\n .command('enqueue')\n .description('Enqueues translations for a given set of files')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Enqueuing translations...');\n await this.handleEnqueue(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n /**\n * Downloads translations that were originally staged\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected setupDownloadCommand(): void {\n attachTranslateFlags(\n this.program\n .command('download')\n .description('Download translations that were originally staged')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Downloading translations...');\n await this.handleDownload(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupTranslateCommand(): void {\n attachTranslateFlags(\n this.program\n .command('translate')\n .description('Translate your project using General Translation')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Starting translation...');\n await this.handleTranslate(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupSendDiffsCommand(): void {\n attachSharedFlags(\n this.program\n .command('save-local')\n .description(\n 'Save local edits for all configured files by sending diffs (no translation enqueued)'\n )\n )\n .option('--publish', 'Publish translations to the CDN', false)\n .action(async (initOptions: SharedFlags) => {\n displayHeader('Saving local edits...');\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await saveLocalEdits(settings);\n logger.endCommand('Saved local edits');\n });\n }\n\n protected async handleSetupProject(\n initOptions: TranslateFlags\n ): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n await handleSetupProject(initOptions, settings, this.library);\n }\n\n protected async handleStage(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n if (!settings.stageTranslations) {\n // Update settings.stageTranslations to true\n settings.stageTranslations = true;\n await updateConfig(settings.config, {\n stageTranslations: true,\n });\n }\n await handleStage(initOptions, settings, this.library, true);\n }\n\n /**\n * Enqueues translations for a given set of files\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected async handleEnqueue(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await handleEnqueue(initOptions, settings, this.library);\n }\n\n /**\n * Downloads translations that were originally staged\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected async handleDownload(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await handleDownload(initOptions, settings, this.library);\n }\n\n protected async handleTranslate(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n if (!settings.stageTranslations) {\n const results = await handleStage(\n initOptions,\n settings,\n this.library,\n false\n );\n if (results) {\n await handleTranslate(\n initOptions,\n settings,\n results.fileVersionData,\n results.jobData,\n results.branchData,\n results.publishMap\n );\n }\n } else {\n await handleDownload(initOptions, settings, this.library);\n }\n // Only postprocess files downloaded in this run\n const include = getNeedsPostprocessing();\n if (include.size > 0) {\n await postProcessTranslations(settings, include);\n }\n // Split Mintlify language entries into $ref files to keep docs.json small\n await splitMintlifyLanguageRefs(settings);\n // Mirror assets after translations are downloaded and locale dirs are populated\n await mirrorAssetsToLocales(settings);\n clearDownloaded();\n displayTranslateSummary();\n clearWarnings();\n }\n\n protected setupUploadCommand(): void {\n attachTranslateFlags(\n this.program\n .command('upload')\n .description(\n 'Upload source files and translations to the General Translation platform'\n )\n ).action(async (initOptions: UploadOptions) => {\n displayHeader('Starting upload...');\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n const options = { ...initOptions, ...settings };\n\n await this.handleUploadCommand(options);\n logger.endCommand('Done!');\n });\n }\n\n protected setupLoginCommand(): void {\n this.program\n .command('auth')\n .description('Generate General Translation API keys and project ID')\n .option(\n '-c, --config <path>',\n 'Filepath to config file, by default gt.config.json',\n findFilepath(['gt.config.json'])\n )\n .option(\n '-t, --key-type <type>',\n 'Type of key to generate, production | development | all'\n )\n .action(async (options: LoginOptions) => {\n displayHeader('Authenticating with General Translation...');\n if (!options.keyType) {\n options.keyType = await promptSelect<\n 'development' | 'production' | 'all'\n >({\n message: 'What type of API key would you like to generate?',\n options: [\n { value: 'development', label: 'Development' },\n { value: 'production', label: 'Production' },\n { value: 'all', label: 'Both' },\n ],\n defaultValue: 'all',\n });\n } else {\n if (\n options.keyType !== 'development' &&\n options.keyType !== 'production' &&\n options.keyType !== 'all'\n ) {\n logErrorAndExit(\n 'Invalid key type, must be development, production, or all'\n );\n }\n }\n await this.handleLoginCommand(options);\n logger.endCommand(\n `Done! ${options.keyType} keys have been generated and saved to your .env.local file.`\n );\n });\n }\n\n protected setupInitCommand(): void {\n this.program\n .command('init')\n .description(\n 'Run the setup wizard to configure your project for General Translation'\n )\n .option(\n '--src <paths...>',\n \"Space-separated list of glob patterns containing the app's source code, by default 'src/**/*.{js,jsx,ts,tsx}' 'app/**/*.{js,jsx,ts,tsx}' 'pages/**/*.{js,jsx,ts,tsx}' 'components/**/*.{js,jsx,ts,tsx}'\"\n )\n .option(\n '-c, --config <path>',\n 'Filepath to config file, by default gt.config.json',\n findFilepath(['gt.config.json'])\n )\n .action(async (options: SetupOptions) => {\n const settings = await generateSettings(options);\n displayHeader('Running setup wizard...');\n\n const framework = await detectFramework();\n\n const useAgent = await (async () => {\n let useAgentMessage;\n if (framework.name === 'mintlify') {\n useAgentMessage = `Mintlify project detected. Would you like to connect to GitHub so that the Locadex AI Agent can translate your project automatically?`;\n }\n if (framework.name === 'next-app') {\n useAgentMessage = `Next.js App Router detected. Would you like to connect to GitHub so that the Locadex AI Agent can set up your project automatically?`;\n }\n if (useAgentMessage) {\n return await promptConfirm({\n message: useAgentMessage,\n defaultValue: false,\n });\n }\n return false;\n })();\n\n if (useAgent) {\n await setupLocadex(settings);\n logger.endCommand(\n 'Once installed, Locadex will open a PR to your repository. See the docs for more information: https://generaltranslation.com/docs/locadex'\n );\n } else {\n // Get framework display info for the defaults message\n const frameworkDisplayName =\n framework.type === 'react'\n ? getFrameworkDisplayName(framework)\n : null;\n const library =\n framework.type === 'react'\n ? getReactFrameworkLibrary(framework)\n : null;\n\n // Build defaults description based on detected framework\n const defaultTranslationsDir =\n framework.name === 'vite'\n ? DEFAULT_VITE_TRANSLATIONS_DIR\n : DEFAULT_TRANSLATIONS_DIR;\n\n const defaultsDescription =\n framework.type === 'react'\n ? `${library} & GTProvider, ${frameworkDisplayName}, Files saved locally in ${defaultTranslationsDir}`\n : `Files saved locally in ${defaultTranslationsDir}`;\n\n // Ask if user wants to use defaults\n const useDefaults = await promptConfirm({\n message: `Would you like to use the recommended General Translation defaults? ${chalk.dim(`(${defaultsDescription})`)}`,\n defaultValue: true,\n });\n\n let ranReactSetup = false;\n\n // so that people can run init in non-js projects\n if (framework.type === 'react') {\n const wrap = useDefaults\n ? true\n : await promptConfirm({\n message: `Would you like to install ${library} and add the GTProvider? See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`,\n defaultValue: true,\n });\n\n if (wrap) {\n logger.info(\n `${chalk.yellow('[EXPERIMENTAL]')} Configuring project...`\n );\n await handleSetupReactCommand(options, framework, useDefaults);\n logger.endCommand(\n `Done! Since this wizard is experimental, please review the changes and make modifications as needed.\n\\nNext step: start internationalizing! See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`\n );\n ranReactSetup = true;\n }\n }\n\n if (ranReactSetup) {\n logger.startCommand('Setting up project config...');\n }\n // Configure gt.config.json\n await this.handleInitCommand(\n ranReactSetup,\n useDefaults,\n framework.name === 'vite'\n );\n\n logger.endCommand(\n 'Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs'\n );\n }\n });\n }\n\n protected setupConfigureCommand(): void {\n this.program\n .command('configure')\n .description(\n 'Configure your project for General Translation. This will create a gt.config.json file in your codebase.'\n )\n .action(async () => {\n displayHeader('Configuring project...');\n\n logger.info(\n 'Welcome! This tool will help you configure your gt.config.json file. See the docs: https://generaltranslation.com/docs/cli/reference/config for more information.'\n );\n\n // Configure gt.config.json\n const framework = await detectFramework();\n await this.handleInitCommand(false, false, framework.name === 'vite');\n\n logger.endCommand(\n 'Done! Make sure you have an API key and project ID to use General Translation. Get them on the dashboard: https://generaltranslation.com/dashboard'\n );\n });\n }\n\n protected async handleUploadCommand(\n settings: Settings & UploadOptions\n ): Promise<void> {\n // dataFormat for JSONs\n let dataFormat: DataFormat;\n if (this.library === 'next-intl') {\n dataFormat = 'ICU';\n } else if (this.library === 'i18next') {\n if (this.additionalModules.includes('i18next-icu')) {\n dataFormat = 'ICU';\n } else {\n dataFormat = 'I18NEXT';\n }\n } else {\n dataFormat = 'JSX';\n }\n\n if (!settings.files) {\n return;\n }\n const {\n resolvedPaths: sourceFiles,\n placeholderPaths,\n transformPaths,\n } = settings.files;\n\n // Process all file types at once with a single call\n await upload(\n sourceFiles,\n placeholderPaths,\n transformPaths,\n dataFormat,\n settings\n );\n }\n\n // Wizard for configuring gt.config.json\n protected async handleInitCommand(\n ranReactSetup: boolean,\n useDefaults: boolean = false,\n isVite: boolean = false\n ): Promise<void> {\n const { defaultLocale, locales } = await getDesiredLocales(); // Locales should still be asked for even if using defaults\n\n const packageJson = await searchForPackageJson();\n\n // Ask if using another i18n library\n const gtInstalled =\n !!packageJson &&\n INLINE_LIBRARIES.some((lib) => isPackageInstalled(lib, packageJson));\n const isUsingGT = ranReactSetup || gtInstalled;\n\n // Ask where the translations are stored\n const usingCDN = await (async () => {\n if (!isUsingGT) return false;\n if (useDefaults) return false; // Default to local\n const selectedValue = await promptSelect({\n message: `Would you like to save translation files locally or use the General Translation CDN to store them?`,\n options: [\n { value: 'local', label: 'Save locally' },\n { value: 'cdn', label: 'Use CDN' },\n ],\n defaultValue: 'local',\n });\n return selectedValue === 'cdn';\n })();\n\n const defaultTranslationsDir = isVite\n ? DEFAULT_VITE_TRANSLATIONS_DIR\n : DEFAULT_TRANSLATIONS_DIR;\n\n // Ask where the translations are stored\n const translationsDir =\n isUsingGT && !usingCDN\n ? useDefaults\n ? defaultTranslationsDir\n : await promptText({\n message:\n 'What is the path to the directory where you would like to store your translation files?',\n defaultValue: defaultTranslationsDir,\n })\n : null;\n\n // Determine final translations directory with fallback\n const finalTranslationsDir =\n translationsDir?.trim() || defaultTranslationsDir;\n\n if (isUsingGT && !usingCDN) {\n // Create loadTranslations.js file for local translations\n await createLoadTranslationsFile(\n process.cwd(),\n finalTranslationsDir,\n locales\n );\n logger.message(\n `Created ${chalk.cyan('loadTranslations.js')} file for local translations.\nMake sure to add this function to your app configuration.\nSee https://generaltranslation.com/en/docs/next/guides/local-tx`\n );\n }\n\n const message = !isUsingGT\n ? 'What is the format of your language resource files? Select as many as applicable.\\nAdditionally, you can translate any other files you have in your project.'\n : `Do you have any additional files in this project to translate? For example, Markdown files for docs. ${chalk.dim(\n '(To continue without selecting press Enter)'\n )}`;\n const fileExtensions =\n useDefaults && isUsingGT\n ? [] // Skip for GT projects when using defaults\n : await promptMultiSelect({\n message,\n options: [\n { value: 'json', label: FILE_EXT_TO_EXT_LABEL.json },\n { value: 'md', label: FILE_EXT_TO_EXT_LABEL.md },\n { value: 'mdx', label: FILE_EXT_TO_EXT_LABEL.mdx },\n { value: 'ts', label: FILE_EXT_TO_EXT_LABEL.ts },\n { value: 'js', label: FILE_EXT_TO_EXT_LABEL.js },\n { value: 'yaml', label: FILE_EXT_TO_EXT_LABEL.yaml },\n // TWILIO_CONTENT_JSON not supported in CLI init as its too niche\n ],\n required: !isUsingGT,\n });\n\n const files: FilesOptions = {};\n for (const fileExtension of fileExtensions) {\n const label = FILE_EXT_TO_EXT_LABEL[fileExtension];\n const paths = await promptGlobPatterns({\n label,\n message: `${chalk.cyan(FILE_EXT_TO_EXT_LABEL[fileExtension])}: Enter a space-separated list of glob patterns matching the location of the ${FILE_EXT_TO_EXT_LABEL[fileExtension]} files you would like to translate.\\nMake sure to include [locale] in the patterns.\\nSee https://generaltranslation.com/docs/cli/reference/config#include for more information.`,\n defaultValue: `./**/[locale]/*.${fileExtension}`,\n });\n\n files[fileExtension] = {\n include: parseGlobPatterns(paths),\n };\n }\n\n // Add GT translations if using GT and storing locally\n if (isUsingGT && !usingCDN) {\n files.gt = {\n output: path.join(finalTranslationsDir, `[locale].json`),\n };\n }\n\n let configFilepath = 'gt.config.json';\n if (fs.existsSync('src/gt.config.json')) {\n configFilepath = 'src/gt.config.json';\n }\n\n // Create gt.config.json\n await createOrUpdateConfig(configFilepath, {\n defaultLocale,\n locales,\n files: Object.keys(files).length > 0 ? files : undefined,\n publish: isUsingGT && usingCDN,\n });\n\n logger.success(\n `Edit ${chalk.cyan(\n configFilepath\n )} to customize your translation setup. Docs: https://generaltranslation.com/docs/cli/reference/config`\n );\n\n // Install gt if not installed\n const isCLIInstalled = packageJson\n ? isPackageInstalled('gt', packageJson, true, true)\n : true; // if no package.json, we can't install it\n\n if (!isCLIInstalled) {\n const packageManager = await getPackageManager();\n const spinner = logger.createSpinner();\n spinner.start(\n `Installing gt as a dev dependency with ${packageManager.name}...`\n );\n await installPackage('gt', packageManager, true);\n spinner.stop(chalk.green('Installed gt.'));\n }\n\n // Set credentials\n if (!areCredentialsSet()) {\n const loginQuestion = useDefaults\n ? true\n : await promptConfirm({\n message:\n 'Would you like the wizard to automatically generate API keys and a project ID for you?',\n defaultValue: true,\n });\n if (loginQuestion) {\n const settings = await generateSettings({});\n const keyType = useDefaults\n ? 'all'\n : await promptSelect<'development' | 'production' | 'all'>({\n message: 'What type of API key would you like to generate?',\n options: [\n { value: 'development', label: 'Development' },\n { value: 'production', label: 'Production' },\n { value: 'all', label: 'Both' },\n ],\n defaultValue: 'all',\n });\n const credentials = await retrieveCredentials(settings, keyType);\n await setCredentials(credentials, settings.framework);\n }\n }\n }\n protected async handleLoginCommand(options: LoginOptions): Promise<void> {\n const settings = await generateSettings({ config: options.config });\n const keyType = options.keyType || 'all';\n const credentials = await retrieveCredentials(settings, keyType);\n await setCredentials(credentials, settings.framework);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CAEA,YACE,SACA,SACA,mBACA;AACA,OAAK,UAAU;AACf,OAAK,UAAU;AACf,OAAK,oBAAoB,qBAAqB,EAAE;AAEhD,OAAK,QAAQ,OACX,wBACA,yDACD;AAED,OAAK,kBAAkB;AACvB,OAAK,uBAAuB;AAC5B,OAAK,oBAAoB;AACzB,OAAK,mBAAmB;AACxB,OAAK,uBAAuB;;CAG9B,OAAc;AACZ,OAAK,0BAA0B;AAC/B,OAAK,mBAAmB;AACxB,OAAK,uBAAuB;AAC5B,OAAK,sBAAsB;AAC3B,OAAK,qBAAqB;;CAG5B,UAAiB;AAEf,MAAI,QAAQ,KAAK,UAAU,EACzB,SAAQ,KAAK,KAAK,OAAO;;CAI7B,2BAA2C;AACzC,uBACE,KAAK,QACF,QAAQ,QAAQ,CAChB,YACC,4DACD,CACJ,CAAC,OAAO,OAAO,gBAAgC;AAC9C,iBAAc,mDAAmD;AACjE,SAAM,KAAK,mBAAmB,YAAY;AAC1C,UAAO,WAAW,QAAQ;IAC1B;;CAGJ,oBAAoC;AAClC,uBACE,KAAK,QACF,QAAQ,QAAQ,CAChB,YACC,2IACD,CACJ,CAAC,OAAO,OAAO,gBAAgC;AAC9C,iBACE,4DACD;AACD,SAAM,KAAK,YAAY,YAAY;AACnC,UAAO,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E,QAAQ,QAAQ,QAAQ,CAAC;AAGnE,QAAM,eAAe,MADK,oBAAoB,UAD9B,QAAQ,WAAW,MAC6B,EAC9B,SAAS,UAAU"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../src/cli/base.ts"],"sourcesContent":["import { Command } from 'commander';\nimport {\n DEFAULT_TRANSLATIONS_DIR,\n DEFAULT_VITE_TRANSLATIONS_DIR,\n} from '../utils/constants.js';\nimport { createOrUpdateConfig } from '../fs/config/setupConfig.js';\nimport findFilepath from '../fs/findFilepath.js';\nimport {\n displayHeader,\n promptText,\n logErrorAndExit,\n promptConfirm,\n promptMultiSelect,\n promptSelect,\n promptGlobPatterns,\n} from '../console/logging.js';\nimport { logger } from '../console/logger.js';\nimport { parseGlobPatterns } from '../console/promptParsing.js';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport {\n FilesOptions,\n Settings,\n SupportedLibraries,\n SetupOptions,\n TranslateFlags,\n SharedFlags,\n} from '../types/index.js';\nimport { generateSettings } from '../config/generateSettings.js';\nimport chalk from 'chalk';\nimport { FILE_EXT_TO_EXT_LABEL } from '../formats/files/supportedFiles.js';\nimport { handleSetupReactCommand } from '../setup/wizard.js';\nimport {\n isPackageInstalled,\n searchForPackageJson,\n} from '../utils/packageJson.js';\nimport { getDesiredLocales } from '../setup/userInput.js';\nimport { installPackage } from '../utils/installPackage.js';\nimport { getPackageManager } from '../utils/packageManager.js';\nimport { retrieveCredentials, setCredentials } from '../utils/credentials.js';\nimport { areCredentialsSet } from '../utils/credentials.js';\nimport { upload } from './commands/upload.js';\nimport { attachSharedFlags, attachTranslateFlags } from './flags.js';\nimport { handleStage } from './commands/stage.js';\nimport { handleSetupProject } from './commands/setupProject.js';\nimport { handleDownload } from './commands/download.js';\nimport {\n handleTranslate,\n postProcessTranslations,\n} from './commands/translate.js';\nimport {\n getNeedsPostprocessing,\n clearDownloaded,\n} from '../state/recentDownloads.js';\nimport { clearWarnings } from '../state/translateWarnings.js';\nimport { displayTranslateSummary } from '../console/displayTranslateSummary.js';\nimport updateConfig from '../fs/config/updateConfig.js';\nimport { createLoadTranslationsFile } from '../fs/createLoadTranslationsFile.js';\nimport { saveLocalEdits } from '../api/saveLocalEdits.js';\nimport processSharedStaticAssets, {\n mirrorAssetsToLocales,\n} from '../utils/sharedStaticAssets.js';\nimport { setupLocadex } from '../locadex/setupFlow.js';\nimport { detectFramework } from '../setup/detectFramework.js';\nimport {\n getFrameworkDisplayName,\n getReactFrameworkLibrary,\n} from '../setup/frameworkUtils.js';\nimport { INLINE_LIBRARIES } from '../types/libraries.js';\nimport { handleEnqueue } from './commands/enqueue.js';\nimport { splitMintlifyLanguageRefs } from '../utils/splitMintlifyLanguageRefs.js';\n\nexport type UploadOptions = {\n config?: string;\n apiKey?: string;\n projectId?: string;\n defaultLocale?: string;\n};\n\nexport type LoginOptions = {\n config?: string;\n keyType?: 'development' | 'production' | 'all';\n};\n\nexport class BaseCLI {\n protected library: SupportedLibraries;\n protected additionalModules: SupportedLibraries[];\n protected program: Command;\n // Constructor is shared amongst all CLI class types\n public constructor(\n program: Command,\n library: SupportedLibraries,\n additionalModules?: SupportedLibraries[]\n ) {\n this.program = program;\n this.library = library;\n this.additionalModules = additionalModules || [];\n\n this.program.option(\n '--skip-version-check',\n 'Skip the monorepo GT package version consistency check'\n );\n\n this.setupInitCommand();\n this.setupConfigureCommand();\n this.setupUploadCommand();\n this.setupLoginCommand();\n this.setupSendDiffsCommand();\n }\n // Init is never called in a child class\n public init() {\n this.setupSetupProjectCommand();\n this.setupStageCommand();\n this.setupTranslateCommand();\n this.setupDownloadCommand();\n this.setupEnqueueCommand();\n }\n // Execute is called by the main program\n public execute() {\n // If no command is specified, run 'init'\n if (process.argv.length <= 2) {\n process.argv.push('init');\n }\n }\n\n protected setupSetupProjectCommand(): void {\n attachTranslateFlags(\n this.program\n .command('setup')\n .description(\n 'Upload source files and setup the project for translation'\n )\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Uploading source files and setting up project...');\n await this.handleSetupProject(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupStageCommand(): void {\n attachTranslateFlags(\n this.program\n .command('stage')\n .description(\n 'Submits the project to the General Translation API for translation. Translations created using this command will require human approval.'\n )\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader(\n 'Staging project for translation with approval required...'\n );\n await this.handleStage(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n /**\n * Enqueues translations for a given set of files\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected setupEnqueueCommand(): void {\n attachTranslateFlags(\n this.program\n .command('enqueue')\n .description('Enqueues translations for a given set of files')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Enqueuing translations...');\n await this.handleEnqueue(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n /**\n * Downloads translations that were originally staged\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected setupDownloadCommand(): void {\n attachTranslateFlags(\n this.program\n .command('download')\n .description('Download translations that were originally staged')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Downloading translations...');\n await this.handleDownload(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupTranslateCommand(): void {\n attachTranslateFlags(\n this.program\n .command('translate')\n .description('Translate your project using General Translation')\n ).action(async (initOptions: TranslateFlags) => {\n displayHeader('Starting translation...');\n await this.handleTranslate(initOptions);\n logger.endCommand('Done!');\n });\n }\n\n protected setupSendDiffsCommand(): void {\n attachSharedFlags(\n this.program\n .command('save-local')\n .description(\n 'Save local edits for all configured files by sending diffs (no translation enqueued)'\n )\n )\n .option('--publish', 'Publish translations to the CDN', false)\n .action(async (initOptions: SharedFlags) => {\n displayHeader('Saving local edits...');\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await saveLocalEdits(settings);\n logger.endCommand('Saved local edits');\n });\n }\n\n protected async handleSetupProject(\n initOptions: TranslateFlags\n ): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n await handleSetupProject(initOptions, settings, this.library);\n }\n\n protected async handleStage(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n if (!settings.stageTranslations) {\n // Update settings.stageTranslations to true\n settings.stageTranslations = true;\n await updateConfig(settings.config, {\n stageTranslations: true,\n });\n }\n await handleStage(initOptions, settings, this.library, true);\n }\n\n /**\n * Enqueues translations for a given set of files\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected async handleEnqueue(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await handleEnqueue(initOptions, settings, this.library);\n }\n\n /**\n * Downloads translations that were originally staged\n * @param initOptions - The options for the command\n * @returns The results of the command\n */\n protected async handleDownload(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n await handleDownload(initOptions, settings, this.library);\n }\n\n protected async handleTranslate(initOptions: TranslateFlags): Promise<void> {\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n // Preprocess shared static assets if configured (move + rewrite sources)\n await processSharedStaticAssets(settings);\n\n if (!settings.stageTranslations) {\n const results = await handleStage(\n initOptions,\n settings,\n this.library,\n false\n );\n if (results) {\n await handleTranslate(\n initOptions,\n settings,\n results.fileVersionData,\n results.jobData,\n results.branchData,\n results.publishMap\n );\n }\n } else {\n await handleDownload(initOptions, settings, this.library);\n }\n // Only postprocess files downloaded in this run\n const include = getNeedsPostprocessing();\n if (include.size > 0) {\n await postProcessTranslations(settings, include);\n }\n // Split Mintlify language entries into $ref files to keep docs.json small\n await splitMintlifyLanguageRefs(settings);\n // Mirror assets after translations are downloaded and locale dirs are populated\n await mirrorAssetsToLocales(settings);\n clearDownloaded();\n displayTranslateSummary();\n clearWarnings();\n }\n\n protected setupUploadCommand(): void {\n attachTranslateFlags(\n this.program\n .command('upload')\n .description(\n 'Upload source files and translations to the General Translation platform'\n )\n ).action(async (initOptions: UploadOptions) => {\n displayHeader('Starting upload...');\n const settings = await generateSettings(initOptions, undefined, {\n requireConfig: true,\n });\n\n const options = { ...initOptions, ...settings };\n\n await this.handleUploadCommand(options);\n logger.endCommand('Done!');\n });\n }\n\n protected setupLoginCommand(): void {\n this.program\n .command('auth')\n .description('Generate General Translation API keys and project ID')\n .option(\n '-c, --config <path>',\n 'Filepath to config file, by default gt.config.json',\n findFilepath(['gt.config.json'])\n )\n .option(\n '-t, --key-type <type>',\n 'Type of key to generate, production | development | all'\n )\n .action(async (options: LoginOptions) => {\n displayHeader('Authenticating with General Translation...');\n if (!options.keyType) {\n options.keyType = await promptSelect<\n 'development' | 'production' | 'all'\n >({\n message: 'What type of API key would you like to generate?',\n options: [\n { value: 'development', label: 'Development' },\n { value: 'production', label: 'Production' },\n { value: 'all', label: 'Both' },\n ],\n defaultValue: 'all',\n });\n } else {\n if (\n options.keyType !== 'development' &&\n options.keyType !== 'production' &&\n options.keyType !== 'all'\n ) {\n logErrorAndExit(\n 'Invalid key type, must be development, production, or all'\n );\n }\n }\n await this.handleLoginCommand(options);\n logger.endCommand(\n `Done! ${options.keyType} keys have been generated and saved to your .env.local file.`\n );\n });\n }\n\n protected setupInitCommand(): void {\n this.program\n .command('init')\n .description(\n 'Run the setup wizard to configure your project for General Translation'\n )\n .option(\n '--src <paths...>',\n \"Space-separated list of glob patterns containing the app's source code, by default 'src/**/*.{js,jsx,ts,tsx}' 'app/**/*.{js,jsx,ts,tsx}' 'pages/**/*.{js,jsx,ts,tsx}' 'components/**/*.{js,jsx,ts,tsx}'\"\n )\n .option(\n '-c, --config <path>',\n 'Filepath to config file, by default gt.config.json',\n findFilepath(['gt.config.json'])\n )\n .action(async (options: SetupOptions) => {\n const settings = await generateSettings(options);\n displayHeader('Running setup wizard...');\n\n const framework = await detectFramework();\n\n const useAgent = await (async () => {\n let useAgentMessage;\n if (framework.name === 'mintlify') {\n useAgentMessage = `Mintlify project detected. Would you like to connect to GitHub so that the Locadex AI Agent can translate your project automatically?`;\n }\n if (framework.name === 'next-app') {\n useAgentMessage = `Next.js App Router detected. Would you like to connect to GitHub so that the Locadex AI Agent can set up your project automatically?`;\n }\n if (useAgentMessage) {\n return await promptConfirm({\n message: useAgentMessage,\n defaultValue: false,\n });\n }\n return false;\n })();\n\n if (useAgent) {\n await setupLocadex(settings);\n logger.endCommand(\n 'Once installed, Locadex will open a PR to your repository. See the docs for more information: https://generaltranslation.com/docs/locadex'\n );\n } else {\n // Get framework display info for the defaults message\n const frameworkDisplayName =\n framework.type === 'react'\n ? getFrameworkDisplayName(framework)\n : null;\n const library =\n framework.type === 'react'\n ? getReactFrameworkLibrary(framework)\n : null;\n\n // Build defaults description based on detected framework\n const defaultTranslationsDir =\n framework.name === 'vite'\n ? DEFAULT_VITE_TRANSLATIONS_DIR\n : DEFAULT_TRANSLATIONS_DIR;\n\n const defaultsDescription =\n framework.type === 'react'\n ? `${library} & GTProvider, ${frameworkDisplayName}, Files saved locally in ${defaultTranslationsDir}`\n : `Files saved locally in ${defaultTranslationsDir}`;\n\n // Ask if user wants to use defaults\n const useDefaults = await promptConfirm({\n message: `Would you like to use the recommended General Translation defaults? ${chalk.dim(`(${defaultsDescription})`)}`,\n defaultValue: true,\n });\n\n let ranReactSetup = false;\n\n // so that people can run init in non-js projects\n if (framework.type === 'react') {\n const wrap = useDefaults\n ? true\n : await promptConfirm({\n message: `Would you like to install ${library} and add the GTProvider? See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`,\n defaultValue: true,\n });\n\n if (wrap) {\n logger.info(\n `${chalk.yellow('[EXPERIMENTAL]')} Configuring project...`\n );\n await handleSetupReactCommand(options, framework, useDefaults);\n logger.endCommand(\n `Done! Since this wizard is experimental, please review the changes and make modifications as needed.\n\\nNext step: start internationalizing! See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`\n );\n ranReactSetup = true;\n }\n }\n\n if (ranReactSetup) {\n logger.startCommand('Setting up project config...');\n }\n // Configure gt.config.json\n await this.handleInitCommand(\n ranReactSetup,\n useDefaults,\n framework.name === 'vite'\n );\n\n logger.endCommand(\n 'Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs'\n );\n }\n });\n }\n\n protected setupConfigureCommand(): void {\n this.program\n .command('configure')\n .description(\n 'Configure your project for General Translation. This will create a gt.config.json file in your codebase.'\n )\n .action(async () => {\n displayHeader('Configuring project...');\n\n logger.info(\n 'Welcome! This tool will help you configure your gt.config.json file. See the docs: https://generaltranslation.com/docs/cli/reference/config for more information.'\n );\n\n // Configure gt.config.json\n const framework = await detectFramework();\n await this.handleInitCommand(false, false, framework.name === 'vite');\n\n logger.endCommand(\n 'Done! Make sure you have an API key and project ID to use General Translation. Get them on the dashboard: https://generaltranslation.com/dashboard'\n );\n });\n }\n\n protected async handleUploadCommand(\n settings: Settings & UploadOptions\n ): Promise<void> {\n if (!settings.files) {\n return;\n }\n\n // Process all file types at once with a single call\n await upload(settings);\n }\n\n // Wizard for configuring gt.config.json\n protected async handleInitCommand(\n ranReactSetup: boolean,\n useDefaults: boolean = false,\n isVite: boolean = false\n ): Promise<void> {\n const { defaultLocale, locales } = await getDesiredLocales(); // Locales should still be asked for even if using defaults\n\n const packageJson = await searchForPackageJson();\n\n // Ask if using another i18n library\n const gtInstalled =\n !!packageJson &&\n INLINE_LIBRARIES.some((lib) => isPackageInstalled(lib, packageJson));\n const isUsingGT = ranReactSetup || gtInstalled;\n\n // Ask where the translations are stored\n const usingCDN = await (async () => {\n if (!isUsingGT) return false;\n if (useDefaults) return false; // Default to local\n const selectedValue = await promptSelect({\n message: `Would you like to save translation files locally or use the General Translation CDN to store them?`,\n options: [\n { value: 'local', label: 'Save locally' },\n { value: 'cdn', label: 'Use CDN' },\n ],\n defaultValue: 'local',\n });\n return selectedValue === 'cdn';\n })();\n\n const defaultTranslationsDir = isVite\n ? DEFAULT_VITE_TRANSLATIONS_DIR\n : DEFAULT_TRANSLATIONS_DIR;\n\n // Ask where the translations are stored\n const translationsDir =\n isUsingGT && !usingCDN\n ? useDefaults\n ? defaultTranslationsDir\n : await promptText({\n message:\n 'What is the path to the directory where you would like to store your translation files?',\n defaultValue: defaultTranslationsDir,\n })\n : null;\n\n // Determine final translations directory with fallback\n const finalTranslationsDir =\n translationsDir?.trim() || defaultTranslationsDir;\n\n if (isUsingGT && !usingCDN) {\n // Create loadTranslations.js file for local translations\n await createLoadTranslationsFile(\n process.cwd(),\n finalTranslationsDir,\n locales\n );\n logger.message(\n `Created ${chalk.cyan('loadTranslations.js')} file for local translations.\nMake sure to add this function to your app configuration.\nSee https://generaltranslation.com/en/docs/next/guides/local-tx`\n );\n }\n\n const message = !isUsingGT\n ? 'What is the format of your language resource files? Select as many as applicable.\\nAdditionally, you can translate any other files you have in your project.'\n : `Do you have any additional files in this project to translate? For example, Markdown files for docs. ${chalk.dim(\n '(To continue without selecting press Enter)'\n )}`;\n const fileExtensions =\n useDefaults && isUsingGT\n ? [] // Skip for GT projects when using defaults\n : await promptMultiSelect({\n message,\n options: [\n { value: 'json', label: FILE_EXT_TO_EXT_LABEL.json },\n { value: 'md', label: FILE_EXT_TO_EXT_LABEL.md },\n { value: 'mdx', label: FILE_EXT_TO_EXT_LABEL.mdx },\n { value: 'ts', label: FILE_EXT_TO_EXT_LABEL.ts },\n { value: 'js', label: FILE_EXT_TO_EXT_LABEL.js },\n { value: 'yaml', label: FILE_EXT_TO_EXT_LABEL.yaml },\n // TWILIO_CONTENT_JSON not supported in CLI init as its too niche\n ],\n required: !isUsingGT,\n });\n\n const files: FilesOptions = {};\n for (const fileExtension of fileExtensions) {\n const label = FILE_EXT_TO_EXT_LABEL[fileExtension];\n const paths = await promptGlobPatterns({\n label,\n message: `${chalk.cyan(FILE_EXT_TO_EXT_LABEL[fileExtension])}: Enter a space-separated list of glob patterns matching the location of the ${FILE_EXT_TO_EXT_LABEL[fileExtension]} files you would like to translate.\\nMake sure to include [locale] in the patterns.\\nSee https://generaltranslation.com/docs/cli/reference/config#include for more information.`,\n defaultValue: `./**/[locale]/*.${fileExtension}`,\n });\n\n files[fileExtension] = {\n include: parseGlobPatterns(paths),\n };\n }\n\n // Add GT translations if using GT and storing locally\n if (isUsingGT && !usingCDN) {\n files.gt = {\n output: path.join(finalTranslationsDir, `[locale].json`),\n };\n }\n\n let configFilepath = 'gt.config.json';\n if (fs.existsSync('src/gt.config.json')) {\n configFilepath = 'src/gt.config.json';\n }\n\n // Create gt.config.json\n await createOrUpdateConfig(configFilepath, {\n defaultLocale,\n locales,\n files: Object.keys(files).length > 0 ? files : undefined,\n publish: isUsingGT && usingCDN,\n });\n\n logger.success(\n `Edit ${chalk.cyan(\n configFilepath\n )} to customize your translation setup. Docs: https://generaltranslation.com/docs/cli/reference/config`\n );\n\n // Install gt if not installed\n const isCLIInstalled = packageJson\n ? isPackageInstalled('gt', packageJson, true, true)\n : true; // if no package.json, we can't install it\n\n if (!isCLIInstalled) {\n const packageManager = await getPackageManager();\n const spinner = logger.createSpinner();\n spinner.start(\n `Installing gt as a dev dependency with ${packageManager.name}...`\n );\n await installPackage('gt', packageManager, true);\n spinner.stop(chalk.green('Installed gt.'));\n }\n\n // Set credentials\n if (!areCredentialsSet()) {\n const loginQuestion = useDefaults\n ? true\n : await promptConfirm({\n message:\n 'Would you like the wizard to automatically generate API keys and a project ID for you?',\n defaultValue: true,\n });\n if (loginQuestion) {\n const settings = await generateSettings({});\n const keyType = useDefaults\n ? 'all'\n : await promptSelect<'development' | 'production' | 'all'>({\n message: 'What type of API key would you like to generate?',\n options: [\n { value: 'development', label: 'Development' },\n { value: 'production', label: 'Production' },\n { value: 'all', label: 'Both' },\n ],\n defaultValue: 'all',\n });\n const credentials = await retrieveCredentials(settings, keyType);\n await setCredentials(credentials, settings.framework);\n }\n }\n }\n protected async handleLoginCommand(options: LoginOptions): Promise<void> {\n const settings = await generateSettings({ config: options.config });\n const keyType = options.keyType || 'all';\n const credentials = await retrieveCredentials(settings, keyType);\n await setCredentials(credentials, settings.framework);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CAEA,YACE,SACA,SACA,mBACA;AACA,OAAK,UAAU;AACf,OAAK,UAAU;AACf,OAAK,oBAAoB,qBAAqB,EAAE;AAEhD,OAAK,QAAQ,OACX,wBACA,yDACD;AAED,OAAK,kBAAkB;AACvB,OAAK,uBAAuB;AAC5B,OAAK,oBAAoB;AACzB,OAAK,mBAAmB;AACxB,OAAK,uBAAuB;;CAG9B,OAAc;AACZ,OAAK,0BAA0B;AAC/B,OAAK,mBAAmB;AACxB,OAAK,uBAAuB;AAC5B,OAAK,sBAAsB;AAC3B,OAAK,qBAAqB;;CAG5B,UAAiB;AAEf,MAAI,QAAQ,KAAK,UAAU,EACzB,SAAQ,KAAK,KAAK,OAAO;;CAI7B,2BAA2C;AACzC,uBACE,KAAK,QACF,QAAQ,QAAQ,CAChB,YACC,4DACD,CACJ,CAAC,OAAO,OAAO,gBAAgC;AAC9C,iBAAc,mDAAmD;AACjE,SAAM,KAAK,mBAAmB,YAAY;AAC1C,UAAO,WAAW,QAAQ;IAC1B;;CAGJ,oBAAoC;AAClC,uBACE,KAAK,QACF,QAAQ,QAAQ,CAChB,YACC,2IACD,CACJ,CAAC,OAAO,OAAO,gBAAgC;AAC9C,iBACE,4DACD;AACD,SAAM,KAAK,YAAY,YAAY;AACnC,UAAO,WAAW,QAAQ;IAC1B;;;;;;;CAQJ,sBAAsC;AACpC,uBACE,KAAK,QACF,QAAQ,UAAU,CAClB,YAAY,iDAAiD,CACjE,CAAC,OAAO,OAAO,gBAAgC;AAC9C,iBAAc,4BAA4B;AAC1C,SAAM,KAAK,cAAc,YAAY;AACrC,UAAO,WAAW,QAAQ;IAC1B;;;;;;;CAQJ,uBAAuC;AACrC,uBACE,KA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,QACL,QAAQ,MAAM,KACZ,eACD,CAAC,sGACH;AAOD,MAAI,EAJmB,cACnB,mBAAmB,MAAM,aAAa,MAAM,KAAK,GACjD,OAEiB;GACnB,MAAM,iBAAiB,MAAM,mBAAmB;GAChD,MAAM,UAAU,OAAO,eAAe;AACtC,WAAQ,MACN,0CAA0C,eAAe,KAAK,KAC/D;AACD,SAAM,eAAe,MAAM,gBAAgB,KAAK;AAChD,WAAQ,KAAK,MAAM,MAAM,gBAAgB,CAAC;;AAI5C,MAAI,CAAC,mBAAmB;OACA,cAClB,OACA,MAAM,cAAc;IAClB,SACE;IACF,cAAc;IACf,CAAC,EACa;IACjB,MAAM,WAAW,MAAM,iBAAiB,EAAE,CAAC;AAa3C,UAAM,eAAe,MADK,oBAAoB,UAX9B,cACZ,QACA,MAAM,aAAmD;KACvD,SAAS;KACT,SAAS;MACP;OAAE,OAAO;OAAe,OAAO;OAAe;MAC9C;OAAE,OAAO;OAAc,OAAO;OAAc;MAC5C;OAAE,OAAO;OAAO,OAAO;OAAQ;MAChC;KACD,cAAc;KACf,CAAC,CAC0D,EAC9B,SAAS,UAAU;;;;CAI3D,MAAgB,mBAAmB,SAAsC;EACvE,MAAM,WAAW,MAAM,iBAAiB,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AAGnE,QAAM,eAAe,MADK,oBAAoB,UAD9B,QAAQ,WAAW,MAC6B,EAC9B,SAAS,UAAU"}
|
|
@@ -13,6 +13,7 @@ async function handleSetupProject(options, settings, library) {
|
|
|
13
13
|
logCollectedFiles(allFiles, reactComponents);
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
+
if (allFiles.length === 0) logger.error("No files to upload were found. Check your configuration and try again.");
|
|
16
17
|
let fileVersionData;
|
|
17
18
|
let branchData;
|
|
18
19
|
if (allFiles.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupProject.js","names":[],"sources":["../../../src/cli/commands/setupProject.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { exitSync, logCollectedFiles } from '../../console/logging.js';\nimport {\n Settings,\n SupportedLibraries,\n TranslateFlags,\n} from '../../types/index.js';\nimport { FileTranslationData } from '../../workflows/download.js';\nimport { BranchData } from '../../types/branch.js';\nimport { collectFiles } from '../../formats/files/collectFiles.js';\nimport { runSetupProjectWorkflow } from '../../workflows/setupProject.js';\nimport { hasValidCredentials, hasValidLocales } from './utils/validation.js';\n\nexport async function handleSetupProject(\n options: TranslateFlags,\n settings: Settings,\n library: SupportedLibraries\n): Promise<{\n fileVersionData: FileTranslationData | undefined;\n branchData: BranchData | undefined;\n} | null> {\n if (!hasValidLocales(settings)) return exitSync(1);\n // Validate credentials if not in dry run\n if (!options.dryRun && !hasValidCredentials(settings)) return exitSync(1);\n\n const { files: allFiles, reactComponents } = await collectFiles(\n options,\n settings,\n library\n );\n\n // Dry run\n if (options.dryRun) {\n logger.success(`Dry run: No files were uploaded to General Translation.`);\n logCollectedFiles(allFiles, reactComponents);\n return null;\n }\n\n // Upload files and run setup step\n let fileVersionData: FileTranslationData | undefined;\n let branchData: BranchData | undefined;\n if (allFiles.length > 0) {\n const { branchData: branchDataResult } = await runSetupProjectWorkflow(\n allFiles,\n options,\n settings\n );\n branchData = branchDataResult;\n\n fileVersionData = Object.fromEntries(\n allFiles.map((file) => [\n file.fileId,\n {\n fileName: file.fileName,\n versionId: file.versionId,\n },\n ])\n );\n }\n return {\n fileVersionData,\n branchData,\n };\n}\n"],"mappings":";;;;;;AAaA,eAAsB,mBACpB,SACA,UACA,SAIQ;AACR,KAAI,CAAC,gBAAgB,SAAS,CAAE,QAAO,SAAS,EAAE;AAElD,KAAI,CAAC,QAAQ,UAAU,CAAC,oBAAoB,SAAS,CAAE,QAAO,SAAS,EAAE;CAEzE,MAAM,EAAE,OAAO,UAAU,oBAAoB,MAAM,aACjD,SACA,UACA,QACD;AAGD,KAAI,QAAQ,QAAQ;AAClB,SAAO,QAAQ,0DAA0D;AACzE,oBAAkB,UAAU,gBAAgB;AAC5C,SAAO;;
|
|
1
|
+
{"version":3,"file":"setupProject.js","names":[],"sources":["../../../src/cli/commands/setupProject.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { exitSync, logCollectedFiles } from '../../console/logging.js';\nimport {\n Settings,\n SupportedLibraries,\n TranslateFlags,\n} from '../../types/index.js';\nimport { FileTranslationData } from '../../workflows/download.js';\nimport { BranchData } from '../../types/branch.js';\nimport { collectFiles } from '../../formats/files/collectFiles.js';\nimport { runSetupProjectWorkflow } from '../../workflows/setupProject.js';\nimport { hasValidCredentials, hasValidLocales } from './utils/validation.js';\n\nexport async function handleSetupProject(\n options: TranslateFlags,\n settings: Settings,\n library: SupportedLibraries\n): Promise<{\n fileVersionData: FileTranslationData | undefined;\n branchData: BranchData | undefined;\n} | null> {\n if (!hasValidLocales(settings)) return exitSync(1);\n // Validate credentials if not in dry run\n if (!options.dryRun && !hasValidCredentials(settings)) return exitSync(1);\n\n const { files: allFiles, reactComponents } = await collectFiles(\n options,\n settings,\n library\n );\n\n // Dry run\n if (options.dryRun) {\n logger.success(`Dry run: No files were uploaded to General Translation.`);\n logCollectedFiles(allFiles, reactComponents);\n return null;\n }\n\n if (allFiles.length === 0) {\n logger.error(\n 'No files to upload were found. Check your configuration and try again.'\n );\n }\n\n // Upload files and run setup step\n let fileVersionData: FileTranslationData | undefined;\n let branchData: BranchData | undefined;\n if (allFiles.length > 0) {\n const { branchData: branchDataResult } = await runSetupProjectWorkflow(\n allFiles,\n options,\n settings\n );\n branchData = branchDataResult;\n\n fileVersionData = Object.fromEntries(\n allFiles.map((file) => [\n file.fileId,\n {\n fileName: file.fileName,\n versionId: file.versionId,\n },\n ])\n );\n }\n return {\n fileVersionData,\n branchData,\n };\n}\n"],"mappings":";;;;;;AAaA,eAAsB,mBACpB,SACA,UACA,SAIQ;AACR,KAAI,CAAC,gBAAgB,SAAS,CAAE,QAAO,SAAS,EAAE;AAElD,KAAI,CAAC,QAAQ,UAAU,CAAC,oBAAoB,SAAS,CAAE,QAAO,SAAS,EAAE;CAEzE,MAAM,EAAE,OAAO,UAAU,oBAAoB,MAAM,aACjD,SACA,UACA,QACD;AAGD,KAAI,QAAQ,QAAQ;AAClB,SAAO,QAAQ,0DAA0D;AACzE,oBAAkB,UAAU,gBAAgB;AAC5C,SAAO;;AAGT,KAAI,SAAS,WAAW,EACtB,QAAO,MACL,yEACD;CAIH,IAAI;CACJ,IAAI;AACJ,KAAI,SAAS,SAAS,GAAG;EACvB,MAAM,EAAE,YAAY,qBAAqB,MAAM,wBAC7C,UACA,SACA,SACD;AACD,eAAa;AAEb,oBAAkB,OAAO,YACvB,SAAS,KAAK,SAAS,CACrB,KAAK,QACL;GACE,UAAU,KAAK;GACf,WAAW,KAAK;GACjB,CACF,CAAC,CACH;;AAEH,QAAO;EACL;EACA;EACD"}
|
|
@@ -17,6 +17,7 @@ async function handleStage(options, settings, library, stage) {
|
|
|
17
17
|
logCollectedFiles(allFiles, reactComponents);
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
+
if (allFiles.length === 0 && !settings.publish) logger.error("No files to translate were found. Check your configuration and try again.");
|
|
20
21
|
let fileVersionData;
|
|
21
22
|
let jobData;
|
|
22
23
|
let branchData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage.js","names":[],"sources":["../../../src/cli/commands/stage.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { exitSync, logCollectedFiles } from '../../console/logging.js';\nimport {\n Settings,\n SupportedLibraries,\n TranslateFlags,\n} from '../../types/index.js';\nimport { runStageFilesWorkflow } from '../../workflows/stage.js';\nimport { writeStagedEntries } from '../../fs/config/downloadedVersions.js';\nimport type { EnqueueFilesResult } from 'generaltranslation/types';\nimport updateConfig from '../../fs/config/updateConfig.js';\nimport { FileTranslationData } from '../../workflows/download.js';\nimport { BranchData } from '../../types/branch.js';\nimport { TEMPLATE_FILE_ID } from '../../utils/constants.js';\nimport { collectFiles } from '../../formats/files/collectFiles.js';\nimport { convertToFileTranslationData } from '../../formats/files/convertToFileTranslationData.js';\nimport { hasValidCredentials, hasValidLocales } from './utils/validation.js';\n\nexport async function handleStage(\n options: TranslateFlags,\n settings: Settings,\n library: SupportedLibraries,\n stage: boolean\n): Promise<{\n fileVersionData: FileTranslationData | undefined;\n jobData: EnqueueFilesResult | undefined;\n branchData: BranchData | undefined;\n publishMap: Map<string, boolean>;\n} | null> {\n if (!hasValidLocales(settings)) return exitSync(1);\n // Validate credentials if not in dry run\n if (!options.dryRun && !hasValidCredentials(settings)) return exitSync(1);\n\n const {\n files: allFiles,\n reactComponents,\n publishMap,\n } = await collectFiles(options, settings, library);\n\n // Dry run\n if (options.dryRun) {\n logger.success(`Dry run: No files were sent to General Translation.`);\n logCollectedFiles(allFiles, reactComponents);\n return null;\n }\n\n // Send translations to General Translation\n let fileVersionData: FileTranslationData | undefined;\n let jobData: EnqueueFilesResult | undefined;\n let branchData: BranchData | undefined;\n if (allFiles.length > 0) {\n const { branchData: branchDataResult, enqueueResult } =\n await runStageFilesWorkflow({ files: allFiles, options, settings });\n jobData = enqueueResult;\n branchData = branchDataResult;\n\n fileVersionData = convertToFileTranslationData(allFiles);\n\n // Write staged entries to the lockfile\n if (stage) {\n const stagedFiles = Object.entries(fileVersionData).map(\n ([fileId, data]) => ({\n fileId,\n versionId: data.versionId,\n fileName: data.fileName,\n })\n );\n writeStagedEntries(settings, stagedFiles, branchData.currentBranch.id);\n }\n const templateData = allFiles.find(\n (file) => file.fileId === TEMPLATE_FILE_ID\n );\n if (templateData?.versionId) {\n await updateConfig(settings.config, {\n _versionId: templateData.versionId,\n _branchId: branchData.currentBranch.id,\n });\n }\n }\n\n // Always delete branch id from config if branching is disabled\n // Avoids incorrect CDN queries at runtime\n if (!settings.branchOptions.enabled) {\n await updateConfig(settings.config, {\n _branchId: null,\n });\n }\n\n return {\n fileVersionData,\n jobData,\n branchData,\n publishMap,\n };\n}\n"],"mappings":";;;;;;;;;;AAkBA,eAAsB,YACpB,SACA,UACA,SACA,OAMQ;AACR,KAAI,CAAC,gBAAgB,SAAS,CAAE,QAAO,SAAS,EAAE;AAElD,KAAI,CAAC,QAAQ,UAAU,CAAC,oBAAoB,SAAS,CAAE,QAAO,SAAS,EAAE;CAEzE,MAAM,EACJ,OAAO,UACP,iBACA,eACE,MAAM,aAAa,SAAS,UAAU,QAAQ;AAGlD,KAAI,QAAQ,QAAQ;AAClB,SAAO,QAAQ,sDAAsD;AACrE,oBAAkB,UAAU,gBAAgB;AAC5C,SAAO;;
|
|
1
|
+
{"version":3,"file":"stage.js","names":[],"sources":["../../../src/cli/commands/stage.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { exitSync, logCollectedFiles } from '../../console/logging.js';\nimport {\n Settings,\n SupportedLibraries,\n TranslateFlags,\n} from '../../types/index.js';\nimport { runStageFilesWorkflow } from '../../workflows/stage.js';\nimport { writeStagedEntries } from '../../fs/config/downloadedVersions.js';\nimport type { EnqueueFilesResult } from 'generaltranslation/types';\nimport updateConfig from '../../fs/config/updateConfig.js';\nimport { FileTranslationData } from '../../workflows/download.js';\nimport { BranchData } from '../../types/branch.js';\nimport { TEMPLATE_FILE_ID } from '../../utils/constants.js';\nimport { collectFiles } from '../../formats/files/collectFiles.js';\nimport { convertToFileTranslationData } from '../../formats/files/convertToFileTranslationData.js';\nimport { hasValidCredentials, hasValidLocales } from './utils/validation.js';\n\nexport async function handleStage(\n options: TranslateFlags,\n settings: Settings,\n library: SupportedLibraries,\n stage: boolean\n): Promise<{\n fileVersionData: FileTranslationData | undefined;\n jobData: EnqueueFilesResult | undefined;\n branchData: BranchData | undefined;\n publishMap: Map<string, boolean>;\n} | null> {\n if (!hasValidLocales(settings)) return exitSync(1);\n // Validate credentials if not in dry run\n if (!options.dryRun && !hasValidCredentials(settings)) return exitSync(1);\n\n const {\n files: allFiles,\n reactComponents,\n publishMap,\n } = await collectFiles(options, settings, library);\n\n // Dry run\n if (options.dryRun) {\n logger.success(`Dry run: No files were sent to General Translation.`);\n logCollectedFiles(allFiles, reactComponents);\n return null;\n }\n\n if (allFiles.length === 0 && !settings.publish) {\n logger.error(\n 'No files to translate were found. Check your configuration and try again.'\n );\n }\n\n // Send translations to General Translation\n let fileVersionData: FileTranslationData | undefined;\n let jobData: EnqueueFilesResult | undefined;\n let branchData: BranchData | undefined;\n if (allFiles.length > 0) {\n const { branchData: branchDataResult, enqueueResult } =\n await runStageFilesWorkflow({ files: allFiles, options, settings });\n jobData = enqueueResult;\n branchData = branchDataResult;\n\n fileVersionData = convertToFileTranslationData(allFiles);\n\n // Write staged entries to the lockfile\n if (stage) {\n const stagedFiles = Object.entries(fileVersionData).map(\n ([fileId, data]) => ({\n fileId,\n versionId: data.versionId,\n fileName: data.fileName,\n })\n );\n writeStagedEntries(settings, stagedFiles, branchData.currentBranch.id);\n }\n const templateData = allFiles.find(\n (file) => file.fileId === TEMPLATE_FILE_ID\n );\n if (templateData?.versionId) {\n await updateConfig(settings.config, {\n _versionId: templateData.versionId,\n _branchId: branchData.currentBranch.id,\n });\n }\n }\n\n // Always delete branch id from config if branching is disabled\n // Avoids incorrect CDN queries at runtime\n if (!settings.branchOptions.enabled) {\n await updateConfig(settings.config, {\n _branchId: null,\n });\n }\n\n return {\n fileVersionData,\n jobData,\n branchData,\n publishMap,\n };\n}\n"],"mappings":";;;;;;;;;;AAkBA,eAAsB,YACpB,SACA,UACA,SACA,OAMQ;AACR,KAAI,CAAC,gBAAgB,SAAS,CAAE,QAAO,SAAS,EAAE;AAElD,KAAI,CAAC,QAAQ,UAAU,CAAC,oBAAoB,SAAS,CAAE,QAAO,SAAS,EAAE;CAEzE,MAAM,EACJ,OAAO,UACP,iBACA,eACE,MAAM,aAAa,SAAS,UAAU,QAAQ;AAGlD,KAAI,QAAQ,QAAQ;AAClB,SAAO,QAAQ,sDAAsD;AACrE,oBAAkB,UAAU,gBAAgB;AAC5C,SAAO;;AAGT,KAAI,SAAS,WAAW,KAAK,CAAC,SAAS,QACrC,QAAO,MACL,4EACD;CAIH,IAAI;CACJ,IAAI;CACJ,IAAI;AACJ,KAAI,SAAS,SAAS,GAAG;EACvB,MAAM,EAAE,YAAY,kBAAkB,kBACpC,MAAM,sBAAsB;GAAE,OAAO;GAAU;GAAS;GAAU,CAAC;AACrE,YAAU;AACV,eAAa;AAEb,oBAAkB,6BAA6B,SAAS;AAGxD,MAAI,MAQF,oBAAmB,UAPC,OAAO,QAAQ,gBAAgB,CAAC,KACjD,CAAC,QAAQ,WAAW;GACnB;GACA,WAAW,KAAK;GAChB,UAAU,KAAK;GAChB,EAEqC,EAAE,WAAW,cAAc,GAAG;EAExE,MAAM,eAAe,SAAS,MAC3B,SAAS,KAAK,WAAW,iBAC3B;AACD,MAAI,cAAc,UAChB,OAAM,aAAa,SAAS,QAAQ;GAClC,YAAY,aAAa;GACzB,WAAW,WAAW,cAAc;GACrC,CAAC;;AAMN,KAAI,CAAC,SAAS,cAAc,QAC1B,OAAM,aAAa,SAAS,QAAQ,EAClC,WAAW,MACZ,CAAC;AAGJ,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DataFormat } from '../../types/data.js';
|
|
1
|
+
import { Settings } from '../../types/index.js';
|
|
3
2
|
import { UploadOptions } from '../base.js';
|
|
4
3
|
/**
|
|
5
4
|
* Sends multiple files to the API for translation
|
|
6
|
-
* @param filePaths - Resolved file paths for different file types
|
|
7
|
-
* @param placeholderPaths - Placeholder paths for translated files
|
|
8
|
-
* @param transformPaths - Transform paths for file naming
|
|
9
|
-
* @param dataFormat - Format of the data within the files
|
|
10
5
|
* @param settings - Translation options including API settings
|
|
11
6
|
* @returns Promise that resolves when translation is complete
|
|
12
7
|
*/
|
|
13
|
-
export declare function upload(
|
|
8
|
+
export declare function upload(settings: Settings & UploadOptions): Promise<void>;
|
|
@@ -1,122 +1,36 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
|
-
import { hashStringSync } from "../../utils/hash.js";
|
|
3
2
|
import { exitSync, logErrorAndExit } from "../../console/logging.js";
|
|
4
3
|
import { getRelative, readFile } from "../../fs/findFilepath.js";
|
|
5
|
-
import { noDefaultLocaleError
|
|
6
|
-
import { SUPPORTED_FILE_EXTENSIONS } from "../../formats/files/supportedFiles.js";
|
|
7
|
-
import { getTransformFormatProperty } from "../../formats/files/transformFormat.js";
|
|
8
|
-
import sanitizeFileContent from "../../utils/sanitizeFileContent.js";
|
|
4
|
+
import { noDefaultLocaleError } from "../../console/index.js";
|
|
9
5
|
import { validateJsonSchema } from "../../formats/json/utils.js";
|
|
10
|
-
import { parseJson } from "../../formats/json/parseJson.js";
|
|
11
6
|
import { extractJson } from "../../formats/json/extractJson.js";
|
|
12
|
-
import { resolveMintlifyRefs, shouldResolveRefs } from "../../utils/resolveMintlifyRefs.js";
|
|
13
7
|
import { runUploadFilesWorkflow } from "../../workflows/upload.js";
|
|
14
8
|
import { createFileMapping } from "../../formats/files/fileMapping.js";
|
|
15
|
-
import parseYaml from "../../formats/yaml/parseYaml.js";
|
|
16
9
|
import { hasValidCredentials } from "./utils/validation.js";
|
|
17
|
-
import { buildPublishMap } from "../../utils/resolvePublish.js";
|
|
18
10
|
import { runPublishWorkflow } from "../../workflows/publish.js";
|
|
11
|
+
import { aggregateFiles } from "../../formats/files/aggregateFiles.js";
|
|
19
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
20
13
|
//#region src/cli/commands/upload.ts
|
|
21
|
-
const SUPPORTED_DATA_FORMATS = [
|
|
22
|
-
"JSX",
|
|
23
|
-
"ICU",
|
|
24
|
-
"I18NEXT"
|
|
25
|
-
];
|
|
26
14
|
/**
|
|
27
15
|
* Sends multiple files to the API for translation
|
|
28
|
-
* @param filePaths - Resolved file paths for different file types
|
|
29
|
-
* @param placeholderPaths - Placeholder paths for translated files
|
|
30
|
-
* @param transformPaths - Transform paths for file naming
|
|
31
|
-
* @param dataFormat - Format of the data within the files
|
|
32
16
|
* @param settings - Translation options including API settings
|
|
33
17
|
* @returns Promise that resolves when translation is complete
|
|
34
18
|
*/
|
|
35
|
-
async function upload(
|
|
36
|
-
|
|
19
|
+
async function upload(settings) {
|
|
20
|
+
if (!settings.files) return;
|
|
37
21
|
const additionalOptions = settings.options || {};
|
|
22
|
+
const { resolvedPaths: filePaths, placeholderPaths, transformPaths, transformFormats } = settings.files;
|
|
23
|
+
const { files: allFiles, publishMap } = await aggregateFiles(settings);
|
|
38
24
|
const compositeJsonFiles = /* @__PURE__ */ new Map();
|
|
39
25
|
if (filePaths.json) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const content = readFile(filePath);
|
|
43
|
-
let contentForParsing = content;
|
|
44
|
-
if (shouldResolveRefs(filePath, additionalOptions)) try {
|
|
45
|
-
const { resolved } = resolveMintlifyRefs(JSON.parse(content), filePath);
|
|
46
|
-
contentForParsing = JSON.stringify(resolved, null, 2);
|
|
47
|
-
} catch {}
|
|
48
|
-
const parsedJson = parseJson(contentForParsing, filePath, additionalOptions, settings.defaultLocale);
|
|
26
|
+
const sourceFileNames = new Set(allFiles.map((file) => file.fileName));
|
|
27
|
+
for (const filePath of filePaths.json) {
|
|
49
28
|
const relativePath = getRelative(filePath);
|
|
29
|
+
if (!sourceFileNames.has(relativePath)) continue;
|
|
50
30
|
if (validateJsonSchema(additionalOptions, filePath)?.composite) compositeJsonFiles.set(relativePath, {
|
|
51
31
|
filePath,
|
|
52
|
-
content
|
|
32
|
+
content: readFile(filePath)
|
|
53
33
|
});
|
|
54
|
-
return {
|
|
55
|
-
content: parsedJson,
|
|
56
|
-
fileName: relativePath,
|
|
57
|
-
fileFormat: "JSON",
|
|
58
|
-
...getTransformFormatProperty(settings, "json"),
|
|
59
|
-
dataFormat,
|
|
60
|
-
locale: settings.defaultLocale,
|
|
61
|
-
fileId: hashStringSync(relativePath),
|
|
62
|
-
versionId: hashStringSync(parsedJson)
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
allFiles.push(...jsonFiles);
|
|
66
|
-
}
|
|
67
|
-
if (filePaths.yaml) {
|
|
68
|
-
if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) logErrorAndExit(noSupportedFormatError);
|
|
69
|
-
const yamlFiles = filePaths.yaml.map((filePath) => {
|
|
70
|
-
const { content: parsedYaml, fileFormat } = parseYaml(readFile(filePath), filePath, additionalOptions);
|
|
71
|
-
const relativePath = getRelative(filePath);
|
|
72
|
-
return {
|
|
73
|
-
content: parsedYaml,
|
|
74
|
-
fileName: relativePath,
|
|
75
|
-
fileFormat,
|
|
76
|
-
...getTransformFormatProperty(settings, "yaml"),
|
|
77
|
-
dataFormat,
|
|
78
|
-
locale: settings.defaultLocale,
|
|
79
|
-
fileId: hashStringSync(relativePath),
|
|
80
|
-
versionId: hashStringSync(parsedYaml)
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
allFiles.push(...yamlFiles);
|
|
84
|
-
}
|
|
85
|
-
if (filePaths.twilioContentJson) {
|
|
86
|
-
const twilioContentJsonFiles = filePaths.twilioContentJson.map((filePath) => {
|
|
87
|
-
const parsedJson = parseJson(readFile(filePath), filePath, additionalOptions, settings.defaultLocale);
|
|
88
|
-
const relativePath = getRelative(filePath);
|
|
89
|
-
return {
|
|
90
|
-
content: parsedJson,
|
|
91
|
-
fileName: relativePath,
|
|
92
|
-
fileFormat: "TWILIO_CONTENT_JSON",
|
|
93
|
-
...getTransformFormatProperty(settings, "twilioContentJson"),
|
|
94
|
-
dataFormat: "STRING",
|
|
95
|
-
locale: settings.defaultLocale,
|
|
96
|
-
fileId: hashStringSync(relativePath),
|
|
97
|
-
versionId: hashStringSync(parsedJson)
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
allFiles.push(...twilioContentJsonFiles);
|
|
101
|
-
}
|
|
102
|
-
for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
|
|
103
|
-
if (fileType === "json" || fileType === "yaml" || fileType === "twilioContentJson") continue;
|
|
104
|
-
if (filePaths[fileType]) {
|
|
105
|
-
const files = filePaths[fileType].map((filePath) => {
|
|
106
|
-
const sanitizedContent = sanitizeFileContent(readFile(filePath));
|
|
107
|
-
const relativePath = getRelative(filePath);
|
|
108
|
-
return {
|
|
109
|
-
content: sanitizedContent,
|
|
110
|
-
fileName: relativePath,
|
|
111
|
-
fileFormat: fileType.toUpperCase(),
|
|
112
|
-
...getTransformFormatProperty(settings, fileType),
|
|
113
|
-
dataFormat,
|
|
114
|
-
locale: settings.defaultLocale,
|
|
115
|
-
fileId: hashStringSync(relativePath),
|
|
116
|
-
versionId: hashStringSync(sanitizedContent)
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
allFiles.push(...files);
|
|
120
34
|
}
|
|
121
35
|
}
|
|
122
36
|
if (allFiles.length === 0) {
|
|
@@ -126,18 +40,9 @@ async function upload(filePaths, placeholderPaths, transformPaths, dataFormat =
|
|
|
126
40
|
if (!settings.defaultLocale) return logErrorAndExit(noDefaultLocaleError);
|
|
127
41
|
if (!hasValidCredentials(settings)) return exitSync(1);
|
|
128
42
|
const locales = settings.locales || [];
|
|
129
|
-
const fileMapping = createFileMapping(filePaths, placeholderPaths, transformPaths,
|
|
43
|
+
const fileMapping = createFileMapping(filePaths, placeholderPaths, transformPaths, transformFormats, locales, settings.defaultLocale);
|
|
130
44
|
const uploadData = allFiles.map((file) => {
|
|
131
|
-
const sourceFile = {
|
|
132
|
-
content: file.content,
|
|
133
|
-
fileName: file.fileName,
|
|
134
|
-
fileFormat: file.fileFormat,
|
|
135
|
-
transformFormat: file.transformFormat,
|
|
136
|
-
dataFormat: file.dataFormat,
|
|
137
|
-
locale: file.locale,
|
|
138
|
-
fileId: file.fileId,
|
|
139
|
-
versionId: file.versionId
|
|
140
|
-
};
|
|
45
|
+
const sourceFile = { ...file };
|
|
141
46
|
const translations = [];
|
|
142
47
|
const compositeInfo = compositeJsonFiles.get(file.fileName);
|
|
143
48
|
for (const locale of locales) if (compositeInfo) {
|
|
@@ -176,7 +81,7 @@ async function upload(filePaths, placeholderPaths, transformPaths, dataFormat =
|
|
|
176
81
|
files: uploadData,
|
|
177
82
|
options: settings
|
|
178
83
|
});
|
|
179
|
-
await runPublishWorkflow(allFiles,
|
|
84
|
+
await runPublishWorkflow(allFiles, publishMap, branchData.currentBranch.id, settings);
|
|
180
85
|
} catch (error) {
|
|
181
86
|
logErrorAndExit(`Error uploading files: ${error}`);
|
|
182
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":[],"sources":["../../../src/cli/commands/upload.ts"],"sourcesContent":["import {\n noSupportedFormatError,\n noDefaultLocaleError,\n} from '../../console/index.js';\nimport { exitSync, logErrorAndExit } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport { getRelative, readFile } from '../../fs/findFilepath.js';\nimport { ResolvedFiles, Settings, TransformFiles } from '../../types/index.js';\nimport { FileFormat, DataFormat } from '../../types/data.js';\nimport { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';\nimport { UploadOptions } from '../base.js';\nimport sanitizeFileContent from '../../utils/sanitizeFileContent.js';\nimport { parseJson } from '../../formats/json/parseJson.js';\nimport { extractJson } from '../../formats/json/extractJson.js';\nimport { validateJsonSchema } from '../../formats/json/utils.js';\nimport {\n resolveMintlifyRefs,\n shouldResolveRefs,\n} from '../../utils/resolveMintlifyRefs.js';\nimport { runUploadFilesWorkflow } from '../../workflows/upload.js';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createFileMapping } from '../../formats/files/fileMapping.js';\nimport parseYaml from '../../formats/yaml/parseYaml.js';\nimport type { FileToUpload } from 'generaltranslation/types';\nimport { hashStringSync } from '../../utils/hash.js';\nimport { hasValidCredentials } from './utils/validation.js';\nimport { buildPublishMap } from '../../utils/resolvePublish.js';\nimport { runPublishWorkflow } from '../../workflows/publish.js';\nimport { getTransformFormatProperty } from '../../formats/files/transformFormat.js';\n\nconst SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];\n\n/**\n * Sends multiple files to the API for translation\n * @param filePaths - Resolved file paths for different file types\n * @param placeholderPaths - Placeholder paths for translated files\n * @param transformPaths - Transform paths for file naming\n * @param dataFormat - Format of the data within the files\n * @param settings - Translation options including API settings\n * @returns Promise that resolves when translation is complete\n */\nexport async function upload(\n filePaths: ResolvedFiles,\n placeholderPaths: ResolvedFiles,\n transformPaths: TransformFiles,\n dataFormat: DataFormat = 'JSX',\n settings: Settings & UploadOptions\n): Promise<void> {\n // Collect all files to translate\n const allFiles: FileToUpload[] = [];\n const additionalOptions = settings.options || {};\n const compositeJsonFiles = new Map<\n string,\n { filePath: string; content: string }\n >();\n\n // Process JSON files\n if (filePaths.json) {\n if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {\n logErrorAndExit(noSupportedFormatError);\n }\n\n const jsonFiles = filePaths.json.map((filePath) => {\n const content = readFile(filePath);\n\n // Resolve $ref before parsing if configured\n let contentForParsing = content;\n if (shouldResolveRefs(filePath, additionalOptions)) {\n try {\n const json = JSON.parse(content);\n const { resolved } = resolveMintlifyRefs(json, filePath);\n contentForParsing = JSON.stringify(resolved, null, 2);\n } catch {\n // JSON parse errors are handled below by parseJson\n }\n }\n\n const parsedJson = parseJson(\n contentForParsing,\n filePath,\n additionalOptions,\n settings.defaultLocale\n );\n\n const relativePath = getRelative(filePath);\n\n const jsonSchema = validateJsonSchema(additionalOptions, filePath);\n if (jsonSchema?.composite) {\n compositeJsonFiles.set(relativePath, { filePath, content });\n }\n\n return {\n content: parsedJson,\n fileName: relativePath,\n fileFormat: 'JSON' as FileFormat,\n ...getTransformFormatProperty(settings, 'json'),\n dataFormat,\n locale: settings.defaultLocale,\n fileId: hashStringSync(relativePath),\n versionId: hashStringSync(parsedJson),\n } satisfies FileToUpload;\n });\n allFiles.push(...jsonFiles);\n }\n\n // Process YAML files\n if (filePaths.yaml) {\n if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {\n logErrorAndExit(noSupportedFormatError);\n }\n\n const yamlFiles = filePaths.yaml.map((filePath) => {\n const content = readFile(filePath);\n const { content: parsedYaml, fileFormat } = parseYaml(\n content,\n filePath,\n additionalOptions\n );\n\n const relativePath = getRelative(filePath);\n return {\n content: parsedYaml,\n fileName: relativePath,\n fileFormat,\n ...getTransformFormatProperty(settings, 'yaml'),\n dataFormat,\n locale: settings.defaultLocale,\n fileId: hashStringSync(relativePath),\n versionId: hashStringSync(parsedYaml),\n } satisfies FileToUpload;\n });\n allFiles.push(...yamlFiles);\n }\n\n // Process Twilio Content JSON files\n if (filePaths.twilioContentJson) {\n const twilioContentJsonFiles = filePaths.twilioContentJson.map(\n (filePath) => {\n const content = readFile(filePath);\n\n const parsedJson = parseJson(\n content,\n filePath,\n additionalOptions,\n settings.defaultLocale\n );\n\n const relativePath = getRelative(filePath);\n\n return {\n content: parsedJson,\n fileName: relativePath,\n fileFormat: 'TWILIO_CONTENT_JSON' as const,\n ...getTransformFormatProperty(settings, 'twilioContentJson'),\n dataFormat: 'STRING' as const,\n locale: settings.defaultLocale,\n fileId: hashStringSync(relativePath),\n versionId: hashStringSync(parsedJson),\n } satisfies FileToUpload;\n }\n );\n allFiles.push(...twilioContentJsonFiles);\n }\n\n for (const fileType of SUPPORTED_FILE_EXTENSIONS) {\n if (\n fileType === 'json' ||\n fileType === 'yaml' ||\n fileType === 'twilioContentJson'\n )\n continue;\n if (filePaths[fileType]) {\n const files = filePaths[fileType].map((filePath) => {\n const content = readFile(filePath);\n const sanitizedContent = sanitizeFileContent(content);\n const relativePath = getRelative(filePath);\n return {\n content: sanitizedContent,\n fileName: relativePath,\n fileFormat: fileType.toUpperCase() as FileFormat,\n ...getTransformFormatProperty(settings, fileType),\n dataFormat,\n locale: settings.defaultLocale,\n fileId: hashStringSync(relativePath),\n versionId: hashStringSync(sanitizedContent),\n } satisfies FileToUpload;\n });\n allFiles.push(...files);\n }\n }\n\n if (allFiles.length === 0) {\n logger.error(\n 'No files to upload were found. Check your configuration and try again.'\n );\n return;\n }\n\n if (!settings.defaultLocale) {\n return logErrorAndExit(noDefaultLocaleError);\n }\n if (!hasValidCredentials(settings)) return exitSync(1);\n\n const locales = settings.locales || [];\n // Create file mapping for all file types\n const fileMapping = createFileMapping(\n filePaths,\n placeholderPaths,\n transformPaths,\n settings.files?.transformFormats || {},\n locales,\n settings.defaultLocale\n );\n\n // construct object\n const uploadData = allFiles.map((file) => {\n const sourceFile: FileToUpload = {\n content: file.content,\n fileName: file.fileName,\n fileFormat: file.fileFormat,\n transformFormat: file.transformFormat,\n dataFormat: file.dataFormat,\n locale: file.locale,\n fileId: file.fileId,\n versionId: file.versionId,\n };\n\n const translations: FileToUpload[] = [];\n const compositeInfo = compositeJsonFiles.get(file.fileName);\n\n for (const locale of locales) {\n if (compositeInfo) {\n // Composite JSON: extract translations from the same source file\n const extracted = extractJson(\n compositeInfo.content,\n compositeInfo.filePath,\n additionalOptions,\n locale,\n settings.defaultLocale\n );\n if (extracted) {\n translations.push({\n content: extracted,\n fileName: file.fileName,\n fileFormat: file.transformFormat ?? file.fileFormat,\n dataFormat: file.dataFormat,\n locale,\n fileId: file.fileId,\n versionId: file.versionId,\n });\n }\n } else {\n // Non-composite: look for separate translation files\n const translatedFileName = fileMapping[locale]?.[file.fileName];\n if (translatedFileName && existsSync(translatedFileName)) {\n const translatedContent = readFileSync(translatedFileName, 'utf8');\n translations.push({\n content: translatedContent,\n fileName: translatedFileName,\n fileFormat: file.transformFormat ?? file.fileFormat,\n dataFormat: file.dataFormat,\n locale,\n fileId: file.fileId,\n versionId: file.versionId,\n });\n }\n }\n }\n return {\n source: sourceFile,\n translations,\n };\n });\n\n try {\n // Send all files in a single API call\n const { branchData } = await runUploadFilesWorkflow({\n files: uploadData,\n options: settings,\n });\n\n // Publish files to CDN if publish config exists\n const publishMap = buildPublishMap(filePaths, settings);\n await runPublishWorkflow(\n allFiles,\n publishMap,\n branchData.currentBranch.id,\n settings\n );\n } catch (error) {\n logErrorAndExit(`Error uploading files: ${error}`);\n }\n}\n"],"m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AS,cACV;CAGD,MAAM,aAAa,SAAS,KAAK,SAAS;EACxC,MAAM,aAA2B;GAC/B,SAAS,KAAK;GACd,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,iBAAiB,KAAK;GACtB,YAAY,KAAK;GACjB,QAAQ,KAAK;GACb,QAAQ,KAAK;GACb,WAAW,KAAK;GACjB;EAED,MAAM,eAA+B,EAAE;EACvC,MAAM,gBAAgB,mBAAmB,IAAI,KAAK,SAAS;AAE3D,OAAK,MAAM,UAAU,QACnB,KAAI,eAAe;GAEjB,MAAM,YAAY,YAChB,cAAc,SACd,cAAc,UACd,mBACA,QACA,SAAS,cACV;AACD,OAAI,UACF,cAAa,KAAK;IAChB,SAAS;IACT,UAAU,KAAK;IACf,YAAY,KAAK,mBAAmB,KAAK;IACzC,YAAY,KAAK;IACjB;IACA,QAAQ,KAAK;IACb,WAAW,KAAK;IACjB,CAAC;SAEC;GAEL,MAAM,qBAAqB,YAAY,UAAU,KAAK;AACtD,OAAI,sBAAsB,WAAW,mBAAmB,EAAE;IACxD,MAAM,oBAAoB,aAAa,oBAAoB,OAAO;AAClE,iBAAa,KAAK;KAChB,SAAS;KACT,UAAU;KACV,YAAY,KAAK,mBAAmB,KAAK;KACzC,YAAY,KAAK;KACjB;KACA,QAAQ,KAAK;KACb,WAAW,KAAK;KACjB,CAAC;;;AAIR,SAAO;GACL,QAAQ;GACR;GACD;GACD;AAEF,KAAI;EAEF,MAAM,EAAE,eAAe,MAAM,uBAAuB;GAClD,OAAO;GACP,SAAS;GACV,CAAC;AAIF,QAAM,mBACJ,UAFiB,gBAAgB,WAAW,SAGlC,EACV,WAAW,cAAc,IACzB,SACD;UACM,OAAO;AACd,kBAAgB,0BAA0B,QAAQ"}
|
|
1
|
+
{"version":3,"file":"upload.js","names":[],"sources":["../../../src/cli/commands/upload.ts"],"sourcesContent":["import { noDefaultLocaleError } from '../../console/index.js';\nimport { exitSync, logErrorAndExit } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport { getRelative, readFile } from '../../fs/findFilepath.js';\nimport { Settings } from '../../types/index.js';\nimport { UploadOptions } from '../base.js';\nimport { extractJson } from '../../formats/json/extractJson.js';\nimport { validateJsonSchema } from '../../formats/json/utils.js';\nimport { runUploadFilesWorkflow } from '../../workflows/upload.js';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createFileMapping } from '../../formats/files/fileMapping.js';\nimport type { FileToUpload } from 'generaltranslation/types';\nimport { hasValidCredentials } from './utils/validation.js';\nimport { runPublishWorkflow } from '../../workflows/publish.js';\nimport { aggregateFiles } from '../../formats/files/aggregateFiles.js';\n\n/**\n * Sends multiple files to the API for translation\n * @param settings - Translation options including API settings\n * @returns Promise that resolves when translation is complete\n */\nexport async function upload(\n settings: Settings & UploadOptions\n): Promise<void> {\n if (!settings.files) {\n return;\n }\n\n const additionalOptions = settings.options || {};\n const {\n resolvedPaths: filePaths,\n placeholderPaths,\n transformPaths,\n transformFormats,\n } = settings.files;\n\n // Reuse the same source aggregation path as translate/stage so source\n // parsing behavior stays consistent across commands.\n const { files: allFiles, publishMap } = await aggregateFiles(settings);\n const compositeJsonFiles = new Map<\n string,\n { filePath: string; content: string }\n >();\n\n if (filePaths.json) {\n const sourceFileNames = new Set(allFiles.map((file) => file.fileName));\n for (const filePath of filePaths.json) {\n const relativePath = getRelative(filePath);\n if (!sourceFileNames.has(relativePath)) continue;\n\n const jsonSchema = validateJsonSchema(additionalOptions, filePath);\n if (jsonSchema?.composite) {\n compositeJsonFiles.set(relativePath, {\n filePath,\n content: readFile(filePath),\n });\n }\n }\n }\n\n if (allFiles.length === 0) {\n logger.error(\n 'No files to upload were found. Check your configuration and try again.'\n );\n return;\n }\n\n if (!settings.defaultLocale) {\n return logErrorAndExit(noDefaultLocaleError);\n }\n if (!hasValidCredentials(settings)) return exitSync(1);\n\n const locales = settings.locales || [];\n // Create file mapping for all file types\n const fileMapping = createFileMapping(\n filePaths,\n placeholderPaths,\n transformPaths,\n transformFormats,\n locales,\n settings.defaultLocale\n );\n\n // construct object\n const uploadData = allFiles.map((file) => {\n const sourceFile: FileToUpload = { ...file };\n\n const translations: FileToUpload[] = [];\n const compositeInfo = compositeJsonFiles.get(file.fileName);\n\n for (const locale of locales) {\n if (compositeInfo) {\n // Composite JSON: extract translations from the same source file\n const extracted = extractJson(\n compositeInfo.content,\n compositeInfo.filePath,\n additionalOptions,\n locale,\n settings.defaultLocale\n );\n if (extracted) {\n translations.push({\n content: extracted,\n fileName: file.fileName,\n fileFormat: file.transformFormat ?? file.fileFormat,\n dataFormat: file.dataFormat,\n locale,\n fileId: file.fileId,\n versionId: file.versionId,\n });\n }\n } else {\n // Non-composite: look for separate translation files\n const translatedFileName = fileMapping[locale]?.[file.fileName];\n if (translatedFileName && existsSync(translatedFileName)) {\n const translatedContent = readFileSync(translatedFileName, 'utf8');\n translations.push({\n content: translatedContent,\n fileName: translatedFileName,\n fileFormat: file.transformFormat ?? file.fileFormat,\n dataFormat: file.dataFormat,\n locale,\n fileId: file.fileId,\n versionId: file.versionId,\n });\n }\n }\n }\n return {\n source: sourceFile,\n translations,\n };\n });\n\n try {\n // Send all files in a single API call\n const { branchData } = await runUploadFilesWorkflow({\n files: uploadData,\n options: settings,\n });\n\n // Publish files to CDN if publish config exists\n await runPublishWorkflow(\n allFiles,\n publishMap,\n branchData.currentBranch.id,\n settings\n );\n } catch (error) {\n logErrorAndExit(`Error uploading files: ${error}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,eAAsB,OACpB,UACe;AACf,KAAI,CAAC,SAAS,MACZ;CAGF,MAAM,oBAAoB,SAAS,WAAW,EAAE;CAChD,MAAM,EACJ,eAAe,WACf,kBACA,gBACA,qBACE,SAAS;CAIb,MAAM,EAAE,OAAO,UAAU,eAAe,MAAM,eAAe,SAAS;CACtE,MAAM,qCAAqB,IAAI,KAG5B;AAEH,KAAI,UAAU,MAAM;EAClB,MAAM,kBAAkB,IAAI,IAAI,SAAS,KAAK,SAAS,KAAK,SAA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D;AAEF,KAAI;EAEF,MAAM,EAAE,eAAe,MAAM,uBAAuB;GAClD,OAAO;GACP,SAAS;GACV,CAAC;AAGF,QAAM,mBACJ,UACA,YACA,WAAW,cAAc,IACzB,SACD;UACM,OAAO;AACd,kBAAgB,0BAA0B,QAAQ"}
|
package/dist/config/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/config/defaults.ts"],"sourcesContent":["import { BaseParsingFlags, GTParsingFlags } from '../types/parsing.js';\n\n/**\n * Default parsing flags for GT files\n * @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both; an object enables selectively.\n * @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.\n */\nexport const GT_PARSING_FLAGS_DEFAULT: GTParsingFlags = {\n autoderive: false,\n includeSourceCodeContext: false,\n enableAutoJsxInjection: false,\n
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/config/defaults.ts"],"sourcesContent":["import { BaseParsingFlags, GTParsingFlags } from '../types/parsing.js';\n\n/**\n * Default parsing flags for GT files\n * @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both; an object enables selectively.\n * @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.\n */\nexport const GT_PARSING_FLAGS_DEFAULT: GTParsingFlags = {\n autoderive: false,\n includeSourceCodeContext: false,\n enableAutoJsxInjection: false,\n};\n\n/**\n * Default parsing flags for all files\n */\nexport const BASE_PARSING_FLAGS_DEFAULT: BaseParsingFlags = {};\n"],"mappings":";;;;;;AAOA,MAAa,2BAA2C;CACtD,YAAY;CACZ,0BAA0B;CAC1B,wBAAwB;CACzB;;;;AAKD,MAAa,6BAA+C,EAAE"}
|
package/dist/console/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const withDeriveFunctionError = (message) => `derive() rules violation: ${messag
|
|
|
8
8
|
const warnApiKeyInConfigSync = (optionsFilepath) => `${colorizeFilepath(optionsFilepath)}: Your API key is exposed! Remove it from the file and include it as an environment variable.`;
|
|
9
9
|
const warnVariablePropSync = (file, attrName, value, location) => withLocation(file, `${colorizeComponent("<T>")} component has dynamic attribute ${colorizeIdString(attrName)} with value: ${colorizeContent(value)}. Change ${colorizeIdString(attrName)} to ensure this content is translated.`, location);
|
|
10
10
|
const warnInvalidReturnSync = (file, functionName, expression, location) => withLocation(file, withDeriveComponentError(`Function ${colorizeFunctionName(functionName)} does not return a derivable (statically analyzable) expression. ${colorizeFunctionName(functionName)} must return either (1) a derivable string literal, (2) another derivable function invocation, (3) derivable JSX content, or (4) a ternary expression. Instead got:\n${colorizeContent(expression)}`), location);
|
|
11
|
-
const warnMissingReturnSync = (file, functionName, location) => withLocation(file, `Function ${colorizeFunctionName(functionName)} is wrapped in ${colorizeComponent("<Derive>")} tags but does not have an explicit return statement. Derivable functions must have an explicit return statement.`, location);
|
|
11
|
+
const warnMissingReturnSync = (file, functionName, location) => withLocation(file, `Function ${colorizeFunctionName(functionName)} is wrapped in ${colorizeComponent("<Derive>")} (formerly ${colorizeComponent("<Static>")}) tags but does not have an explicit return statement. Derivable functions must have an explicit return statement.`, location);
|
|
12
12
|
const warnHasUnwrappedExpressionSync = (file, unwrappedExpressions, id, location) => withLocation(file, `${colorizeComponent("<T>")} component${id ? ` with id ${colorizeIdString(id)}` : ""} has children that could change at runtime. Use a variable component like ${colorizeComponent("<Var>")} to ensure this content is translated.\n${colorizeContent(unwrappedExpressions.join("\n"))}`, location);
|
|
13
13
|
const warnFailedToConstructJsxTreeSync = (file, code, location) => withLocation(file, `Failed to construct JsxTree! Call expression is not a valid createElement call: ${colorizeContent(code)}`, location);
|
|
14
14
|
const warnNestedTComponent = (file, location) => withLocation(file, `Found nested <T> component. <T> components cannot be directly nested.`, location);
|
|
@@ -31,9 +31,9 @@ Example: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = () =>
|
|
|
31
31
|
Invalid: ${colorizeContent(`const ${colorizeFunctionName(functionName)} = [() => { ... }][0]`)}`), location);
|
|
32
32
|
const warnDataAttrOnBranch = (file, attrName, location) => withLocation(file, `${colorizeComponent(`<${BRANCH_COMPONENT}>`)} component ignores attributes prefixed with ${colorizeIdString("\"data-\"")}. Found ${colorizeIdString(attrName)}. Remove it or use a different attribute name.`, location);
|
|
33
33
|
const warnRecursiveFunctionCallSync = (file, functionName, location) => withLocation(file, withDeriveComponentError(`Recursive function call detected: ${colorizeFunctionName(functionName)}. A derivable (statically analyzable) function cannot use recursive calls to construct its result.`), location);
|
|
34
|
-
const warnDeriveFunctionNotWrappedSync = (file, functionName, location) => withLocation(file, withDeriveFunctionError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. This call is not wrapped in derive(). Ensure the function is properly wrapped with derive() and does not have circular import dependencies.`), location);
|
|
34
|
+
const warnDeriveFunctionNotWrappedSync = (file, functionName, location) => withLocation(file, withDeriveFunctionError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. This call is not wrapped in derive() (formerly declareStatic()). Ensure the function is properly wrapped with derive() and does not have circular import dependencies.`), location);
|
|
35
35
|
const warnDeriveNonConstVariableSync = (file, varName, kind, location) => withLocation(file, withDeriveFunctionError(`Variable ${colorizeFunctionName(varName)} is declared with '${kind}' but only 'const' declarations can be resolved statically. Change it to 'const'.`), location);
|
|
36
|
-
const warnDeriveFunctionNoResultsSync = (file, functionName, location) => withLocation(file, withDeriveFunctionError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. derive() can only receive function invocations and cannot use undefined values or looped calls to construct its result.`), location);
|
|
36
|
+
const warnDeriveFunctionNoResultsSync = (file, functionName, location) => withLocation(file, withDeriveFunctionError(`Could not resolve ${colorizeFunctionName(formatCodeClamp(functionName))}. derive() (formerly declareStatic()) can only receive function invocations and cannot use undefined values or looped calls to construct its result.`), location);
|
|
37
37
|
const warnAutoderiveNoResultsSync = (file, expression, location) => withLocation(file, `Autoderive could not resolve ${colorizeFunctionName(formatCodeClamp(expression))}. Only function calls with statically determinable return values can be used directly in t(). Consider wrapping with derive() for explicit derivation, or use an interpolation variable instead.`, location);
|
|
38
38
|
const warnDeriveUnresolvableValueSync = (file, key, location) => withLocation(file, withDeriveFunctionError(`Object property ${colorizeFunctionName(formatCodeClamp(key))} could not be resolved to a static string value. Only string literals, template literals, conditionals, and function calls returning strings are supported.`), location);
|
|
39
39
|
const warnDeriveCircularSpreadSync = (file, varName, location) => withLocation(file, withDeriveFunctionError(`Circular spread detected involving ${colorizeFunctionName(varName)}. Spread references that form a cycle cannot be resolved statically.`), location);
|