Skip to content

Commit 76d12c7

Browse files
committed
chore: split dist files
1 parent 5c1186c commit 76d12c7

6 files changed

Lines changed: 169 additions & 160 deletions

File tree

packages/appkit-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"build:watch": "tsdown --config tsdown.config.ts --watch",
3939
"clean:full": "rm -rf dist node_modules tmp",
4040
"clean": "rm -rf dist tmp",
41-
"dist": "tsx ../../tools/dist.ts",
41+
"dist": "tsx ../../tools/dist-appkit.ts",
4242
"tarball": "rm -rf tmp && pnpm dist && npm pack ./tmp --pack-destination ./tmp",
4343
"typecheck": "tsc --noEmit"
4444
},

packages/appkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"build:watch": "tsdown --config tsdown.config.ts --watch",
3838
"clean:full": "rm -rf dist node_modules tmp",
3939
"clean": "rm -rf dist tmp",
40-
"dist": "tsx ../../tools/dist.ts",
40+
"dist": "tsx ../../tools/dist-appkit.ts",
4141
"tarball": "rm -rf tmp && pnpm dist && npm pack ./tmp --pack-destination ./tmp",
4242
"typecheck": "tsc --noEmit"
4343
},

packages/lakebase/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"build:watch": "tsdown --config tsdown.config.ts --watch",
4040
"clean:full": "rm -rf dist node_modules tmp",
4141
"clean": "rm -rf dist tmp",
42-
"dist": "tsx ../../tools/dist.ts",
42+
"dist": "tsx ../../tools/dist-lakebase.ts",
4343
"tarball": "rm -rf tmp && pnpm dist && npm pack ./tmp --pack-destination ./tmp",
4444
"typecheck": "tsc --noEmit",
4545
"release": "release-it",

