Skip to content

Commit 9b03edd

Browse files
committed
wip
1 parent dd31780 commit 9b03edd

File tree

9 files changed

+113
-22
lines changed

9 files changed

+113
-22
lines changed

investigation/investigation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ All those limitations can be resolved by contributions to the plugin, post-proce
4848
1. Host `llms.txt` and MD files on our website (versioned docs)
4949
- Advantage: We can update the AI docs without releasing new versions of the packages
5050
- Downside: Agent needs to fetch the documentation from the website which are not as reliable as the local files
51-
2. Embed llms.txt and MD files into the packages
51+
2. Embed `llms.txt` and MD files into the packages
5252
1. Embed llms.txt and MD files into the packages - all docs files
5353
2. Split generation for appkit and appkit-ui
5454
1. Limitations: we'd need to contribute to the plugin to add support for:

packages/appkit-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dist",
1212
"bin",
1313
"scripts",
14+
"docs",
1415
"CLAUDE.md",
1516
"AGENTS.md",
1617
"llms.txt",

packages/appkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dist",
1414
"bin",
1515
"scripts",
16+
"docs",
1617
"CLAUDE.md",
1718
"llms.txt",
1819
"AGENTS.md",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Command } from "commander";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
function findPackageRoot(): string {
10+
let dir = __dirname;
11+
while (dir !== path.parse(dir).root) {
12+
if (fs.existsSync(path.join(dir, "package.json"))) {
13+
return dir;
14+
}
15+
dir = path.dirname(dir);
16+
}
17+
throw new Error("Could not find package root");
18+
}
19+
20+
function runDocs(docPath?: string) {
21+
const packageRoot = findPackageRoot();
22+
23+
if (!docPath) {
24+
// Display llms.txt by default
25+
const llmsPath = path.join(packageRoot, "llms.txt");
26+
27+
if (!fs.existsSync(llmsPath)) {
28+
console.error("Error: llms.txt not found in package");
29+
process.exit(1);
30+
}
31+
32+
const content = fs.readFileSync(llmsPath, "utf-8");
33+
console.log(content);
34+
return;
35+
}
36+
37+
// Handle path - remove leading /appkit/docs/ or /docs/ prefix
38+
let normalizedPath = docPath;
39+
normalizedPath = normalizedPath.replace(/^\/appkit\/docs\//, "");
40+
normalizedPath = normalizedPath.replace(/^\/docs\//, "");
41+
normalizedPath = normalizedPath.replace(/^docs\//, "");
42+
43+
const fullPath = path.join(packageRoot, "docs", normalizedPath);
44+
45+
if (!fs.existsSync(fullPath)) {
46+
console.error(`Error: Documentation file not found: ${docPath}`);
47+
console.error(`Tried: ${fullPath}`);
48+
process.exit(1);
49+
}
50+
51+
const content = fs.readFileSync(fullPath, "utf-8");
52+
console.log(content);
53+
}
54+
55+
export const docsCommand = new Command("docs")
56+
.description("Display embedded documentation")
57+
.argument(
58+
"[path]",
59+
"Path to specific documentation file (e.g., /appkit/docs/api/appkit-ui/components/Sidebar.md)",
60+
)
61+
.action(runDocs);

packages/shared/src/cli/commands/generate-types.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function runGenerateTypes(
88
rootDir?: string,
99
outFile?: string,
1010
warehouseId?: string,
11-
options?: { noCache?: boolean }
11+
options?: { noCache?: boolean },
1212
) {
1313
try {
1414
// Try to import the type generator from @databricks/appkit
@@ -26,7 +26,7 @@ async function runGenerateTypes(
2626
warehouseId || process.env.DATABRICKS_WAREHOUSE_ID;
2727
if (!resolvedWarehouseId) {
2828
console.error(
29-
"Error: DATABRICKS_WAREHOUSE_ID is not set. Please provide it as an argument or environment variable."
29+
"Error: DATABRICKS_WAREHOUSE_ID is not set. Please provide it as an argument or environment variable.",
3030
);
3131
process.exit(1);
3232
}
@@ -43,11 +43,9 @@ async function runGenerateTypes(
4343
error.message.includes("Cannot find module")
4444
) {
4545
console.error(
46-
"Error: The 'generate-types' command is only available in @databricks/appkit."
47-
);
48-
console.error(
49-
"Please install @databricks/appkit to use this command."
46+
"Error: The 'generate-types' command is only available in @databricks/appkit.",
5047
);
48+
console.error("Please install @databricks/appkit to use this command.");
5149
process.exit(1);
5250
}
5351
throw error;
@@ -60,7 +58,7 @@ export const generateTypesCommand = new Command("generate-types")
6058
.argument(
6159
"[outFile]",
6260
"Output file path",
63-
path.join(process.cwd(), "client/src/appKitTypes.d.ts")
61+
path.join(process.cwd(), "client/src/appKitTypes.d.ts"),
6462
)
6563
.argument("[warehouseId]", "Databricks warehouse ID")
6664
.option("--no-cache", "Disable caching for type generation")

packages/shared/src/cli/commands/setup.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ function findInstalledPackages() {
2121
const installed = [];
2222

2323
for (const pkg of PACKAGES) {
24-
const packagePath = path.join(cwd, "node_modules", pkg.name, "package.json");
24+
const packagePath = path.join(
25+
cwd,
26+
"node_modules",
27+
pkg.name,
28+
"package.json",
29+
);
2530
if (fs.existsSync(packagePath)) {
2631
installed.push(pkg);
2732
}

packages/shared/src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Command } from "commander";
44
import { setupCommand } from "./commands/setup.js";
55
import { generateTypesCommand } from "./commands/generate-types.js";
66
import { lintCommand } from "./commands/lint.js";
7+
import { docsCommand } from "./commands/docs.js";
78

89
const program = new Command();
910

@@ -16,5 +17,6 @@ program
1617
program.addCommand(setupCommand);
1718
program.addCommand(generateTypesCommand);
1819
program.addCommand(lintCommand);
20+
program.addCommand(docsCommand);
1921

2022
program.parse();

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/dist.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const sharedPostinstall = path.join(
2323
if (isAppKitPackage) {
2424
if (fs.existsSync(sharedBin)) {
2525
pkg.bin = pkg.bin || {};
26-
pkg.bin["appkit"] = "./bin/appkit.js";
26+
pkg.bin.appkit = "./bin/appkit.js";
2727
}
2828
if (fs.existsSync(sharedPostinstall)) {
2929
pkg.scripts = pkg.scripts || {};
@@ -51,22 +51,42 @@ if (isAppKitPackage) {
5151
}
5252
}
5353

54-
// Copy documentation from docs/build
54+
// Copy documentation from docs/build into tmp/docs/
5555
const docsBuildPath = path.join(__dirname, "../docs/build");
5656

57-
// Copy llms.txt
58-
fs.copyFileSync(path.join(docsBuildPath, "llms.txt"), "tmp/llms.txt");
57+
// Copy all .md files and docs/ subdirectory from docs/build to tmp/docs
58+
fs.mkdirSync("tmp/docs", { recursive: true });
59+
60+
// Copy all files and directories we want, preserving structure
61+
const itemsToCopy = fs.readdirSync(docsBuildPath);
62+
for (const item of itemsToCopy) {
63+
const sourcePath = path.join(docsBuildPath, item);
64+
const stat = fs.statSync(sourcePath);
65+
66+
// Copy .md files and docs directory
67+
if (item.endsWith('.md') || item === 'docs') {
68+
const destPath = path.join("tmp/docs", item);
69+
if (stat.isDirectory()) {
70+
fs.cpSync(sourcePath, destPath, { recursive: true });
71+
} else {
72+
fs.copyFileSync(sourcePath, destPath);
73+
}
74+
}
75+
}
76+
77+
// Process llms.txt (keep existing logic but update path replacement)
78+
const llmsSourcePath = path.join(docsBuildPath, "llms.txt");
79+
let llmsContent = fs.readFileSync(llmsSourcePath, "utf-8");
80+
81+
// Replace /appkit/ with ./docs/ to match new structure
82+
llmsContent = llmsContent.replace(/\/appkit\//g, "./docs/");
83+
84+
fs.writeFileSync("tmp/llms.txt", llmsContent);
5985

6086
// Copy llms.txt as CLAUDE.md and AGENTS.md (npm pack doesn't support symlinks)
6187
fs.copyFileSync("tmp/llms.txt", "tmp/CLAUDE.md");
6288
fs.copyFileSync("tmp/llms.txt", "tmp/AGENTS.md");
6389

64-
// Copy markdown documentation structure
65-
const docsPath = path.join(docsBuildPath, "docs");
66-
if (fs.existsSync(docsPath)) {
67-
fs.cpSync(docsPath, "tmp/docs", { recursive: true });
68-
}
69-
7090
fs.copyFileSync(path.join(__dirname, "../README.md"), "tmp/README.md");
7191
fs.copyFileSync(path.join(__dirname, "../LICENSE"), "tmp/LICENSE");
7292
fs.copyFileSync(path.join(__dirname, "../DCO"), "tmp/DCO");

0 commit comments

Comments
 (0)