ghostcn 1.0.3 → 1.2.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.
Files changed (41) hide show
  1. package/README.md +96 -5
  2. package/dist/commands/add.js +41 -36
  3. package/dist/commands/create.d.ts +5 -0
  4. package/dist/commands/create.js +115 -0
  5. package/dist/commands/doctor.d.ts +1 -0
  6. package/dist/commands/doctor.js +7 -0
  7. package/dist/commands/init.js +134 -26
  8. package/dist/commands/pack.d.ts +1 -0
  9. package/dist/commands/pack.js +8 -0
  10. package/dist/index.js +12 -0
  11. package/dist/registry/components/author-card.json +2 -2
  12. package/dist/registry/components/featured-posts.json +27 -0
  13. package/dist/registry/components/member-cta.json +27 -0
  14. package/dist/registry/components/newsletter-form.json +9 -6
  15. package/dist/registry/components/pagination.json +28 -0
  16. package/dist/registry/components/post-card.json +2 -2
  17. package/dist/registry/components/post-header.json +27 -0
  18. package/dist/registry/components/pricing-table.json +5 -5
  19. package/dist/registry/components/site-footer.json +27 -0
  20. package/dist/registry/components/site-header.json +27 -0
  21. package/dist/registry/index.json +61 -1
  22. package/dist/templates/theme-tools.mjs +178 -0
  23. package/dist/utils/component-installer.d.ts +16 -0
  24. package/dist/utils/component-installer.js +60 -0
  25. package/dist/utils/registry.d.ts +1 -0
  26. package/dist/utils/registry.js +42 -19
  27. package/dist/utils/styles.d.ts +3 -0
  28. package/dist/utils/styles.js +20 -0
  29. package/dist/utils/theme-files.d.ts +13 -0
  30. package/dist/utils/theme-files.js +108 -0
  31. package/dist/utils/theme-project.d.ts +29 -0
  32. package/dist/utils/theme-project.js +46 -0
  33. package/dist/utils/theme-scaffold.d.ts +21 -0
  34. package/dist/utils/theme-scaffold.js +313 -0
  35. package/dist/utils/theme-tooling.d.ts +2 -0
  36. package/dist/utils/theme-tooling.js +20 -0
  37. package/dist/utils/theme.d.ts +46 -0
  38. package/dist/utils/theme.js +429 -0
  39. package/package.json +7 -4
  40. package/dist/test/registry.test.d.ts +0 -1
  41. package/dist/test/registry.test.js +0 -62
