Skip to content

Commit 5dc79b4

Browse files
Ehespdackers86
andauthored
feat(shadcn): add build workflow (#1269)
Co-authored-by: Darren Ackers <ackers86@hotmail.com>
1 parent 68d52c3 commit 5dc79b4

File tree

8 files changed

+243
-14
lines changed

8 files changed

+243
-14
lines changed

packages/shadcn/build.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
import parser from "yargs-parser";
218
import fs from "fs";
319
import path from "path";
420
import { execSync } from "child_process";
21+
import pkgJson from "./package.json";
522

623
const args = parser(process.argv.slice(2));
724
const domain = String(args.domain);
8-
const publicDir = args.publicDir ? String(args.publicDir) : "public/r";
25+
const outDir = args.outDir ? String(args.outDir) : "dist/registry";
926
const isDev = !!args.dev;
1027

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

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

38+
// Replace version placeholder
39+
replaced = replaced.replace(/{{\s*VERSION\s*}}/g, pkgJson.version);
40+
2141
// Replace dependency placeholder based on dev flag
2242
replaced = replaced.replace(/{{\s*DEP\s*\|\s*([^}]+)\s*}}/g, (_, packageName) => {
2343
return isDev ? `${packageName.trim()}@workspace:*` : packageName.trim();
2444
});
2545
fs.writeFileSync("registry.json", replaced, "utf8");
2646

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

3252
try {
3353
try {
34-
execSync(`./node_modules/.bin/shadcn build -o ${publicDir}`, { stdio: "inherit" });
54+
execSync(`./node_modules/.bin/shadcn build -o ${outDir}`, { stdio: "inherit" });
3555
} catch (error) {
3656
console.error("shadcn build failed:", error);
3757
process.exit(1);

packages/shadcn/cli.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { parseArgs } from "node:util";
18+
import fs from "node:fs";
19+
import path from "node:path";
20+
import { fileURLToPath } from "node:url";
21+
22+
const __filename = fileURLToPath(import.meta.url);
23+
const __dirname = path.dirname(__filename);
24+
25+
const { values, positionals } = parseArgs({
26+
options: {
27+
outDir: {
28+
type: "string",
29+
default: "./public-dev/r",
30+
},
31+
},
32+
allowPositionals: true,
33+
});
34+
35+
const command = positionals[0];
36+
const outputPath = positionals[1] || values.outDir;
37+
38+
// Registry is at dist/registry, CLI is at dist/bin, so go up one level
39+
const sourceDir = "../registry";
40+
41+
if (command === "copy") {
42+
const sourcePath = path.resolve(__dirname, sourceDir);
43+
44+
// Output path should be relative to where the user runs the command from
45+
const destPath = path.resolve(process.cwd(), outputPath);
46+
47+
// Check if source directory exists
48+
if (!fs.existsSync(sourcePath)) {
49+
console.error(`Error: Source directory "${sourcePath}" does not exist`);
50+
process.exit(1);
51+
}
52+
53+
// Create destination directory if it doesn't exist
54+
if (!fs.existsSync(destPath)) {
55+
fs.mkdirSync(destPath, { recursive: true });
56+
}
57+
58+
// Copy files from source to destination
59+
const files = fs.readdirSync(sourcePath);
60+
let copiedCount = 0;
61+
62+
for (const file of files) {
63+
const sourceFile = path.join(sourcePath, file);
64+
const destFile = path.join(destPath, file);
65+
66+
const stat = fs.statSync(sourceFile);
67+
if (stat.isFile()) {
68+
fs.copyFileSync(sourceFile, destFile);
69+
copiedCount++;
70+
console.log(`Copied: ${file}`);
71+
}
72+
}
73+
74+
console.log(`\nSuccessfully copied ${copiedCount} item(s) from "${sourcePath}" to "${destPath}"`);
75+
} else {
76+
console.error(`Unknown command: ${command || "none"}`);
77+
console.error("Usage: copy <output-path>");
78+
process.exit(1);
79+
}

packages/shadcn/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"name": "@invertase/firebaseui-shadcn",
3-
"private": true,
4-
"version": "0.0.0",
3+
"version": "0.0.2",
54
"type": "module",
5+
"bin": "./dist/bin/cli.js",
6+
"files": [
7+
"dist"
8+
],
69
"scripts": {
10+
"prepare": "pnpm run build",
711
"dev": "vite",
8-
"build": "tsx build.ts --domain https://fir-ui-shadcn-registry.web.app",
12+
"build": "tsup && tsx build.ts --domain https://fir-ui-shadcn-registry.web.app",
913
"preview": "vite preview",
1014
"test": "vitest run"
1115
},
@@ -24,6 +28,7 @@
2428
"react-dom": "catalog:",
2529
"shadcn": "2.9.3-canary.0",
2630
"tailwindcss": "catalog:",
31+
"tsup": "catalog:",
2732
"tsx": "^4.20.6",
2833
"tw-animate-css": "^1.4.0",
2934
"typescript": "catalog:",
@@ -33,9 +38,9 @@
3338
"yargs-parser": "^22.0.0"
3439
},
3540
"dependencies": {
41+
"@hookform/resolvers": "^5.2.2",
3642
"@invertase/firebaseui-core": "workspace:*",
3743
"@invertase/firebaseui-react": "workspace:*",
38-
"@hookform/resolvers": "^5.2.2",
3944
"@radix-ui/react-label": "^2.1.7",
4045
"@radix-ui/react-select": "^2.2.6",
4146
"@radix-ui/react-separator": "^1.1.7",

0 commit comments

Comments
 (0)