usetraceforge-cli 0.1.7 → 0.1.8

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.
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { spinner } from "@clack/prompts";
4
4
  import chalk from "chalk";
5
+ import { Project, SyntaxKind } from "ts-morph";
5
6
  export async function installNextJs(apiKey, endpoint) {
6
7
  const s = spinner();
7
8
  s.start("Agent: Configuring Next.js Instrumentation...");
@@ -43,6 +44,48 @@ export function onRequestError(err: any, request: any) {
43
44
  else {
44
45
  console.log(chalk.yellow(`\nAgent: instrumentation.ts already exists. Please manually add TraceForge.`));
45
46
  }
47
+ // 3. Layout AST Injection (Client-side Provider)
48
+ const project = new Project();
49
+ const layoutPaths = [
50
+ path.resolve(process.cwd(), "app/layout.tsx"),
51
+ path.resolve(process.cwd(), "src/app/layout.tsx"),
52
+ ];
53
+ let targetLayout = null;
54
+ for (const p of layoutPaths) {
55
+ if (fs.existsSync(p)) {
56
+ targetLayout = p;
57
+ break;
58
+ }
59
+ }
60
+ if (targetLayout) {
61
+ const sourceFile = project.addSourceFileAtPath(targetLayout);
62
+ if (!sourceFile.getFullText().includes("TraceForgeProvider")) {
63
+ sourceFile.addImportDeclaration({
64
+ namedImports: ["TraceForgeProvider"],
65
+ moduleSpecifier: "usetraceforge/react"
66
+ });
67
+ // Find body tag
68
+ const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement);
69
+ let bodyTag = jsxElements.find(el => el.getOpeningElement().getTagNameNode().getText() === "body");
70
+ if (bodyTag) {
71
+ const childrenText = bodyTag.getJsxChildren().map(c => c.getText()).join("");
72
+ const opening = bodyTag.getOpeningElement().getText();
73
+ const closing = bodyTag.getClosingElement().getText();
74
+ bodyTag.replaceWithText(`${opening}\n <TraceForgeProvider>\n ${childrenText}\n </TraceForgeProvider>\n ${closing}`);
75
+ sourceFile.saveSync();
76
+ console.log(chalk.green(`\nAgent: Injected <TraceForgeProvider> into ${targetLayout.replace(process.cwd(), "")}`));
77
+ }
78
+ else {
79
+ console.log(chalk.yellow("\nAgent: Could not find <body> tag in layout.tsx. Please add <TraceForgeProvider> manually."));
80
+ }
81
+ }
82
+ else {
83
+ console.log(chalk.blue(`\nAgent: <TraceForgeProvider> already exists in layout.tsx`));
84
+ }
85
+ }
86
+ else {
87
+ console.log(chalk.yellow("\nAgent: Could not find layout.tsx. Please add <TraceForgeProvider> manually."));
88
+ }
46
89
  s.stop(chalk.green("Agent: Next.js configuration complete!"));
47
90
  }
48
91
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usetraceforge-cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "TraceForge CLI Wizard for 2-click installations",
5
5
  "bin": {
6
6
  "traceforge": "./dist/index.js"