@@ -0,0 +1,313 @@
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.REQUIRED_STARTER_COMPONENTS = void 0;
7
+ exports.sanitizeThemeName = sanitizeThemeName;
8
+ exports.scaffoldTheme = scaffoldTheme;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const theme_files_1 = require("./theme-files");
12
+ const styles_1 = require("./styles");
13
+ const theme_tooling_1 = require("./theme-tooling");
14
+ exports.REQUIRED_STARTER_COMPONENTS = [
15
+ 'site-header',
16
+ 'site-footer',
17
+ 'featured-posts',
18
+ 'pagination',
19
+ 'post-header',
20
+ 'member-cta',
21
+ 'post-card'
22
+ ];
23
+ function sanitizeThemeName(value) {
24
+ const name = value.trim().toLowerCase();
25
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(name) || name.endsWith('-') || name.includes('--')) {
26
+ throw new Error('Theme names must use lowercase letters, numbers, and single hyphens (for example: my-theme).');
27
+ }
28
+ return name;
29
+ }
30
+ function baseThemeCss() {
31
+ return `/* Theme-level styles. ghostcn components keep their own portable stylesheets. */
32
+ *, *::before, *::after { box-sizing: border-box; }
33
+ html { font-size: 100%; }
34
+ body {
35
+ min-height: 100vh;
36
+ margin: 0;
37
+ color: var(--foreground, #09090b);
38
+ background: var(--background, #fff);
39
+ font-family: var(--gh-font-body, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
40
+ font-size: 1rem;
41
+ line-height: 1.6;
42
+ -webkit-font-smoothing: antialiased;
43
+ }
44
+ img { max-width: 100%; }
45
+ /* Ghost comments paints its own text colors inside a transparent iframe.
46
+ Match the embedded document's native scheme so dark mode does not force a white canvas. */
47
+ iframe[title="comments-frame"] { color-scheme: normal; }
48
+ h1, h2, h3, h4, h5, h6 { font-family: var(--gh-font-heading, inherit); }
49
+ .ghcn-main { min-height: 65vh; }
50
+ .ghcn-page-heading { width: min(100% - 2rem, 72rem); margin: 4rem auto 2rem; }
51
+ .ghcn-page-heading h1 { margin: 0; font-size: clamp(2.25rem, 6vw, 4rem); line-height: 1; letter-spacing: -0.05em; }
52
+ .ghcn-page-heading p { max-width: 42rem; margin: 1rem 0 0; color: var(--muted-foreground); font-size: 1.125rem; }
53
+ .ghcn-post-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; width: min(100% - 2rem, 72rem); margin: 2rem auto 4rem; }
54
+ .ghcn-article { width: min(100% - 2rem, 46rem); margin: 0 auto 4rem; }
55
+ .ghcn-article-content { color: var(--foreground); font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: clamp(1.0625rem, 2vw, 1.1875rem); }
56
+ .ghcn-article-content > * { margin-block: 0 1.5em; }
57
+ .ghcn-article-content h2, .ghcn-article-content h3 { margin-top: 2em; line-height: 1.15; letter-spacing: -0.025em; }
58
+ .ghcn-article-content a { color: var(--primary); }
59
+ .ghcn-article-content img, .ghcn-article-content .kg-card { max-width: 100%; }
60
+ .ghcn-article-content .kg-width-wide { width: min(72rem, 100vw - 2rem); max-width: none; margin-left: 50%; transform: translateX(-50%); }
61
+ .ghcn-article-content .kg-width-full { width: 100vw; max-width: none; margin-left: 50%; transform: translateX(-50%); }
62
+ .ghcn-empty { width: min(100% - 2rem, 42rem); margin: 4rem auto; padding: 3rem; border: 1px dashed var(--border); border-radius: min(var(--radius), 1rem); color: var(--muted-foreground); text-align: center; }
63
+ @media (max-width: 900px) { .ghcn-post-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
64
+ @media (max-width: 620px) { .ghcn-post-grid { grid-template-columns: 1fr; } }
65
+ `;
66
+ }
67
+ function defaultTemplate(_colorScheme) {
68
+ return `<!DOCTYPE html>
69
+ <html lang="{{@site.locale}}"{{#match @custom.color_scheme "Dark"}} class="dark-mode"{{else match @custom.color_scheme "Auto"}} class="auto-color"{{/match}}>
70
+ <head>
71
+ <meta charset="utf-8" />
72
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
73
+ <title>{{meta_title}}</title>
74
+ {{!-- ghostcn:theme-styles --}}
75
+ <link rel="stylesheet" href="{{asset "built/screen.css"}}" />
76
+ {{ghost_head}}
77
+ </head>
78
+ <body class="{{body_class}}">
79
+ {{> "components/site-header"}}
80
+ <main class="ghcn-main">{{{body}}}</main>
81
+ {{> "components/site-footer"}}
82
+ {{ghost_foot}}
83
+ </body>
84
+ </html>
85
+ `;
86
+ }
87
+ function indexTemplate(options) {
88
+ const extras = [
89
+ options.includeNewsletter ? '{{> "components/newsletter-form" title="Never miss a story"}}' : '',
90
+ options.includePricing ? '{{> "components/pricing-table" title="Support this publication"}}' : ''
91
+ ].filter(Boolean).join('\n\n');
92
+ return `{{!< default}}
93
+
94
+ {{#is "home"}}{{> "components/featured-posts"}}{{/is}}
95
+
96
+ <header class="ghcn-page-heading">
97
+ <h1>{{@site.title}}</h1>
98
+ {{#if @site.description}}<p>{{@site.description}}</p>{{/if}}
99
+ </header>
100
+
101
+ {{#if posts}}
102
+ <section class="ghcn-post-grid" aria-label="Latest posts">
103
+ {{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
104
+ </section>
105
+ {{else}}
106
+ <div class="ghcn-empty">Publish your first post in Ghost Admin to see it here.</div>
107
+ {{/if}}
108
+
109
+ {{pagination}}
110
+ ${extras ? `\n${extras}\n` : ''}`;
111
+ }
112
+ function postTemplate(options) {
113
+ const author = options.includeAuthorCard
114
+ ? '\n {{#primary_author}}{{> "components/author-card"}}{{/primary_author}}\n'
115
+ : '';
116
+ return `{{!< default}}
117
+
118
+ {{#post}}
119
+ {{> "components/post-header"}}
120
+ <article class="ghcn-article {{post_class}}">
121
+ <div class="ghcn-article-content">{{content}}</div>
122
+ </article>
123
+ {{#if access}}{{> "components/member-cta"}}{{/if}}
124
+ ${author} {{comments}}
125
+ {{/post}}
126
+ `;
127
+ }
128
+ function pageTemplate() {
129
+ return `{{!< default}}
130
+
131
+ {{#post}}
132
+ {{#match @page.show_title_and_feature_image}}
133
+ {{> "components/post-header"}}
134
+ {{/match}}
135
+ <article class="ghcn-article {{post_class}}">
136
+ <div class="ghcn-article-content">{{content}}</div>
137
+ </article>
138
+ {{/post}}
139
+ `;
140
+ }
141
+ function archiveTemplate(kind) {
142
+ const header = kind === 'tag'
143
+ ? `{{#tag}}<header class="ghcn-page-heading"><h1>{{name}}</h1>{{#if description}}<p>{{description}}</p>{{/if}}</header>{{/tag}}`
144
+ : `{{#author}}<header class="ghcn-page-heading"><h1>{{name}}</h1>{{#if bio}}<p>{{bio}}</p>{{/if}}</header>{{/author}}`;
145
+ return `{{!< default}}
146
+
147
+ ${header}
148
+ <section class="ghcn-post-grid" aria-label="Posts">
149
+ {{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
150
+ </section>
151
+ {{pagination}}
152
+ `;
153
+ }
154
+ function packageJson(options) {
155
+ const gscanCommand = {
156
+ npm: 'npx --yes gscan@6.4.2 .',
157
+ pnpm: 'pnpm dlx gscan@6.4.2 .',
158
+ yarn: 'yarn dlx gscan@6.4.2 .',
159
+ bun: 'bunx gscan@6.4.2 .'
160
+ };
161
+ const scripts = options.style === 'tailwind'
162
+ ? {
163
+ dev: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --watch',
164
+ build: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --minify',
165
+ test: 'node ./scripts/check.mjs',
166
+ zip: 'npm run build && node ./scripts/zip.mjs',
167
+ validate: gscanCommand[options.packageManager]
168
+ }
169
+ : {
170
+ dev: 'node ./scripts/dev.mjs',
171
+ build: 'node ./scripts/build.mjs',
172
+ test: 'node ./scripts/check.mjs',
173
+ zip: 'npm run build && node ./scripts/zip.mjs',
174
+ validate: gscanCommand[options.packageManager]
175
+ };
176
+ const devDependencies = {};
177
+ // Use the selected package manager for the build preceding archive creation.
178
+ scripts.zip = `${options.packageManager} run build && node ./scripts/zip.mjs`;
179
+ if (options.style === 'tailwind') {
180
+ devDependencies.tailwindcss = '^4.1.0';
181
+ devDependencies['@tailwindcss/cli'] = '^4.1.0';
182
+ }
183
+ return JSON.stringify({
184
+ name: options.themeName,
185
+ description: `A Ghost theme created with ghostcn`,
186
+ version: '1.0.0',
187
+ private: true,
188
+ author: {
189
+ name: options.authorName || 'Theme Author',
190
+ email: options.authorEmail || 'hello@example.com'
191
+ },
192
+ engines: { ghost: '>=5.54.1', node: options.style === 'tailwind' ? '>=20.0.0' : '>=18.0.0' },
193
+ license: 'MIT',
194
+ keywords: ['ghost-theme', 'ghost', 'ghostcn'],
195
+ scripts,
196
+ devDependencies,
197
+ config: {
198
+ posts_per_page: 9,
199
+ card_assets: true,
200
+ image_sizes: { xs: { width: 160 }, s: { width: 400 }, m: { width: 750 }, l: { width: 1200 }, xl: { width: 2000 } },
201
+ custom: {
202
+ color_scheme: { type: 'select', options: ['Light', 'Dark', 'Auto'], default: options.colorScheme }
203
+ }
204
+ }
205
+ }, null, 2) + '\n';
206
+ }
207
+ function readme(options) {
208
+ const run = options.packageManager === 'npm' ? 'npm run' : `${options.packageManager} run`;
209
+ return `# ${options.themeName}
210
+
211
+ A Ghost theme generated by [ghostcn](https://www.npmjs.com/package/ghostcn).
212
+
213
+ ## Development
214
+
215
+ \`\`\`bash
216
+ ${options.packageManager} install
217
+ ${run} dev
218
+ \`\`\`
219
+
220
+ Use \`${run} build\` for a production stylesheet, \`${run} test\` for offline scaffold checks, and \`${run} validate\` for official gscan validation (downloads the pinned validator on demand).
221
+
222
+ The dev command only watches CSS. It does not start Ghost or serve this theme.
223
+ Use Node 22.13.1+ or Node 24 for official gscan validation. ${options.style === 'tailwind' ? 'The Tailwind build requires Node 20 or later.' : 'The vanilla build needs Node 18 or later.'}
224
+
225
+ ## Preview in Ghost
226
+
227
+ 1. Install and start a local Ghost development site using the [official guide](https://docs.ghost.org/install/local/).
228
+ 2. Place this entire theme folder under that site's \`content/themes\` directory. Run the commands above from the moved folder.
229
+ 3. From the Ghost installation directory, run \`ghost restart\` so Ghost discovers the new theme.
230
+ 4. Open your site's \`/ghost/\` admin, go to Settings → Design → Change theme, and activate this theme.
231
+ 5. Open the site's URL (usually http://localhost:2368). Keep \`${run} dev\` running and refresh the browser after edits. If Ghost is not running, use \`ghost start\` from its installation directory.
232
+
233
+ Do not edit or replace Ghost's own installation files. For remote Ghost or Ghost(Pro), upload a ZIP instead of using the local preview steps.
234
+
235
+ ## Customize
236
+
237
+ You own the files in \`partials/components\` and \`assets/css/components\`. ${options.style === 'tailwind'
238
+ ? 'Add normal Tailwind classes to the markup, for example `ghcn-button bg-purple-600 hover:bg-purple-700 text-white`. No important modifier is needed for ghostcn defaults. Semantic utilities such as `bg-primary` and `border-border` are configured in `assets/css/ghostcn-tailwind.css`. Put additional CSS in `assets/css/source.css`.'
239
+ : 'Edit the component CSS directly, or put token and selector overrides in `assets/css/source.css`. The built stylesheet loads after ghostcn, so equal-specificity overrides win.'}
240
+
241
+ Membership UI follows Ghost's enabled/invite-only/paid settings. Pricing comes from public tiers configured in Ghost Admin; payments must be configured before paid plans appear. The custom \`partials/content-cta.hbs\` renders one paywall for protected posts without exposing restricted content.
242
+
243
+ ## Package for upload
244
+
245
+ \`\`\`bash
246
+ ${run} test
247
+ ${run} validate
248
+ ${run} zip
249
+ \`\`\`
250
+
251
+ The zip command builds first, then writes \`dist/${options.themeName}-1.0.0.zip\` (the filename follows package.json's version). It contains runtime templates and assets, not node_modules, scripts, lockfiles, or repository metadata. Re-running replaces that generated ZIP. Upload it in Ghost Admin → Settings → Design → Change theme → Upload theme. Offline checks do not replace gscan or testing on your target Ghost version (minimum 5.54.1).
252
+ `;
253
+ }
254
+ const vanillaBuildScript = `import { copyFileSync, mkdirSync } from 'node:fs';
255
+ mkdirSync(new URL('../assets/built/', import.meta.url), { recursive: true });
256
+ copyFileSync(new URL('../assets/css/source.css', import.meta.url), new URL('../assets/built/screen.css', import.meta.url));
257
+ console.log('Built assets/built/screen.css');
258
+ `;
259
+ const vanillaDevScript = `import { watch } from 'node:fs';
260
+ import './build.mjs';
261
+ const source = new URL('../assets/css/source.css', import.meta.url);
262
+ let timer;
263
+ console.log('Watching assets/css/source.css — press Ctrl+C to stop.');
264
+ watch(source, () => {
265
+ clearTimeout(timer);
266
+ timer = setTimeout(() => import('./build.mjs?' + Date.now()), 50);
267
+ });
268
+ `;
269
+ function scaffoldTheme(options) {
270
+ const themeName = sanitizeThemeName(options.themeName);
271
+ const parent = path_1.default.resolve(options.parentDirectory);
272
+ const themeRoot = path_1.default.resolve(parent, themeName);
273
+ if (themeRoot === parent || !themeRoot.startsWith(`${parent}${path_1.default.sep}`)) {
274
+ throw new Error('The generated theme must stay inside the selected parent directory.');
275
+ }
276
+ if (fs_1.default.existsSync(themeRoot) && fs_1.default.readdirSync(themeRoot).length > 0) {
277
+ throw new Error(`Cannot create "${themeName}" because that directory is not empty.`);
278
+ }
279
+ fs_1.default.mkdirSync(themeRoot, { recursive: true });
280
+ const css = baseThemeCss();
281
+ const sourceCss = options.style === 'tailwind'
282
+ ? `@import "tailwindcss";\n@source "../../**/*.hbs";\n@import "./ghostcn-tailwind.css";\n\n@layer base {\n${css}}\n`
283
+ : css;
284
+ const files = {
285
+ 'package.json': packageJson({ ...options, themeName }),
286
+ 'default.hbs': defaultTemplate(options.colorScheme),
287
+ 'index.hbs': indexTemplate(options),
288
+ 'post.hbs': postTemplate(options),
289
+ 'partials/content-cta.hbs': '{{{html}}}\n{{> "components/member-cta"}}\n',
290
+ 'page.hbs': pageTemplate(),
291
+ 'tag.hbs': archiveTemplate('tag'),
292
+ 'author.hbs': archiveTemplate('author'),
293
+ 'assets/css/source.css': sourceCss,
294
+ 'assets/built/screen.css': css,
295
+ 'scripts/check.mjs': "import { fileURLToPath } from 'node:url';\nimport { reportTheme } from './theme-tools.mjs';\nif (!reportTheme(fileURLToPath(new URL('../', import.meta.url)))) process.exitCode = 1;\n",
296
+ 'scripts/zip.mjs': "import { fileURLToPath } from 'node:url';\nimport { packageTheme } from './theme-tools.mjs';\nconsole.log('Created ' + packageTheme(fileURLToPath(new URL('../', import.meta.url))).output);\n",
297
+ 'scripts/theme-tools.mjs': fs_1.default.readFileSync((0, theme_tooling_1.themeToolPath)(), 'utf8'),
298
+ '.gitignore': 'node_modules\n*.zip\n.DS_Store\n',
299
+ 'README.md': readme(options)
300
+ };
301
+ if (options.style === 'css') {
302
+ files['scripts/build.mjs'] = vanillaBuildScript;
303
+ files['scripts/dev.mjs'] = vanillaDevScript;
304
+ }
305
+ if (options.style === 'tailwind')
306
+ files['assets/css/ghostcn-tailwind.css'] = (0, styles_1.tailwindTheme)();
307
+ for (const [relativePath, content] of Object.entries(files)) {
308
+ const target = (0, theme_files_1.resolveWithinTheme)(themeRoot, relativePath);
309
+ fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
310
+ fs_1.default.writeFileSync(target, content, 'utf8');
311
+ }
312
+ return { themeRoot, files: Object.keys(files) };
313
+ }
@@ -0,0 +1,2 @@
1
+ export declare function themeToolPath(): string;
2
+ export declare function runThemeTool(action: 'doctor' | 'pack', themeRoot: string): number;
@@ -0,0 +1,20 @@
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.themeToolPath = themeToolPath;
7
+ exports.runThemeTool = runThemeTool;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const child_process_1 = require("child_process");
11
+ function themeToolPath() {
12
+ const bundled = path_1.default.join(__dirname, '../templates/theme-tools.mjs');
13
+ return fs_1.default.existsSync(bundled) ? bundled : path_1.default.join(__dirname, '../../templates/theme-tools.mjs');
14
+ }
15
+ function runThemeTool(action, themeRoot) {
16
+ const result = (0, child_process_1.spawnSync)(process.execPath, [themeToolPath(), action, themeRoot], { stdio: 'inherit' });
17
+ if (result.error)
18
+ console.error(result.error.message);
19
+ return result.status ?? 1;
20
+ }
@@ -0,0 +1,46 @@
1
+ export type BaseColor = 'zinc' | 'slate' | 'stone' | 'gray' | 'neutral';
2
+ export type AccentColor = 'ghost' | 'zinc' | 'indigo' | 'violet' | 'blue' | 'emerald' | 'rose' | 'orange';
3
+ export type Radius = '0' | '0.25rem' | '0.5rem' | '0.75rem' | '1rem' | '9999px';
4
+ export interface ThemeConfig {
5
+ style: 'tailwind' | 'css';
6
+ baseColor: BaseColor;
7
+ accentColor: AccentColor;
8
+ radius: Radius;
9
+ }
10
+ interface ColorTokens {
11
+ background: string;
12
+ foreground: string;
13
+ card: string;
14
+ cardForeground: string;
15
+ popover: string;
16
+ popoverForeground: string;
17
+ secondary: string;
18
+ secondaryForeground: string;
19
+ muted: string;
20
+ mutedForeground: string;
21
+ accent: string;
22
+ accentForeground: string;
23
+ destructive: string;
24
+ destructiveForeground: string;
25
+ border: string;
26
+ input: string;
27
+ ring: string;
28
+ }
29
+ export declare const BASE_PALETTES: Record<BaseColor, {
30
+ light: ColorTokens;
31
+ dark: ColorTokens;
32
+ }>;
33
+ export declare const ACCENT_COLORS: Record<AccentColor, {
34
+ light: {
35
+ primary: string;
36
+ primaryForeground: string;
37
+ ring?: string;
38
+ };
39
+ dark: {
40
+ primary: string;
41
+ primaryForeground: string;
42
+ ring?: string;
43
+ };
44
+ }>;
45
+ export declare function generateThemeCss(config: ThemeConfig): string;
46
+ export {};