tools/dist-appkit.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
4+
const __dirname = path.dirname(new URL(import.meta.url).pathname);
5+
6+
// Read CLI dependencies from shared package
7+
const sharedPkgPath = path.join(__dirname, "../packages/shared/package.json");
8+
const sharedPkg = JSON.parse(fs.readFileSync(sharedPkgPath, "utf-8"));
9+
const CLI_DEPENDENCIES = sharedPkg.dependencies;
10+
11+
fs.mkdirSync("tmp", { recursive: true });
12+
13+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
14+
15+
// Packages that are workspace-local but published separately — replace workspace:* with real version.
16+
// "shared" is intentionally excluded: it is bundled directly into appkit/appkit-ui via noExternal.
17+
const WORKSPACE_PACKAGE_REPLACEMENTS = ["@databricks/lakebase"];
18+
19+
delete pkg.dependencies.shared;
20+
21+
for (const depName of WORKSPACE_PACKAGE_REPLACEMENTS) {
22+
if (pkg.dependencies?.[depName] === "workspace:*") {
23+
const pkgDirName = depName.split("/").pop() ?? depName;
24+
const depPkgPath = path.join(
25+
__dirname,
26+
`../packages/${pkgDirName}/package.json`,
27+
);
28+
const depPkg = JSON.parse(fs.readFileSync(depPkgPath, "utf-8"));
29+
pkg.dependencies[depName] = `^${depPkg.version}`;
30+
}
31+
}
32+
33+
pkg.exports = pkg.publishConfig.exports;
34+
delete pkg.publishConfig.exports;
35+
36+
const sharedBin = path.join(__dirname, "../packages/shared/bin/appkit.js");
37+
const sharedPostinstall = path.join(
38+
__dirname,
39+
"../packages/shared/scripts/postinstall.js",
40+
);
41+
42+
// Add appkit bin and postinstall
43+
if (fs.existsSync(sharedBin)) {
44+
pkg.bin = pkg.bin || {};
45+
pkg.bin.appkit = "./bin/appkit.js";
46+
}
47+
if (fs.existsSync(sharedPostinstall)) {
48+
pkg.scripts = pkg.scripts || {};
49+
pkg.scripts.postinstall = "node scripts/postinstall.js";
50+
}
51+
52+
// Add CLI dependencies from shared package (required for bin commands to work)
53+
pkg.dependencies = pkg.dependencies || {};
54+
Object.assign(pkg.dependencies, CLI_DEPENDENCIES);
55+
56+
fs.writeFileSync("tmp/package.json", JSON.stringify(pkg, null, 2));
57+
58+
fs.cpSync("dist", "tmp/dist", { recursive: true });
59+
60+
if (fs.existsSync("bin")) {
61+
fs.cpSync("bin", "tmp/bin", { recursive: true });
62+
}
63+
64+
// Copy bin and scripts from shared package
65+
if (fs.existsSync(sharedBin)) {
66+
fs.mkdirSync("tmp/bin", { recursive: true });
67+
fs.copyFileSync(sharedBin, "tmp/bin/appkit.js");
68+
69+
// Copy CLI code from shared/dist/cli to tmp/dist/cli
70+
const sharedCliDist = path.join(__dirname, "../packages/shared/dist/cli");
71+
if (fs.existsSync(sharedCliDist)) {
72+
const tmpCliDist = "tmp/dist/cli";
73+
fs.mkdirSync(tmpCliDist, { recursive: true });
74+
fs.cpSync(sharedCliDist, tmpCliDist, { recursive: true });
75+
}
76+
}
77+
if (fs.existsSync(sharedPostinstall)) {
78+
fs.mkdirSync("tmp/scripts", { recursive: true });
79+
fs.copyFileSync(sharedPostinstall, "tmp/scripts/postinstall.js");
80+
}
81+
82+
// Copy documentation from docs/build into tmp/docs/
83+
const docsBuildPath = path.join(__dirname, "../docs/build");
84+
85+
// Copy all .md files and docs/ subdirectory from docs/build to tmp/docs
86+
fs.mkdirSync("tmp/docs", { recursive: true });
87+
88+
// Copy all files and directories we want, preserving structure
89+
const itemsToCopy = fs.readdirSync(docsBuildPath);
90+
for (const item of itemsToCopy) {
91+
const sourcePath = path.join(docsBuildPath, item);
92+
const stat = fs.statSync(sourcePath);
93+
94+
// Copy .md files and docs directory
95+
if (item.endsWith(".md") || item === "docs") {
96+
const destPath = path.join("tmp/docs", item);
97+
if (stat.isDirectory()) {
98+
fs.cpSync(sourcePath, destPath, { recursive: true });
99+
} else {
100+
fs.copyFileSync(sourcePath, destPath);
101+
}
102+
}
103+
}
104+
105+
// Process llms.txt (keep existing logic but update path replacement)
106+
const llmsSourcePath = path.join(docsBuildPath, "llms.txt");
107+
let llmsContent = fs.readFileSync(llmsSourcePath, "utf-8");
108+
109+
// Replace /appkit/ with ./docs/ to match new structure
110+
llmsContent = llmsContent.replace(/\/appkit\//g, "./docs/");
111+
112+
// Prepend AI agent guidance for navigating documentation
113+
const agentGuidance = `## For AI Agents/Assistants
114+
115+
To view specific documentation files referenced below, use the appkit CLI:
116+
117+
\`\`\`bash
118+
npx @databricks/appkit docs <path>
119+
\`\`\`
120+
121+
Examples:
122+
- View main documentation: \`npx @databricks/appkit docs\`
123+
- View specific file: \`npx @databricks/appkit docs ./docs/docs.md\`
124+
- View API reference: \`npx @databricks/appkit docs ./docs/docs/api.md\`
125+
- View component docs: \`npx @databricks/appkit docs ./docs/docs/api/appkit-ui/components/Sidebar.md\`
126+
127+
The CLI will display the documentation content directly in the terminal.
128+
129+
---
130+
131+
`;
132+
133+
llmsContent = agentGuidance + llmsContent;
134+
fs.writeFileSync("tmp/llms.txt", llmsContent);
135+
// Copy llms.txt as CLAUDE.md (npm pack doesn't support symlinks)
136+
fs.copyFileSync("tmp/llms.txt", "tmp/CLAUDE.md");
137+
138+
fs.copyFileSync(path.join(__dirname, "../README.md"), "tmp/README.md");
139+
fs.copyFileSync(path.join(__dirname, "../LICENSE"), "tmp/LICENSE");
140+
fs.copyFileSync(path.join(__dirname, "../DCO"), "tmp/DCO");
141+
fs.copyFileSync(path.join(__dirname, "../NOTICE.md"), "tmp/NOTICE.md");

tools/dist-lakebase.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
4+
const __dirname = path.dirname(new URL(import.meta.url).pathname);
5+
6+
fs.mkdirSync("tmp", { recursive: true });
7+
8+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
9+
10+
pkg.exports = pkg.publishConfig.exports;
11+
delete pkg.publishConfig.exports;
12+
13+
fs.writeFileSync("tmp/package.json", JSON.stringify(pkg, null, 2));
14+
15+
fs.cpSync("dist", "tmp/dist", { recursive: true });
16+
17+
// Use the package's own README.md if present, otherwise fall back to the root one
18+
const localReadme = "README.md";
19+
const rootReadme = path.join(__dirname, "../README.md");
20+
fs.copyFileSync(
21+
fs.existsSync(localReadme) ? localReadme : rootReadme,
22+
"tmp/README.md",
23+
);
24+
fs.copyFileSync(path.join(__dirname, "../LICENSE"), "tmp/LICENSE");
25+
fs.copyFileSync(path.join(__dirname, "../DCO"), "tmp/DCO");

tools/dist.ts

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)