Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/shadcn/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import parser from "yargs-parser";
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
import pkgJson from "./package.json";

const args = parser(process.argv.slice(2));
const domain = String(args.domain);
const publicDir = args.publicDir ? String(args.publicDir) : "public/r";
const outDir = args.outDir ? String(args.outDir) : "dist/registry";
const isDev = !!args.dev;

if (!domain) {
Expand All @@ -18,20 +35,23 @@ const registryRaw = fs.readFileSync(registryPath, "utf8");

let replaced = registryRaw.replace(/{{\s*DOMAIN\s*}}/g, domain);

// Replace version placeholder
replaced = replaced.replace(/{{\s*VERSION\s*}}/g, pkgJson.version);

// Replace dependency placeholder based on dev flag
replaced = replaced.replace(/{{\s*DEP\s*\|\s*([^}]+)\s*}}/g, (_, packageName) => {
return isDev ? `${packageName.trim()}@workspace:*` : packageName.trim();
});
fs.writeFileSync("registry.json", replaced, "utf8");

const publicRDir = path.resolve(publicDir);
const publicRDir = path.resolve(outDir);
if (fs.existsSync(publicRDir)) {
execSync("rm -rf " + publicRDir, { stdio: "inherit" });
}

try {
try {
execSync(`./node_modules/.bin/shadcn build -o ${publicDir}`, { stdio: "inherit" });
execSync(`./node_modules/.bin/shadcn build -o ${outDir}`, { stdio: "inherit" });
} catch (error) {
console.error("shadcn build failed:", error);
process.exit(1);
Expand Down
79 changes: 79 additions & 0 deletions packages/shadcn/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { parseArgs } from "node:util";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const { values, positionals } = parseArgs({
options: {
outDir: {
type: "string",
default: "./public-dev/r",
},
},
allowPositionals: true,
});

const command = positionals[0];
const outputPath = positionals[1] || values.outDir;

// Registry is at dist/registry, CLI is at dist/bin, so go up one level
const sourceDir = "../registry";

if (command === "copy") {
const sourcePath = path.resolve(__dirname, sourceDir);

// Output path should be relative to where the user runs the command from
const destPath = path.resolve(process.cwd(), outputPath);

// Check if source directory exists
if (!fs.existsSync(sourcePath)) {
console.error(`Error: Source directory "${sourcePath}" does not exist`);
process.exit(1);
}

// Create destination directory if it doesn't exist
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath, { recursive: true });
}

// Copy files from source to destination
const files = fs.readdirSync(sourcePath);
let copiedCount = 0;

for (const file of files) {
const sourceFile = path.join(sourcePath, file);
const destFile = path.join(destPath, file);

const stat = fs.statSync(sourceFile);
if (stat.isFile()) {
fs.copyFileSync(sourceFile, destFile);
copiedCount++;
console.log(`Copied: ${file}`);
}
}

console.log(`\nSuccessfully copied ${copiedCount} item(s) from "${sourcePath}" to "${destPath}"`);
} else {
console.error(`Unknown command: ${command || "none"}`);
console.error("Usage: copy <output-path>");
process.exit(1);
}
13 changes: 9 additions & 4 deletions packages/shadcn/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "@invertase/firebaseui-shadcn",
"private": true,
"version": "0.0.0",
"version": "0.0.2",
"type": "module",
"bin": "./dist/bin/cli.js",
"files": [
"dist"
],
"scripts": {
"prepare": "pnpm run build",
"dev": "vite",
"build": "tsx build.ts --domain https://fir-ui-shadcn-registry.web.app",
"build": "tsup && tsx build.ts --domain https://fir-ui-shadcn-registry.web.app",
"preview": "vite preview",
"test": "vitest run"
},
Expand All @@ -24,6 +28,7 @@
"react-dom": "catalog:",
"shadcn": "2.9.3-canary.0",
"tailwindcss": "catalog:",
"tsup": "catalog:",
"tsx": "^4.20.6",
"tw-animate-css": "^1.4.0",
"typescript": "catalog:",
Expand All @@ -33,9 +38,9 @@
"yargs-parser": "^22.0.0"
},
"dependencies": {
"@hookform/resolvers": "^5.2.2",
"@invertase/firebaseui-core": "workspace:*",
"@invertase/firebaseui-react": "workspace:*",
"@hookform/resolvers": "^5.2.2",
"@radix-ui/react-label": "^2.1.7",
"@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-separator": "^1.1.7",
Expand Down
Loading