|
| 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"); |
0 commit comments