gtx-cli 1.2.13 → 1.2.15
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 +7 -0
- package/package.json +1 -2
- package/.env +0 -2
- package/dist/api/checkFileTranslations.d.ts +0 -19
- package/dist/api/checkFileTranslations.js +0 -244
- package/dist/api/downloadFile.d.ts +0 -1
- package/dist/api/downloadFile.js +0 -83
- package/dist/api/downloadFileBatch.d.ts +0 -16
- package/dist/api/downloadFileBatch.js +0 -127
- package/dist/api/fetchTranslations.d.ts +0 -10
- package/dist/api/fetchTranslations.js +0 -35
- package/dist/api/sendFiles.d.ts +0 -24
- package/dist/api/sendFiles.js +0 -63
- package/dist/api/sendUpdates.d.ts +0 -19
- package/dist/api/sendUpdates.js +0 -75
- package/dist/api/waitForUpdates.d.ts +0 -11
- package/dist/api/waitForUpdates.js +0 -96
- package/dist/cli/base.d.ts +0 -28
- package/dist/cli/base.js +0 -322
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -27
- package/dist/cli/react.d.ts +0 -18
- package/dist/cli/react.js +0 -305
- package/dist/config/generateSettings.d.ts +0 -7
- package/dist/config/generateSettings.js +0 -94
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -7
- package/dist/config/validateSettings.d.ts +0 -2
- package/dist/config/validateSettings.js +0 -23
- package/dist/console/colors.d.ts +0 -5
- package/dist/console/colors.js +0 -26
- package/dist/console/console.d.ts +0 -1
- package/dist/console/console.js +0 -20
- package/dist/console/errors.d.ts +0 -1
- package/dist/console/errors.js +0 -20
- package/dist/console/index.d.ts +0 -19
- package/dist/console/index.js +0 -48
- package/dist/console/logging.d.ts +0 -55
- package/dist/console/logging.js +0 -207
- package/dist/console/warnings.d.ts +0 -1
- package/dist/console/warnings.js +0 -20
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -23
- package/dist/formats/files/supportedFiles.d.ts +0 -8
- package/dist/formats/files/supportedFiles.js +0 -17
- package/dist/formats/files/translate.d.ts +0 -14
- package/dist/formats/files/translate.js +0 -218
- package/dist/formats/gt/save.d.ts +0 -10
- package/dist/formats/gt/save.js +0 -34
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -15
- package/dist/fs/config/parseFilesConfig.d.ts +0 -23
- package/dist/fs/config/parseFilesConfig.js +0 -128
- package/dist/fs/config/setupConfig.d.ts +0 -15
- package/dist/fs/config/setupConfig.js +0 -51
- package/dist/fs/config/updateConfig.d.ts +0 -11
- package/dist/fs/config/updateConfig.js +0 -41
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -52
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -101
- package/dist/fs/findJsxFilepath.d.ts +0 -7
- package/dist/fs/findJsxFilepath.js +0 -36
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -2
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -23
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -13
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -19
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -118
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -24
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -12
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -59
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -82
- package/dist/next/parse/handleInitGT.d.ts +0 -1
- package/dist/next/parse/handleInitGT.js +0 -153
- package/dist/next/parse/wrapContent.d.ts +0 -11
- package/dist/next/parse/wrapContent.js +0 -181
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -125
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -1
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -84
- package/dist/react/jsx/evaluateJsx.d.ts +0 -17
- package/dist/react/jsx/evaluateJsx.js +0 -133
- package/dist/react/jsx/parse/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/parse/parseStringFunction.js +0 -118
- package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
- package/dist/react/jsx/trimJsxStringChildren.js +0 -100
- package/dist/react/jsx/utils/parseAst.d.ts +0 -30
- package/dist/react/jsx/utils/parseAst.js +0 -319
- package/dist/react/jsx/utils/parseJsx.d.ts +0 -13
- package/dist/react/jsx/utils/parseJsx.js +0 -245
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/utils/parseStringFunction.js +0 -121
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -411
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -78
- package/dist/react/parse/createInlineUpdates.d.ts +0 -5
- package/dist/react/parse/createInlineUpdates.js +0 -135
- package/dist/react/parse/wrapContent.d.ts +0 -11
- package/dist/react/parse/wrapContent.js +0 -197
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -79
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -14
- package/dist/react/utils/getVariableName.d.ts +0 -2
- package/dist/react/utils/getVariableName.js +0 -17
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -35
- package/dist/setup/wizard.d.ts +0 -2
- package/dist/setup/wizard.js +0 -171
- package/dist/translation/parse.d.ts +0 -14
- package/dist/translation/parse.js +0 -82
- package/dist/translation/stage.d.ts +0 -5
- package/dist/translation/stage.js +0 -80
- package/dist/translation/translate.d.ts +0 -2
- package/dist/translation/translate.js +0 -21
- package/dist/types/api.d.ts +0 -6
- package/dist/types/api.js +0 -2
- package/dist/types/data.d.ts +0 -31
- package/dist/types/data.js +0 -2
- package/dist/types/index.d.ts +0 -101
- package/dist/types/index.js +0 -2
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -128
- package/dist/utils/installPackage.d.ts +0 -2
- package/dist/utils/installPackage.js +0 -45
- package/dist/utils/packageJson.d.ts +0 -5
- package/dist/utils/packageJson.js +0 -78
- package/dist/utils/packageManager.d.ts +0 -23
- package/dist/utils/packageManager.js +0 -261
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.detectFormatter = detectFormatter;
|
|
7
|
-
exports.formatFiles = formatFiles;
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const console_1 = require("../console");
|
|
11
|
-
async function detectFormatter() {
|
|
12
|
-
// Try Prettier
|
|
13
|
-
try {
|
|
14
|
-
require('prettier');
|
|
15
|
-
return 'prettier';
|
|
16
|
-
}
|
|
17
|
-
catch { }
|
|
18
|
-
// Try Biome
|
|
19
|
-
try {
|
|
20
|
-
return await new Promise((resolve, reject) => {
|
|
21
|
-
const { spawn } = require('child_process');
|
|
22
|
-
const child = spawn('npx', ['@biomejs/biome', '--version'], {
|
|
23
|
-
stdio: 'ignore',
|
|
24
|
-
});
|
|
25
|
-
child.on('error', () => {
|
|
26
|
-
resolve(null);
|
|
27
|
-
});
|
|
28
|
-
child.on('close', (code) => {
|
|
29
|
-
if (code === 0) {
|
|
30
|
-
resolve('biome');
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
resolve(null);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch { }
|
|
39
|
-
// Try ESLint
|
|
40
|
-
try {
|
|
41
|
-
require('eslint');
|
|
42
|
-
return 'eslint';
|
|
43
|
-
}
|
|
44
|
-
catch { }
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
async function formatFiles(filesUpdated, formatter) {
|
|
48
|
-
if (filesUpdated.length === 0)
|
|
49
|
-
return;
|
|
50
|
-
try {
|
|
51
|
-
const detectedFormatter = formatter || (await detectFormatter());
|
|
52
|
-
if (!detectedFormatter) {
|
|
53
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('No supported formatter detected'));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (detectedFormatter === 'prettier') {
|
|
57
|
-
(0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with prettier...'));
|
|
58
|
-
const prettier = require('prettier');
|
|
59
|
-
for (const file of filesUpdated) {
|
|
60
|
-
const config = await prettier.resolveConfig(file);
|
|
61
|
-
const content = await node_fs_1.default.promises.readFile(file, 'utf-8');
|
|
62
|
-
const formatted = await prettier.format(content, {
|
|
63
|
-
...config,
|
|
64
|
-
filepath: file,
|
|
65
|
-
});
|
|
66
|
-
await node_fs_1.default.promises.writeFile(file, formatted);
|
|
67
|
-
}
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (detectedFormatter === 'biome') {
|
|
71
|
-
(0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with biome...'));
|
|
72
|
-
try {
|
|
73
|
-
await new Promise((resolve, reject) => {
|
|
74
|
-
const { spawn } = require('child_process');
|
|
75
|
-
const args = [
|
|
76
|
-
'@biomejs/biome',
|
|
77
|
-
'format',
|
|
78
|
-
'--write',
|
|
79
|
-
...filesUpdated.map((file) => file),
|
|
80
|
-
];
|
|
81
|
-
const child = spawn('npx', args, {
|
|
82
|
-
stdio: ['ignore', 'inherit', 'inherit'],
|
|
83
|
-
});
|
|
84
|
-
child.on('error', (error) => {
|
|
85
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('Biome formatting failed: ' + error.message));
|
|
86
|
-
resolve();
|
|
87
|
-
});
|
|
88
|
-
child.on('close', (code) => {
|
|
89
|
-
if (code !== 0) {
|
|
90
|
-
(0, console_1.logWarning)(chalk_1.default.yellow(`Biome formatting failed with exit code ${code}`));
|
|
91
|
-
}
|
|
92
|
-
resolve();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('Biome formatting failed: ' + String(error)));
|
|
98
|
-
}
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (detectedFormatter === 'eslint') {
|
|
102
|
-
(0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with eslint...'));
|
|
103
|
-
const { ESLint } = require('eslint');
|
|
104
|
-
const eslint = new ESLint({
|
|
105
|
-
fix: true,
|
|
106
|
-
overrideConfigFile: undefined, // Will use project's .eslintrc
|
|
107
|
-
});
|
|
108
|
-
for (const file of filesUpdated) {
|
|
109
|
-
const results = await eslint.lintFiles([file]);
|
|
110
|
-
await ESLint.outputFixes(results);
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('Unable to run code formatter: ' + String(e)));
|
|
117
|
-
}
|
|
118
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseCLI = void 0;
|
|
4
|
-
exports.default = main;
|
|
5
|
-
const base_1 = require("./cli/base");
|
|
6
|
-
Object.defineProperty(exports, "BaseCLI", { enumerable: true, get: function () { return base_1.BaseCLI; } });
|
|
7
|
-
const next_1 = require("./cli/next");
|
|
8
|
-
const react_1 = require("./cli/react");
|
|
9
|
-
const determineFramework_1 = require("./fs/determineFramework");
|
|
10
|
-
function main() {
|
|
11
|
-
const { library, additionalModules } = (0, determineFramework_1.determineLibrary)();
|
|
12
|
-
let cli;
|
|
13
|
-
if (library === 'gt-next') {
|
|
14
|
-
cli = new next_1.NextCLI(library, additionalModules);
|
|
15
|
-
}
|
|
16
|
-
else if (library === 'gt-react') {
|
|
17
|
-
cli = new react_1.ReactCLI(library, additionalModules);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
cli = new base_1.BaseCLI(library, additionalModules);
|
|
21
|
-
}
|
|
22
|
-
cli.init();
|
|
23
|
-
cli.execute();
|
|
24
|
-
}
|
package/dist/main.d.ts
DELETED
package/dist/main.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const index_1 = __importDefault(require("./index"));
|
|
8
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
-
dotenv_1.default.config({ path: '.env' });
|
|
10
|
-
dotenv_1.default.config({ path: '.env.local', override: true });
|
|
11
|
-
dotenv_1.default.config({ path: '.env.production', override: true });
|
|
12
|
-
(0, index_1.default)();
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts projectId, defaultLocale, and locales from a next.config.js file.
|
|
3
|
-
* @param {string} filePath - The path to the next.config.js file.
|
|
4
|
-
* @returns {object|null} - An object containing the extracted values or null if none found or incorrect types.
|
|
5
|
-
*/
|
|
6
|
-
export declare function parseNextConfig(filePath: string): Promise<{
|
|
7
|
-
projectId?: string;
|
|
8
|
-
defaultLocale?: string;
|
|
9
|
-
locales?: string[];
|
|
10
|
-
}>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseNextConfig = parseNextConfig;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const generaltranslation_1 = require("generaltranslation");
|
|
9
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
/**
|
|
11
|
-
* Extracts projectId, defaultLocale, and locales from a next.config.js file.
|
|
12
|
-
* @param {string} filePath - The path to the next.config.js file.
|
|
13
|
-
* @returns {object|null} - An object containing the extracted values or null if none found or incorrect types.
|
|
14
|
-
*/
|
|
15
|
-
async function parseNextConfig(filePath) {
|
|
16
|
-
// Resolve the absolute path
|
|
17
|
-
const absoluteFilePath = node_path_1.default.resolve(filePath);
|
|
18
|
-
// Check if the file exists
|
|
19
|
-
if (!node_fs_1.default.existsSync(absoluteFilePath)) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
// Read the file content
|
|
23
|
-
const fileContent = await node_fs_1.default.promises.readFile(absoluteFilePath, 'utf8');
|
|
24
|
-
// Regular expressions to extract the values
|
|
25
|
-
const defaultLocaleRegex = /defaultLocale:\s*['"]([^'"]+)['"]/;
|
|
26
|
-
const projectIdRegex = /projectId:\s*['"]([^'"]+)['"]/;
|
|
27
|
-
const localesRegex = /locales:\s*\[([^\]]+)\]/;
|
|
28
|
-
// Extract the values
|
|
29
|
-
const defaultLocaleMatch = fileContent.match(defaultLocaleRegex);
|
|
30
|
-
const projectIdMatch = fileContent.match(projectIdRegex);
|
|
31
|
-
const localesMatch = fileContent.match(localesRegex);
|
|
32
|
-
const defaultLocale = defaultLocaleMatch && typeof defaultLocaleMatch[1] === 'string'
|
|
33
|
-
? defaultLocaleMatch[1]
|
|
34
|
-
: undefined;
|
|
35
|
-
const projectId = projectIdMatch && typeof projectIdMatch[1] === 'string'
|
|
36
|
-
? projectIdMatch[1]
|
|
37
|
-
: undefined;
|
|
38
|
-
const locales = localesMatch
|
|
39
|
-
? localesMatch[1]
|
|
40
|
-
.split(',')
|
|
41
|
-
.map((locale) => locale.trim().replace(/['"]/g, ''))
|
|
42
|
-
.filter((locale) => typeof locale === 'string')
|
|
43
|
-
: undefined;
|
|
44
|
-
// Ensure approvedLocales is an array of strings
|
|
45
|
-
const validLocales = locales && locales.every((locale) => (0, generaltranslation_1.isValidLocale)(locale))
|
|
46
|
-
? locales
|
|
47
|
-
: undefined;
|
|
48
|
-
// Return the extracted values if they pass type checks or return null
|
|
49
|
-
if (defaultLocale || projectId || validLocales) {
|
|
50
|
-
return {
|
|
51
|
-
...(defaultLocale && { defaultLocale }),
|
|
52
|
-
...(projectId && { projectId }),
|
|
53
|
-
...(validLocales && { locales: validLocales }),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
}
|
package/dist/next/jsx/utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { NodePath } from '@babel/traverse';
|
|
3
|
-
export declare function isHtmlElement(element: t.JSXOpeningElement): boolean;
|
|
4
|
-
export declare function isBodyElement(element: t.JSXOpeningElement): boolean;
|
|
5
|
-
export declare function hasGTProviderChild(element: t.JSXElement): boolean;
|
|
6
|
-
export declare function addDynamicLangAttribute(element: t.JSXOpeningElement): void;
|
|
7
|
-
export declare function makeParentFunctionAsync(path: NodePath): boolean;
|
package/dist/next/jsx/utils.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.isHtmlElement = isHtmlElement;
|
|
37
|
-
exports.isBodyElement = isBodyElement;
|
|
38
|
-
exports.hasGTProviderChild = hasGTProviderChild;
|
|
39
|
-
exports.addDynamicLangAttribute = addDynamicLangAttribute;
|
|
40
|
-
exports.makeParentFunctionAsync = makeParentFunctionAsync;
|
|
41
|
-
const t = __importStar(require("@babel/types"));
|
|
42
|
-
// Helper function to check if is the <html> fragment
|
|
43
|
-
function isHtmlElement(element) {
|
|
44
|
-
return (t.isJSXIdentifier(element.name) &&
|
|
45
|
-
element.name.name.toLowerCase() === 'html');
|
|
46
|
-
}
|
|
47
|
-
// Helper function to check if is the <body> fragment
|
|
48
|
-
function isBodyElement(element) {
|
|
49
|
-
return (t.isJSXIdentifier(element.name) &&
|
|
50
|
-
element.name.name.toLowerCase() === 'body');
|
|
51
|
-
}
|
|
52
|
-
// Helper function to check if the <body> element has a <GTProvider> child
|
|
53
|
-
function hasGTProviderChild(element) {
|
|
54
|
-
return element.children.some((child) => t.isJSXElement(child) &&
|
|
55
|
-
t.isJSXIdentifier(child.openingElement.name) &&
|
|
56
|
-
child.openingElement.name.name === 'GTProvider');
|
|
57
|
-
}
|
|
58
|
-
function addDynamicLangAttribute(element) {
|
|
59
|
-
// Remove existing lang attribute if present
|
|
60
|
-
const langAttrIndex = element.attributes.findIndex((attr) => t.isJSXAttribute(attr) &&
|
|
61
|
-
t.isJSXIdentifier(attr.name) &&
|
|
62
|
-
attr.name.name === 'lang');
|
|
63
|
-
if (langAttrIndex !== -1) {
|
|
64
|
-
element.attributes.splice(langAttrIndex, 1);
|
|
65
|
-
}
|
|
66
|
-
// Add lang={await getLocale()} attribute
|
|
67
|
-
element.attributes.push(t.jsxAttribute(t.jsxIdentifier('lang'), t.jsxExpressionContainer(t.awaitExpression(t.callExpression(t.identifier('getLocale'), [])))));
|
|
68
|
-
}
|
|
69
|
-
function makeParentFunctionAsync(path) {
|
|
70
|
-
const functionParent = path.getFunctionParent();
|
|
71
|
-
if (!functionParent)
|
|
72
|
-
return false;
|
|
73
|
-
const node = functionParent.node;
|
|
74
|
-
if ((t.isFunctionDeclaration(node) ||
|
|
75
|
-
t.isFunctionExpression(node) ||
|
|
76
|
-
t.isArrowFunctionExpression(node)) &&
|
|
77
|
-
!node.async) {
|
|
78
|
-
node.async = true;
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function handleInitGT(filepath: string, errors: string[], warnings: string[], filesUpdated: string[]): Promise<void>;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default = handleInitGT;
|
|
40
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
|
-
const parser_1 = require("@babel/parser");
|
|
42
|
-
const generator_1 = __importDefault(require("@babel/generator"));
|
|
43
|
-
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
44
|
-
const t = __importStar(require("@babel/types"));
|
|
45
|
-
const console_1 = require("../../console");
|
|
46
|
-
async function handleInitGT(filepath, errors, warnings, filesUpdated) {
|
|
47
|
-
const code = await node_fs_1.default.promises.readFile(filepath, 'utf8');
|
|
48
|
-
let ast;
|
|
49
|
-
try {
|
|
50
|
-
ast = (0, parser_1.parse)(code, {
|
|
51
|
-
sourceType: 'module',
|
|
52
|
-
plugins: ['jsx', 'typescript'],
|
|
53
|
-
tokens: true,
|
|
54
|
-
createParenthesizedExpressions: true,
|
|
55
|
-
});
|
|
56
|
-
const needsCJS = filepath.endsWith('.js');
|
|
57
|
-
// Check if withGTConfig or initGT is already imported/required
|
|
58
|
-
let hasGTConfig = false;
|
|
59
|
-
let hasInitGT = false;
|
|
60
|
-
(0, traverse_1.default)(ast, {
|
|
61
|
-
ImportDeclaration(path) {
|
|
62
|
-
if (path.node.source.value === 'gt-next/config') {
|
|
63
|
-
path.node.specifiers.forEach((spec) => {
|
|
64
|
-
if (t.isImportSpecifier(spec)) {
|
|
65
|
-
if (spec.local.name === 'withGTConfig')
|
|
66
|
-
hasGTConfig = true;
|
|
67
|
-
if (spec.local.name === 'initGT')
|
|
68
|
-
hasInitGT = true;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
VariableDeclaration(path) {
|
|
74
|
-
path.node.declarations.forEach((dec) => {
|
|
75
|
-
if (t.isVariableDeclarator(dec) &&
|
|
76
|
-
t.isCallExpression(dec.init) &&
|
|
77
|
-
t.isIdentifier(dec.init.callee, { name: 'require' }) &&
|
|
78
|
-
t.isStringLiteral(dec.init.arguments[0], {
|
|
79
|
-
value: 'gt-next/config',
|
|
80
|
-
})) {
|
|
81
|
-
if (t.isIdentifier(dec.id, { name: 'withGTConfig' }))
|
|
82
|
-
hasGTConfig = true;
|
|
83
|
-
if (t.isIdentifier(dec.id, { name: 'initGT' }))
|
|
84
|
-
hasInitGT = true;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
// Return early if either withGTConfig or initGT is already present
|
|
90
|
-
if (hasGTConfig || hasInitGT) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
ast.program.body.unshift(needsCJS
|
|
94
|
-
? t.variableDeclaration('const', [
|
|
95
|
-
t.variableDeclarator(t.identifier('withGTConfig'), t.memberExpression(t.callExpression(t.identifier('require'), [
|
|
96
|
-
t.stringLiteral('gt-next/config'),
|
|
97
|
-
]), t.identifier('withGTConfig'))),
|
|
98
|
-
])
|
|
99
|
-
: t.importDeclaration([
|
|
100
|
-
t.importSpecifier(t.identifier('withGTConfig'), t.identifier('withGTConfig')),
|
|
101
|
-
], t.stringLiteral('gt-next/config')));
|
|
102
|
-
// Find and transform the default export
|
|
103
|
-
(0, traverse_1.default)(ast, {
|
|
104
|
-
ExportDefaultDeclaration(path) {
|
|
105
|
-
const oldExport = path.node.declaration;
|
|
106
|
-
let exportExpression;
|
|
107
|
-
if (t.isFunctionDeclaration(oldExport)) {
|
|
108
|
-
exportExpression = t.functionExpression(oldExport.id, oldExport.params, oldExport.body, oldExport.generator, oldExport.async);
|
|
109
|
-
}
|
|
110
|
-
else if (t.isClassDeclaration(oldExport)) {
|
|
111
|
-
exportExpression = t.classExpression(oldExport.id, oldExport.superClass, oldExport.body, oldExport.decorators);
|
|
112
|
-
}
|
|
113
|
-
else if (t.isTSDeclareFunction(oldExport)) {
|
|
114
|
-
// For TypeScript declare functions, create an empty function expression
|
|
115
|
-
// since declare functions don't have a runtime implementation
|
|
116
|
-
warnings.push(`Found TypeScript declare function in ${filepath}. Converting to empty function.`);
|
|
117
|
-
exportExpression = t.functionExpression(oldExport.id, oldExport.params, t.blockStatement([]), false, false);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
exportExpression = oldExport;
|
|
121
|
-
}
|
|
122
|
-
// Validate that we have a valid Next.js config export
|
|
123
|
-
if (!t.isObjectExpression(exportExpression) &&
|
|
124
|
-
!t.isFunctionExpression(exportExpression) &&
|
|
125
|
-
!t.isArrowFunctionExpression(exportExpression)) {
|
|
126
|
-
warnings.push(`Unexpected export type in ${filepath}. Next.js config should export an object or a function returning an object.`);
|
|
127
|
-
}
|
|
128
|
-
path.node.declaration = t.callExpression(t.identifier('withGTConfig'), [
|
|
129
|
-
exportExpression,
|
|
130
|
-
t.objectExpression([]),
|
|
131
|
-
]);
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
// Generate the modified code
|
|
135
|
-
const output = (0, generator_1.default)(ast, {
|
|
136
|
-
retainLines: true,
|
|
137
|
-
retainFunctionParens: true,
|
|
138
|
-
comments: true,
|
|
139
|
-
compact: 'auto',
|
|
140
|
-
}, code);
|
|
141
|
-
// Post-process the output to fix import spacing
|
|
142
|
-
let processedCode = output.code;
|
|
143
|
-
// Add newline after the comment only
|
|
144
|
-
processedCode = processedCode.replace(/((?:import\s*{\s*withGTConfig\s*}\s*from|const\s*{\s*withGTConfig\s*}\s*=\s*require)\s*['"]gt-next\/config['"];?)/, '$1\n');
|
|
145
|
-
// Write the modified code back to the file
|
|
146
|
-
await node_fs_1.default.promises.writeFile(filepath, processedCode);
|
|
147
|
-
filesUpdated.push(filepath);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
(0, console_1.logError)(`Error parsing file ${filepath}: ${error}`);
|
|
151
|
-
errors.push(`Failed to parse ${filepath}: ${error}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WrapOptions } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Wraps all JSX elements in the src directory with a <T> tag, with unique ids.
|
|
4
|
-
* - Ignores pure strings
|
|
5
|
-
*
|
|
6
|
-
* @param options - The options object
|
|
7
|
-
* @returns An object containing the updates and errors
|
|
8
|
-
*/
|
|
9
|
-
export default function wrapContentNext(options: WrapOptions, pkg: 'gt-next', errors: string[], warnings: string[]): Promise<{
|
|
10
|
-
filesUpdated: string[];
|
|
11
|
-
}>;
|