@cloudwick/astral-ui-cli 0.1.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/README.md +357 -0
- package/dist/index.js +3794 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/constants/index.ts +3 -0
- package/dist/templates/constants/keyboardKey.ts +16 -0
- package/dist/templates/css/variables.css +82 -0
- package/dist/templates/schema/components-config.schema.json +56 -0
- package/dist/templates/utils/cn.ts +13 -0
- package/dist/templates/utils/debounce.tsx +33 -0
- package/dist/templates/utils/findParentAttribute.tsx +23 -0
- package/dist/templates/utils/getElementType.ts +38 -0
- package/dist/templates/utils/index.tsx +7 -0
- package/dist/templates/utils/numberUtils/index.tsx +40 -0
- package/dist/templates/utils/stringUtils/fileSize.tsx +13 -0
- package/dist/templates/utils/stringUtils/getInitials.tsx +22 -0
- package/dist/templates/utils/stringUtils/index.tsx +4 -0
- package/dist/templates/utils/stringUtils/placeholderText.tsx +93 -0
- package/dist/templates/utils/stringUtils/regexSearch.tsx +29 -0
- package/dist/templates/utils/useOnScreen.tsx +22 -0
- package/dist/templates/utils/useWindowSize.ts +33 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# Astral CLI
|
|
2
|
+
|
|
3
|
+
A command-line tool for installing and managing Astral UI components in any codebase.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install globally with npm
|
|
9
|
+
npm install -g @cloudwick/astral-ui-cli
|
|
10
|
+
|
|
11
|
+
# Install globally with yarn
|
|
12
|
+
yarn global add @cloudwick/astral-ui-cli
|
|
13
|
+
|
|
14
|
+
# Or run directly with npx/yarn without installing
|
|
15
|
+
npx @cloudwick/astral-ui-cli init
|
|
16
|
+
# or more simply:
|
|
17
|
+
npx astral-ui init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Initialize your project
|
|
24
|
+
npx astral-ui init
|
|
25
|
+
|
|
26
|
+
# Follow instructions to set up path aliases
|
|
27
|
+
npx astral-ui setup-aliases
|
|
28
|
+
|
|
29
|
+
# Add components
|
|
30
|
+
npx astral-ui add button card
|
|
31
|
+
|
|
32
|
+
# Start using in your code
|
|
33
|
+
import { Button } from '@components/ui/button';
|
|
34
|
+
import { cn } from '@utils';
|
|
35
|
+
import { keyboardKeys, mobileBreakPoint } from '@constants';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Workflow
|
|
39
|
+
|
|
40
|
+
For the best experience, follow these steps in order:
|
|
41
|
+
|
|
42
|
+
1. **Initialize** your project with `astral-ui init`
|
|
43
|
+
2. **Set up path aliases** using `astral-ui setup-aliases` and follow the instructions
|
|
44
|
+
3. **Add components** with `astral-ui add [component...]`
|
|
45
|
+
4. **Repair Tailwind** if needed with `astral-ui repair-tailwind`
|
|
46
|
+
5. **Import and use** components in your application
|
|
47
|
+
|
|
48
|
+
## Commands
|
|
49
|
+
|
|
50
|
+
### `init`
|
|
51
|
+
|
|
52
|
+
Initialize a project with Astral Core configuration.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
astral init
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
This command will:
|
|
59
|
+
- Create a `components.json` configuration file
|
|
60
|
+
- Set up necessary dependencies
|
|
61
|
+
- Install Tailwind CSS if not already present
|
|
62
|
+
- Add required configuration to existing Tailwind config or create a new one
|
|
63
|
+
- Add utility functions
|
|
64
|
+
|
|
65
|
+
#### Options
|
|
66
|
+
|
|
67
|
+
| Option | Alias | Description |
|
|
68
|
+
|--------|-------|-------------|
|
|
69
|
+
| `--yes` | `-y` | Skip confirmation prompts |
|
|
70
|
+
| `--defaults` | `-d` | Use default configuration |
|
|
71
|
+
| `--force` | `-f` | Force overwrite of existing configuration |
|
|
72
|
+
| `--cwd <dir>` | `-c` | Specify the working directory |
|
|
73
|
+
| `--silent` | `-s` | Mute output |
|
|
74
|
+
|
|
75
|
+
### `setup-aliases`
|
|
76
|
+
|
|
77
|
+
Display instructions for setting up path aliases in your project.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
astral setup-aliases
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This command will:
|
|
84
|
+
- Analyze your project structure
|
|
85
|
+
- Detect the type of project (Next.js, Vite, Webpack, etc.)
|
|
86
|
+
- Provide specific instructions for configuring path aliases based on your project type
|
|
87
|
+
- Check for special configurations like tsconfig.app.json (used in Angular projects)
|
|
88
|
+
|
|
89
|
+
#### Options
|
|
90
|
+
|
|
91
|
+
| Option | Alias | Description |
|
|
92
|
+
|--------|-------|-------------|
|
|
93
|
+
| `--cwd <dir>` | `-c` | Specify the working directory |
|
|
94
|
+
| `--silent` | `-s` | Mute output |
|
|
95
|
+
|
|
96
|
+
#### Examples
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Generate instructions for current directory
|
|
100
|
+
astral setup-aliases
|
|
101
|
+
|
|
102
|
+
# Generate instructions for a specific project
|
|
103
|
+
astral setup-aliases --cwd ./my-project
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `add`
|
|
107
|
+
|
|
108
|
+
Add components to your project.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
astral add [component...]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Options
|
|
115
|
+
|
|
116
|
+
| Option | Alias | Description |
|
|
117
|
+
|--------|-------|-------------|
|
|
118
|
+
| `--yes` | `-y` | Skip confirmation prompts |
|
|
119
|
+
| `--overwrite` | `-o` | Overwrite existing files |
|
|
120
|
+
| `--cwd <dir>` | `-c` | Specify the working directory |
|
|
121
|
+
| `--all` | `-a` | Add all available components |
|
|
122
|
+
| `--path <path>` | `-p` | Specify the path to add the component to |
|
|
123
|
+
| `--silent` | `-s` | Mute output |
|
|
124
|
+
|
|
125
|
+
#### Examples
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Add specific components
|
|
129
|
+
astral add button card select
|
|
130
|
+
|
|
131
|
+
# Add all components
|
|
132
|
+
astral add --all
|
|
133
|
+
|
|
134
|
+
# Add a component to a specific directory
|
|
135
|
+
astral add button --path ./components/custom
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `repair-tailwind`
|
|
139
|
+
|
|
140
|
+
Repair Tailwind configuration when setup fails - only use if experiencing issues with Tailwind.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
astral repair-tailwind
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
This command will:
|
|
147
|
+
- Check for existing Tailwind configuration and create a timestamped backup
|
|
148
|
+
- Create a new Tailwind configuration with the appropriate file extension for your project
|
|
149
|
+
- Update CSS variables required by components
|
|
150
|
+
- Ensure proper dependencies are installed
|
|
151
|
+
|
|
152
|
+
#### Options
|
|
153
|
+
|
|
154
|
+
| Option | Alias | Description |
|
|
155
|
+
|--------|-------|-------------|
|
|
156
|
+
| `--force` | `-f` | Force overwrite of existing configuration without prompting |
|
|
157
|
+
| `--cwd <dir>` | `-c` | Specify the working directory |
|
|
158
|
+
| `--silent` | `-s` | Mute output |
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
### components.json
|
|
163
|
+
|
|
164
|
+
The `components.json` file is created during initialization and contains configuration for your project:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"$schema": "./schema/components-config.schema.json",
|
|
169
|
+
"tailwind": {
|
|
170
|
+
"config": "tailwind.config.js",
|
|
171
|
+
"css": "src/styles/globals.css",
|
|
172
|
+
},
|
|
173
|
+
"aliases": {
|
|
174
|
+
"components": "src/components",
|
|
175
|
+
"utils": "src/utils",
|
|
176
|
+
"constants": "src/constants"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
You can edit this file to customize:
|
|
182
|
+
- **tailwind.config**: Path to your Tailwind configuration file
|
|
183
|
+
- **css**: Path to your global CSS file
|
|
184
|
+
- **aliases**: Paths where components, utilities, and constants are installed
|
|
185
|
+
|
|
186
|
+
> **Note**: The `utils` path in `components.json` is stored without a file extension. The CLI automatically adds `.ts` or `.js` extension based on whether your project uses TypeScript or JavaScript. When configuring path aliases, you should use the path without an extension as shown in the `components.json` file.
|
|
187
|
+
|
|
188
|
+
### Components JSON Schema
|
|
189
|
+
|
|
190
|
+
Alongside your `components.json`, the CLI generates a JSON Schema file at `schema/components-config.schema.json`.
|
|
191
|
+
You can use this schema in your editor or CI to validate your configuration. It defines:
|
|
192
|
+
- `$schema` (string): URI of this schema file.
|
|
193
|
+
- `tailwind` (object): Paths to your Tailwind config (`config`) and CSS file (`css`).
|
|
194
|
+
- `aliases` (object): Directories for `components`, `utils`, and `constants`.
|
|
195
|
+
- `extensions` (string[]): File extensions to search for components.
|
|
196
|
+
|
|
197
|
+
For full details, see `schema/components-config.schema.json` in your project.
|
|
198
|
+
|
|
199
|
+
## Available Components
|
|
200
|
+
|
|
201
|
+
| Component | Description |
|
|
202
|
+
|-----------|-------------|
|
|
203
|
+
| `button` | A button component with various styles, sizes, and states |
|
|
204
|
+
| `card` | A card component for displaying content in a contained way |
|
|
205
|
+
| `select` | A select component for selecting options from a list |
|
|
206
|
+
|
|
207
|
+
## Using Components
|
|
208
|
+
|
|
209
|
+
After adding components, you can import and use them in your application:
|
|
210
|
+
|
|
211
|
+
### React/Next.js Example
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { Button } from '@components/ui/button';
|
|
215
|
+
import { Card, CardHeader, CardContent } from '@components/ui/card';
|
|
216
|
+
import { cn } from '@utils';
|
|
217
|
+
import { keyboardKeys, mobileBreakPoint } from '@constants';
|
|
218
|
+
|
|
219
|
+
export function MyComponent() {
|
|
220
|
+
return (
|
|
221
|
+
<Card>
|
|
222
|
+
<CardHeader>My Card</CardHeader>
|
|
223
|
+
<CardContent>
|
|
224
|
+
<p>Card content goes here</p>
|
|
225
|
+
<Button
|
|
226
|
+
className={cn("mt-4", "custom-class")}
|
|
227
|
+
variant="outline"
|
|
228
|
+
>
|
|
229
|
+
Click Me
|
|
230
|
+
</Button>
|
|
231
|
+
</CardContent>
|
|
232
|
+
</Card>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### About the Utils File
|
|
238
|
+
|
|
239
|
+
The CLI creates a utility file with the `cn` function that helps combine Tailwind classes. This file:
|
|
240
|
+
|
|
241
|
+
- Is automatically created during initialization in the path specified in `components.json` (`utils` field)
|
|
242
|
+
- Has the appropriate file extension (`.ts` for TypeScript projects, `.js` for JavaScript projects) added automatically
|
|
243
|
+
- Should be imported in your components as `import { cn } from '@utils'` after setting up path aliases
|
|
244
|
+
|
|
245
|
+
The `cn` function allows you to conditionally combine class names and automatically handles Tailwind class conflicts.
|
|
246
|
+
|
|
247
|
+
## Styling Components
|
|
248
|
+
|
|
249
|
+
The components in the registry require Tailwind CSS to be properly configured in your application. When you run `astral-ui init`, the CLI will:
|
|
250
|
+
|
|
251
|
+
1. Check for an existing Tailwind configuration and upgrade it with required settings
|
|
252
|
+
2. Create a CSS file with required CSS variables for component styling
|
|
253
|
+
3. Generate a STYLING.md file with documentation on the styling system
|
|
254
|
+
|
|
255
|
+
### Tailwind Integration
|
|
256
|
+
|
|
257
|
+
The CLI intelligently handles existing Tailwind configurations:
|
|
258
|
+
|
|
259
|
+
- Automatically detects existing configuration files with any extension (.js, .ts, .mjs, .cjs)
|
|
260
|
+
- Creates a timestamped backup of any existing Tailwind configuration file
|
|
261
|
+
- Creates a new tailwind.config file with the appropriate extension based on your project type:
|
|
262
|
+
- TypeScript projects: `.ts` extension
|
|
263
|
+
- ESM projects: `.mjs` extension
|
|
264
|
+
- CommonJS projects: `.js` extension
|
|
265
|
+
- CommonJS in an ESM package (with "type": "module"): `.cjs` extension
|
|
266
|
+
- Preserves your project's language (TypeScript or JavaScript) and module system (ESM or CommonJS)
|
|
267
|
+
|
|
268
|
+
Required Tailwind features included in the configuration:
|
|
269
|
+
- Color system with RGB variables for primary, secondary, success, warning, error, and gray scales
|
|
270
|
+
- Custom box shadows for card components
|
|
271
|
+
- Dark mode support ("class" mode for theme toggling)
|
|
272
|
+
- Animation utilities via tailwindcss-animate plugin
|
|
273
|
+
|
|
274
|
+
### CSS Variables
|
|
275
|
+
|
|
276
|
+
The CSS file includes all necessary CSS variables that components reference, including:
|
|
277
|
+
|
|
278
|
+
- Base colors (primary, secondary, etc.)
|
|
279
|
+
- State colors (success, error, warning)
|
|
280
|
+
- Theme variables for light/dark mode
|
|
281
|
+
|
|
282
|
+
## Troubleshooting
|
|
283
|
+
|
|
284
|
+
### Path Alias Issues
|
|
285
|
+
|
|
286
|
+
If you're having problems with imports:
|
|
287
|
+
|
|
288
|
+
1. **Check your configuration**: Make sure the paths in tsconfig.json/jsconfig.json match your project structure
|
|
289
|
+
2. **Framework-specific issues**:
|
|
290
|
+
- **Next.js**: Make sure you're using the correct import format for your Next.js version
|
|
291
|
+
- **Angular**: Configure paths in tsconfig.app.json instead of tsconfig.json
|
|
292
|
+
- **Create React App**: You'll need CRACO or similar to enable path aliases
|
|
293
|
+
3. **Verify setup**: Run `astral-ui setup-aliases` again to get fresh instructions
|
|
294
|
+
4. **Check components.json**: Make sure the paths in the "aliases" section match your project structure
|
|
295
|
+
|
|
296
|
+
### Styling Issues
|
|
297
|
+
|
|
298
|
+
If components don't appear correctly styled:
|
|
299
|
+
|
|
300
|
+
1. Make sure the Tailwind CSS configuration is properly loaded in your application
|
|
301
|
+
2. Verify the CSS variables are included in your main CSS file
|
|
302
|
+
3. Check that your component is properly importing the required utilities
|
|
303
|
+
4. Run `astral-ui repair-tailwind` to create a fresh Tailwind configuration
|
|
304
|
+
5. If you need to combine the new configuration with your existing customizations, use your backup file as a reference
|
|
305
|
+
|
|
306
|
+
## Development
|
|
307
|
+
|
|
308
|
+
### Setup
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Install dependencies
|
|
312
|
+
yarn install
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Building
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
# Build the CLI
|
|
319
|
+
yarn build
|
|
320
|
+
|
|
321
|
+
# Watch for changes and rebuild automatically
|
|
322
|
+
yarn dev
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Linting
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# Run both ESLint and Stylelint
|
|
329
|
+
yarn lint
|
|
330
|
+
|
|
331
|
+
# Run only ESLint for TypeScript
|
|
332
|
+
yarn lint:js
|
|
333
|
+
|
|
334
|
+
# Run only Stylelint for CSS/SCSS
|
|
335
|
+
yarn lint:style
|
|
336
|
+
|
|
337
|
+
# Fix auto-fixable ESLint issues
|
|
338
|
+
yarn lint:fix
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Testing
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# Run tests
|
|
345
|
+
yarn test
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Utilities
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
# Copy CSS variables from the UI library
|
|
352
|
+
yarn copy-css
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT
|