New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

shadreg

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shadreg

build registry files for your UI library with shadcn

latest
Source
npmnpm
Version
0.0.75
Version published
Maintainers
0
Created
Source

shadreg

A CLI tool for generating a ShadCN component registry JSON for your UI library.

Commands

init

The init command initializes the necessary dependencies for your project and generates a configuration file.

npx shadreg init

You will be prompted with a series of questions to configure your project.

Example interaction:

✔ A shadreg.config.ts file already exists. Overwrite it? Yes
✔ Enter the output directory: ./shadreg
✔ Enter the base url of your components: ./src/components
✔ Do you want to include registry example? Yes

Config File Template

// shadreg.config.ts

import { shadregConfig } from "shadreg"

export default shadregConfig({
  baseUrl: "./src/components", // Path to your component files
  outputDir: "./shadreg", // Output directory for the registry files
  registries: [
    {
      name: "cool-text", // Component name
      type: "registry:ui", // Type of registry (e.g., UI component)
      registryDependencies: ["button"], // Components your component depends on
      dependencies: [], // Regular dependencies
      devDependencies: [], // Dev dependencies
      tailwind: {
        config: {}, // Tailwind config if necessary
      },
      cssVars: {}, // CSS variables for your component
      files: ["cool-text.tsx"], // Files associated with the component
    },
  ],
})

// your "cool-text" component should located at ./src/components/cool-text.tsx

Properties

PropertyTypeDescriptionDefault
baseUrlstringThe base url of your components./src/components
outputDirstringWhere the registry json files and _generated.json will be saved./shadreg
registriesRegistryA list of registry entries. See Shadcn Registry Schema for more details.

build

The build command generates the registry JSON files in the specified output directory.

npx shadcn build

This will generate the registry JSON files and a _generated.json in the outputDir you set.

_generated.json Structure

PropertyTypeDescription
namestringThe name of the component
urlstring?The url of the component after publishing to Vercel Blob Store.
entryRegistryEntryThe registry entry for the component. See Shadcn Registry Schema for more details.

A allRegistries object is exported from index.mjs and index.d.ts files, which can be imported into your Next.js project, used in API endpoints, etc.

So that you can make your component public with API endpoint and Shadcn CLI.

Example for Next.js Integration

  • Update path alias in tsconfig.json or jsconfig.json :
"paths": {
  "@/*": ["./src/*"],
  "@/shadreg": ["./shadreg/index.mjs"] // <-- add this line
}
  • Create an API route in src/app/api/registry/[name]/route.ts :
// src/app/api/registry/[name]/route.ts

import { NextResponse } from "next/server"
import { allRegistries } from "@/shadreg"

export async function GET(
  request: Request,
  { params }: { params: { name: string } },
) {
  const { name } = params
  const registry = allRegistries.find((entry) => entry.name === name)

  if (!registry) {
    return NextResponse.json(
      { error: `Registry with name "${name}" not found` },
      { status: 404 },
    )
  }

  return NextResponse.json(registry.entry)
}

To fetch the registry:

GET http://localhost:3000/api/registry/cool-text

To add the registry with shadcn:

npx shadcn@latest add http://localhost:3000/api/registry/cool-text

publish

The publish command uploads the registry JSON to Vercel Blob Store, making it publicly accessible.

npx shadcn publish

You must provide a Vercel Blob token in your .env file.

BLOB_READ_WRITE_TOKEN=your-vercel-blob-token

Once published, the Vercel Blob URL will be added to the _generated.json file.

License

Licensed under the MIT license.

FAQs

Package last updated on 12 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts