Skip to content

Commit 92fe541

Browse files
authored
feat: add COMPONENTS_BASE_URL for development (#115)
1 parent fa3af5d commit 92fe541

12 files changed

Lines changed: 141 additions & 117 deletions

File tree

.changeset/khaki-roses-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadcn/ui": patch
3+
---
4+
5+
Initial commit.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadcn/ui": patch
3+
---
4+
5+
implement component base url

.github/workflows/prerelease-comment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
for (const artifact of allArtifacts.data.artifacts) {
3030
// Extract the PR number and package version from the artifact name
31-
const match = /^npm-package-\@shadcn\/ui@(.*?)-pr-(\d+)/.exec(artifact.name);
31+
const match = /^npm-package-shadcn-ui@(.*?)-pr-(\d+)/.exec(artifact.name);
3232
3333
if (match) {
3434
require("fs").appendFileSync(
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
number: ${{ env.WORKFLOW_RUN_PR }}
4848
message: |
49-
A new @shadcn/ui prerelease is available for testing. You can install this latest build in your project with:
49+
A new @shadcn/ui prerelease is available for testing. You can use this latest build in your project with:
5050
5151
```sh
5252
pnpm @shadcn/ui@${{ env.BETA_PACKAGE_VERSION }}

.github/workflows/prerelease.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ name: Release - Beta
44

55
on:
66
pull_request:
7-
types: [labeled]
7+
# types: [labeled]
88
branches:
99
- main
1010
jobs:
1111
prerelease:
12-
if: |
13-
github.repository_owner == 'shadcn' &&
14-
contains(github.event.pull_request.labels.*.name, '🚀 autorelease')
12+
# if: |
13+
# github.repository_owner == 'shadcn' &&
14+
# contains(github.event.pull_request.labels.*.name, '🚀 autorelease')
1515
name: Build & Publish a beta release to NPM
1616
runs-on: ubuntu-latest
17+
environment: Preview
1718

1819
steps:
1920
- name: Checkout Repo
@@ -36,13 +37,13 @@ jobs:
3637
- name: Modify package.json version
3738
run: node .github/version-script-beta.js
3839

39-
# - name: Authenticate to NPM
40-
# run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_ACCESS_TOKEN }}" > packages/cli/.npmrc
40+
- name: Authenticate to NPM
41+
run: echo "//registry.npmjs.org/:_authToken=$NPM_ACCESS_TOKEN" >> packages/cli/.npmrc
42+
env:
43+
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
4144

4245
- name: Publish Beta to NPM
4346
run: pnpm pub:beta
44-
env:
45-
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
4647

4748
- name: get-npm-version
4849
id: package-version
@@ -53,5 +54,5 @@ jobs:
5354
- name: Upload packaged artifact
5455
uses: actions/upload-artifact@v2
5556
with:
56-
name: npm-package-@shadcn\/ui@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name
57+
name: npm-package-@shadcn-ui@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name
5758
path: packages/cli/dist/index.js

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Adapted from create-t3-app.
2+
3+
name: Publish
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency: ${{ github.workflow }}-${{ github.ref }}
11+
12+
jobs:
13+
build:
14+
if: ${{ github.repository_owner == 'shadcn' }}
15+
name: Create a PR for release workflow
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Repo
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Use PNPM
24+
uses: pnpm/action-setup@v2.2.4
25+
26+
- name: Use Node.js 18
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 18
30+
cache: "pnpm"
31+
32+
- name: Install NPM Dependencies
33+
run: pnpm install
34+
35+
- name: Create Version PR or Publish to NPM
36+
id: changesets
37+
uses: changesets/action@v1.4.1
38+
with:
39+
commit: "chore(release): version packages"
40+
title: "chore(release): version packages"
41+
publish: pnpm build:cli
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
45+
NODE_ENV: "production"

apps/www/pages/api/components.json

Lines changed: 40 additions & 94 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@changesets/cli": "^2.26.0",
3838
"@ianvs/prettier-plugin-sort-imports": "^3.7.1",
3939
"@tailwindcss/line-clamp": "^0.4.2",
40+
"cross-env": "^7.0.3",
4041
"eslint": "^8.31.0",
4142
"eslint-config-next": "13.0.0",
4243
"eslint-config-prettier": "^8.3.0",

packages/cli/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @shadcn/ui
2+
3+
## Usage
4+
5+
```
6+
npx @shadcn/ui
7+
```

packages/cli/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"name": "@shadcn/ui",
33
"version": "0.0.2",
44
"description": "Add @shadcn/ui components to your app.",
5+
"publishConfig": {
6+
"access": "public"
7+
},
58
"license": "MIT",
69
"author": {
710
"name": "shadcn",
@@ -22,7 +25,7 @@
2225
"type": "module",
2326
"exports": "./dist/index.js",
2427
"bin": {
25-
"@shadcn/cli": "./dist/index.js"
28+
"@shadcn/ui": "./dist/index.js"
2629
},
2730
"scripts": {
2831
"dev": "tsup --watch",
@@ -33,9 +36,9 @@
3336
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
3437
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
3538
"release": "changeset version",
36-
"pub:beta": "pnpm build && npm publish --access public --tag beta",
37-
"pub:next": "pnpm build && npm publish --access public --tag next",
38-
"pub:release": "pnpm build && npm publish --access public"
39+
"pub:beta": "pnpm build && pnpm publish --no-git-checks --access public --tag beta",
40+
"pub:next": "pnpm build && pnpm publish --no-git-checks --access public --tag next",
41+
"pub:release": "pnpm build && pnpm publish --access public"
3942
},
4043
"dependencies": {
4144
"chalk": "5.2.0",

packages/cli/src/utils/get-components.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import fetch from "node-fetch"
22
import * as z from "zod"
33

4-
const baseUrl =
5-
process.env.NODE_ENV === "production"
6-
? "https://ui.shadcn.com"
7-
: "http://localhost:3000"
4+
const baseUrl = process.env.COMPONENTS_BASE_URL ?? "https://ui.shadcn.com"
85

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

3027
return componentsSchema.parse(components)
3128
} catch (error) {
32-
throw new Error("Failed to fetch components")
29+
throw new Error(
30+
`Failed to fetch components from ${baseUrl}/api/components.`
31+
)
3332
}
3433
}

0 commit comments

Comments
 (0)