gtx-cli 2.3.6-alpha.2 → 2.3.6
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 -0
- package/dist/api/checkFileTranslations.d.ts +23 -0
- package/dist/api/checkFileTranslations.js +236 -0
- package/dist/api/downloadFileBatch.d.ts +20 -0
- package/dist/api/downloadFileBatch.js +113 -0
- package/dist/api/sendFiles.d.ts +17 -0
- package/dist/api/sendFiles.js +115 -0
- package/dist/api/uploadFiles.d.ts +27 -0
- package/dist/api/uploadFiles.js +40 -0
- package/dist/cli/base.d.ts +32 -0
- package/dist/cli/base.js +335 -0
- package/dist/cli/commands/stage.d.ts +5 -0
- package/dist/cli/commands/stage.js +100 -0
- package/dist/cli/commands/translate.d.ts +6 -0
- package/dist/cli/commands/translate.js +63 -0
- package/dist/cli/flags.d.ts +3 -0
- package/dist/cli/flags.js +38 -0
- package/dist/cli/next.d.ts +11 -0
- package/dist/cli/next.js +20 -0
- package/dist/cli/react.d.ts +18 -0
- package/dist/cli/react.js +175 -0
- package/dist/config/generateSettings.d.ts +9 -0
- package/dist/config/generateSettings.js +176 -0
- package/dist/config/optionPresets.d.ts +2 -0
- package/dist/config/optionPresets.js +56 -0
- package/dist/config/resolveConfig.d.ts +4 -0
- package/dist/config/resolveConfig.js +19 -0
- package/dist/config/utils.d.ts +2 -0
- package/dist/config/utils.js +4 -0
- package/dist/config/validateSettings.d.ts +3 -0
- package/dist/config/validateSettings.js +32 -0
- package/dist/console/colors.d.ts +5 -0
- package/dist/console/colors.js +16 -0
- package/dist/console/index.d.ts +21 -0
- package/dist/console/index.js +24 -0
- package/dist/console/logging.d.ts +53 -0
- package/dist/console/logging.js +185 -0
- package/dist/formats/files/fileMapping.d.ts +11 -0
- package/dist/formats/files/fileMapping.js +82 -0
- package/dist/formats/files/save.d.ts +5 -0
- package/dist/formats/files/save.js +17 -0
- package/dist/formats/files/supportedFiles.d.ts +10 -0
- package/dist/formats/files/supportedFiles.js +18 -0
- package/dist/formats/files/translate.d.ts +4 -0
- package/dist/formats/files/translate.js +119 -0
- package/dist/formats/files/upload.d.ts +13 -0
- package/dist/formats/files/upload.js +136 -0
- package/dist/formats/gt/save.d.ts +9 -0
- package/dist/formats/gt/save.js +26 -0
- package/dist/formats/json/flattenJson.d.ts +14 -0
- package/dist/formats/json/flattenJson.js +64 -0
- package/dist/formats/json/mergeJson.d.ts +13 -0
- package/dist/formats/json/mergeJson.js +257 -0
- package/dist/formats/json/parseJson.d.ts +2 -0
- package/dist/formats/json/parseJson.js +108 -0
- package/dist/formats/json/utils.d.ts +47 -0
- package/dist/formats/json/utils.js +149 -0
- package/dist/formats/utils.d.ts +2 -0
- package/dist/formats/utils.js +24 -0
- package/dist/formats/yaml/mergeYaml.d.ts +5 -0
- package/dist/formats/yaml/mergeYaml.js +55 -0
- package/dist/formats/yaml/parseYaml.d.ts +5 -0
- package/dist/formats/yaml/parseYaml.js +23 -0
- package/dist/formats/yaml/utils.d.ts +2 -0
- package/dist/formats/yaml/utils.js +22 -0
- package/dist/fs/config/loadConfig.d.ts +1 -0
- package/dist/fs/config/loadConfig.js +9 -0
- package/dist/fs/config/parseFilesConfig.d.ts +27 -0
- package/dist/fs/config/parseFilesConfig.js +129 -0
- package/dist/fs/config/setupConfig.d.ts +17 -0
- package/dist/fs/config/setupConfig.js +50 -0
- package/dist/fs/config/updateConfig.d.ts +10 -0
- package/dist/fs/config/updateConfig.js +36 -0
- package/dist/fs/config/updateVersions.d.ts +10 -0
- package/dist/fs/config/updateVersions.js +30 -0
- package/dist/fs/copyFile.d.ts +7 -0
- package/dist/fs/copyFile.js +39 -0
- package/dist/fs/createLoadTranslationsFile.d.ts +1 -0
- package/dist/fs/createLoadTranslationsFile.js +36 -0
- package/dist/fs/determineFramework.d.ts +5 -0
- package/dist/fs/determineFramework.js +46 -0
- package/dist/fs/findFilepath.d.ts +36 -0
- package/dist/fs/findFilepath.js +89 -0
- package/dist/fs/getPackageResource.d.ts +1 -0
- package/dist/fs/getPackageResource.js +6 -0
- package/dist/fs/index.d.ts +1 -0
- package/dist/fs/index.js +1 -0
- package/dist/fs/loadJSON.d.ts +6 -0
- package/dist/fs/loadJSON.js +17 -0
- package/dist/fs/matchFiles.d.ts +1 -0
- package/dist/fs/matchFiles.js +8 -0
- package/dist/fs/saveJSON.d.ts +1 -0
- package/dist/fs/saveJSON.js +7 -0
- package/dist/fs/utils.d.ts +1 -0
- package/dist/fs/utils.js +16 -0
- package/dist/hooks/postProcess.d.ts +4 -0
- package/dist/hooks/postProcess.js +110 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -0
- package/dist/next/config/parseNextConfig.d.ts +10 -0
- package/dist/next/config/parseNextConfig.js +53 -0
- package/dist/next/jsx/utils.d.ts +7 -0
- package/dist/next/jsx/utils.js +42 -0
- package/dist/next/parse/handleInitGT.d.ts +7 -0
- package/dist/next/parse/handleInitGT.js +208 -0
- package/dist/next/parse/wrapContent.d.ts +11 -0
- package/dist/next/parse/wrapContent.js +163 -0
- package/dist/react/config/createESBuildConfig.d.ts +2 -0
- package/dist/react/config/createESBuildConfig.js +119 -0
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +8 -0
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +111 -0
- package/dist/react/jsx/evaluateJsx.d.ts +17 -0
- package/dist/react/jsx/evaluateJsx.js +85 -0
- package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
- package/dist/react/jsx/trimJsxStringChildren.js +95 -0
- package/dist/react/jsx/utils/constants.d.ts +10 -0
- package/dist/react/jsx/utils/constants.js +31 -0
- package/dist/react/jsx/utils/parseAst.d.ts +30 -0
- package/dist/react/jsx/utils/parseAst.js +277 -0
- package/dist/react/jsx/utils/parseJsx.d.ts +21 -0
- package/dist/react/jsx/utils/parseJsx.js +244 -0
- package/dist/react/jsx/utils/parseStringFunction.d.ts +16 -0
- package/dist/react/jsx/utils/parseStringFunction.js +411 -0
- package/dist/react/jsx/utils/validateStringFunction.d.ts +7 -0
- package/dist/react/jsx/utils/validateStringFunction.js +31 -0
- package/dist/react/jsx/wrapJsx.d.ts +51 -0
- package/dist/react/jsx/wrapJsx.js +387 -0
- package/dist/react/parse/createDictionaryUpdates.d.ts +3 -0
- package/dist/react/parse/createDictionaryUpdates.js +169 -0
- package/dist/react/parse/createInlineUpdates.d.ts +6 -0
- package/dist/react/parse/createInlineUpdates.js +122 -0
- package/dist/react/parse/wrapContent.d.ts +11 -0
- package/dist/react/parse/wrapContent.js +162 -0
- package/dist/react/utils/flattenDictionary.d.ts +20 -0
- package/dist/react/utils/flattenDictionary.js +75 -0
- package/dist/react/utils/getEntryAndMetadata.d.ts +5 -0
- package/dist/react/utils/getEntryAndMetadata.js +11 -0
- package/dist/react/utils/getVariableName.d.ts +25 -0
- package/dist/react/utils/getVariableName.js +37 -0
- package/dist/setup/userInput.d.ts +4 -0
- package/dist/setup/userInput.js +29 -0
- package/dist/setup/wizard.d.ts +2 -0
- package/dist/setup/wizard.js +127 -0
- package/dist/translation/parse.d.ts +15 -0
- package/dist/translation/parse.js +76 -0
- package/dist/translation/stage.d.ts +2 -0
- package/dist/translation/stage.js +44 -0
- package/dist/translation/validate.d.ts +2 -0
- package/dist/translation/validate.js +50 -0
- package/dist/types/data/json.d.ts +6 -0
- package/dist/types/data/json.js +1 -0
- package/dist/types/data.d.ts +30 -0
- package/dist/types/data.js +1 -0
- package/dist/types/files.d.ts +1 -0
- package/dist/types/files.js +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/addExplicitAnchorIds.d.ts +24 -0
- package/dist/utils/addExplicitAnchorIds.js +260 -0
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +2 -0
- package/dist/utils/credentials.d.ts +12 -0
- package/dist/utils/credentials.js +119 -0
- package/dist/utils/flattenJsonFiles.d.ts +2 -0
- package/dist/utils/flattenJsonFiles.js +36 -0
- package/dist/utils/gt.d.ts +2 -0
- package/dist/utils/gt.js +2 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.js +11 -0
- package/dist/utils/headers.d.ts +1 -0
- package/dist/utils/headers.js +14 -0
- package/dist/utils/installPackage.d.ts +3 -0
- package/dist/utils/installPackage.js +77 -0
- package/dist/utils/localizeStaticImports.d.ts +15 -0
- package/dist/utils/localizeStaticImports.js +341 -0
- package/dist/utils/localizeStaticUrls.d.ts +19 -0
- package/dist/utils/localizeStaticUrls.js +432 -0
- package/dist/utils/packageInfo.d.ts +3 -0
- package/dist/utils/packageInfo.js +17 -0
- package/dist/utils/packageJson.d.ts +6 -0
- package/dist/utils/packageJson.js +76 -0
- package/dist/utils/packageManager.d.ts +28 -0
- package/dist/utils/packageManager.js +269 -0
- package/dist/utils/processAnchorIds.d.ts +6 -0
- package/dist/utils/processAnchorIds.js +47 -0
- package/dist/utils/sanitizeFileContent.d.ts +6 -0
- package/dist/utils/sanitizeFileContent.js +29 -0
- package/dist/utils/validateMdx.d.ts +10 -0
- package/dist/utils/validateMdx.js +25 -0
- package/package.json +3 -3
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// This file is MIT licensed and was adapted from https://github.com/getsentry/sentry-wizard/blob/master/src/utils/package-manager.ts and https://github.com/getsentry/sentry-wizard/blob/master/src/utils/clack/index.ts
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { getPackageJson, updatePackageJson } from './packageJson.js';
|
|
5
|
+
import { promptSelect } from '../console/logging.js';
|
|
6
|
+
export class NoPackageManagerError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'NoPackageManagerError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const BUN = {
|
|
13
|
+
id: 'bun',
|
|
14
|
+
name: 'bun',
|
|
15
|
+
label: 'Bun',
|
|
16
|
+
installCommand: 'add',
|
|
17
|
+
installAllCommand: 'bun install',
|
|
18
|
+
buildCommand: 'bun run build',
|
|
19
|
+
runScriptCommand: 'bun run',
|
|
20
|
+
flags: '',
|
|
21
|
+
forceInstallFlag: '--force',
|
|
22
|
+
devDependencyFlag: '--dev',
|
|
23
|
+
detect: (cwd) => ['bun.lockb', 'bun.lock'].some((lockFile) => {
|
|
24
|
+
try {
|
|
25
|
+
return fs.existsSync(path.join(cwd, lockFile));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}),
|
|
31
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
32
|
+
const packageDotJson = await getPackageJson();
|
|
33
|
+
if (!packageDotJson) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const overrides = packageDotJson.overrides || {};
|
|
37
|
+
await updatePackageJson({
|
|
38
|
+
...packageDotJson,
|
|
39
|
+
overrides: {
|
|
40
|
+
...overrides,
|
|
41
|
+
[pkgName]: pkgVersion,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const DENO = {
|
|
47
|
+
id: 'deno',
|
|
48
|
+
name: 'deno',
|
|
49
|
+
label: 'Deno',
|
|
50
|
+
installCommand: 'install',
|
|
51
|
+
installAllCommand: 'deno install',
|
|
52
|
+
buildCommand: 'deno task build',
|
|
53
|
+
runScriptCommand: 'deno task',
|
|
54
|
+
flags: '',
|
|
55
|
+
forceInstallFlag: '--force',
|
|
56
|
+
devDependencyFlag: '--dev',
|
|
57
|
+
registry: 'npm',
|
|
58
|
+
detect: (cwd) => {
|
|
59
|
+
try {
|
|
60
|
+
return fs.existsSync(path.join(cwd, 'deno.lock'));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
67
|
+
const packageDotJson = await getPackageJson();
|
|
68
|
+
if (!packageDotJson) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const overrides = packageDotJson.overrides || {};
|
|
72
|
+
await updatePackageJson({
|
|
73
|
+
...packageDotJson,
|
|
74
|
+
overrides: {
|
|
75
|
+
...overrides,
|
|
76
|
+
[pkgName]: pkgVersion,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
export const YARN_V1 = {
|
|
82
|
+
id: 'yarn_v1',
|
|
83
|
+
name: 'yarn',
|
|
84
|
+
label: 'Yarn V1',
|
|
85
|
+
installCommand: 'add',
|
|
86
|
+
installAllCommand: 'yarn install',
|
|
87
|
+
buildCommand: 'yarn build',
|
|
88
|
+
runScriptCommand: 'yarn',
|
|
89
|
+
flags: '--ignore-workspace-root-check',
|
|
90
|
+
forceInstallFlag: '--force',
|
|
91
|
+
devDependencyFlag: '--dev',
|
|
92
|
+
detect: (cwd) => {
|
|
93
|
+
try {
|
|
94
|
+
return fs
|
|
95
|
+
.readFileSync(path.join(cwd, 'yarn.lock'), 'utf-8')
|
|
96
|
+
.slice(0, 500)
|
|
97
|
+
.includes('yarn lockfile v1');
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
104
|
+
const packageDotJson = await getPackageJson();
|
|
105
|
+
if (!packageDotJson) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const resolutions = packageDotJson.resolutions || {};
|
|
109
|
+
await updatePackageJson({
|
|
110
|
+
...packageDotJson,
|
|
111
|
+
resolutions: {
|
|
112
|
+
...resolutions,
|
|
113
|
+
[pkgName]: pkgVersion,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
/** YARN V2/3/4 */
|
|
119
|
+
export const YARN_V2 = {
|
|
120
|
+
id: 'yarn_v2',
|
|
121
|
+
name: 'yarn',
|
|
122
|
+
label: 'Yarn V2/3/4',
|
|
123
|
+
installCommand: 'add',
|
|
124
|
+
installAllCommand: 'yarn install',
|
|
125
|
+
buildCommand: 'yarn build',
|
|
126
|
+
runScriptCommand: 'yarn',
|
|
127
|
+
flags: '',
|
|
128
|
+
forceInstallFlag: '--force',
|
|
129
|
+
devDependencyFlag: '--dev',
|
|
130
|
+
detect: (cwd) => {
|
|
131
|
+
try {
|
|
132
|
+
return fs
|
|
133
|
+
.readFileSync(path.join(cwd, 'yarn.lock'), 'utf-8')
|
|
134
|
+
.slice(0, 500)
|
|
135
|
+
.includes('__metadata');
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
142
|
+
const packageDotJson = await getPackageJson();
|
|
143
|
+
if (!packageDotJson) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const resolutions = packageDotJson.resolutions || {};
|
|
147
|
+
await updatePackageJson({
|
|
148
|
+
...packageDotJson,
|
|
149
|
+
resolutions: {
|
|
150
|
+
...resolutions,
|
|
151
|
+
[pkgName]: pkgVersion,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
export const PNPM = {
|
|
157
|
+
id: 'pnpm',
|
|
158
|
+
name: 'pnpm',
|
|
159
|
+
label: 'PNPM',
|
|
160
|
+
installCommand: 'add',
|
|
161
|
+
installAllCommand: 'pnpm install',
|
|
162
|
+
buildCommand: 'pnpm build',
|
|
163
|
+
runScriptCommand: 'pnpm',
|
|
164
|
+
flags: '--ignore-workspace-root-check',
|
|
165
|
+
forceInstallFlag: '--force',
|
|
166
|
+
devDependencyFlag: '--save-dev',
|
|
167
|
+
detect: (cwd) => {
|
|
168
|
+
try {
|
|
169
|
+
return fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'));
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
176
|
+
const packageDotJson = await getPackageJson();
|
|
177
|
+
if (!packageDotJson) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const pnpm = packageDotJson.pnpm || {};
|
|
181
|
+
const overrides = pnpm.overrides || {};
|
|
182
|
+
await updatePackageJson({
|
|
183
|
+
...packageDotJson,
|
|
184
|
+
pnpm: {
|
|
185
|
+
...pnpm,
|
|
186
|
+
overrides: {
|
|
187
|
+
...overrides,
|
|
188
|
+
[pkgName]: pkgVersion,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
export const NPM = {
|
|
195
|
+
id: 'npm',
|
|
196
|
+
name: 'npm',
|
|
197
|
+
label: 'NPM',
|
|
198
|
+
installCommand: 'install',
|
|
199
|
+
installAllCommand: 'npm ci',
|
|
200
|
+
buildCommand: 'npm run build',
|
|
201
|
+
runScriptCommand: 'npm run',
|
|
202
|
+
flags: '',
|
|
203
|
+
forceInstallFlag: '--force',
|
|
204
|
+
devDependencyFlag: '--save-dev',
|
|
205
|
+
detect: (cwd) => {
|
|
206
|
+
try {
|
|
207
|
+
return fs.existsSync(path.join(cwd, 'package-lock.json'));
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
addOverride: async (pkgName, pkgVersion) => {
|
|
214
|
+
const packageDotJson = await getPackageJson();
|
|
215
|
+
if (!packageDotJson) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const overrides = packageDotJson.overrides || {};
|
|
219
|
+
await updatePackageJson({
|
|
220
|
+
...packageDotJson,
|
|
221
|
+
overrides: {
|
|
222
|
+
...overrides,
|
|
223
|
+
[pkgName]: pkgVersion,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
export const packageManagers = [NPM, YARN_V1, YARN_V2, PNPM, BUN, DENO];
|
|
229
|
+
export function _detectPackageManger(cwd) {
|
|
230
|
+
const foundPackageMangers = packageManagers.filter((packageManager) => packageManager.detect(cwd));
|
|
231
|
+
// Only consider a package manager detected if we found exactly one.
|
|
232
|
+
// If we find more than one, we should not make any assumptions.
|
|
233
|
+
if (foundPackageMangers.length === 1) {
|
|
234
|
+
return foundPackageMangers[0];
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
// Get the package manager for the current project
|
|
239
|
+
// Uses a global cache to avoid prompting the user multiple times
|
|
240
|
+
export async function getPackageManager(cwd = process.cwd(), specifiedPackageManager, errorIfNotFound = false) {
|
|
241
|
+
const globalWizard = global;
|
|
242
|
+
if (globalWizard._gt_wizard_cached_package_manager) {
|
|
243
|
+
return globalWizard._gt_wizard_cached_package_manager;
|
|
244
|
+
}
|
|
245
|
+
if (specifiedPackageManager) {
|
|
246
|
+
const packageManager = packageManagers.find((packageManager) => packageManager.id === specifiedPackageManager);
|
|
247
|
+
if (packageManager) {
|
|
248
|
+
globalWizard._gt_wizard_cached_package_manager = packageManager;
|
|
249
|
+
return packageManager;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const detectedPackageManager = _detectPackageManger(cwd);
|
|
253
|
+
if (detectedPackageManager) {
|
|
254
|
+
globalWizard._gt_wizard_cached_package_manager = detectedPackageManager;
|
|
255
|
+
return detectedPackageManager;
|
|
256
|
+
}
|
|
257
|
+
if (errorIfNotFound) {
|
|
258
|
+
throw new NoPackageManagerError('No package manager found');
|
|
259
|
+
}
|
|
260
|
+
const selectedPackageManager = await promptSelect({
|
|
261
|
+
message: 'Please select your package manager.',
|
|
262
|
+
options: packageManagers.map((packageManager) => ({
|
|
263
|
+
value: packageManager,
|
|
264
|
+
label: packageManager.label,
|
|
265
|
+
})),
|
|
266
|
+
});
|
|
267
|
+
globalWizard._gt_wizard_cached_package_manager = selectedPackageManager;
|
|
268
|
+
return selectedPackageManager;
|
|
269
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { addExplicitAnchorIds, extractHeadingInfo, } from './addExplicitAnchorIds.js';
|
|
2
|
+
import { readFile } from '../fs/findFilepath.js';
|
|
3
|
+
import { createFileMapping } from '../formats/files/fileMapping.js';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
/**
|
|
6
|
+
* Processes all translated MD/MDX files to add explicit anchor IDs
|
|
7
|
+
* This preserves navigation links when headings are translated
|
|
8
|
+
*/
|
|
9
|
+
export default async function processAnchorIds(settings) {
|
|
10
|
+
if (!settings.files)
|
|
11
|
+
return;
|
|
12
|
+
const { resolvedPaths, placeholderPaths, transformPaths } = settings.files;
|
|
13
|
+
const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
|
|
14
|
+
// Process each locale's translated files
|
|
15
|
+
const processPromises = Object.entries(fileMapping)
|
|
16
|
+
.filter(([locale, filesMap]) => locale !== settings.defaultLocale) // Skip default locale
|
|
17
|
+
.map(async ([locale, filesMap]) => {
|
|
18
|
+
// Get all translated files that are md or mdx
|
|
19
|
+
const translatedFiles = Object.values(filesMap).filter((path) => path && (path.endsWith('.md') || path.endsWith('.mdx')));
|
|
20
|
+
for (const translatedPath of translatedFiles) {
|
|
21
|
+
try {
|
|
22
|
+
// Check if translated file exists before processing
|
|
23
|
+
if (!fs.existsSync(translatedPath)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
// Find the corresponding source file
|
|
27
|
+
const sourcePath = Object.keys(filesMap).find((key) => filesMap[key] === translatedPath);
|
|
28
|
+
if (!sourcePath) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// Extract heading info from source file
|
|
32
|
+
const sourceContent = readFile(sourcePath);
|
|
33
|
+
const sourceHeadingMap = extractHeadingInfo(sourceContent);
|
|
34
|
+
// Read translated file and apply anchor IDs
|
|
35
|
+
const translatedContent = readFile(translatedPath);
|
|
36
|
+
const result = addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath);
|
|
37
|
+
if (result.hasChanges) {
|
|
38
|
+
fs.writeFileSync(translatedPath, result.content, 'utf8');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.warn(`Failed to process IDs for ${translatedPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
await Promise.all(processPromises);
|
|
47
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes content to escape curl commands within tick marks and existing escape strings
|
|
3
|
+
* @param content - The content to process
|
|
4
|
+
* @returns the processed content with escaped curl commands
|
|
5
|
+
*/
|
|
6
|
+
export default function sanitizeFileContent(content: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes content to escape curl commands within tick marks and existing escape strings
|
|
3
|
+
* @param content - The content to process
|
|
4
|
+
* @returns the processed content with escaped curl commands
|
|
5
|
+
*/
|
|
6
|
+
export default function sanitizeFileContent(content) {
|
|
7
|
+
const ESCAPE_STRING = '_GT_INTERNAL_ESCAPE';
|
|
8
|
+
const allTickMarkRegex = /`([^`]*)`/g;
|
|
9
|
+
let processedContent = content;
|
|
10
|
+
// First, escape any existing tick marks followed by _GT_INTERNAL_ESCAPE
|
|
11
|
+
// This protects pre-existing escapes
|
|
12
|
+
processedContent = processedContent.replace(new RegExp('`' + ESCAPE_STRING, 'g'), '`' + ESCAPE_STRING + ESCAPE_STRING);
|
|
13
|
+
// Then find ALL tick mark pairs and process them individually
|
|
14
|
+
// This approach is more reliable than negative lookahead with modified content
|
|
15
|
+
processedContent = processedContent.replace(allTickMarkRegex, (match, innerContent) => {
|
|
16
|
+
// Skip if this already starts with our escape string (protected or already processed)
|
|
17
|
+
if (innerContent.startsWith(ESCAPE_STRING)) {
|
|
18
|
+
return match;
|
|
19
|
+
}
|
|
20
|
+
// Check if the content contains a curl command
|
|
21
|
+
if (/\bcurl\b/i.test(innerContent)) {
|
|
22
|
+
// Insert escape string after opening tick
|
|
23
|
+
return '`' + ESCAPE_STRING + innerContent + '`';
|
|
24
|
+
}
|
|
25
|
+
// Return original match if no curl command found
|
|
26
|
+
return match;
|
|
27
|
+
});
|
|
28
|
+
return processedContent;
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates if an MDX file content can be parsed as a valid AST
|
|
3
|
+
* @param content - The MDX file content to validate
|
|
4
|
+
* @param filePath - The file path for error reporting
|
|
5
|
+
* @returns object with isValid boolean and optional error message
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidMdx(content: string, filePath: string): {
|
|
8
|
+
isValid: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkMdx from 'remark-mdx';
|
|
4
|
+
import remarkFrontmatter from 'remark-frontmatter';
|
|
5
|
+
/**
|
|
6
|
+
* Validates if an MDX file content can be parsed as a valid AST
|
|
7
|
+
* @param content - The MDX file content to validate
|
|
8
|
+
* @param filePath - The file path for error reporting
|
|
9
|
+
* @returns object with isValid boolean and optional error message
|
|
10
|
+
*/
|
|
11
|
+
export function isValidMdx(content, filePath) {
|
|
12
|
+
try {
|
|
13
|
+
const parseProcessor = unified()
|
|
14
|
+
.use(remarkParse)
|
|
15
|
+
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
16
|
+
.use(remarkMdx);
|
|
17
|
+
const ast = parseProcessor.parse(content);
|
|
18
|
+
parseProcessor.runSync(ast);
|
|
19
|
+
return { isValid: true };
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
23
|
+
return { isValid: false, error: errorMessage };
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.3.6
|
|
3
|
+
"version": "2.3.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"unified": "^11.0.5",
|
|
92
92
|
"unist-util-visit": "^5.0.0",
|
|
93
93
|
"yaml": "^2.8.0",
|
|
94
|
-
"generaltranslation": "7.6.4
|
|
94
|
+
"generaltranslation": "7.6.4"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@babel/types": "^7.28.4",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
},
|
|
117
117
|
"scripts": {
|
|
118
118
|
"build": "tsc",
|
|
119
|
-
"build:clean": "
|
|
119
|
+
"build:clean": "sh ../../scripts/clean.sh && pnpm run build",
|
|
120
120
|
"build:release": "pnpm run build:clean",
|
|
121
121
|
"lint": "eslint \"src/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\"",
|
|
122
122
|
"lint:fix": "eslint \"src/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\" --fix",
|