ghostcn 1.2.0 → 1.4.1
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 +16 -244
- package/dist/commands/add.d.ts +6 -1
- package/dist/commands/add.js +121 -83
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/playground.d.ts +3 -0
- package/dist/commands/playground.js +29 -0
- package/dist/index.js +18 -3
- package/dist/registry/components/alert.json +62 -0
- package/dist/registry/components/archive-header.json +57 -0
- package/dist/registry/components/author-card.json +23 -2
- package/dist/registry/components/author-list.json +55 -0
- package/dist/registry/components/badge.json +51 -0
- package/dist/registry/components/button.json +74 -0
- package/dist/registry/components/card.json +70 -0
- package/dist/registry/components/featured-posts.json +18 -1
- package/dist/registry/components/input.json +94 -0
- package/dist/registry/components/member-cta.json +15 -1
- package/dist/registry/components/newsletter-form.json +23 -2
- package/dist/registry/components/pagination.json +12 -1
- package/dist/registry/components/post-card.json +25 -2
- package/dist/registry/components/post-grid.json +54 -0
- package/dist/registry/components/post-header.json +18 -1
- package/dist/registry/components/post-navigation.json +41 -0
- package/dist/registry/components/pricing-table.json +31 -2
- package/dist/registry/components/related-posts.json +53 -0
- package/dist/registry/components/site-footer.json +15 -1
- package/dist/registry/components/site-header.json +16 -1
- package/dist/registry/components/table-of-contents.json +47 -0
- package/dist/registry/components/tag-grid.json +64 -0
- package/dist/registry/components/tag-list.json +38 -0
- package/dist/registry/index.json +131 -0
- package/dist/templates/playground/index.html +5 -0
- package/dist/templates/playground/playground.css +18 -0
- package/dist/templates/playground/playground.js +71 -0
- package/dist/templates/playground/preview.css +5 -0
- package/dist/templates/playground/preview.js +12 -0
- package/dist/templates/theme-tools.mjs +1 -1
- package/dist/utils/component-diff.d.ts +18 -0
- package/dist/utils/component-diff.js +93 -0
- package/dist/utils/component-files.d.ts +9 -0
- package/dist/utils/component-files.js +48 -0
- package/dist/utils/component-history.d.ts +11 -0
- package/dist/utils/component-history.js +47 -0
- package/dist/utils/component-installer.d.ts +2 -0
- package/dist/utils/component-installer.js +34 -37
- package/dist/utils/component-plan.d.ts +7 -0
- package/dist/utils/component-plan.js +43 -0
- package/dist/utils/playground-server.d.ts +9 -0
- package/dist/utils/playground-server.js +189 -0
- package/dist/utils/preview-renderer.d.ts +143 -0
- package/dist/utils/preview-renderer.js +70 -0
- package/dist/utils/registry.d.ts +7 -0
- package/dist/utils/registry.js +12 -18
- package/dist/utils/theme-files.d.ts +2 -0
- package/dist/utils/theme-files.js +41 -3
- package/dist/utils/theme-scaffold.js +14 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,262 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Ghostcn
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
<strong>The <code>shadcn/ui</code> for Ghost CMS themes.</strong><br>
|
|
5
|
-
Beautiful, accessible, copy-pasteable Handlebars partials and stylesheets for modern Ghost theme development.
|
|
6
|
-
</p>
|
|
3
|
+
Copy Ghost-native Handlebars components and styles into a theme you own. Use Tailwind CSS or vanilla CSS.
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
<a href="https://www.npmjs.com/package/ghostcn"><img src="https://img.shields.io/npm/v/ghostcn?color=6366f1&style=flat-square" alt="npm version" /></a>
|
|
10
|
-
<a href="https://www.npmjs.com/package/ghostcn"><img src="https://img.shields.io/npm/dm/ghostcn?color=3b82f6&style=flat-square" alt="npm downloads" /></a>
|
|
11
|
-
<a href="https://ghost.org"><img src="https://img.shields.io/badge/Ghost-%3E%3D5.0.0-15171a?style=flat-square" alt="Ghost Version" /></a>
|
|
12
|
-
<a href="https://github.com/Geekbits-Org/ghost-ui/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License" /></a>
|
|
13
|
-
</p>
|
|
5
|
+
**[Documentation](https://ghostcn.geekbits.dev)** · [Component reference](https://ghostcn.geekbits.dev/docs/components) · [Changelog](https://ghostcn.geekbits.dev/changelog)
|
|
14
6
|
|
|
15
|
-
|
|
7
|
+
## Start a new theme
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
**ghostcn** brings the modern component distribution model to **Ghost CMS**.
|
|
20
|
-
|
|
21
|
-
Instead of installing cumbersome plugins or monolithic npm modules that lock down your markup, ghostcn injects clean, production-ready **Handlebars (`.hbs`) partials** and **CSS** directly into your theme repository.
|
|
22
|
-
|
|
23
|
-
You own the code. You customize the classes. Zero vendor lock-in.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Features
|
|
28
|
-
|
|
29
|
-
- 📦 **Theme-Native**: Directly installs raw Handlebars partials and CSS into your theme folders.
|
|
30
|
-
- ⚡ **Zero Latency**: Bundled offline registry ensures blazing fast installation even without internet.
|
|
31
|
-
- 🎯 **Interactive Multi-Select**: Run `npx ghostcn add` without arguments to select and batch-install multiple components interactively.
|
|
32
|
-
- 🎨 **Tailwind & Vanilla CSS**: Pre-styled with utility classes and full Vanilla CSS stylesheets with Ghost CSS custom properties.
|
|
33
|
-
- 🔑 **Ghost Members API**: Native support for Ghost attributes (`data-members-form="subscribe"`, Portal checkout triggers).
|
|
34
|
-
- 🛡️ **Theme validation**: Generated themes include offline diagnostics and official gscan validation. Validate your customized theme against your target Ghost version before shipping.
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## Available Components
|
|
39
|
-
|
|
40
|
-
| Component | Description | Files |
|
|
41
|
-
| :--- | :--- | :--- |
|
|
42
|
-
| **`newsletter-form`** | Native Ghost members subscription form with success/error states | `newsletter-form.hbs`, `newsletter-form.css` |
|
|
43
|
-
| **`pricing-table`** | Public Ghost tiers with live prices, currencies, benefits and tier-specific Portal checkout | `pricing-table.hbs`, `pricing-table.css` |
|
|
44
|
-
| **`author-card`** | Author bio box with avatar, biography, social links, and post counts | `author-card.hbs`, `author-card.css` |
|
|
45
|
-
| **`post-card`** | Post loop preview card with feature image, tags, excerpt, and reading time | `post-card.hbs`, `post-card.css` |
|
|
46
|
-
| **`site-header`** | Responsive navigation with search, mobile menu, sign-in, and subscribe actions | `site-header.hbs`, `site-header.css` |
|
|
47
|
-
| **`site-footer`** | Secondary navigation, publication information, social links, and attribution | `site-footer.hbs`, `site-footer.css` |
|
|
48
|
-
| **`featured-posts`** | Homepage hero grid backed by Ghost featured posts | `featured-posts.hbs`, `featured-posts.css` |
|
|
49
|
-
| **`pagination`** | Accessible replacement for Ghost’s native pagination partial | `partials/pagination.hbs`, `pagination.css` |
|
|
50
|
-
| **`post-header`** | Editorial post heading, author metadata, reading time, and responsive image | `post-header.hbs`, `post-header.css` |
|
|
51
|
-
| **`member-cta`** | Context-aware calls to action for visitors, free members, and paid members | `member-cta.hbs`, `member-cta.css` |
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Quick Start
|
|
56
|
-
|
|
57
|
-
### Create a complete Ghost theme
|
|
58
|
-
|
|
59
|
-
Start a new, production-ready theme with an interactive setup:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
npx ghostcn create my-theme
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
The wizard configures Tailwind CSS or vanilla CSS, design tokens, color mode, package manager, optional components, and dependency installation. The generated theme includes Ghost templates for the home page, posts, pages, tags, and authors; responsive navigation; member flows; build scripts; and gscan validation.
|
|
66
|
-
|
|
67
|
-
Use recommended defaults without installing dependencies:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npx ghostcn create my-theme -y --skip-install
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Tailwind themes include a complete Tailwind CLI build and watch pipeline. Vanilla themes include a zero-dependency CSS copy/watch pipeline. In both cases:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
9
|
+
```sh
|
|
10
|
+
npx ghostcn@latest create my-theme
|
|
76
11
|
cd my-theme
|
|
77
12
|
npm run dev
|
|
78
13
|
```
|
|
79
14
|
|
|
80
|
-
|
|
15
|
+
The dev command watches CSS; it does not start Ghost. Follow the [theme setup guide](https://ghostcn.geekbits.dev/docs/getting-started/create-a-theme) to activate and preview the theme in Ghost.
|
|
81
16
|
|
|
82
|
-
|
|
17
|
+
## Add to an existing theme
|
|
83
18
|
|
|
84
|
-
|
|
19
|
+
From your Ghost theme directory:
|
|
85
20
|
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
npm run zip
|
|
21
|
+
```sh
|
|
22
|
+
npx ghostcn@latest init
|
|
23
|
+
npx ghostcn@latest add newsletter-form --skip-existing
|
|
90
24
|
```
|
|
91
25
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
For an existing theme, run `npx ghostcn doctor` to check configuration, linked assets, partials and Ghost hooks. After running **your theme's build**, `npx ghostcn pack` packages it without invoking or changing its build system. Doctor is an offline diagnostic, not a replacement for gscan or browser testing.
|
|
95
|
-
|
|
96
|
-
### Styling components
|
|
97
|
-
|
|
98
|
-
For a generated Tailwind theme, customize the markup with ordinary utilities:
|
|
26
|
+
Call the installed partial from a Handlebars template:
|
|
99
27
|
|
|
100
28
|
```handlebars
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
No `!` modifier is required to override ghostcn defaults. Component styles and primitives use Tailwind's `components` layer; utilities take precedence, even if a component stylesheet loads later. Semantic colors (`bg-primary`, `text-muted-foreground`, `border-border`, `ring-ring`) and `rounded-ghostcn` are mapped by `assets/css/ghostcn-tailwind.css`. Ghost's explicit and automatic dark modes are supported.
|
|
105
|
-
|
|
106
|
-
For **existing Tailwind v4 themes**, import the generated `ghostcn-tailwind.css` into your Tailwind source and make sure the build scans `.hbs` files. For example, when using `assets/css/source.css`:
|
|
107
|
-
|
|
108
|
-
```css
|
|
109
|
-
@import "tailwindcss";
|
|
110
|
-
@import "./ghostcn-tailwind.css";
|
|
111
|
-
@source "../../**/*.hbs";
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
`init` and `add` do not replace an existing theme's build pipeline. Unlayered host CSS can still override layered styles; place such host rules in an appropriate lower layer or adjust your theme deliberately. Older Tailwind builds must configure their own semantic token mappings.
|
|
115
|
-
|
|
116
|
-
Vanilla themes ship standalone CSS: edit component files or put token and selector overrides in `assets/css/source.css`. The generated build stylesheet loads after ghostcn defaults. On an existing theme, link your override stylesheet after the managed ghostcn block.
|
|
117
|
-
|
|
118
|
-
Membership components respect disabled, invite-only and self-signup settings. Paid pricing is shown only when Ghost enables paid membership, using active public tiers configured in Ghost Admin—not sample amounts or invented benefits. The starter uses `partials/content-cta.hbs` for one custom paywall; adding `member-cta` below native `{{content}}` on an existing protected post can otherwise duplicate Ghost's paywall. Follow the starter pattern rather than rendering both.
|
|
119
|
-
|
|
120
|
-
### Updating an existing ghostcn theme
|
|
121
|
-
|
|
122
|
-
Your copied files are yours; an npm update does not silently rewrite them. Back up or commit your theme first. Compare the new components in a fresh throwaway theme, then merge the changes you want. To replace unmodified files directly, run `ghostcn init` with your existing palette/paths and re-add the relevant components. Initialization regenerates tokens; `add -y` overwrites component customizations, so use it only deliberately. Existing Tailwind styles from older ghostcn releases are unlayered and need the new token/component CSS for ordinary utility overrides to work.
|
|
123
|
-
|
|
124
|
-
### 1. Initialize your Ghost Theme
|
|
125
|
-
|
|
126
|
-
Run the `init` command from the root of any Ghost theme (must have `engines.ghost` in its `package.json`):
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
npx ghostcn init
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Or pass `-y` to use default paths non-interactively:
|
|
133
|
-
```bash
|
|
134
|
-
npx ghostcn init -y
|
|
29
|
+
{{> "components/newsletter-form"}}
|
|
135
30
|
```
|
|
136
31
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
It generates `assets/css/ghostcn.css` with semantic design tokens, creates `components.json`, and adds a managed stylesheet block to `default.hbs`:
|
|
140
|
-
```json
|
|
141
|
-
{
|
|
142
|
-
"$schema": "https://ghostcn.com/schema.json",
|
|
143
|
-
"style": "tailwind",
|
|
144
|
-
"theme": {
|
|
145
|
-
"baseColor": "zinc",
|
|
146
|
-
"accentColor": "ghost",
|
|
147
|
-
"radius": "0.5rem"
|
|
148
|
-
},
|
|
149
|
-
"aliases": {
|
|
150
|
-
"partials": "partials/components",
|
|
151
|
-
"styles": "assets/css/components"
|
|
152
|
-
},
|
|
153
|
-
"cssFile": "assets/css/ghostcn.css"
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
The CLI keeps the token stylesheet and every installed component stylesheet linked automatically:
|
|
158
|
-
```handlebars
|
|
159
|
-
{{!-- ghostcn:styles:start --}}
|
|
160
|
-
<link rel="stylesheet" href="{{asset "css/ghostcn.css"}}" />
|
|
161
|
-
{{!-- Component styles are added here by `ghostcn add` --}}
|
|
162
|
-
{{!-- ghostcn:styles:end --}}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
If a theme uses a layout other than `default.hbs`, the CLI leaves the layout untouched and prints the link you need to add manually.
|
|
166
|
-
|
|
167
|
-
### 2. Browse Components
|
|
168
|
-
|
|
169
|
-
List all available components in the registry:
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
npx ghostcn list
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### 3. Add Components
|
|
176
|
-
|
|
177
|
-
Add a specific component:
|
|
178
|
-
```bash
|
|
179
|
-
npx ghostcn add newsletter-form
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Or run `add` without arguments to pick interactively from a checklist:
|
|
183
|
-
```bash
|
|
184
|
-
npx ghostcn add
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
To overwrite existing files without prompts:
|
|
188
|
-
```bash
|
|
189
|
-
npx ghostcn add pricing-table -y
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### 4. Use in your Templates
|
|
193
|
-
|
|
194
|
-
Include the installed partial anywhere in your Handlebars templates:
|
|
195
|
-
|
|
196
|
-
```handlebars
|
|
197
|
-
{{!-- Newsletter Form --}}
|
|
198
|
-
{{> "components/newsletter-form" title="Subscribe to our Newsletter"}}
|
|
199
|
-
|
|
200
|
-
{{!-- Pricing & Membership Table --}}
|
|
201
|
-
{{> "components/pricing-table" title="Choose your membership plan"}}
|
|
202
|
-
|
|
203
|
-
{{!-- Author Card --}}
|
|
204
|
-
{{#primary_author}}
|
|
205
|
-
{{> "components/author-card"}}
|
|
206
|
-
{{/primary_author}}
|
|
207
|
-
|
|
208
|
-
{{!-- Post Loop --}}
|
|
209
|
-
{{#foreach posts}}
|
|
210
|
-
{{> "components/post-card"}}
|
|
211
|
-
{{/foreach}}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
---
|
|
215
|
-
|
|
216
|
-
## Project Structure
|
|
217
|
-
|
|
218
|
-
```text
|
|
219
|
-
ghostcn/
|
|
220
|
-
├── packages/
|
|
221
|
-
│ └── cli/ # ghostcn CLI (Commander, Prompts, TypeScript, tests)
|
|
222
|
-
├── registry/
|
|
223
|
-
│ ├── index.json # Registry catalog index
|
|
224
|
-
│ └── components/ # Component manifests and templates
|
|
225
|
-
├── example-theme/ # Sample Ghost theme showing integration
|
|
226
|
-
└── .github/workflows/ # Automated CI pipeline
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## Development & Testing
|
|
232
|
-
|
|
233
|
-
```bash
|
|
234
|
-
# Install dependencies
|
|
235
|
-
npm install
|
|
236
|
-
|
|
237
|
-
# Build CLI and bundle registry
|
|
238
|
-
npm run build
|
|
239
|
-
|
|
240
|
-
# Run automated tests
|
|
241
|
-
npm test
|
|
242
|
-
|
|
243
|
-
# Verify theme compatibility with Ghost validator
|
|
244
|
-
cd example-theme
|
|
245
|
-
npx gscan .
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## Troubleshooting
|
|
251
|
-
|
|
252
|
-
### Clearing npx cache
|
|
253
|
-
If you've previously run an older version of `ghostcn`, npx may cache it locally. To always run the latest version:
|
|
254
|
-
```bash
|
|
255
|
-
npx ghostcn@latest <command>
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
---
|
|
259
|
-
|
|
260
|
-
## License
|
|
32
|
+
See the [existing theme guide](https://ghostcn.geekbits.dev/docs/getting-started/existing-theme) for stylesheet setup. Updating the CLI does not rewrite your copied components; [review changes](https://ghostcn.geekbits.dev/docs/guides/updating-components) before replacing them.
|
|
261
33
|
|
|
262
|
-
|
|
34
|
+
[Source code](https://github.com/Geekbits-Org/ghost-ui) · [Report an issue](https://github.com/Geekbits-Org/ghost-ui/issues)
|
package/dist/commands/add.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export interface AddOptions {
|
|
2
2
|
yes?: boolean;
|
|
3
|
+
skipExisting?: boolean;
|
|
3
4
|
}
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function createOverwriteDecision(name: string, spinner: {
|
|
6
|
+
stop(): unknown;
|
|
7
|
+
start(): unknown;
|
|
8
|
+
}, interactive?: boolean): (relativePath: string) => Promise<boolean>;
|
|
9
|
+
export declare function add(componentNames?: string[] | string, options?: AddOptions): Promise<void>;
|
package/dist/commands/add.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createOverwriteDecision = createOverwriteDecision;
|
|
6
7
|
exports.add = add;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -11,112 +12,149 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
11
12
|
const ora_1 = __importDefault(require("ora"));
|
|
12
13
|
const registry_1 = require("../utils/registry");
|
|
13
14
|
const component_installer_1 = require("../utils/component-installer");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
class AddCancelled extends Error {
|
|
16
|
+
}
|
|
17
|
+
// One decision per requested component, never a spinner competing with a prompt.
|
|
18
|
+
// Installer mechanics and dependency preservation remain in the shared installer.
|
|
19
|
+
function createOverwriteDecision(name, spinner, interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
20
|
+
let decision;
|
|
21
|
+
return async (relativePath) => {
|
|
22
|
+
if (decision !== undefined)
|
|
23
|
+
return decision;
|
|
24
|
+
spinner.stop();
|
|
25
|
+
if (!interactive)
|
|
26
|
+
return decision = false;
|
|
27
|
+
console.log(chalk_1.default.yellow(`Component "${name}" already has files, including ${relativePath}.`));
|
|
28
|
+
console.log(`Press Enter / N to keep existing files and continue; Y replaces this component's files.`);
|
|
29
|
+
console.log(`Review first: ghostcn diff ${name}. Cancel with Ctrl+C. Dependencies are preserved.`);
|
|
30
|
+
let cancelled = false;
|
|
31
|
+
const response = await (0, prompts_1.default)({
|
|
32
|
+
type: 'confirm', name: 'overwrite', message: `Replace existing files for "${name}"?`, initial: false
|
|
33
|
+
}, { onCancel: () => { cancelled = true; } });
|
|
34
|
+
if (cancelled)
|
|
35
|
+
throw new AddCancelled('Cancelled. Existing files were kept; earlier installs were not rolled back.');
|
|
36
|
+
decision = Boolean(response.overwrite);
|
|
37
|
+
spinner.start();
|
|
38
|
+
return decision;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function installSingleComponent(name, config, options) {
|
|
42
|
+
const spinner = (0, ora_1.default)(`Installing component "${name}" (registry requests time out after 5 seconds)...`).start();
|
|
25
43
|
let result;
|
|
26
44
|
try {
|
|
27
45
|
result = await (0, component_installer_1.installComponent)({
|
|
28
|
-
themeRoot: cwd,
|
|
29
|
-
|
|
30
|
-
config,
|
|
31
|
-
overwrite: options.yes,
|
|
32
|
-
shouldOverwrite: async (relativePath) => {
|
|
33
|
-
const response = await (0, prompts_1.default)({
|
|
34
|
-
type: 'confirm',
|
|
35
|
-
name: 'overwrite',
|
|
36
|
-
message: `File ${relativePath} already exists. Overwrite?`,
|
|
37
|
-
initial: false
|
|
38
|
-
}, {
|
|
39
|
-
onCancel: () => {
|
|
40
|
-
console.log(chalk_1.default.yellow('\nOperation cancelled.'));
|
|
41
|
-
process.exit(0);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return Boolean(response.overwrite);
|
|
45
|
-
}
|
|
46
|
+
themeRoot: process.cwd(), componentName: name, config, overwrite: options.yes,
|
|
47
|
+
shouldOverwrite: options.skipExisting ? async () => false : createOverwriteDecision(name, spinner)
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
catch (error) {
|
|
51
|
+
if (error instanceof AddCancelled) {
|
|
52
|
+
spinner.stop();
|
|
53
|
+
console.log(chalk_1.default.yellow(error.message));
|
|
54
|
+
return 'cancelled';
|
|
55
|
+
}
|
|
49
56
|
spinner.fail(chalk_1.default.red(error.message));
|
|
50
|
-
|
|
57
|
+
console.error(`Check the component name and registry connection, then retry: ghostcn add ${name}`);
|
|
58
|
+
return 'failed';
|
|
59
|
+
}
|
|
60
|
+
const outcome = result.installed.length ? 'installed' : 'kept';
|
|
61
|
+
spinner.succeed(outcome === 'installed' ? `Installed "${name}".` : `Kept existing "${name}" files.`);
|
|
62
|
+
for (const dependency of result.dependencies || []) {
|
|
63
|
+
for (const file of dependency.installed)
|
|
64
|
+
console.log(chalk_1.default.green(` ✓ Dependency ${dependency.name}: installed ${file}`));
|
|
65
|
+
for (const file of dependency.skipped)
|
|
66
|
+
console.log(chalk_1.default.yellow(` - Dependency ${dependency.name}: preserved ${file}`));
|
|
67
|
+
}
|
|
68
|
+
for (const file of result.installed)
|
|
69
|
+
console.log(chalk_1.default.green(` ✓ Installed ${file}`));
|
|
70
|
+
for (const file of result.skipped)
|
|
71
|
+
console.log(chalk_1.default.yellow(` - Preserved ${file}`));
|
|
72
|
+
if (result.skipped.length) {
|
|
73
|
+
console.log(`Review changes: ghostcn diff ${name}`);
|
|
74
|
+
console.log(`To replace deliberately (back up first): ghostcn add ${name} --yes`);
|
|
51
75
|
}
|
|
52
|
-
spinner.succeed(`Found "${sanitizedName}"!`);
|
|
53
|
-
for (const installed of result.installed)
|
|
54
|
-
console.log(chalk_1.default.green(` ✓ Installed ${installed}`));
|
|
55
|
-
for (const skipped of result.skipped)
|
|
56
|
-
console.log(chalk_1.default.yellow(` - Skipped ${skipped}`));
|
|
57
76
|
if (result.styleSync?.status === 'missing-template') {
|
|
58
77
|
console.warn(chalk_1.default.yellow(' ⚠ default.hbs was not found, so component styles could not be linked automatically.'));
|
|
59
78
|
}
|
|
60
79
|
else if (result.styleSync?.status === 'updated') {
|
|
61
80
|
console.log(chalk_1.default.green(' ✓ Updated the managed stylesheet links in default.hbs'));
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
if (result.scriptSync?.status === 'updated')
|
|
83
|
+
console.log(chalk_1.default.green(' ✓ Updated managed component script links in default.hbs'));
|
|
84
|
+
if (result.scriptSync?.status === 'missing-template') {
|
|
85
|
+
console.warn(chalk_1.default.yellow(' ⚠ Add these script links before </body> in your layout:'));
|
|
86
|
+
for (const asset of result.scriptSync.assetPaths)
|
|
87
|
+
console.log(`<script defer src="{{asset "${asset}"}}"></script>`);
|
|
88
|
+
}
|
|
89
|
+
return outcome;
|
|
65
90
|
}
|
|
66
|
-
async function add(
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
async function add(componentNames = [], options = {}) {
|
|
92
|
+
if (options.yes && options.skipExisting) {
|
|
93
|
+
console.error('Choose either --yes (replace) or --skip-existing (preserve), not both.');
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const configPath = path_1.default.join(process.cwd(), 'components.json');
|
|
69
98
|
if (!fs_1.default.existsSync(configPath)) {
|
|
70
|
-
console.error(chalk_1.default.red('components.json not found.
|
|
71
|
-
process.
|
|
99
|
+
console.error(chalk_1.default.red('components.json not found. Run "ghostcn init" from your theme directory first.'));
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
return;
|
|
72
102
|
}
|
|
73
103
|
let config;
|
|
104
|
+
let names;
|
|
74
105
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
console.error(chalk_1.default.red('Could not parse components.json. Ensure it contains valid JSON.'));
|
|
80
|
-
process.exit(1);
|
|
106
|
+
config = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
|
|
107
|
+
names = [...new Set((typeof componentNames === 'string' ? [componentNames] : componentNames).map(registry_1.sanitizeComponentName))];
|
|
81
108
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!ok)
|
|
86
|
-
process.exit(1);
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error(chalk_1.default.red(error instanceof SyntaxError ? 'Could not parse components.json. Ensure it contains valid JSON.' : error.message));
|
|
111
|
+
process.exitCode = 1;
|
|
87
112
|
return;
|
|
88
113
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
if (!names.length) {
|
|
115
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
116
|
+
console.error('Interactive selection requires a terminal. Specify names: ghostcn add button card --skip-existing');
|
|
117
|
+
process.exitCode = 1;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const spinner = (0, ora_1.default)('Loading component catalog (registry requests time out after 5 seconds)...').start();
|
|
121
|
+
let availableItems;
|
|
122
|
+
try {
|
|
123
|
+
availableItems = await (0, registry_1.getRegistryIndex)();
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
spinner.stop();
|
|
127
|
+
}
|
|
128
|
+
if (!availableItems.length) {
|
|
129
|
+
console.error('No components found. Check your registry connection and retry "ghostcn list".');
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
let cancelled = false;
|
|
134
|
+
const response = await (0, prompts_1.default)({
|
|
135
|
+
type: 'multiselect', name: 'selected', message: 'Which components would you like to install?',
|
|
136
|
+
choices: availableItems.map(item => ({ title: `${item.name.padEnd(18)} ${chalk_1.default.dim(item.description)}`, value: item.name })),
|
|
137
|
+
hint: '- Space to select. Return to submit. Ctrl+C to cancel.'
|
|
138
|
+
}, { onCancel: () => { cancelled = true; } });
|
|
139
|
+
if (cancelled) {
|
|
140
|
+
console.log('Cancelled. No components were installed.');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
names = response.selected || [];
|
|
144
|
+
if (!names.length) {
|
|
145
|
+
console.log('No components selected. Exiting.');
|
|
146
|
+
return;
|
|
110
147
|
}
|
|
111
|
-
});
|
|
112
|
-
if (!response.selected || response.selected.length === 0) {
|
|
113
|
-
console.log(chalk_1.default.yellow('No components selected. Exiting.'));
|
|
114
|
-
return;
|
|
115
148
|
}
|
|
116
|
-
console.log(chalk_1.default.blue(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
console.log(chalk_1.default.blue(`Installing ${names.length} component(s)...`));
|
|
150
|
+
const counts = { installed: 0, kept: 0, failed: 0 };
|
|
151
|
+
for (const name of names) {
|
|
152
|
+
const outcome = await installSingleComponent(name, config, options);
|
|
153
|
+
if (outcome === 'cancelled')
|
|
154
|
+
return;
|
|
155
|
+
counts[outcome]++;
|
|
120
156
|
}
|
|
121
|
-
console.log(
|
|
157
|
+
console.log(`Finished: ${counts.installed} installed, ${counts.kept} kept existing, ${counts.failed} failed.`);
|
|
158
|
+
if (counts.failed)
|
|
159
|
+
process.exitCode = 1;
|
|
122
160
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.diff = diff;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const component_diff_1 = require("../utils/component-diff");
|
|
10
|
+
const registry_1 = require("../utils/registry");
|
|
11
|
+
const component_history_1 = require("../utils/component-history");
|
|
12
|
+
const component_files_1 = require("../utils/component-files");
|
|
13
|
+
async function diff(component, options = {}) {
|
|
14
|
+
try {
|
|
15
|
+
const root = process.cwd();
|
|
16
|
+
const config = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'components.json'), 'utf8').replace(/^\uFEFF/, ''));
|
|
17
|
+
let names;
|
|
18
|
+
if (component)
|
|
19
|
+
names = [(0, registry_1.sanitizeComponentName)(component)];
|
|
20
|
+
else {
|
|
21
|
+
const tracked = Object.keys((0, component_history_1.readHistory)(root).components);
|
|
22
|
+
const installed = [];
|
|
23
|
+
for (const item of await (0, registry_1.getRegistryIndex)()) {
|
|
24
|
+
const manifest = await (0, component_diff_1.comparisonManifest)(item.name, false);
|
|
25
|
+
if ((0, component_files_1.componentFiles)(root, config, manifest).some(file => fs_1.default.existsSync(file.target)))
|
|
26
|
+
installed.push(item.name);
|
|
27
|
+
}
|
|
28
|
+
names = [...new Set([...tracked, ...installed])];
|
|
29
|
+
}
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const name of names)
|
|
32
|
+
results.push((0, component_diff_1.compareComponent)(root, config, await (0, component_diff_1.comparisonManifest)(name, !!options.latest)));
|
|
33
|
+
if (options.json)
|
|
34
|
+
console.log(JSON.stringify({ source: options.latest ? 'latest-registry' : 'installed-cli-registry', components: results }, null, 2));
|
|
35
|
+
else {
|
|
36
|
+
console.log(`Read-only comparison against ${options.latest ? 'the latest registry (main), not necessarily the latest npm release' : 'this CLI\'s registry'}. No files are changed.`);
|
|
37
|
+
if (!results.length)
|
|
38
|
+
console.log('No installed components found.');
|
|
39
|
+
for (const result of results) {
|
|
40
|
+
console.log(`\n${result.name}: ${result.installedRevision?.slice(0, 12) || 'unknown baseline'} -> ${result.incomingRevision.slice(0, 12)}`);
|
|
41
|
+
for (const file of result.files) {
|
|
42
|
+
console.log(` ${file.status}: ${file.path}`);
|
|
43
|
+
if (!options.summary && file.local !== file.incoming)
|
|
44
|
+
console.log((0, component_diff_1.unifiedDiff)(file.local, file.incoming, file.path));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log('\nKeep your local files; manually merge the changes you want. Do not use add -y to review updates.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(`Could not compare components: ${error.message}`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.playground = playground;
|
|
4
|
+
const playground_server_1 = require("../utils/playground-server");
|
|
5
|
+
async function playground(options = {}) {
|
|
6
|
+
try {
|
|
7
|
+
if (options.port !== undefined && !/^\d+$/.test(options.port))
|
|
8
|
+
throw new Error('Port must be an integer between 0 and 65535.');
|
|
9
|
+
const runtime = await (0, playground_server_1.startPlayground)({ themeRoot: process.cwd(), port: options.port === undefined ? undefined : Number(options.port) });
|
|
10
|
+
console.log(`Ghostcn playground: ${runtime.url}`);
|
|
11
|
+
console.log('Read-only previews of installed components with synthetic content. Keep npm run dev running for CSS changes.');
|
|
12
|
+
console.log('Press Ctrl+C to stop.');
|
|
13
|
+
let stopping = false;
|
|
14
|
+
const stop = async () => {
|
|
15
|
+
if (stopping)
|
|
16
|
+
return;
|
|
17
|
+
stopping = true;
|
|
18
|
+
process.off('SIGINT', stop);
|
|
19
|
+
process.off('SIGTERM', stop);
|
|
20
|
+
await runtime.close();
|
|
21
|
+
};
|
|
22
|
+
process.on('SIGINT', stop);
|
|
23
|
+
process.on('SIGTERM', stop);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(error.message);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
}
|
|
29
|
+
}
|