create-shadcn-js 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +159 -2
- package/bin/cli.js +8 -0
- package/package.json +52 -4
- package/src/index.js +149 -0
- package/src/prompts.js +169 -0
- package/src/scaffold.js +148 -0
- package/src/shadcn.js +105 -0
- package/src/templates/app.js +137 -0
- package/src/templates/configs.js +126 -0
- package/src/templates/indexCss.js +15 -0
- package/src/utils.js +129 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Skandan-V
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-shadcn-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Scaffold a fully configured **Vite + React (JavaScript) + Tailwind CSS + shadcn/ui** project in seconds — zero manual setup, zero config headaches.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/create-shadcn-js)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Why create-shadcn-js?
|
|
11
|
+
|
|
12
|
+
The official `shadcn` CLI only provides TypeScript templates (`--template vite` creates `.tsx` and `tsconfig.json`). If you build with **JavaScript / JSX**, setting up Vite with shadcn and Tailwind requires tedious manual work every single time:
|
|
13
|
+
|
|
14
|
+
1. **Creating `jsconfig.json`** with `baseUrl` and `@/*` paths so both your editor and the CLI can resolve imports.
|
|
15
|
+
2. **Updating `vite.config.js`** with `path.resolve` and `@` path alias mapping.
|
|
16
|
+
3. **Installing and configuring Tailwind CSS** (Tailwind v4 with `@tailwindcss/vite` and `@import "tailwindcss";` in `index.css`, or v3 with `tailwind.config.js` and `postcss.config.js`).
|
|
17
|
+
4. **Purging default Vite boilerplate** (conflicting `App.css` styling and SVGs).
|
|
18
|
+
5. **Configuring `components.json`** with `"tsx": false` so shadcn generates `.jsx` and `utils.js` files rather than TypeScript.
|
|
19
|
+
|
|
20
|
+
`create-shadcn-js` takes care of all of this automatically with an interactive CLI powered by [`@clack/prompts`](https://github.com/natemoo-re/clack).
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
Run any of the following in your terminal:
|
|
27
|
+
|
|
28
|
+
### With `npx`:
|
|
29
|
+
```bash
|
|
30
|
+
npx create-shadcn-js@latest
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### With `npm`:
|
|
34
|
+
```bash
|
|
35
|
+
npm create shadcn-js@latest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### With `pnpm`:
|
|
39
|
+
```bash
|
|
40
|
+
pnpm create shadcn-js
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With `bun`:
|
|
44
|
+
```bash
|
|
45
|
+
bun create shadcn-js
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- **Vite + React (JavaScript)**: Fast HMR and build speeds using standard `.jsx`.
|
|
53
|
+
- **Tailwind CSS v4 & v3**: Defaults to the new Tailwind CSS v4 (`@tailwindcss/vite`), with support for Tailwind CSS v3.
|
|
54
|
+
- **Seamless shadcn/ui Integration**: Directly hands off to the official `shadcn@latest init` wizard so you can pick your preferred primitive library (**Base UI**, **Radix UI**, or **React Aria**), presets (**Nova**, **Vega**, etc.), and color palettes.
|
|
55
|
+
- **Auto-Configured Path Aliases**: Generates `jsconfig.json` and updates `vite.config.js` with `@/*` mapping out of the box.
|
|
56
|
+
- **Clean Slate**: Automatically removes conflicting default Vite styles and sets up a responsive `index.html` with clean typography.
|
|
57
|
+
- **Interactive Showcase Demo**: Optionally installs a starter `Button` component and an interactive dark/light mode demo in `src/App.jsx`.
|
|
58
|
+
- **CLI Flags for CI/Automation**: Supports non-interactive `-y` / `--yes` mode, preset flags, and custom package managers.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## CLI Usage & Options
|
|
63
|
+
|
|
64
|
+
You can specify the project name directly or pass command-line options:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npx create-shadcn-js [project-name] [options]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Options:
|
|
71
|
+
|
|
72
|
+
| Flag | Description | Default |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| `[project-name]` | Name of the project directory to create | Prompted (`my-shadcn-app`) |
|
|
75
|
+
| `--pm <manager>` | Package manager to use (`npm`, `pnpm`, `yarn`, `bun`) | Auto-detected |
|
|
76
|
+
| `-t, --tailwind <v>` | Tailwind version (`v4` or `v3`) | `v4` |
|
|
77
|
+
| `-m, --mode <mode>` | Init mode (`interactive` or `quickstart`) | `interactive` |
|
|
78
|
+
| `-b, --base <base>` | Component library (`base`, `radix`, `aria`) | User selection |
|
|
79
|
+
| `-p, --preset <preset>` | Style preset (`nova`, `vega`, `maia`, etc.) | User selection |
|
|
80
|
+
| `-y, --yes` | Skip interactive prompts and use recommended defaults | `false` |
|
|
81
|
+
| `-f, --force` | Overwrite existing directory without confirmation | `false` |
|
|
82
|
+
| `--no-sample` | Skip installing sample starter Button component | `false` |
|
|
83
|
+
| `--no-git` | Skip initializing a Git repository | `false` |
|
|
84
|
+
| `-v, --version` | Output CLI version | — |
|
|
85
|
+
| `-h, --help` | Display help screen | — |
|
|
86
|
+
|
|
87
|
+
### Examples:
|
|
88
|
+
|
|
89
|
+
#### 1. Interactive Wizard (Recommended)
|
|
90
|
+
```bash
|
|
91
|
+
npx create-shadcn-js
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### 2. Create in a Specific Directory
|
|
95
|
+
```bash
|
|
96
|
+
npx create-shadcn-js my-dashboard
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### 3. Quick Non-Interactive Setup (Fast CI / Demo)
|
|
100
|
+
```bash
|
|
101
|
+
npx create-shadcn-js my-app -y
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 4. Custom Preset with pnpm and Tailwind v4
|
|
105
|
+
```bash
|
|
106
|
+
npx create-shadcn-js my-app --pm pnpm --base radix --preset nova -y
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## What the Generated Project Looks Like
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
my-shadcn-app/
|
|
115
|
+
├── index.html # Pre-configured viewport and Geist font
|
|
116
|
+
├── jsconfig.json # {"paths": {"@/*": ["./src/*"]}}
|
|
117
|
+
├── vite.config.js # Vite config with @ alias & Tailwind v4 plugin
|
|
118
|
+
├── components.json # Configured with "tsx": false for JavaScript
|
|
119
|
+
├── package.json
|
|
120
|
+
├── src/
|
|
121
|
+
│ ├── components/
|
|
122
|
+
│ │ └── ui/
|
|
123
|
+
│ │ └── button.jsx # (Optional starter component)
|
|
124
|
+
│ ├── lib/
|
|
125
|
+
│ │ └── utils.js # cn() helper function
|
|
126
|
+
│ ├── App.jsx # Interactive demo with Dark Mode toggle
|
|
127
|
+
│ ├── index.css # Clean Tailwind CSS theme variables
|
|
128
|
+
│ └── main.jsx
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Adding More Components
|
|
134
|
+
|
|
135
|
+
Once your project is created, simply `cd` into your project and use the official shadcn CLI as usual:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
cd my-shadcn-app
|
|
139
|
+
npx shadcn@latest add dialog dropdown-menu input card avatar table
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Components will automatically be added as `.jsx` files inside `src/components/ui/`!
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Contributing
|
|
147
|
+
|
|
148
|
+
Contributions, issues, and feature requests are welcome!
|
|
149
|
+
|
|
150
|
+
1. Fork the repository
|
|
151
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
152
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
153
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
154
|
+
5. Open a Pull Request
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
[MIT](LICENSE) © 2026 create-shadcn-js
|
package/bin/cli.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-shadcn-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a Vite + React + shadcn/ui JavaScript project with zero manual configuration.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-shadcn-js": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./src/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "node ./bin/cli.js",
|
|
18
|
+
"test": "node ./bin/cli.js --help"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Skandan-V/create-shadcn-js.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"create-shadcn-js",
|
|
26
|
+
"shadcn",
|
|
27
|
+
"shadcn-ui",
|
|
28
|
+
"vite",
|
|
29
|
+
"react",
|
|
30
|
+
"javascript",
|
|
31
|
+
"jsx",
|
|
32
|
+
"tailwind",
|
|
33
|
+
"tailwindcss",
|
|
34
|
+
"cli",
|
|
35
|
+
"scaffold",
|
|
36
|
+
"clack"
|
|
37
|
+
],
|
|
38
|
+
"author": "Skandan-V <skandan.studio4as@gmail.com>",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/Skandan-V/create-shadcn-js/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/Skandan-V/create-shadcn-js#readme",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@clack/prompts": "^0.9.1",
|
|
49
|
+
"commander": "^13.1.0",
|
|
50
|
+
"cross-spawn": "^7.0.6",
|
|
51
|
+
"fs-extra": "^11.3.0",
|
|
52
|
+
"picocolors": "^1.1.1"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import fs from "fs-extra"
|
|
3
|
+
import * as p from "@clack/prompts"
|
|
4
|
+
import pc from "picocolors"
|
|
5
|
+
import { Command } from "commander"
|
|
6
|
+
import { runInteractivePrompts } from "./prompts.js"
|
|
7
|
+
import { scaffoldProject } from "./scaffold.js"
|
|
8
|
+
import { initShadcn, addComponents } from "./shadcn.js"
|
|
9
|
+
import { runCommandOutput, formatPath } from "./utils.js"
|
|
10
|
+
|
|
11
|
+
// Package metadata
|
|
12
|
+
const packageJson = fs.readJsonSync(
|
|
13
|
+
new URL("../package.json", import.meta.url)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initializes Git repository in target directory.
|
|
18
|
+
* @param {string} targetDir
|
|
19
|
+
*/
|
|
20
|
+
function initializeGit(targetDir) {
|
|
21
|
+
try {
|
|
22
|
+
if (!fs.existsSync(path.join(targetDir, ".git"))) {
|
|
23
|
+
runCommandOutput("git", ["init"], { cwd: targetDir })
|
|
24
|
+
runCommandOutput("git", ["add", "-A"], { cwd: targetDir })
|
|
25
|
+
runCommandOutput("git", ["commit", "-m", "Initial commit from create-shadcn-js"], {
|
|
26
|
+
cwd: targetDir,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
// Non-fatal if Git is not installed or configured
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Main CLI runner.
|
|
36
|
+
*/
|
|
37
|
+
export async function run() {
|
|
38
|
+
const program = new Command()
|
|
39
|
+
|
|
40
|
+
program
|
|
41
|
+
.name("create-shadcn-js")
|
|
42
|
+
.description("Scaffold a Vite + React + shadcn/ui JavaScript project with zero manual setup")
|
|
43
|
+
.version(packageJson.version, "-v, --version", "Output the current version")
|
|
44
|
+
.argument("[project-name]", "Name of the project directory")
|
|
45
|
+
.option("--pm <manager>", "Package manager to use (npm, pnpm, yarn, bun)")
|
|
46
|
+
.option("-t, --tailwind <version>", "Tailwind CSS version (v4, v3)", "v4")
|
|
47
|
+
.option("-m, --mode <mode>", "shadcn init mode (interactive, quickstart)")
|
|
48
|
+
.option("-b, --base <base>", "Component library (base, radix, aria)")
|
|
49
|
+
.option("-p, --preset <preset>", "shadcn preset (nova, vega, maia, etc.)")
|
|
50
|
+
.option("--no-sample", "Skip installing sample components")
|
|
51
|
+
.option("--no-git", "Skip initializing a git repository")
|
|
52
|
+
.option("-y, --yes", "Skip interactive prompts and use defaults")
|
|
53
|
+
.option("-f, --force", "Overwrite existing directory without prompt")
|
|
54
|
+
.parse(process.argv)
|
|
55
|
+
|
|
56
|
+
const args = program.args
|
|
57
|
+
const opts = program.opts()
|
|
58
|
+
|
|
59
|
+
const cliOptions = {
|
|
60
|
+
name: args[0],
|
|
61
|
+
pm: opts.pm,
|
|
62
|
+
tailwind: opts.tailwind,
|
|
63
|
+
mode: opts.mode,
|
|
64
|
+
base: opts.base,
|
|
65
|
+
preset: opts.preset,
|
|
66
|
+
sampleComponents: opts.sample === false ? false : undefined,
|
|
67
|
+
git: opts.git === false ? false : undefined,
|
|
68
|
+
force: opts.force || false,
|
|
69
|
+
yes: opts.yes || false,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// If -y / --yes is passed, supply defaults for any missing arguments
|
|
73
|
+
if (cliOptions.yes) {
|
|
74
|
+
cliOptions.name = cliOptions.name || "my-shadcn-app"
|
|
75
|
+
cliOptions.pm = cliOptions.pm || "npm"
|
|
76
|
+
cliOptions.tailwind = cliOptions.tailwind || "v4"
|
|
77
|
+
cliOptions.mode = cliOptions.mode || "quickstart"
|
|
78
|
+
cliOptions.sampleComponents = cliOptions.sampleComponents ?? true
|
|
79
|
+
cliOptions.git = cliOptions.git ?? true
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
// 1. Run interactive prompts (or resolve defaults)
|
|
84
|
+
const answers = await runInteractivePrompts(cliOptions)
|
|
85
|
+
|
|
86
|
+
// 2. Scaffold Vite React JavaScript project with Tailwind and Aliases
|
|
87
|
+
await scaffoldProject({
|
|
88
|
+
projectName: answers.projectName,
|
|
89
|
+
targetDir: answers.targetDir,
|
|
90
|
+
packageManager: answers.packageManager,
|
|
91
|
+
tailwindVersion: answers.tailwindVersion,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// 3. Initialize shadcn/ui (custom interactive or quickstart)
|
|
95
|
+
await initShadcn({
|
|
96
|
+
targetDir: answers.targetDir,
|
|
97
|
+
packageManager: answers.packageManager,
|
|
98
|
+
initMode: answers.initMode,
|
|
99
|
+
nonInteractive: cliOptions.yes,
|
|
100
|
+
base: cliOptions.base,
|
|
101
|
+
preset: cliOptions.preset,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// 4. Optionally install sample components and starter demo
|
|
105
|
+
if (answers.addSampleComponents) {
|
|
106
|
+
await addComponents({
|
|
107
|
+
targetDir: answers.targetDir,
|
|
108
|
+
packageManager: answers.packageManager,
|
|
109
|
+
components: ["button"],
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 5. Optionally initialize Git repository
|
|
114
|
+
if (answers.initGit) {
|
|
115
|
+
initializeGit(answers.targetDir)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 6. Success message and next steps
|
|
119
|
+
const relPath = formatPath(answers.targetDir)
|
|
120
|
+
const cdCmd = relPath === "." ? "" : `cd ${relPath}\n `
|
|
121
|
+
const devCmd =
|
|
122
|
+
answers.packageManager === "npm"
|
|
123
|
+
? "npm run dev"
|
|
124
|
+
: `${answers.packageManager} dev`
|
|
125
|
+
const addCmd =
|
|
126
|
+
answers.packageManager === "npm"
|
|
127
|
+
? "npx shadcn@latest add <component>"
|
|
128
|
+
: answers.packageManager === "pnpm"
|
|
129
|
+
? "pnpm dlx shadcn@latest add <component>"
|
|
130
|
+
: answers.packageManager === "bun"
|
|
131
|
+
? "bunx --bun shadcn@latest add <component>"
|
|
132
|
+
: "yarn dlx shadcn@latest add <component>"
|
|
133
|
+
|
|
134
|
+
p.note(
|
|
135
|
+
`${pc.bold("Next steps:")}\n\n` +
|
|
136
|
+
` ${pc.cyan(cdCmd + devCmd)}\n\n` +
|
|
137
|
+
`${pc.bold("Add shadcn components anytime:")}\n\n` +
|
|
138
|
+
` ${pc.cyan(addCmd)}`,
|
|
139
|
+
"🎉 Project ready!"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
p.outro(
|
|
143
|
+
`${pc.green("All set!")} Happy hacking with ${pc.bold("Vite")}, ${pc.bold("JavaScript")}, and ${pc.bold("shadcn/ui")}! 🚀`
|
|
144
|
+
)
|
|
145
|
+
} catch (error) {
|
|
146
|
+
p.cancel(`Error: ${error.message}`)
|
|
147
|
+
process.exit(1)
|
|
148
|
+
}
|
|
149
|
+
}
|
package/src/prompts.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as p from "@clack/prompts"
|
|
2
|
+
import pc from "picocolors"
|
|
3
|
+
import fs from "fs-extra"
|
|
4
|
+
import path from "node:path"
|
|
5
|
+
import { detectPackageManager, validateProjectName } from "./utils.js"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Handles all interactive CLI prompts using @clack/prompts.
|
|
9
|
+
* @param {object} cliOptions
|
|
10
|
+
* @returns {Promise<object>}
|
|
11
|
+
*/
|
|
12
|
+
export async function runInteractivePrompts(cliOptions = {}) {
|
|
13
|
+
p.intro(`${pc.bgCyan(pc.black(" create-shadcn-js "))} ${pc.dim("v1.0.0")}`)
|
|
14
|
+
|
|
15
|
+
// 1. Project name / directory
|
|
16
|
+
let projectName = cliOptions.name
|
|
17
|
+
if (!projectName) {
|
|
18
|
+
const defaultName = "my-shadcn-app"
|
|
19
|
+
const response = await p.text({
|
|
20
|
+
message: "What is your project named?",
|
|
21
|
+
placeholder: defaultName,
|
|
22
|
+
defaultValue: defaultName,
|
|
23
|
+
validate: (value) => {
|
|
24
|
+
const val = value.trim() || defaultName
|
|
25
|
+
const res = validateProjectName(val)
|
|
26
|
+
return typeof res === "string" ? res : undefined
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
if (p.isCancel(response)) {
|
|
31
|
+
p.cancel("Operation cancelled by user.")
|
|
32
|
+
process.exit(0)
|
|
33
|
+
}
|
|
34
|
+
projectName = response.trim() || defaultName
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const targetDir = path.resolve(process.cwd(), projectName)
|
|
38
|
+
|
|
39
|
+
// Check if directory exists and is not empty
|
|
40
|
+
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
41
|
+
if (!cliOptions.force) {
|
|
42
|
+
const overwrite = await p.confirm({
|
|
43
|
+
message: `Target directory "${projectName}" is not empty. Remove existing files and continue?`,
|
|
44
|
+
initialValue: false,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
if (p.isCancel(overwrite) || !overwrite) {
|
|
48
|
+
p.cancel("Setup aborted. Please choose an empty directory or rename your project.")
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 2. Package manager selection
|
|
55
|
+
let packageManager = cliOptions.pm
|
|
56
|
+
if (!packageManager) {
|
|
57
|
+
const detectedPm = detectPackageManager()
|
|
58
|
+
const pmResponse = await p.select({
|
|
59
|
+
message: "Which package manager do you want to use?",
|
|
60
|
+
initialValue: detectedPm,
|
|
61
|
+
options: [
|
|
62
|
+
{ value: "npm", label: "npm", hint: detectedPm === "npm" ? "detected" : undefined },
|
|
63
|
+
{ value: "pnpm", label: "pnpm", hint: detectedPm === "pnpm" ? "detected" : undefined },
|
|
64
|
+
{ value: "bun", label: "bun", hint: detectedPm === "bun" ? "detected" : undefined },
|
|
65
|
+
{ value: "yarn", label: "yarn", hint: detectedPm === "yarn" ? "detected" : undefined },
|
|
66
|
+
],
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (p.isCancel(pmResponse)) {
|
|
70
|
+
p.cancel("Operation cancelled by user.")
|
|
71
|
+
process.exit(0)
|
|
72
|
+
}
|
|
73
|
+
packageManager = pmResponse
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 3. Tailwind CSS version selection
|
|
77
|
+
let tailwindVersion = cliOptions.tailwind
|
|
78
|
+
if (!tailwindVersion) {
|
|
79
|
+
const twResponse = await p.select({
|
|
80
|
+
message: "Which Tailwind CSS version would you like to use?",
|
|
81
|
+
initialValue: "v4",
|
|
82
|
+
options: [
|
|
83
|
+
{
|
|
84
|
+
value: "v4",
|
|
85
|
+
label: "Tailwind CSS v4",
|
|
86
|
+
hint: "Recommended: Vite plugin, CSS-first, zero config",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
value: "v3",
|
|
90
|
+
label: "Tailwind CSS v3",
|
|
91
|
+
hint: "Classic: tailwind.config.js & postcss.config.js",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
if (p.isCancel(twResponse)) {
|
|
97
|
+
p.cancel("Operation cancelled by user.")
|
|
98
|
+
process.exit(0)
|
|
99
|
+
}
|
|
100
|
+
tailwindVersion = twResponse
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 4. shadcn/ui initialization mode
|
|
104
|
+
let initMode = cliOptions.mode
|
|
105
|
+
if (!initMode) {
|
|
106
|
+
const modeResponse = await p.select({
|
|
107
|
+
message: "How would you like to configure shadcn/ui?",
|
|
108
|
+
initialValue: "interactive",
|
|
109
|
+
options: [
|
|
110
|
+
{
|
|
111
|
+
value: "interactive",
|
|
112
|
+
label: "Interactive shadcn CLI",
|
|
113
|
+
hint: "Select component library (Radix/Base), style presets, and colors directly in shadcn CLI",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
value: "quickstart",
|
|
117
|
+
label: "Quickstart Preset",
|
|
118
|
+
hint: "Auto-configured with Radix UI + Nova style (Lucide icons)",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if (p.isCancel(modeResponse)) {
|
|
124
|
+
p.cancel("Operation cancelled by user.")
|
|
125
|
+
process.exit(0)
|
|
126
|
+
}
|
|
127
|
+
initMode = modeResponse
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 5. Sample components
|
|
131
|
+
let addSampleComponents = cliOptions.sampleComponents
|
|
132
|
+
if (addSampleComponents === undefined) {
|
|
133
|
+
const sampleResponse = await p.confirm({
|
|
134
|
+
message: "Would you like to install the starter Button component and interactive showcase demo?",
|
|
135
|
+
initialValue: true,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
if (p.isCancel(sampleResponse)) {
|
|
139
|
+
p.cancel("Operation cancelled by user.")
|
|
140
|
+
process.exit(0)
|
|
141
|
+
}
|
|
142
|
+
addSampleComponents = sampleResponse
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 6. Git initialization
|
|
146
|
+
let initGit = cliOptions.git
|
|
147
|
+
if (initGit === undefined) {
|
|
148
|
+
const gitResponse = await p.confirm({
|
|
149
|
+
message: "Initialize a new Git repository?",
|
|
150
|
+
initialValue: true,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
if (p.isCancel(gitResponse)) {
|
|
154
|
+
p.cancel("Operation cancelled by user.")
|
|
155
|
+
process.exit(0)
|
|
156
|
+
}
|
|
157
|
+
initGit = gitResponse
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
projectName,
|
|
162
|
+
targetDir,
|
|
163
|
+
packageManager,
|
|
164
|
+
tailwindVersion,
|
|
165
|
+
initMode,
|
|
166
|
+
addSampleComponents,
|
|
167
|
+
initGit,
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/scaffold.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from "fs-extra"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
import * as p from "@clack/prompts"
|
|
4
|
+
import pc from "picocolors"
|
|
5
|
+
import { getPackageManagerCommands, runCommandSync, runCommandOutput } from "./utils.js"
|
|
6
|
+
import {
|
|
7
|
+
getJsConfig,
|
|
8
|
+
getViteConfig,
|
|
9
|
+
getTailwindConfigV3,
|
|
10
|
+
getPostcssConfigV3,
|
|
11
|
+
getIndexHtml,
|
|
12
|
+
} from "./templates/configs.js"
|
|
13
|
+
import { getIndexCss } from "./templates/indexCss.js"
|
|
14
|
+
import { getAppJsx } from "./templates/app.js"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Scaffolds the base Vite + React (JavaScript) project.
|
|
18
|
+
* @param {object} options
|
|
19
|
+
*/
|
|
20
|
+
export async function scaffoldProject({
|
|
21
|
+
projectName,
|
|
22
|
+
targetDir,
|
|
23
|
+
packageManager,
|
|
24
|
+
tailwindVersion,
|
|
25
|
+
}) {
|
|
26
|
+
const spinner = p.spinner()
|
|
27
|
+
|
|
28
|
+
// 1. Prepare directory
|
|
29
|
+
if (fs.existsSync(targetDir)) {
|
|
30
|
+
fs.emptyDirSync(targetDir)
|
|
31
|
+
} else {
|
|
32
|
+
fs.ensureDirSync(targetDir)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 2. Scaffold Vite React JavaScript template
|
|
36
|
+
spinner.start("Scaffolding Vite React JavaScript project...")
|
|
37
|
+
try {
|
|
38
|
+
const parentDir = path.dirname(targetDir)
|
|
39
|
+
const folderName = path.basename(targetDir)
|
|
40
|
+
|
|
41
|
+
// Run create-vite to generate template
|
|
42
|
+
runCommandOutput(
|
|
43
|
+
"npx",
|
|
44
|
+
["--yes", "create-vite@latest", folderName, "--template", "react", "-y"],
|
|
45
|
+
{ cwd: parentDir }
|
|
46
|
+
)
|
|
47
|
+
spinner.stop(`${pc.green("✔")} Vite project scaffolded successfully.`)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
spinner.stop(`${pc.red("✖")} Failed to scaffold Vite project.`)
|
|
50
|
+
throw error
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const pmCmds = getPackageManagerCommands(packageManager)
|
|
54
|
+
|
|
55
|
+
// 3. Install base dependencies
|
|
56
|
+
spinner.start(`Installing project dependencies with ${pc.cyan(packageManager)}...`)
|
|
57
|
+
try {
|
|
58
|
+
const [installBin, installArgs] = pmCmds.install
|
|
59
|
+
runCommandOutput(installBin, installArgs, { cwd: targetDir })
|
|
60
|
+
spinner.stop(`${pc.green("✔")} Dependencies installed.`)
|
|
61
|
+
} catch (error) {
|
|
62
|
+
spinner.stop(`${pc.red("✖")} Failed to install dependencies.`)
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 4. Install Tailwind CSS dependencies
|
|
67
|
+
const tailwindDeps =
|
|
68
|
+
tailwindVersion === "v4"
|
|
69
|
+
? ["tailwindcss", "@tailwindcss/vite"]
|
|
70
|
+
: ["tailwindcss", "postcss", "autoprefixer"]
|
|
71
|
+
|
|
72
|
+
spinner.start(`Installing Tailwind CSS (${tailwindVersion}) dependencies...`)
|
|
73
|
+
try {
|
|
74
|
+
const [addBin, addArgs] = pmCmds.add(tailwindDeps, false)
|
|
75
|
+
runCommandOutput(addBin, addArgs, { cwd: targetDir })
|
|
76
|
+
spinner.stop(`${pc.green("✔")} Tailwind CSS (${tailwindVersion}) installed.`)
|
|
77
|
+
} catch (error) {
|
|
78
|
+
spinner.stop(`${pc.red("✖")} Failed to install Tailwind CSS dependencies.`)
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 5. Configure project files
|
|
83
|
+
spinner.start("Configuring path aliases and build configurations...")
|
|
84
|
+
try {
|
|
85
|
+
// Write jsconfig.json
|
|
86
|
+
fs.writeFileSync(path.join(targetDir, "jsconfig.json"), getJsConfig(), "utf-8")
|
|
87
|
+
|
|
88
|
+
// Write vite.config.js
|
|
89
|
+
fs.writeFileSync(
|
|
90
|
+
path.join(targetDir, "vite.config.js"),
|
|
91
|
+
getViteConfig(tailwindVersion),
|
|
92
|
+
"utf-8"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
// For Tailwind v3, write config files
|
|
96
|
+
if (tailwindVersion === "v3") {
|
|
97
|
+
fs.writeFileSync(
|
|
98
|
+
path.join(targetDir, "tailwind.config.js"),
|
|
99
|
+
getTailwindConfigV3(),
|
|
100
|
+
"utf-8"
|
|
101
|
+
)
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(targetDir, "postcss.config.js"),
|
|
104
|
+
getPostcssConfigV3(),
|
|
105
|
+
"utf-8"
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Write src/index.css
|
|
110
|
+
fs.writeFileSync(
|
|
111
|
+
path.join(targetDir, "src", "index.css"),
|
|
112
|
+
getIndexCss(tailwindVersion),
|
|
113
|
+
"utf-8"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
// Remove src/App.css if present to avoid conflicting default styles
|
|
117
|
+
const appCssPath = path.join(targetDir, "src", "App.css")
|
|
118
|
+
if (fs.existsSync(appCssPath)) {
|
|
119
|
+
fs.removeSync(appCssPath)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Remove App.css import from App.jsx or main.jsx if it exists
|
|
123
|
+
const mainJsxPath = path.join(targetDir, "src", "main.jsx")
|
|
124
|
+
if (fs.existsSync(mainJsxPath)) {
|
|
125
|
+
let mainContent = fs.readFileSync(mainJsxPath, "utf-8")
|
|
126
|
+
mainContent = mainContent.replace(/import\s+['"]\.\/App\.css['"];?\n?/, "")
|
|
127
|
+
fs.writeFileSync(mainJsxPath, mainContent, "utf-8")
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Update index.html title
|
|
131
|
+
const indexHtmlPath = path.join(targetDir, "index.html")
|
|
132
|
+
if (fs.existsSync(indexHtmlPath)) {
|
|
133
|
+
fs.writeFileSync(indexHtmlPath, getIndexHtml(projectName), "utf-8")
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Write clean initial App.jsx
|
|
137
|
+
fs.writeFileSync(
|
|
138
|
+
path.join(targetDir, "src", "App.jsx"),
|
|
139
|
+
getAppJsx({ hasButton: false }),
|
|
140
|
+
"utf-8"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
spinner.stop(`${pc.green("✔")} Project configurations applied.`)
|
|
144
|
+
} catch (error) {
|
|
145
|
+
spinner.stop(`${pc.red("✖")} Failed to write configuration files.`)
|
|
146
|
+
throw error
|
|
147
|
+
}
|
|
148
|
+
}
|
package/src/shadcn.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from "fs-extra"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
import * as p from "@clack/prompts"
|
|
4
|
+
import pc from "picocolors"
|
|
5
|
+
import { getPackageManagerCommands, runCommandSync, runCommandOutput } from "./utils.js"
|
|
6
|
+
import { getAppJsx } from "./templates/app.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Initializes shadcn/ui in the scaffolded project.
|
|
10
|
+
* @param {object} options
|
|
11
|
+
*/
|
|
12
|
+
export async function initShadcn({
|
|
13
|
+
targetDir,
|
|
14
|
+
packageManager,
|
|
15
|
+
initMode = "interactive",
|
|
16
|
+
nonInteractive = false,
|
|
17
|
+
base,
|
|
18
|
+
preset,
|
|
19
|
+
}) {
|
|
20
|
+
const pmCmds = getPackageManagerCommands(packageManager)
|
|
21
|
+
|
|
22
|
+
if (initMode === "interactive" && !nonInteractive) {
|
|
23
|
+
p.log.step(`${pc.cyan("◆")} Launching official shadcn/ui CLI...`)
|
|
24
|
+
p.log.message(
|
|
25
|
+
pc.dim(" Select your component library, preset, and styles below:\n")
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const initArgs = ["init", "--no-monorepo"]
|
|
30
|
+
if (base) initArgs.push("-b", base)
|
|
31
|
+
if (preset) initArgs.push("-p", preset)
|
|
32
|
+
|
|
33
|
+
// Run shadcn init interactively with inherited stdio
|
|
34
|
+
const [runnerBin, runnerArgs] = pmCmds.dlx("shadcn@latest", initArgs)
|
|
35
|
+
runCommandSync(runnerBin, runnerArgs, { cwd: targetDir })
|
|
36
|
+
} catch (error) {
|
|
37
|
+
p.log.warn(
|
|
38
|
+
pc.yellow("Notice: shadcn init encountered an issue or was exited. Checking configuration...")
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
// Quickstart / non-interactive preset
|
|
43
|
+
const selectedBase = base || "radix"
|
|
44
|
+
const selectedPreset = preset || "nova"
|
|
45
|
+
const spinner = p.spinner()
|
|
46
|
+
spinner.start(`Initializing shadcn/ui with ${selectedBase} library & ${selectedPreset} preset...`)
|
|
47
|
+
try {
|
|
48
|
+
const [runnerBin, runnerArgs] = pmCmds.dlx("shadcn@latest", [
|
|
49
|
+
"init",
|
|
50
|
+
"--no-monorepo",
|
|
51
|
+
"-b",
|
|
52
|
+
selectedBase,
|
|
53
|
+
"-p",
|
|
54
|
+
selectedPreset,
|
|
55
|
+
"-y",
|
|
56
|
+
])
|
|
57
|
+
runCommandOutput(runnerBin, runnerArgs, { cwd: targetDir })
|
|
58
|
+
spinner.stop(`${pc.green("✔")} shadcn/ui initialized.`)
|
|
59
|
+
} catch (error) {
|
|
60
|
+
spinner.stop(`${pc.red("✖")} Failed to initialize shadcn/ui in quickstart mode.`)
|
|
61
|
+
throw error
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Ensure components.json tsx is set to false for pure JavaScript
|
|
66
|
+
const componentsJsonPath = path.join(targetDir, "components.json")
|
|
67
|
+
if (fs.existsSync(componentsJsonPath)) {
|
|
68
|
+
try {
|
|
69
|
+
const compJson = fs.readJsonSync(componentsJsonPath)
|
|
70
|
+
if (compJson.tsx !== false) {
|
|
71
|
+
compJson.tsx = false
|
|
72
|
+
fs.writeJsonSync(componentsJsonPath, compJson, { spaces: 2 })
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// Ignore JSON parse errors if file is being written
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Adds default components to the project.
|
|
82
|
+
* @param {object} options
|
|
83
|
+
*/
|
|
84
|
+
export async function addComponents({ targetDir, packageManager, components = ["button"] }) {
|
|
85
|
+
if (!components || components.length === 0) return
|
|
86
|
+
|
|
87
|
+
const spinner = p.spinner()
|
|
88
|
+
spinner.start(`Adding shadcn component(s): ${pc.cyan(components.join(", "))}...`)
|
|
89
|
+
|
|
90
|
+
const pmCmds = getPackageManagerCommands(packageManager)
|
|
91
|
+
try {
|
|
92
|
+
const [runnerBin, runnerArgs] = pmCmds.dlx("shadcn@latest", ["add", ...components, "-y"])
|
|
93
|
+
runCommandOutput(runnerBin, runnerArgs, { cwd: targetDir })
|
|
94
|
+
spinner.stop(`${pc.green("✔")} Added component(s): ${pc.cyan(components.join(", "))}`)
|
|
95
|
+
|
|
96
|
+
// Update App.jsx with interactive component showcase
|
|
97
|
+
const hasButton = components.includes("button")
|
|
98
|
+
const appJsxPath = path.join(targetDir, "src", "App.jsx")
|
|
99
|
+
fs.writeFileSync(appJsxPath, getAppJsx({ hasButton }), "utf-8")
|
|
100
|
+
} catch (error) {
|
|
101
|
+
spinner.stop(
|
|
102
|
+
`${pc.yellow("⚠")} Could not automatically add ${components.join(", ")}. You can add it later via: ${pc.cyan("npx shadcn@latest add " + components.join(" "))}`
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates an interactive, polished App.jsx file.
|
|
3
|
+
* @param {object} options
|
|
4
|
+
* @param {boolean} [options.hasButton=true]
|
|
5
|
+
* @param {boolean} [options.hasCard=false]
|
|
6
|
+
* @param {boolean} [options.hasBadge=false]
|
|
7
|
+
*/
|
|
8
|
+
export function getAppJsx({ hasButton = true, hasCard = false, hasBadge = false } = {}) {
|
|
9
|
+
if (hasButton) {
|
|
10
|
+
return `import { useState, useEffect } from "react"
|
|
11
|
+
import { Button } from "@/components/ui/button"
|
|
12
|
+
|
|
13
|
+
export default function App() {
|
|
14
|
+
const [count, setCount] = useState(0)
|
|
15
|
+
const [isDark, setIsDark] = useState(() => {
|
|
16
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (isDark) {
|
|
21
|
+
document.documentElement.classList.add("dark")
|
|
22
|
+
} else {
|
|
23
|
+
document.documentElement.classList.remove("dark")
|
|
24
|
+
}
|
|
25
|
+
}, [isDark])
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="flex min-h-screen flex-col items-center justify-center p-6 bg-background text-foreground transition-colors duration-200">
|
|
29
|
+
<div className="w-full max-w-2xl space-y-8 text-center">
|
|
30
|
+
{/* Header Badge & Title */}
|
|
31
|
+
<div className="space-y-3">
|
|
32
|
+
<div className="inline-flex items-center gap-2 rounded-full border border-border bg-muted/60 px-3 py-1 text-xs font-medium text-muted-foreground shadow-xs">
|
|
33
|
+
<span className="size-2 rounded-full bg-emerald-500 animate-pulse" />
|
|
34
|
+
Vite + React (JavaScript) + shadcn/ui
|
|
35
|
+
</div>
|
|
36
|
+
<h1 className="text-4xl font-extrabold tracking-tight sm:text-5xl">
|
|
37
|
+
create-shadcn-js
|
|
38
|
+
</h1>
|
|
39
|
+
<p className="text-lg text-muted-foreground max-w-lg mx-auto">
|
|
40
|
+
Zero-config Vite + Tailwind CSS + shadcn/ui setup for JavaScript. Path aliases, configs, and components ready to roll.
|
|
41
|
+
</p>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
{/* Interactive Showcase Card */}
|
|
45
|
+
<div className="rounded-xl border border-border bg-card p-6 shadow-sm space-y-6 text-card-foreground">
|
|
46
|
+
<div className="flex items-center justify-between border-b border-border/60 pb-4">
|
|
47
|
+
<div className="text-left">
|
|
48
|
+
<h2 className="text-sm font-semibold">Interactive Component Demo</h2>
|
|
49
|
+
<p className="text-xs text-muted-foreground">Tailwind CSS theme tokens & Radix/Base primitives</p>
|
|
50
|
+
</div>
|
|
51
|
+
<Button
|
|
52
|
+
variant="outline"
|
|
53
|
+
size="sm"
|
|
54
|
+
onClick={() => setIsDark((prev) => !prev)}
|
|
55
|
+
>
|
|
56
|
+
{isDark ? "Light Mode" : "Dark Mode"}
|
|
57
|
+
</Button>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
{/* Button Variants Preview */}
|
|
61
|
+
<div className="flex flex-wrap items-center justify-center gap-3">
|
|
62
|
+
<Button onClick={() => setCount((c) => c + 1)}>
|
|
63
|
+
Clicked {count} {count === 1 ? "time" : "times"}
|
|
64
|
+
</Button>
|
|
65
|
+
<Button variant="secondary" onClick={() => setCount(0)}>
|
|
66
|
+
Reset Count
|
|
67
|
+
</Button>
|
|
68
|
+
<Button variant="outline">
|
|
69
|
+
Outline
|
|
70
|
+
</Button>
|
|
71
|
+
<Button variant="ghost">
|
|
72
|
+
Ghost
|
|
73
|
+
</Button>
|
|
74
|
+
<Button variant="destructive">
|
|
75
|
+
Destructive
|
|
76
|
+
</Button>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
{/* Code snippet suggestion */}
|
|
80
|
+
<div className="rounded-lg bg-muted/60 p-4 text-left font-mono text-xs text-muted-foreground border border-border/40">
|
|
81
|
+
<p className="text-foreground font-semibold mb-1">Add more components anytime:</p>
|
|
82
|
+
<code>npx shadcn@latest add dialog dropdown-menu input table</code>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
{/* Footer info */}
|
|
87
|
+
<p className="text-xs text-muted-foreground">
|
|
88
|
+
Edit <code className="font-semibold text-foreground">src/App.jsx</code> to start building your application.
|
|
89
|
+
</p>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Fallback when no components installed yet
|
|
98
|
+
return `import { useState, useEffect } from "react"
|
|
99
|
+
|
|
100
|
+
export default function App() {
|
|
101
|
+
const [isDark, setIsDark] = useState(() => {
|
|
102
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (isDark) {
|
|
107
|
+
document.documentElement.classList.add("dark")
|
|
108
|
+
} else {
|
|
109
|
+
document.documentElement.classList.remove("dark")
|
|
110
|
+
}
|
|
111
|
+
}, [isDark])
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div className="flex min-h-screen flex-col items-center justify-center p-6 bg-background text-foreground transition-colors duration-200">
|
|
115
|
+
<div className="w-full max-w-xl space-y-6 text-center">
|
|
116
|
+
<div className="inline-flex items-center gap-2 rounded-full border border-border bg-muted/60 px-3 py-1 text-xs font-medium text-muted-foreground shadow-xs">
|
|
117
|
+
<span className="size-2 rounded-full bg-emerald-500 animate-pulse" />
|
|
118
|
+
Vite + React (JavaScript) + shadcn/ui Ready
|
|
119
|
+
</div>
|
|
120
|
+
<h1 className="text-4xl font-extrabold tracking-tight">
|
|
121
|
+
create-shadcn-js
|
|
122
|
+
</h1>
|
|
123
|
+
<p className="text-base text-muted-foreground">
|
|
124
|
+
Your project is fully configured with Tailwind CSS, jsconfig.json, and shadcn/ui.
|
|
125
|
+
</p>
|
|
126
|
+
<div className="rounded-xl border border-border bg-card p-6 shadow-sm text-left font-mono text-xs text-muted-foreground space-y-2">
|
|
127
|
+
<p className="text-foreground font-semibold">Add your first shadcn component:</p>
|
|
128
|
+
<div className="p-3 bg-muted rounded-md text-foreground">
|
|
129
|
+
<code>npx shadcn@latest add button</code>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
`
|
|
137
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates jsconfig.json content for path alias support in Vite + React JS.
|
|
3
|
+
*/
|
|
4
|
+
export function getJsConfig() {
|
|
5
|
+
return JSON.stringify(
|
|
6
|
+
{
|
|
7
|
+
compilerOptions: {
|
|
8
|
+
baseUrl: ".",
|
|
9
|
+
paths: {
|
|
10
|
+
"@/*": ["./src/*"]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
null,
|
|
15
|
+
2
|
|
16
|
+
) + "\n"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generates vite.config.js content.
|
|
21
|
+
* @param {'v4' | 'v3'} tailwindVersion
|
|
22
|
+
*/
|
|
23
|
+
export function getViteConfig(tailwindVersion = "v4") {
|
|
24
|
+
if (tailwindVersion === "v4") {
|
|
25
|
+
return `import path from "node:path"
|
|
26
|
+
import { fileURLToPath } from "node:url"
|
|
27
|
+
import tailwindcss from "@tailwindcss/vite"
|
|
28
|
+
import react from "@vitejs/plugin-react"
|
|
29
|
+
import { defineConfig } from "vite"
|
|
30
|
+
|
|
31
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
32
|
+
|
|
33
|
+
// https://vite.dev/config/
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [react(), tailwindcss()],
|
|
36
|
+
resolve: {
|
|
37
|
+
alias: {
|
|
38
|
+
"@": path.resolve(__dirname, "./src"),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Tailwind v3 (uses PostCSS plugin)
|
|
46
|
+
return `import path from "node:path"
|
|
47
|
+
import { fileURLToPath } from "node:url"
|
|
48
|
+
import react from "@vitejs/plugin-react"
|
|
49
|
+
import { defineConfig } from "vite"
|
|
50
|
+
|
|
51
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
52
|
+
|
|
53
|
+
// https://vite.dev/config/
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [react()],
|
|
56
|
+
resolve: {
|
|
57
|
+
alias: {
|
|
58
|
+
"@": path.resolve(__dirname, "./src"),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generates tailwind.config.js for Tailwind CSS v3.
|
|
67
|
+
*/
|
|
68
|
+
export function getTailwindConfigV3() {
|
|
69
|
+
return `/** @type {import('tailwindcss').Config} */
|
|
70
|
+
export default {
|
|
71
|
+
darkMode: ["class"],
|
|
72
|
+
content: [
|
|
73
|
+
"./index.html",
|
|
74
|
+
"./src/**/*.{js,ts,jsx,tsx}",
|
|
75
|
+
],
|
|
76
|
+
theme: {
|
|
77
|
+
extend: {
|
|
78
|
+
borderRadius: {
|
|
79
|
+
lg: "var(--radius)",
|
|
80
|
+
md: "calc(var(--radius) - 2px)",
|
|
81
|
+
sm: "calc(var(--radius) - 4px)",
|
|
82
|
+
},
|
|
83
|
+
colors: {},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
plugins: [],
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Generates postcss.config.js for Tailwind CSS v3.
|
|
93
|
+
*/
|
|
94
|
+
export function getPostcssConfigV3() {
|
|
95
|
+
return `export default {
|
|
96
|
+
plugins: {
|
|
97
|
+
tailwindcss: {},
|
|
98
|
+
autoprefixer: {},
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generates a clean index.html with nice typography and titles.
|
|
106
|
+
* @param {string} title
|
|
107
|
+
*/
|
|
108
|
+
export function getIndexHtml(title = "shadcn/ui + Vite") {
|
|
109
|
+
return `<!doctype html>
|
|
110
|
+
<html lang="en">
|
|
111
|
+
<head>
|
|
112
|
+
<meta charset="UTF-8" />
|
|
113
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
114
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
115
|
+
<title>${title}</title>
|
|
116
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
117
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
118
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@100..900&family=Geist+Mono:wght@100..900&display=swap" rel="stylesheet">
|
|
119
|
+
</head>
|
|
120
|
+
<body class="min-h-screen bg-background font-sans antialiased text-foreground">
|
|
121
|
+
<div id="root"></div>
|
|
122
|
+
<script type="module" src="/src/main.jsx"></script>
|
|
123
|
+
</body>
|
|
124
|
+
</html>
|
|
125
|
+
`
|
|
126
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates initial index.css based on Tailwind version.
|
|
3
|
+
* @param {'v4' | 'v3'} tailwindVersion
|
|
4
|
+
*/
|
|
5
|
+
export function getIndexCss(tailwindVersion = "v4") {
|
|
6
|
+
if (tailwindVersion === "v4") {
|
|
7
|
+
return `@import "tailwindcss";
|
|
8
|
+
`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return `@tailwind base;
|
|
12
|
+
@tailwind components;
|
|
13
|
+
@tailwind utilities;
|
|
14
|
+
`
|
|
15
|
+
}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import fs from "fs-extra"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
import spawn from "cross-spawn"
|
|
4
|
+
import pc from "picocolors"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Detects the package manager used to run the CLI.
|
|
8
|
+
* @returns {'npm' | 'pnpm' | 'yarn' | 'bun'}
|
|
9
|
+
*/
|
|
10
|
+
export function detectPackageManager() {
|
|
11
|
+
const userAgent = process.env.npm_config_user_agent || ""
|
|
12
|
+
if (userAgent.startsWith("pnpm")) return "pnpm"
|
|
13
|
+
if (userAgent.startsWith("yarn")) return "yarn"
|
|
14
|
+
if (userAgent.startsWith("bun")) return "bun"
|
|
15
|
+
return "npm"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns package manager execution commands.
|
|
20
|
+
* @param {'npm' | 'pnpm' | 'yarn' | 'bun'} pm
|
|
21
|
+
*/
|
|
22
|
+
export function getPackageManagerCommands(pm) {
|
|
23
|
+
switch (pm) {
|
|
24
|
+
case "pnpm":
|
|
25
|
+
return {
|
|
26
|
+
install: ["pnpm", ["install"]],
|
|
27
|
+
add: (deps, isDev = false) => ["pnpm", ["add", ...(isDev ? ["-D"] : []), ...deps]],
|
|
28
|
+
run: (script) => ["pnpm", [script]],
|
|
29
|
+
dlx: (pkg, args = []) => ["pnpm", ["dlx", pkg, ...args]],
|
|
30
|
+
runner: "pnpm dlx",
|
|
31
|
+
}
|
|
32
|
+
case "yarn":
|
|
33
|
+
return {
|
|
34
|
+
install: ["yarn", []],
|
|
35
|
+
add: (deps, isDev = false) => ["yarn", ["add", ...(isDev ? ["-D"] : []), ...deps]],
|
|
36
|
+
run: (script) => ["yarn", [script]],
|
|
37
|
+
dlx: (pkg, args = []) => ["yarn", ["dlx", pkg, ...args]],
|
|
38
|
+
runner: "yarn dlx",
|
|
39
|
+
}
|
|
40
|
+
case "bun":
|
|
41
|
+
return {
|
|
42
|
+
install: ["bun", ["install"]],
|
|
43
|
+
add: (deps, isDev = false) => ["bun", ["add", ...(isDev ? ["-d"] : []), ...deps]],
|
|
44
|
+
run: (script) => ["bun", ["run", script]],
|
|
45
|
+
dlx: (pkg, args = []) => ["bunx", ["--bun", pkg, ...args]],
|
|
46
|
+
runner: "bunx --bun",
|
|
47
|
+
}
|
|
48
|
+
case "npm":
|
|
49
|
+
default:
|
|
50
|
+
return {
|
|
51
|
+
install: ["npm", ["install"]],
|
|
52
|
+
add: (deps, isDev = false) => ["npm", ["install", ...(isDev ? ["-D"] : []), ...deps]],
|
|
53
|
+
run: (script) => ["npm", ["run", script]],
|
|
54
|
+
dlx: (pkg, args = []) => ["npx", ["--yes", pkg, ...args]],
|
|
55
|
+
runner: "npx",
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Executes a command synchronously with inherited stdio.
|
|
62
|
+
* @param {string} cmd
|
|
63
|
+
* @param {string[]} args
|
|
64
|
+
* @param {import('child_process').SpawnOptions} [options]
|
|
65
|
+
*/
|
|
66
|
+
export function runCommandSync(cmd, args, options = {}) {
|
|
67
|
+
const result = spawn.sync(cmd, args, {
|
|
68
|
+
stdio: "inherit",
|
|
69
|
+
...options,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
if (result.error) {
|
|
73
|
+
throw result.error
|
|
74
|
+
}
|
|
75
|
+
if (result.status !== 0) {
|
|
76
|
+
throw new Error(`Command "${cmd} ${args.join(" ")}" failed with exit code ${result.status}`)
|
|
77
|
+
}
|
|
78
|
+
return result
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Executes a command silently or with custom stdio, returning stdout string.
|
|
83
|
+
* @param {string} cmd
|
|
84
|
+
* @param {string[]} args
|
|
85
|
+
* @param {import('child_process').SpawnOptions} [options]
|
|
86
|
+
*/
|
|
87
|
+
export function runCommandOutput(cmd, args, options = {}) {
|
|
88
|
+
const result = spawn.sync(cmd, args, {
|
|
89
|
+
encoding: "utf-8",
|
|
90
|
+
...options,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
if (result.error) {
|
|
94
|
+
throw result.error
|
|
95
|
+
}
|
|
96
|
+
if (result.status !== 0) {
|
|
97
|
+
const errorMsg = result.stderr ? result.stderr.trim() : `exit code ${result.status}`
|
|
98
|
+
throw new Error(`Command "${cmd} ${args.join(" ")}" failed: ${errorMsg}`)
|
|
99
|
+
}
|
|
100
|
+
return result.stdout ? result.stdout.trim() : ""
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Validates a project directory name.
|
|
105
|
+
* @param {string} name
|
|
106
|
+
* @returns {string | boolean} Returns error message if invalid, or true if valid
|
|
107
|
+
*/
|
|
108
|
+
export function validateProjectName(name) {
|
|
109
|
+
if (!name || name.trim().length === 0) {
|
|
110
|
+
return "Project name cannot be empty."
|
|
111
|
+
}
|
|
112
|
+
const trimmed = name.trim()
|
|
113
|
+
if (/[<>:"/\\|?*]/.test(trimmed)) {
|
|
114
|
+
return "Project name contains invalid characters."
|
|
115
|
+
}
|
|
116
|
+
if (/^[._]/.test(trimmed)) {
|
|
117
|
+
return "Project name cannot start with a dot or underscore."
|
|
118
|
+
}
|
|
119
|
+
return true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Formats a path to display nicely to the user.
|
|
124
|
+
* @param {string} targetPath
|
|
125
|
+
* @returns {string}
|
|
126
|
+
*/
|
|
127
|
+
export function formatPath(targetPath) {
|
|
128
|
+
return path.relative(process.cwd(), targetPath) || "."
|
|
129
|
+
}
|