Skip to content

Commit

Permalink
feat: add COMPONENTS_BASE_URL for development (shadcn-ui#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn authored Mar 8, 2023
1 parent fa3af5d commit 92fe541
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-roses-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shadcn/ui": patch
---

Initial commit.
5 changes: 5 additions & 0 deletions .changeset/nervous-knives-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shadcn/ui": patch
---

implement component base url
4 changes: 2 additions & 2 deletions .github/workflows/prerelease-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
for (const artifact of allArtifacts.data.artifacts) {
// Extract the PR number and package version from the artifact name
const match = /^npm-package-\@shadcn\/ui@(.*?)-pr-(\d+)/.exec(artifact.name);
const match = /^npm-package-shadcn-ui@(.*?)-pr-(\d+)/.exec(artifact.name);
if (match) {
require("fs").appendFileSync(
Expand All @@ -46,7 +46,7 @@ jobs:
with:
number: ${{ env.WORKFLOW_RUN_PR }}
message: |
A new @shadcn/ui prerelease is available for testing. You can install this latest build in your project with:
A new @shadcn/ui prerelease is available for testing. You can use this latest build in your project with:
```sh
pnpm @shadcn/ui@${{ env.BETA_PACKAGE_VERSION }}
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ name: Release - Beta

on:
pull_request:
types: [labeled]
# types: [labeled]
branches:
- main
jobs:
prerelease:
if: |
github.repository_owner == 'shadcn' &&
contains(github.event.pull_request.labels.*.name, '🚀 autorelease')
# if: |
# github.repository_owner == 'shadcn' &&
# contains(github.event.pull_request.labels.*.name, '🚀 autorelease')
name: Build & Publish a beta release to NPM
runs-on: ubuntu-latest
environment: Preview

steps:
- name: Checkout Repo
Expand All @@ -36,13 +37,13 @@ jobs:
- name: Modify package.json version
run: node .github/version-script-beta.js

# - name: Authenticate to NPM
# run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_ACCESS_TOKEN }}" > packages/cli/.npmrc
- name: Authenticate to NPM
run: echo "//registry.npmjs.org/:_authToken=$NPM_ACCESS_TOKEN" >> packages/cli/.npmrc
env:
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

- name: Publish Beta to NPM
run: pnpm pub:beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

- name: get-npm-version
id: package-version
Expand All @@ -53,5 +54,5 @@ jobs:
- name: Upload packaged artifact
uses: actions/upload-artifact@v2
with:
name: npm-package-@shadcn\/ui@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name
name: npm-package-@shadcn-ui@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name
path: packages/cli/dist/index.js
45 changes: 45 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Adapted from create-t3-app.

name: Publish

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
if: ${{ github.repository_owner == 'shadcn' }}
name: Create a PR for release workflow
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use PNPM
uses: pnpm/[email protected]

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"

- name: Install NPM Dependencies
run: pnpm install

- name: Create Version PR or Publish to NPM
id: changesets
uses: changesets/[email protected]
with:
commit: "chore(release): version packages"
title: "chore(release): version packages"
publish: pnpm build:cli
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
NODE_ENV: "production"
134 changes: 40 additions & 94 deletions apps/www/pages/api/components.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@changesets/cli": "^2.26.0",
"@ianvs/prettier-plugin-sort-imports": "^3.7.1",
"@tailwindcss/line-clamp": "^0.4.2",
"cross-env": "^7.0.3",
"eslint": "^8.31.0",
"eslint-config-next": "13.0.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @shadcn/ui

## Usage

```
npx @shadcn/ui
```
11 changes: 7 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@shadcn/ui",
"version": "0.0.2",
"description": "Add @shadcn/ui components to your app.",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"author": {
"name": "shadcn",
Expand All @@ -22,7 +25,7 @@
"type": "module",
"exports": "./dist/index.js",
"bin": {
"@shadcn/cli": "./dist/index.js"
"@shadcn/ui": "./dist/index.js"
},
"scripts": {
"dev": "tsup --watch",
Expand All @@ -33,9 +36,9 @@
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
"release": "changeset version",
"pub:beta": "pnpm build && npm publish --access public --tag beta",
"pub:next": "pnpm build && npm publish --access public --tag next",
"pub:release": "pnpm build && npm publish --access public"
"pub:beta": "pnpm build && pnpm publish --no-git-checks --access public --tag beta",
"pub:next": "pnpm build && pnpm publish --no-git-checks --access public --tag next",
"pub:release": "pnpm build && pnpm publish --access public"
},
"dependencies": {
"chalk": "5.2.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/utils/get-components.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fetch from "node-fetch"
import * as z from "zod"

const baseUrl =
process.env.NODE_ENV === "production"
? "https://ui.shadcn.com"
: "http://localhost:3000"
const baseUrl = process.env.COMPONENTS_BASE_URL ?? "https://ui.shadcn.com"

const componentSchema = z.object({
name: z.string(),
Expand All @@ -29,6 +26,8 @@ export async function getAvailableComponents() {

return componentsSchema.parse(components)
} catch (error) {
throw new Error("Failed to fetch components")
throw new Error(
`Failed to fetch components from ${baseUrl}/api/components.`
)
}
}
17 changes: 14 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"NEXT_PUBLIC_APP_URL",
"UPSTASH_REDIS_REST_URL",
"UPSTASH_REDIS_REST_TOKEN",
"COMPONENTS_BASE_URL",
"npm_config_user_agent"
],
"outputs": ["dist/**", ".next/**"]
Expand Down

0 comments on commit 92fe541

Please sign in to comment.