Skip to content

Commit d34a5a0

Browse files
committed
[add] GitHub action for NPM publishing
[optimize] NPM configuration [fix] 2 compatibility bugs in Windows
1 parent 7bc5513 commit d34a5a0

File tree

6 files changed

+65
-13
lines changed

6 files changed

+65
-13
lines changed

.github/workflows/main.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI & CD
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
jobs:
7+
Build-and-Publish:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
id-token: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: pnpm/action-setup@v4
16+
with:
17+
version: 10
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
registry-url: https://registry.npmjs.org
22+
cache: pnpm
23+
- name: Install Dependencies
24+
run: pnpm i --frozen-lockfile
25+
26+
- name: Build & Publish
27+
run: npm publish --access public --provenance
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
31+
- name: Update document
32+
uses: peaceiris/actions-gh-pages@v4
33+
with:
34+
publish_dir: ./docs
35+
personal_token: ${{ secrets.GITHUB_TOKEN }}
36+
force_orphan: true

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# ShadcnX
1+
# ShadcnX CLI
22

33
A command line helper for [Shadcn UI CLI][1], `git commit` modified component codes only.
44

5+
[![CI & CD](https://github.com/idea2app/ShadcnX/actions/workflows/main.yml/badge.svg)][2]
6+
57
## Installation
68

79
```bash
@@ -39,3 +41,4 @@ shadcn-x edit component-name
3941
1. https://github.com/idea2app/Next-shadcn-ts
4042

4143
[1]: https://ui.shadcn.com/docs/cli
44+
[2]: https://github.com/idea2app/ShadcnX/actions/workflows/main.yml

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "shadcn-x",
33
"version": "0.3.0",
4+
"license": "LGPL-3.0-or-later",
5+
"author": "shiy2008@gmail.com",
46
"description": "A command line helper for Shadcn UI CLI, `git commit` modified component codes only.",
7+
"keywords": [
8+
"shadcn",
9+
"component",
10+
"command",
11+
"helper"
12+
],
513
"type": "module",
614
"bin": "./dist/command.js",
7-
"scripts": {
8-
"install": "npm i shadcn -g",
9-
"test": "cd test && tsx ../source/command",
10-
"build": "rm -rf dist/ && tsc && cp source/components.json dist/",
11-
"prepublishOnly": "npm t add button badge && npm run build"
12-
},
13-
"author": "shiy2008@gmail.com",
14-
"license": "LGPL-3.0-or-later",
1515
"dependencies": {
1616
"array-unique-proposal": "^0.3.4",
1717
"open": "^10.1.2",
@@ -31,5 +31,11 @@
3131
"prettier": {
3232
"singleQuote": true,
3333
"arrowParens": "avoid"
34+
},
35+
"scripts": {
36+
"install": "pnpm i shadcn -g || npm i shadcn -g",
37+
"test": "cd test && tsx ../source/command",
38+
"build": "rm -rf dist/ && tsc && cp source/components.json dist/",
39+
"prepublishOnly": "npm t add button badge && npm run build"
3440
}
3541
}

source/command.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import 'array-unique-proposal';
55
import { $, fs, path } from 'zx';
66
import open from 'open';
77

8+
import { localPathOf } from './utility.js';
9+
810
$.verbose = true;
911

1012
const [command, ...args] = process.argv.slice(2);
1113

1214
const configurationTarget = 'components.json';
1315

1416
if (!fs.existsSync(configurationTarget)) {
15-
const configurationSource = (
16-
new URL('components.json', import.meta.url) + ''
17-
).replace('file://', '');
17+
const configurationSource = localPathOf(import.meta.url, configurationTarget);
1818

1919
await fs.copy(configurationSource, configurationTarget);
2020
}
@@ -72,7 +72,9 @@ async function editComponent(component: string) {
7272

7373
await saveIndex(oldList);
7474

75-
const filePath = path.join(componentsFilePath, `${component}.tsx`);
75+
const filePath = path
76+
.join(componentsFilePath, `${component}.tsx`)
77+
.replace(/\\/g, '/');
7678

7779
await fs.appendFile('.gitignore', `!${filePath}`);
7880

source/utility.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const localPathOf = (importMetaURL: string, relativePath: string) =>
2+
(new URL(relativePath, importMetaURL) + '')
3+
.replace('file://' + (process.platform === 'win32' ? '/' : ''), '')
4+
.replace(/\\/g, '/');

0 commit comments

Comments
 (0)