gtx-cli 2.6.31 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1261
- package/README.md +12 -3
- package/dist/bin/bin-entry.js +2 -1
- package/dist/config/generateSettings.d.ts +1 -9
- package/dist/config/generateSettings.js +1 -214
- package/dist/config/resolveConfig.d.ts +1 -4
- package/dist/config/resolveConfig.js +1 -33
- package/dist/fs/config/setupConfig.d.ts +1 -17
- package/dist/fs/config/setupConfig.js +1 -50
- package/dist/fs/matchFiles.d.ts +1 -1
- package/dist/fs/matchFiles.js +1 -8
- package/dist/functions.d.ts +1 -7
- package/dist/functions.js +1 -6
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -27
- package/dist/main.js +2 -2
- package/dist/next/parse/handleInitGT.d.ts +1 -7
- package/dist/next/parse/handleInitGT.js +1 -157
- package/dist/next/parse/wrapContent.d.ts +1 -12
- package/dist/next/parse/wrapContent.js +1 -164
- package/dist/react/parse/wrapContent.d.ts +1 -12
- package/dist/react/parse/wrapContent.js +1 -162
- package/dist/types/index.d.ts +1 -243
- package/dist/types/index.js +1 -1
- package/dist/utils/installPackage.d.ts +1 -3
- package/dist/utils/installPackage.js +1 -77
- package/dist/utils/packageInfo.d.ts +1 -3
- package/dist/utils/packageInfo.js +1 -17
- package/dist/utils/packageJson.d.ts +1 -6
- package/dist/utils/packageJson.js +1 -68
- package/dist/utils/packageManager.d.ts +1 -28
- package/dist/utils/packageManager.js +1 -269
- package/package.json +11 -97
- package/dist/api/collectUserEditDiffs.d.ts +0 -9
- package/dist/api/collectUserEditDiffs.js +0 -159
- package/dist/api/downloadFileBatch.d.ts +0 -23
- package/dist/api/downloadFileBatch.js +0 -190
- package/dist/api/saveLocalEdits.d.ts +0 -6
- package/dist/api/saveLocalEdits.js +0 -38
- package/dist/cli/base.d.ts +0 -59
- package/dist/cli/base.js +0 -529
- package/dist/cli/commands/download.d.ts +0 -8
- package/dist/cli/commands/download.js +0 -51
- package/dist/cli/commands/enqueue.d.ts +0 -9
- package/dist/cli/commands/enqueue.js +0 -27
- package/dist/cli/commands/setupProject.d.ts +0 -7
- package/dist/cli/commands/setupProject.js +0 -37
- package/dist/cli/commands/stage.d.ts +0 -9
- package/dist/cli/commands/stage.js +0 -59
- package/dist/cli/commands/translate.d.ts +0 -7
- package/dist/cli/commands/translate.js +0 -70
- package/dist/cli/commands/upload.d.ts +0 -13
- package/dist/cli/commands/upload.js +0 -142
- package/dist/cli/commands/utils/validation.d.ts +0 -13
- package/dist/cli/commands/utils/validation.js +0 -38
- package/dist/cli/flags.d.ts +0 -15
- package/dist/cli/flags.js +0 -70
- package/dist/cli/inline.d.ts +0 -17
- package/dist/cli/inline.js +0 -135
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -12
- package/dist/cli/node.d.ts +0 -10
- package/dist/cli/node.js +0 -9
- package/dist/cli/react.d.ts +0 -12
- package/dist/cli/react.js +0 -72
- package/dist/config/optionPresets.d.ts +0 -3
- package/dist/config/optionPresets.js +0 -65
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -4
- package/dist/config/validateSettings.d.ts +0 -3
- package/dist/config/validateSettings.js +0 -32
- package/dist/console/colors.d.ts +0 -6
- package/dist/console/colors.js +0 -19
- package/dist/console/displayTranslateSummary.d.ts +0 -1
- package/dist/console/displayTranslateSummary.js +0 -42
- package/dist/console/formatting.d.ts +0 -1
- package/dist/console/formatting.js +0 -7
- package/dist/console/index.d.ts +0 -34
- package/dist/console/index.js +0 -46
- package/dist/console/logger.d.ts +0 -35
- package/dist/console/logger.js +0 -250
- package/dist/console/logging.d.ts +0 -52
- package/dist/console/logging.js +0 -175
- package/dist/formats/files/aggregateFiles.d.ts +0 -4
- package/dist/formats/files/aggregateFiles.js +0 -156
- package/dist/formats/files/collectFiles.d.ts +0 -6
- package/dist/formats/files/collectFiles.js +0 -49
- package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
- package/dist/formats/files/convertToFileTranslationData.js +0 -21
- package/dist/formats/files/fileMapping.d.ts +0 -11
- package/dist/formats/files/fileMapping.js +0 -115
- package/dist/formats/files/preprocess/mdx.d.ts +0 -6
- package/dist/formats/files/preprocess/mdx.js +0 -14
- package/dist/formats/files/preprocess/mintlify.d.ts +0 -5
- package/dist/formats/files/preprocess/mintlify.js +0 -15
- package/dist/formats/files/preprocessContent.d.ts +0 -8
- package/dist/formats/files/preprocessContent.js +0 -23
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -17
- package/dist/formats/files/supportedFiles.d.ts +0 -11
- package/dist/formats/files/supportedFiles.js +0 -20
- package/dist/formats/json/extractJson.d.ts +0 -15
- package/dist/formats/json/extractJson.js +0 -101
- package/dist/formats/json/flattenJson.d.ts +0 -14
- package/dist/formats/json/flattenJson.js +0 -64
- package/dist/formats/json/mergeJson.d.ts +0 -13
- package/dist/formats/json/mergeJson.js +0 -367
- package/dist/formats/json/parseJson.d.ts +0 -2
- package/dist/formats/json/parseJson.js +0 -109
- package/dist/formats/json/utils.d.ts +0 -47
- package/dist/formats/json/utils.js +0 -150
- package/dist/formats/utils.d.ts +0 -2
- package/dist/formats/utils.js +0 -24
- package/dist/formats/yaml/mergeYaml.d.ts +0 -5
- package/dist/formats/yaml/mergeYaml.js +0 -61
- package/dist/formats/yaml/parseYaml.d.ts +0 -5
- package/dist/formats/yaml/parseYaml.js +0 -24
- package/dist/formats/yaml/utils.d.ts +0 -2
- package/dist/formats/yaml/utils.js +0 -23
- package/dist/fs/clearLocaleDirs.d.ts +0 -8
- package/dist/fs/clearLocaleDirs.js +0 -126
- package/dist/fs/config/downloadedVersions.d.ts +0 -21
- package/dist/fs/config/downloadedVersions.js +0 -50
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -9
- package/dist/fs/config/parseFilesConfig.d.ts +0 -27
- package/dist/fs/config/parseFilesConfig.js +0 -150
- package/dist/fs/config/updateConfig.d.ts +0 -21
- package/dist/fs/config/updateConfig.js +0 -57
- package/dist/fs/config/updateVersions.d.ts +0 -11
- package/dist/fs/config/updateVersions.js +0 -30
- package/dist/fs/copyFile.d.ts +0 -7
- package/dist/fs/copyFile.js +0 -39
- package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
- package/dist/fs/createLoadTranslationsFile.js +0 -49
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -53
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -90
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -1
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -17
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -7
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -16
- package/dist/generated/version.d.ts +0 -1
- package/dist/generated/version.js +0 -2
- package/dist/git/branches.d.ts +0 -7
- package/dist/git/branches.js +0 -88
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -110
- package/dist/locadex/setupFlow.d.ts +0 -2
- package/dist/locadex/setupFlow.js +0 -9
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -53
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -42
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -119
- package/dist/react/jsx/evaluateJsx.d.ts +0 -24
- package/dist/react/jsx/evaluateJsx.js +0 -123
- package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
- package/dist/react/jsx/utils/buildImportMap.js +0 -30
- package/dist/react/jsx/utils/constants.d.ts +0 -15
- package/dist/react/jsx/utils/constants.js +0 -49
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
- package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
- package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
- package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -138
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -918
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
- package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
- package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
- package/dist/react/jsx/utils/mapAttributeName.js +0 -12
- package/dist/react/jsx/utils/parseAst.d.ts +0 -31
- package/dist/react/jsx/utils/parseAst.js +0 -278
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
- package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
- package/dist/react/jsx/utils/parseString.d.ts +0 -25
- package/dist/react/jsx/utils/parseString.js +0 -540
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
- package/dist/react/jsx/utils/parseStringFunction.js +0 -348
- package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
- package/dist/react/jsx/utils/resolveImportPath.js +0 -111
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
- package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
- package/dist/react/jsx/utils/stringParsing/types.js +0 -1
- package/dist/react/jsx/utils/types.d.ts +0 -14
- package/dist/react/jsx/utils/types.js +0 -1
- package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
- package/dist/react/jsx/utils/validateStringFunction.js +0 -31
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -387
- package/dist/react/parse/addVitePlugin/index.d.ts +0 -22
- package/dist/react/parse/addVitePlugin/index.js +0 -41
- package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
- package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
- package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -187
- package/dist/react/parse/createInlineUpdates.d.ts +0 -13
- package/dist/react/parse/createInlineUpdates.js +0 -161
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -75
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -11
- package/dist/react/utils/getVariableName.d.ts +0 -25
- package/dist/react/utils/getVariableName.js +0 -37
- package/dist/setup/agentInstructions.d.ts +0 -24
- package/dist/setup/agentInstructions.js +0 -138
- package/dist/setup/detectFramework.d.ts +0 -31
- package/dist/setup/detectFramework.js +0 -106
- package/dist/setup/frameworkUtils.d.ts +0 -3
- package/dist/setup/frameworkUtils.js +0 -30
- package/dist/setup/instructions/base.md +0 -29
- package/dist/setup/instructions/gt-next.md +0 -107
- package/dist/setup/instructions/gt-react.md +0 -98
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -32
- package/dist/setup/wizard.d.ts +0 -3
- package/dist/setup/wizard.js +0 -147
- package/dist/state/recentDownloads.d.ts +0 -12
- package/dist/state/recentDownloads.js +0 -18
- package/dist/state/translateWarnings.d.ts +0 -10
- package/dist/state/translateWarnings.js +0 -13
- package/dist/translation/parse.d.ts +0 -17
- package/dist/translation/parse.js +0 -77
- package/dist/translation/stage.d.ts +0 -3
- package/dist/translation/stage.js +0 -44
- package/dist/translation/validate.d.ts +0 -14
- package/dist/translation/validate.js +0 -100
- package/dist/types/branch.d.ts +0 -14
- package/dist/types/branch.js +0 -1
- package/dist/types/data/json.d.ts +0 -6
- package/dist/types/data/json.js +0 -1
- package/dist/types/data.d.ts +0 -37
- package/dist/types/data.js +0 -1
- package/dist/types/files.d.ts +0 -8
- package/dist/types/files.js +0 -1
- package/dist/types/libraries.d.ts +0 -31
- package/dist/types/libraries.js +0 -72
- package/dist/types/parsing.d.ts +0 -3
- package/dist/types/parsing.js +0 -1
- package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
- package/dist/utils/addExplicitAnchorIds.js +0 -416
- package/dist/utils/constants.d.ts +0 -5
- package/dist/utils/constants.js +0 -6
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -120
- package/dist/utils/flattenJsonFiles.d.ts +0 -2
- package/dist/utils/flattenJsonFiles.js +0 -36
- package/dist/utils/gitDiff.d.ts +0 -8
- package/dist/utils/gitDiff.js +0 -34
- package/dist/utils/gt.d.ts +0 -2
- package/dist/utils/gt.js +0 -2
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -11
- package/dist/utils/headers.d.ts +0 -1
- package/dist/utils/headers.js +0 -14
- package/dist/utils/localizeRelativeAssets.d.ts +0 -8
- package/dist/utils/localizeRelativeAssets.js +0 -166
- package/dist/utils/localizeStaticImports.d.ts +0 -15
- package/dist/utils/localizeStaticImports.js +0 -397
- package/dist/utils/localizeStaticUrls.d.ts +0 -19
- package/dist/utils/localizeStaticUrls.js +0 -450
- package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
- package/dist/utils/mintlifyTitleFallback.js +0 -80
- package/dist/utils/parse/needsCJS.d.ts +0 -20
- package/dist/utils/parse/needsCJS.js +0 -72
- package/dist/utils/persistPostprocessHashes.d.ts +0 -12
- package/dist/utils/persistPostprocessHashes.js +0 -39
- package/dist/utils/processAnchorIds.d.ts +0 -6
- package/dist/utils/processAnchorIds.js +0 -56
- package/dist/utils/processOpenApi.d.ts +0 -8
- package/dist/utils/processOpenApi.js +0 -651
- package/dist/utils/sanitizeFileContent.d.ts +0 -6
- package/dist/utils/sanitizeFileContent.js +0 -29
- package/dist/utils/sharedStaticAssets.d.ts +0 -9
- package/dist/utils/sharedStaticAssets.js +0 -384
- package/dist/utils/validateMdx.d.ts +0 -10
- package/dist/utils/validateMdx.js +0 -25
- package/dist/utils/wrapPlainUrls.d.ts +0 -8
- package/dist/utils/wrapPlainUrls.js +0 -72
- package/dist/workflows/download.d.ts +0 -32
- package/dist/workflows/download.js +0 -131
- package/dist/workflows/enqueue.d.ts +0 -17
- package/dist/workflows/enqueue.js +0 -59
- package/dist/workflows/setupProject.d.ts +0 -13
- package/dist/workflows/setupProject.js +0 -48
- package/dist/workflows/stage.d.ts +0 -18
- package/dist/workflows/stage.js +0 -59
- package/dist/workflows/steps/BranchStep.d.ts +0 -13
- package/dist/workflows/steps/BranchStep.js +0 -161
- package/dist/workflows/steps/DownloadStep.d.ts +0 -19
- package/dist/workflows/steps/DownloadStep.js +0 -131
- package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
- package/dist/workflows/steps/EnqueueStep.js +0 -33
- package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
- package/dist/workflows/steps/PollJobsStep.js +0 -288
- package/dist/workflows/steps/SetupStep.d.ts +0 -16
- package/dist/workflows/steps/SetupStep.js +0 -72
- package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
- package/dist/workflows/steps/UploadSourcesStep.js +0 -131
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
- package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
- package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -2
- package/dist/workflows/upload.d.ts +0 -15
- package/dist/workflows/upload.js +0 -47
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { isStaticExpression, isStaticValue } from './evaluateJsx.js';
|
|
3
|
-
import { warnTernarySync } from '../../console/index.js';
|
|
4
|
-
function wrapJsxExpression(node, options, isMeaningful, mark) {
|
|
5
|
-
const expression = t.isParenthesizedExpression(node.expression)
|
|
6
|
-
? node.expression.expression
|
|
7
|
-
: node.expression;
|
|
8
|
-
// Ignore template literals containing quasis - they should not be counted as meaningful
|
|
9
|
-
if (t.isTemplateLiteral(expression) && expression.expressions.length > 0) {
|
|
10
|
-
return {
|
|
11
|
-
node,
|
|
12
|
-
hasMeaningfulContent: false,
|
|
13
|
-
wrappedInT: false,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
// Handle both JSX Elements and Fragments
|
|
17
|
-
if (t.isJSXElement(expression) ||
|
|
18
|
-
t.isJSXFragment(expression) ||
|
|
19
|
-
t.isStringLiteral(expression) ||
|
|
20
|
-
t.isJSXText(expression) ||
|
|
21
|
-
t.isTemplateLiteral(expression)) {
|
|
22
|
-
if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {
|
|
23
|
-
const result = wrapJsxElement(expression, options, isMeaningful, mark);
|
|
24
|
-
// re-wrap the result in a JSXExpressionContainer
|
|
25
|
-
if (t.isParenthesizedExpression(node.expression)) {
|
|
26
|
-
node.expression.expression = result.node;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
node.expression = result.node;
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
node,
|
|
33
|
-
hasMeaningfulContent: result.hasMeaningfulContent,
|
|
34
|
-
wrappedInT: result.wrappedInT,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
node,
|
|
39
|
-
hasMeaningfulContent: isMeaningful(expression),
|
|
40
|
-
wrappedInT: false,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
// Handle conditional expressions (ternary)
|
|
44
|
-
else if (t.isConditionalExpression(expression)) {
|
|
45
|
-
const consequent = t.isParenthesizedExpression(expression.consequent)
|
|
46
|
-
? expression.consequent.expression
|
|
47
|
-
: expression.consequent;
|
|
48
|
-
const alternate = t.isParenthesizedExpression(expression.alternate)
|
|
49
|
-
? expression.alternate.expression
|
|
50
|
-
: expression.alternate;
|
|
51
|
-
// Handle consequent
|
|
52
|
-
if (t.isJSXElement(consequent) || t.isJSXFragment(consequent)) {
|
|
53
|
-
const result = handleJsxElement(consequent, options, isMeaningful);
|
|
54
|
-
// Re-insert into parenthesized expression if necessary
|
|
55
|
-
if (t.isParenthesizedExpression(expression.consequent)) {
|
|
56
|
-
expression.consequent.expression = result.node;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
expression.consequent = result.node;
|
|
60
|
-
}
|
|
61
|
-
// Warn about ternary (should use branch instead)
|
|
62
|
-
if (result.wrappedInT && !mark) {
|
|
63
|
-
options.warnings.push(warnTernarySync(options.file, `${consequent.loc?.start?.line}:${consequent.loc?.start?.column}`));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (t.isConditionalExpression(consequent) ||
|
|
67
|
-
t.isLogicalExpression(consequent)) {
|
|
68
|
-
// Recursively handle nested ternary in consequent
|
|
69
|
-
const consequentResult = wrapJsxExpression(t.jsxExpressionContainer(consequent), options, isMeaningful, mark);
|
|
70
|
-
if (t.isJSXExpressionContainer(consequentResult.node) &&
|
|
71
|
-
t.isExpression(consequentResult.node.expression)) {
|
|
72
|
-
expression.consequent = consequentResult.node.expression;
|
|
73
|
-
// Re-insert into parenthesized expression if necessary
|
|
74
|
-
if (t.isParenthesizedExpression(expression.consequent)) {
|
|
75
|
-
expression.consequent.expression = consequentResult.node.expression;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
expression.consequent = consequentResult.node.expression;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else if (t.isTemplateLiteral(consequent) &&
|
|
83
|
-
consequent.expressions.length > 0) {
|
|
84
|
-
// Ignore template literals in consequent with expressions (${}), don't wrap them
|
|
85
|
-
// Do nothing
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
if (isStaticValue(consequent) && isMeaningful(consequent)) {
|
|
89
|
-
const wrapped = wrapExpressionWithT(consequent, options, false);
|
|
90
|
-
// Re-insert into parenthesized expression if necessary
|
|
91
|
-
if (t.isParenthesizedExpression(expression.consequent)) {
|
|
92
|
-
expression.consequent.expression = wrapped;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
expression.consequent = wrapped;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// Handle alternate
|
|
100
|
-
if (t.isJSXElement(alternate) || t.isJSXFragment(alternate)) {
|
|
101
|
-
const result = handleJsxElement(alternate, options, isMeaningful);
|
|
102
|
-
// Re-insert into parenthesized expression if necessary
|
|
103
|
-
if (t.isParenthesizedExpression(expression.alternate)) {
|
|
104
|
-
expression.alternate.expression = result.node;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
expression.alternate = result.node;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (t.isConditionalExpression(alternate) ||
|
|
111
|
-
t.isLogicalExpression(alternate)) {
|
|
112
|
-
// Recursively handle nested ternary in alternate
|
|
113
|
-
const alternateResult = wrapJsxExpression(t.jsxExpressionContainer(alternate), options, isMeaningful, mark);
|
|
114
|
-
if (t.isJSXExpressionContainer(alternateResult.node) &&
|
|
115
|
-
t.isExpression(alternateResult.node.expression)) {
|
|
116
|
-
expression.alternate = alternateResult.node.expression;
|
|
117
|
-
// Re-insert into parenthesized expression if necessary
|
|
118
|
-
if (t.isParenthesizedExpression(expression.alternate)) {
|
|
119
|
-
expression.alternate.expression = alternateResult.node.expression;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
expression.alternate = alternateResult.node.expression;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (t.isTemplateLiteral(alternate) &&
|
|
127
|
-
alternate.expressions.length > 0) {
|
|
128
|
-
// Ignore template literals in alternate with expressions (${}), don't wrap them
|
|
129
|
-
// Do nothing
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
if (isStaticValue(alternate) && isMeaningful(alternate)) {
|
|
133
|
-
const wrapped = wrapExpressionWithT(alternate, options, false);
|
|
134
|
-
// Re-insert into parenthesized expression if necessary
|
|
135
|
-
if (t.isParenthesizedExpression(expression.alternate)) {
|
|
136
|
-
expression.alternate.expression = wrapped;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
expression.alternate = wrapped;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// Handle logical expressions (&& and ||)
|
|
145
|
-
else if (t.isLogicalExpression(expression)) {
|
|
146
|
-
const left = t.isParenthesizedExpression(expression.left)
|
|
147
|
-
? expression.left.expression
|
|
148
|
-
: expression.left;
|
|
149
|
-
const right = t.isParenthesizedExpression(expression.right)
|
|
150
|
-
? expression.right.expression
|
|
151
|
-
: expression.right;
|
|
152
|
-
if (t.isJSXElement(left) || t.isJSXFragment(left)) {
|
|
153
|
-
const result = handleJsxElement(left, options, isMeaningful);
|
|
154
|
-
// Re-insert into parenthesized expression if necessary
|
|
155
|
-
if (t.isParenthesizedExpression(expression.left)) {
|
|
156
|
-
expression.left.expression = result.node;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
expression.left = result.node;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (t.isLogicalExpression(left) || t.isConditionalExpression(left)) {
|
|
163
|
-
// Recursively handle nested logical expressions
|
|
164
|
-
const leftResult = wrapJsxExpression(t.jsxExpressionContainer(left), options, isMeaningful, mark);
|
|
165
|
-
if (t.isJSXExpressionContainer(leftResult.node) &&
|
|
166
|
-
t.isExpression(leftResult.node.expression)) {
|
|
167
|
-
// Re-insert into parenthesized expression if necessary
|
|
168
|
-
if (t.isParenthesizedExpression(expression.left)) {
|
|
169
|
-
expression.left.expression = leftResult.node.expression;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
expression.left = leftResult.node.expression;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
else if (t.isTemplateLiteral(left) && left.expressions.length > 0) {
|
|
177
|
-
// Ignore template literals with expressions (${}) in left side of logical expression
|
|
178
|
-
// Do nothing - don't wrap them
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
if (isStaticValue(left) &&
|
|
182
|
-
isMeaningful(left) &&
|
|
183
|
-
expression.operator !== '&&') {
|
|
184
|
-
const wrapped = wrapExpressionWithT(left, options, false);
|
|
185
|
-
// Re-insert into parenthesized expression if necessary
|
|
186
|
-
if (t.isParenthesizedExpression(expression.left)) {
|
|
187
|
-
expression.left.expression = wrapped;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
expression.left = wrapped;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (t.isJSXElement(right) || t.isJSXFragment(right)) {
|
|
195
|
-
const result = handleJsxElement(right, options, isMeaningful);
|
|
196
|
-
// Re-insert into parenthesized expression if necessary
|
|
197
|
-
if (t.isParenthesizedExpression(expression.right)) {
|
|
198
|
-
expression.right.expression = result.node;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
expression.right = result.node;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else if (t.isLogicalExpression(right) ||
|
|
205
|
-
t.isConditionalExpression(right)) {
|
|
206
|
-
// Recursively handle nested logical expressions
|
|
207
|
-
const rightResult = wrapJsxExpression(t.jsxExpressionContainer(right), options, isMeaningful, mark);
|
|
208
|
-
if (t.isJSXExpressionContainer(rightResult.node) &&
|
|
209
|
-
t.isExpression(rightResult.node.expression)) {
|
|
210
|
-
// Re-insert into parenthesized expression if necessary
|
|
211
|
-
if (t.isParenthesizedExpression(expression.right)) {
|
|
212
|
-
expression.right.expression = rightResult.node.expression;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
expression.right = rightResult.node.expression;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else if (t.isTemplateLiteral(right) && right.expressions.length > 0) {
|
|
220
|
-
// Ignore template literals with expressions (${}) in right side of logical expression
|
|
221
|
-
// Do nothing - don't wrap them
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
if (isStaticValue(right) &&
|
|
225
|
-
isMeaningful(right) &&
|
|
226
|
-
expression.operator !== '||') {
|
|
227
|
-
const wrapped = wrapExpressionWithT(right, options, false);
|
|
228
|
-
// Re-insert into parenthesized expression if necessary
|
|
229
|
-
if (t.isParenthesizedExpression(expression.right)) {
|
|
230
|
-
expression.right.expression = wrapped;
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
expression.right = wrapped;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const staticCheck = isStaticExpression(expression);
|
|
239
|
-
// If the expression is not static or if it's already wrapped in T,
|
|
240
|
-
// wrap with Var
|
|
241
|
-
if (!staticCheck.isStatic) {
|
|
242
|
-
return {
|
|
243
|
-
node: wrapWithVar(node, options, mark),
|
|
244
|
-
hasMeaningfulContent: false,
|
|
245
|
-
wrappedInT: false,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
// If it's a static expression, check if it's meaningful
|
|
249
|
-
return {
|
|
250
|
-
node,
|
|
251
|
-
hasMeaningfulContent: false,
|
|
252
|
-
wrappedInT: false,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Recursively traverse a JSX element and wrap variables with a <Var> component
|
|
257
|
-
* @param node - The JSX element to wrap
|
|
258
|
-
* @param options - Optional component names for T and Var
|
|
259
|
-
* @param isMeaningful - A function to determine if a node is meaningful
|
|
260
|
-
* @returns The wrapped JSX element
|
|
261
|
-
*/
|
|
262
|
-
export function wrapJsxElement(node, options, isMeaningful, mark) {
|
|
263
|
-
const TComponentName = options.TComponent || 'T';
|
|
264
|
-
const VarComponentName = options.VarComponent || 'Var';
|
|
265
|
-
// Handle both JSX Elements and Fragments
|
|
266
|
-
if (t.isJSXElement(node) || t.isJSXFragment(node)) {
|
|
267
|
-
// For elements, check if it's already a T or Var component
|
|
268
|
-
if (t.isJSXElement(node)) {
|
|
269
|
-
const name = node.openingElement.name;
|
|
270
|
-
if (t.isJSXIdentifier(name) &&
|
|
271
|
-
(name.name === TComponentName || name.name === VarComponentName)) {
|
|
272
|
-
return {
|
|
273
|
-
node,
|
|
274
|
-
hasMeaningfulContent: false,
|
|
275
|
-
wrappedInT: name.name === TComponentName,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
// Process children recursively (DFS postorder)
|
|
280
|
-
let hasMeaningfulContent = false;
|
|
281
|
-
let wrappedInT = false;
|
|
282
|
-
const processedChildren = node.children.map((child) => {
|
|
283
|
-
if (t.isJSXElement(child) || t.isJSXFragment(child)) {
|
|
284
|
-
const result = wrapJsxElement(child, options, isMeaningful, mark);
|
|
285
|
-
hasMeaningfulContent =
|
|
286
|
-
hasMeaningfulContent || result.hasMeaningfulContent;
|
|
287
|
-
wrappedInT = wrappedInT || result.wrappedInT;
|
|
288
|
-
return result.node;
|
|
289
|
-
}
|
|
290
|
-
if (t.isJSXExpressionContainer(child)) {
|
|
291
|
-
const result = wrapJsxExpression(child, options, isMeaningful, mark);
|
|
292
|
-
wrappedInT = wrappedInT || result.wrappedInT;
|
|
293
|
-
hasMeaningfulContent =
|
|
294
|
-
hasMeaningfulContent || result.hasMeaningfulContent;
|
|
295
|
-
// Expressions are never meaningful because they will either:
|
|
296
|
-
// 1. be sub-wrapped in a T (if they contain meaningful content)
|
|
297
|
-
// 2. be wrapped in a Var (if they are not static)
|
|
298
|
-
return result.node;
|
|
299
|
-
}
|
|
300
|
-
const isMeaningfulVal = isMeaningful(child);
|
|
301
|
-
if (isMeaningfulVal) {
|
|
302
|
-
hasMeaningfulContent = true;
|
|
303
|
-
}
|
|
304
|
-
return child;
|
|
305
|
-
});
|
|
306
|
-
node.children = processedChildren;
|
|
307
|
-
return {
|
|
308
|
-
node,
|
|
309
|
-
hasMeaningfulContent: hasMeaningfulContent,
|
|
310
|
-
wrappedInT: wrappedInT,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
// For any other node types, return as-is
|
|
314
|
-
return {
|
|
315
|
-
node,
|
|
316
|
-
hasMeaningfulContent: false,
|
|
317
|
-
wrappedInT: false,
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Wraps a JSX element with a <T> component and unique id
|
|
322
|
-
* @param rootNode - The JSX element to wrap
|
|
323
|
-
* @param options - Optional component names for T and Var
|
|
324
|
-
* @param isMeaningful - A function to determine if a node is meaningful
|
|
325
|
-
* @returns The wrapped JSX element
|
|
326
|
-
*/
|
|
327
|
-
export function handleJsxElement(rootNode, options, isMeaningful) {
|
|
328
|
-
const result = wrapJsxElement(rootNode, options, isMeaningful, true);
|
|
329
|
-
// Only wrap with T at the root level if there's meaningful content
|
|
330
|
-
if (result.hasMeaningfulContent) {
|
|
331
|
-
const output = wrapJsxElement(result.node, options, isMeaningful, false);
|
|
332
|
-
const node = wrapWithT(output.node, options, false);
|
|
333
|
-
return {
|
|
334
|
-
node,
|
|
335
|
-
hasMeaningfulContent: true,
|
|
336
|
-
wrappedInT: true,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
node: result.node,
|
|
341
|
-
hasMeaningfulContent: false,
|
|
342
|
-
wrappedInT: result.wrappedInT,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
function wrapWithT(node, options, mark) {
|
|
346
|
-
if (mark) {
|
|
347
|
-
return node;
|
|
348
|
-
}
|
|
349
|
-
const TComponentName = options.TComponent || 'T';
|
|
350
|
-
const uniqueId = `${options.idPrefix}.${options.idCount}`;
|
|
351
|
-
options.modified = true;
|
|
352
|
-
options.idCount++;
|
|
353
|
-
if (!options.usedImports.includes(TComponentName)) {
|
|
354
|
-
options.usedImports.push(TComponentName);
|
|
355
|
-
}
|
|
356
|
-
if (options.createIds) {
|
|
357
|
-
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(uniqueId))], false), t.jsxClosingElement(t.jsxIdentifier(TComponentName)), [node], false);
|
|
358
|
-
}
|
|
359
|
-
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [], false), t.jsxClosingElement(t.jsxIdentifier(TComponentName)), [node], false);
|
|
360
|
-
}
|
|
361
|
-
function wrapExpressionWithT(node, options, mark) {
|
|
362
|
-
if (mark) {
|
|
363
|
-
return node;
|
|
364
|
-
}
|
|
365
|
-
const TComponentName = options.TComponent || 'T';
|
|
366
|
-
const uniqueId = `${options.idPrefix}.${options.idCount}`;
|
|
367
|
-
options.modified = true;
|
|
368
|
-
options.idCount++;
|
|
369
|
-
if (!options.usedImports.includes(TComponentName)) {
|
|
370
|
-
options.usedImports.push(TComponentName);
|
|
371
|
-
}
|
|
372
|
-
if (options.createIds) {
|
|
373
|
-
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(uniqueId))], false), t.jsxClosingElement(t.jsxIdentifier(TComponentName)), [t.jsxExpressionContainer(node)], false);
|
|
374
|
-
}
|
|
375
|
-
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [], false), t.jsxClosingElement(t.jsxIdentifier(TComponentName)), [t.jsxExpressionContainer(node)], false);
|
|
376
|
-
}
|
|
377
|
-
function wrapWithVar(node, options, mark) {
|
|
378
|
-
if (mark) {
|
|
379
|
-
return node;
|
|
380
|
-
}
|
|
381
|
-
const VarComponentName = options.VarComponent || 'Var';
|
|
382
|
-
options.modified = true;
|
|
383
|
-
if (!options.usedImports.includes(VarComponentName)) {
|
|
384
|
-
options.usedImports.push(VarComponentName);
|
|
385
|
-
}
|
|
386
|
-
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(VarComponentName), [], false), t.jsxClosingElement(t.jsxIdentifier(VarComponentName)), [node], false);
|
|
387
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds the gt compiler plugin to the vite config file
|
|
3
|
-
*/
|
|
4
|
-
export declare function addVitePlugin({ errors, warnings, filesUpdated, packageJson, tsconfigJson, }: {
|
|
5
|
-
errors: string[];
|
|
6
|
-
warnings: string[];
|
|
7
|
-
filesUpdated: string[];
|
|
8
|
-
packageJson?: {
|
|
9
|
-
type?: string;
|
|
10
|
-
dependencies?: Record<string, string>;
|
|
11
|
-
devDependencies?: Record<string, string>;
|
|
12
|
-
};
|
|
13
|
-
tsconfigJson?: {
|
|
14
|
-
compilerOptions?: {
|
|
15
|
-
module?: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
}): Promise<{
|
|
19
|
-
errors: string[];
|
|
20
|
-
warnings: string[];
|
|
21
|
-
filesUpdated: string[];
|
|
22
|
-
}>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import findFilepath from '../../../fs/findFilepath.js';
|
|
2
|
-
import { logger } from '../../../console/logger.js';
|
|
3
|
-
import { installCompiler } from './installCompiler.js';
|
|
4
|
-
import { updateViteConfig } from './updateViteConfig.js';
|
|
5
|
-
import { exitSync } from '../../../console/logging.js';
|
|
6
|
-
const VITE_CONFIG_PATH_BASE = './vite.config.';
|
|
7
|
-
/**
|
|
8
|
-
* Adds the gt compiler plugin to the vite config file
|
|
9
|
-
*/
|
|
10
|
-
export async function addVitePlugin({ errors, warnings, filesUpdated, packageJson, tsconfigJson, }) {
|
|
11
|
-
// Resolve file path
|
|
12
|
-
const viteConfigPath = findFilepath([
|
|
13
|
-
VITE_CONFIG_PATH_BASE + 'js',
|
|
14
|
-
VITE_CONFIG_PATH_BASE + 'ts',
|
|
15
|
-
VITE_CONFIG_PATH_BASE + 'mjs',
|
|
16
|
-
VITE_CONFIG_PATH_BASE + 'mts',
|
|
17
|
-
VITE_CONFIG_PATH_BASE + 'cjs',
|
|
18
|
-
VITE_CONFIG_PATH_BASE + 'cts',
|
|
19
|
-
]);
|
|
20
|
-
if (!viteConfigPath) {
|
|
21
|
-
logger.error(`No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Please add the @generaltranslation/compiler plugin to your vite configuration file:
|
|
22
|
-
import { vite as gtCompiler } from '@generaltranslation/compiler';
|
|
23
|
-
export default defineConfig({
|
|
24
|
-
plugins: [gtCompiler()],
|
|
25
|
-
});
|
|
26
|
-
`);
|
|
27
|
-
exitSync(1);
|
|
28
|
-
}
|
|
29
|
-
// Install @generaltranslation/compiler if not installed
|
|
30
|
-
await installCompiler({ packageJson });
|
|
31
|
-
// Update the config file
|
|
32
|
-
await updateViteConfig({
|
|
33
|
-
errors,
|
|
34
|
-
warnings,
|
|
35
|
-
filesUpdated,
|
|
36
|
-
viteConfigPath,
|
|
37
|
-
packageJson,
|
|
38
|
-
tsconfigJson,
|
|
39
|
-
});
|
|
40
|
-
return { errors, warnings, filesUpdated };
|
|
41
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../../console/logger.js';
|
|
2
|
-
import { installPackage } from '../../../utils/installPackage.js';
|
|
3
|
-
import { isPackageInstalled } from '../../../utils/packageJson.js';
|
|
4
|
-
import { getPackageManager } from '../../../utils/packageManager.js';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
/**
|
|
7
|
-
* Installs @generaltranslation/compiler if not installed
|
|
8
|
-
*/
|
|
9
|
-
export async function installCompiler({ packageJson, }) {
|
|
10
|
-
// Check if installed
|
|
11
|
-
if (isPackageInstalled('@generaltranslation/compiler', packageJson || {})) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
// Animation
|
|
15
|
-
const spinner = logger.createSpinner();
|
|
16
|
-
spinner.start(`Installing @generaltranslation/compiler...`);
|
|
17
|
-
// Install
|
|
18
|
-
const packageManager = await getPackageManager();
|
|
19
|
-
await installPackage('@generaltranslation/compiler', packageManager, true);
|
|
20
|
-
// Animation
|
|
21
|
-
spinner.stop(chalk.green('Installed @generaltranslation/compiler.'));
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* - Reads the vite config file
|
|
3
|
-
* - Updates the ast to add the gt compiler plugin
|
|
4
|
-
* - Writes the file back to the filesystem
|
|
5
|
-
*/
|
|
6
|
-
export declare function updateViteConfig({ errors, warnings, filesUpdated, viteConfigPath, packageJson, tsconfigJson, }: {
|
|
7
|
-
errors: string[];
|
|
8
|
-
warnings: string[];
|
|
9
|
-
filesUpdated: string[];
|
|
10
|
-
viteConfigPath: string;
|
|
11
|
-
packageJson?: {
|
|
12
|
-
type?: string;
|
|
13
|
-
};
|
|
14
|
-
tsconfigJson?: {
|
|
15
|
-
compilerOptions?: {
|
|
16
|
-
module?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
}): Promise<void>;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../../console/logger.js';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import generateModule from '@babel/generator';
|
|
5
|
-
import { parse } from '@babel/parser';
|
|
6
|
-
import { needsCJS } from '../../../utils/parse/needsCJS.js';
|
|
7
|
-
import { addCompilerImport } from './utils/addCompilerImport.js';
|
|
8
|
-
import { checkCompilerImport } from './utils/checkCompilerImport.js';
|
|
9
|
-
import { checkPluginInvocation } from './utils/checkPluginInvocation.js';
|
|
10
|
-
import { addPluginInvocation } from './utils/addPluginInvocation.js';
|
|
11
|
-
import { exitSync } from '../../../console/logging.js';
|
|
12
|
-
// Handle CommonJS/ESM interop
|
|
13
|
-
const generate = generateModule.default || generateModule;
|
|
14
|
-
/**
|
|
15
|
-
* - Reads the vite config file
|
|
16
|
-
* - Updates the ast to add the gt compiler plugin
|
|
17
|
-
* - Writes the file back to the filesystem
|
|
18
|
-
*/
|
|
19
|
-
export async function updateViteConfig({ errors, warnings, filesUpdated, viteConfigPath, packageJson, tsconfigJson, }) {
|
|
20
|
-
// Animation
|
|
21
|
-
const spinner = logger.createSpinner();
|
|
22
|
-
spinner.start(`Adding gt compiler plugin to ${viteConfigPath}...`);
|
|
23
|
-
// Read the file
|
|
24
|
-
let code;
|
|
25
|
-
try {
|
|
26
|
-
code = await fs.promises.readFile(viteConfigPath, 'utf8');
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
logger.error(`Error: Failed to read ${viteConfigPath}: ${error}`);
|
|
30
|
-
exitSync(1);
|
|
31
|
-
}
|
|
32
|
-
// Update the ast
|
|
33
|
-
let updatedCode, success;
|
|
34
|
-
try {
|
|
35
|
-
({ updatedCode, success } = await updateViteConfigAst({
|
|
36
|
-
code,
|
|
37
|
-
errors,
|
|
38
|
-
warnings,
|
|
39
|
-
viteConfigPath,
|
|
40
|
-
packageJson,
|
|
41
|
-
tsconfigJson,
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
logger.error(`Error: Failed to update ${viteConfigPath}: ${error}`);
|
|
46
|
-
exitSync(1);
|
|
47
|
-
}
|
|
48
|
-
// Write the file
|
|
49
|
-
try {
|
|
50
|
-
await fs.promises.writeFile(viteConfigPath, updatedCode);
|
|
51
|
-
filesUpdated.push(viteConfigPath);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
logger.error(`Error: Failed to write ${viteConfigPath}: ${error}`);
|
|
55
|
-
exitSync(1);
|
|
56
|
-
}
|
|
57
|
-
// Animation
|
|
58
|
-
spinner.stop(success
|
|
59
|
-
? chalk.green(`Success! Added gt compiler plugin to ${viteConfigPath}`)
|
|
60
|
-
: chalk.red(`Failed to add gt compiler plugin to ${viteConfigPath}. Continuing setup...`));
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Orchestrates AST manipulation
|
|
64
|
-
* @param code - The code to update
|
|
65
|
-
* @param errors - The errors to update
|
|
66
|
-
* @param warnings - The warnings to update
|
|
67
|
-
* @param viteConfigPath - The path to the vite config file
|
|
68
|
-
* @param packageJson - The package.json file
|
|
69
|
-
* @param tsconfigJson - The tsconfig.json file
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
async function updateViteConfigAst({ code, warnings, viteConfigPath, packageJson, tsconfigJson, }) {
|
|
73
|
-
// Parse the code
|
|
74
|
-
const ast = parse(code, {
|
|
75
|
-
sourceType: 'module',
|
|
76
|
-
plugins: ['jsx', 'typescript'],
|
|
77
|
-
});
|
|
78
|
-
// Get cjs or esm
|
|
79
|
-
const cjsEnabled = needsCJS({
|
|
80
|
-
ast,
|
|
81
|
-
warnings,
|
|
82
|
-
filepath: viteConfigPath,
|
|
83
|
-
packageJson,
|
|
84
|
-
tsconfigJson,
|
|
85
|
-
});
|
|
86
|
-
// Check if the compiler import is already present
|
|
87
|
-
let { hasCompilerImport, alias, namespaces } = checkCompilerImport(ast);
|
|
88
|
-
// Add the import declaration
|
|
89
|
-
if (!hasCompilerImport) {
|
|
90
|
-
addCompilerImport({ ast, cjsEnabled });
|
|
91
|
-
hasCompilerImport = true;
|
|
92
|
-
alias = 'gtCompiler';
|
|
93
|
-
namespaces = [];
|
|
94
|
-
}
|
|
95
|
-
// Check if plugin is already present
|
|
96
|
-
let pluginAlreadyPresent = false;
|
|
97
|
-
if (hasCompilerImport) {
|
|
98
|
-
pluginAlreadyPresent = checkPluginInvocation({ ast, alias, namespaces });
|
|
99
|
-
}
|
|
100
|
-
// Insert plugin invocation
|
|
101
|
-
let success = false;
|
|
102
|
-
if (!pluginAlreadyPresent) {
|
|
103
|
-
success = addPluginInvocation({ ast, alias, namespaces });
|
|
104
|
-
if (!success) {
|
|
105
|
-
warnings.push(`Failed to add gt compiler plugin to ${viteConfigPath}. Please add the plugin manually:
|
|
106
|
-
import { vite as gtCompiler } from '@generaltranslation/compiler';
|
|
107
|
-
export default defineConfig({
|
|
108
|
-
plugins: [gtCompiler()],
|
|
109
|
-
});`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// Generate the modified code
|
|
113
|
-
const output = generate(ast, {
|
|
114
|
-
retainLines: true,
|
|
115
|
-
retainFunctionParens: true,
|
|
116
|
-
comments: true,
|
|
117
|
-
compact: 'auto',
|
|
118
|
-
}, code);
|
|
119
|
-
return { updatedCode: output.code, success };
|
|
120
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ParseResult } from '@babel/parser';
|
|
2
|
-
import * as t from '@babel/types';
|
|
3
|
-
/**
|
|
4
|
-
* Given the vite config file ast, inserts the import declaration for the @generaltranslation/compiler package
|
|
5
|
-
*/
|
|
6
|
-
export declare function addCompilerImport({ ast, cjsEnabled, }: {
|
|
7
|
-
ast: ParseResult<t.File>;
|
|
8
|
-
cjsEnabled: boolean;
|
|
9
|
-
}): void;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
/**
|
|
3
|
-
* Given the vite config file ast, inserts the import declaration for the @generaltranslation/compiler package
|
|
4
|
-
*/
|
|
5
|
-
export function addCompilerImport({ ast, cjsEnabled, }) {
|
|
6
|
-
if (cjsEnabled) {
|
|
7
|
-
handleCjsImport(ast);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
handleEsmImport(ast);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Adds a CJS import declaration for the @generaltranslation/compiler package
|
|
15
|
-
* @param ast - The ast of the file
|
|
16
|
-
* const gtCompiler = require('@generaltranslation/compiler').vite;
|
|
17
|
-
*/
|
|
18
|
-
function handleCjsImport(ast) {
|
|
19
|
-
const variableDeclaration = t.variableDeclaration('const', [
|
|
20
|
-
t.variableDeclarator(t.identifier('gtCompiler'), t.memberExpression(t.callExpression(t.identifier('require'), [
|
|
21
|
-
t.stringLiteral('@generaltranslation/compiler'),
|
|
22
|
-
]), t.identifier('vite'))),
|
|
23
|
-
]);
|
|
24
|
-
ast.program.body.unshift(variableDeclaration);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Adds an ESM import declaration for the @generaltranslation/compiler package
|
|
28
|
-
* @param ast - The ast of the file
|
|
29
|
-
* import { vite as gtCompiler } from '@generaltranslation/compiler';
|
|
30
|
-
*/
|
|
31
|
-
function handleEsmImport(ast) {
|
|
32
|
-
const importDeclaration = t.importDeclaration([t.importSpecifier(t.identifier('gtCompiler'), t.identifier('vite'))], t.stringLiteral('@generaltranslation/compiler'));
|
|
33
|
-
ast.program.body.unshift(importDeclaration);
|
|
34
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { ParseResult } from '@babel/parser';
|
|
3
|
-
/**
|
|
4
|
-
* Adds the plugin invocation to the vite config file
|
|
5
|
-
* Naive solution: look for an object with a plugins property only inside of a defineConfig call
|
|
6
|
-
*/
|
|
7
|
-
export declare function addPluginInvocation({ ast, alias, namespaces, }: {
|
|
8
|
-
ast: ParseResult<t.File>;
|
|
9
|
-
alias: string | null;
|
|
10
|
-
namespaces: string[];
|
|
11
|
-
}): boolean;
|