usetraceforge-cli 0.1.3 → 0.1.4
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/dist/installers/nextjs.js +28 -0
- package/package.json +1 -1
|
@@ -72,6 +72,34 @@ export function TraceForgeProvider({ children }: { children: React.ReactNode })
|
|
|
72
72
|
layoutCode = layoutCode.replace(/(<body[^>]*>)/g, `$1\n <TraceForgeProvider>`);
|
|
73
73
|
layoutCode = layoutCode.replace(/<\/body>/g, ` </TraceForgeProvider>\n </body>`);
|
|
74
74
|
fs.writeFileSync(targetLayout, layoutCode);
|
|
75
|
+
// 5. Update next.config.js / next.config.mjs
|
|
76
|
+
const configPaths = [
|
|
77
|
+
path.resolve(process.cwd(), "next.config.mjs"),
|
|
78
|
+
path.resolve(process.cwd(), "next.config.js"),
|
|
79
|
+
];
|
|
80
|
+
let targetConfig = null;
|
|
81
|
+
for (const p of configPaths) {
|
|
82
|
+
if (fs.existsSync(p)) {
|
|
83
|
+
targetConfig = p;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (targetConfig) {
|
|
88
|
+
let configCode = fs.readFileSync(targetConfig, "utf-8");
|
|
89
|
+
if (!configCode.includes("withTraceForgeConfig")) {
|
|
90
|
+
const isMjs = targetConfig.endsWith(".mjs") || configCode.includes("export default");
|
|
91
|
+
// Add import
|
|
92
|
+
if (isMjs) {
|
|
93
|
+
configCode = `import { withTraceForgeConfig } from "usetraceforge/next-plugin";\n` + configCode;
|
|
94
|
+
configCode = configCode.replace(/export default (.+);/g, `export default withTraceForgeConfig($1);`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
configCode = `const { withTraceForgeConfig } = require("usetraceforge/next-plugin");\n` + configCode;
|
|
98
|
+
configCode = configCode.replace(/module\.exports = (.+);/g, `module.exports = withTraceForgeConfig($1);`);
|
|
99
|
+
}
|
|
100
|
+
fs.writeFileSync(targetConfig, configCode);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
75
103
|
s.stop(chalk.green("Next.js configuration complete!"));
|
|
76
104
|
}
|
|
77
105
|
catch (error) {
|