@opencloudcms/cli 0.0.0-stage → 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.
@@ -0,0 +1,519 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitignore = exports.extensionsTs = exports.tsconfigNextJson = exports.nextEnvDts = exports.postcssConfig = exports.globalsCss = exports.exampleBlockTsx = exports.blocksIndexTs = exports.previewExitRouteTs = exports.previewRouteTs = exports.siteCatchAllPageTsx = exports.siteMessagesTs = exports.defaultTheme = exports.providersTsx = exports.siteLayoutTsx = exports.adminWithBlocksTsx = exports.adminPageTsx = exports.adminLayoutTsx = exports.appModuleTs = exports.mainTs = exports.rootTs = exports.configTs = exports.tsconfigServerJson = void 0;
4
+ exports.packageJson = packageJson;
5
+ exports.nextConfigTs = nextConfigTs;
6
+ exports.envFile = envFile;
7
+ exports.dockerCompose = dockerCompose;
8
+ exports.readme = readme;
9
+ function packageJson(name, deps, devDeps) {
10
+ const sort = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b)));
11
+ return (JSON.stringify({
12
+ name,
13
+ private: true,
14
+ version: '0.1.0',
15
+ scripts: {
16
+ dev: 'opencloudcms migrate:up && tsx --tsconfig tsconfig.server.json src/main.ts',
17
+ build: 'tsc -p tsconfig.server.json && next build',
18
+ start: 'cross-env NODE_ENV=production opencloudcms migrate:up && cross-env NODE_ENV=production node dist/src/main.js',
19
+ opencloudcms: 'opencloudcms',
20
+ },
21
+ dependencies: sort(deps),
22
+ devDependencies: sort(devDeps),
23
+ // pnpm 10 skips install scripts unless allowed: argon2 and sharp are native modules.
24
+ pnpm: { onlyBuiltDependencies: ['@nestjs/core', 'argon2', 'esbuild', 'sharp'] },
25
+ }, null, 2) + '\n');
26
+ }
27
+ const tsconfigServerJson = () => JSON.stringify({
28
+ compilerOptions: {
29
+ target: 'ES2022',
30
+ module: 'CommonJS',
31
+ moduleResolution: 'node',
32
+ lib: ['ES2022'],
33
+ strict: true,
34
+ experimentalDecorators: true,
35
+ emitDecoratorMetadata: true,
36
+ esModuleInterop: true,
37
+ skipLibCheck: true,
38
+ // Block files (src/blocks/**/*.block.tsx) are TSX: the server imports them for blockManifest.
39
+ jsx: 'react-jsx',
40
+ outDir: 'dist',
41
+ rootDir: '.',
42
+ },
43
+ include: ['src', 'opencloudcms.config.ts'],
44
+ // Browser-only page action files (Next compiles them, with `@/` imports); the server never loads them.
45
+ exclude: ['src/actions/*.client.ts', 'src/actions/client.ts'],
46
+ }, null, 2) + '\n';
47
+ exports.tsconfigServerJson = tsconfigServerJson;
48
+ const configTs = () => `import { defineConfig } from '@opencloudcms/schema';
49
+ import locales from './src/locales';
50
+
51
+ export default defineConfig({
52
+ database: { url: process.env.DATABASE_URL! },
53
+ // Website languages live in src/locales.ts (managed from the admin: Settings > Languages).
54
+ ...locales,
55
+ });
56
+ `;
57
+ exports.configTs = configTs;
58
+ const rootTs = () => `import * as fs from 'node:fs';
59
+ import * as path from 'node:path';
60
+
61
+ /** Project root = nearest directory (walking up from \`from\`) with a package.json; works from src/ and dist/src/. */
62
+ export function findProjectRoot(from: string): string {
63
+ let dir = from;
64
+ for (;;) {
65
+ if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
66
+ const parent = path.dirname(dir);
67
+ if (parent === dir) return process.cwd();
68
+ dir = parent;
69
+ }
70
+ }
71
+ `;
72
+ exports.rootTs = rootTs;
73
+ const mainTs = () => `import 'reflect-metadata';
74
+ import * as fs from 'node:fs';
75
+ import * as path from 'node:path';
76
+ import { NestFactory } from '@nestjs/core';
77
+ import { findProjectRoot } from './root';
78
+
79
+ async function bootstrap() {
80
+ // Load .env before the app (and opencloudcms.config.ts) is evaluated; variables already set win.
81
+ const envFile = path.join(findProjectRoot(__dirname), '.env');
82
+ if (fs.existsSync(envFile)) {
83
+ try {
84
+ process.loadEnvFile(envFile);
85
+ } catch (e) {
86
+ console.warn(\`Could not load \${envFile}: \${(e as Error).message}\`);
87
+ }
88
+ }
89
+ const { AppModule } = await import('./app.module');
90
+ // bodyParser: false — @opencloudcms/core owns request body parsing.
91
+ const app = await NestFactory.create(AppModule, { bodyParser: false });
92
+ // useProcessExit: after hooks finish, exit even if Next left open handles; SIGINT/SIGTERM only.
93
+ app.enableShutdownHooks(['SIGINT', 'SIGTERM'], { useProcessExit: true });
94
+ const port = Number(process.env.PORT ?? 4000);
95
+ await app.listen(port);
96
+ const publicUrl = process.env.OPENCLOUDCMS_PUBLIC_URL ?? \`http://localhost:\${port}\`;
97
+ console.log(\`OpenCloudCMS ready at \${publicUrl}\`);
98
+ console.log(\`Admin: \${publicUrl}/admin\`);
99
+ }
100
+ // Exit on a boot failure: Next installs its own unhandledRejection handler, which would keep the process alive.
101
+ bootstrap().catch((e: unknown) => {
102
+ console.error(e);
103
+ process.exit(1);
104
+ });
105
+ `;
106
+ exports.mainTs = mainTs;
107
+ const appModuleTs = () => `import { Module } from '@nestjs/common';
108
+ import { OpenCloudCmsModule } from '@opencloudcms/core';
109
+ import { blockManifest } from '@opencloudcms/core/blocks';
110
+ import config from '../opencloudcms.config';
111
+ import blocks from './blocks';
112
+ import contentGroups from './content-groups';
113
+ import { contentTypes } from './generated';
114
+ import { hooks } from './extensions';
115
+ import { findProjectRoot } from './root';
116
+
117
+ const projectRoot = findProjectRoot(__dirname);
118
+
119
+ @Module({
120
+ imports: [
121
+ OpenCloudCmsModule.forRoot({
122
+ root: projectRoot,
123
+ config,
124
+ contentTypes,
125
+ // Sidebar groups of the content types (src/content-groups.ts, managed from Settings > Content types).
126
+ contentGroups,
127
+ hooks,
128
+ // Content Type Builder writes schema files + migrations: dev only.
129
+ schemaEditable: process.env.NODE_ENV !== 'production',
130
+ // One Next app (app/) serves the admin at /admin and the website everywhere else.
131
+ // Set \`web: { enabled: false }\` to serve only the API (no admin, no website).
132
+ web: { dir: projectRoot },
133
+ // Page builder: publishing a page that uses a block missing from src/blocks fails with 422 unknown_block.
134
+ pages: { blocks: blockManifest(blocks) },
135
+ }),
136
+ ],
137
+ })
138
+ export class AppModule {}
139
+ `;
140
+ exports.appModuleTs = appModuleTs;
141
+ const adminLayoutTsx = () => `import '../globals.css';
142
+ import AdminLayout, { metadata as adminMetadata } from '@opencloudcms/core/admin/layout';
143
+
144
+ export const dynamic = 'force-dynamic';
145
+ export const metadata = adminMetadata;
146
+ export default AdminLayout;
147
+ `;
148
+ exports.adminLayoutTsx = adminLayoutTsx;
149
+ const adminPageTsx = () => `export { default } from '../AdminWithBlocks';
150
+ `;
151
+ exports.adminPageTsx = adminPageTsx;
152
+ /** The project registry holds functions (render), so only a client component can hand it to AdminApp. */
153
+ const adminWithBlocksTsx = () => `'use client';
154
+ // The admin with the page-builder blocks of this project (src/blocks). A client component: the block
155
+ // registry holds functions, which a server component cannot pass to AdminApp.
156
+ import AdminApp from '@opencloudcms/core/admin';
157
+ import blocks from '@/blocks';
158
+
159
+ export default function AdminWithBlocks() {
160
+ return <AdminApp blocks={blocks} />;
161
+ }
162
+ `;
163
+ exports.adminWithBlocksTsx = adminWithBlocksTsx;
164
+ const siteLayoutTsx = (name) => `import '../globals.css';
165
+ import type { Metadata } from 'next';
166
+ import type { ReactNode } from 'react';
167
+ import { ThemeStyle } from '@opencloudcms/core/blocks';
168
+ import locales from '@/locales';
169
+ import theme from '@/theme';
170
+ import Providers from '../providers';
171
+
172
+ export const metadata: Metadata = {
173
+ title: '${name}',
174
+ };
175
+
176
+ // ThemeStyle writes the brand colors of src/theme.ts (active palette) as --ocms-color-* variables; blocks use them
177
+ // as \`brand:<name>\` colors. Providers (app/providers.tsx) gives client components the storefront SDK hooks.
178
+ export default function SiteLayout({ children }: { children: ReactNode }) {
179
+ return (
180
+ <html lang={locales.defaultLocale}>
181
+ <head>
182
+ <ThemeStyle theme={theme} />
183
+ </head>
184
+ <body className="bg-(--ocms-color-surface) text-(--ocms-color-ink) antialiased">
185
+ <Providers>{children}</Providers>
186
+ </body>
187
+ </html>
188
+ );
189
+ }
190
+ `;
191
+ exports.siteLayoutTsx = siteLayoutTsx;
192
+ /** `app/providers.tsx`: the storefront SDK provider (customer, sign-in, page actions) around the website. */
193
+ const providersTsx = () => `'use client';
194
+ // Client-side providers of the website. OpenCloudCmsProvider (@opencloudcms/client) gives client components
195
+ // useCustomer / useSignIn / useSignOut / useClient; signInPath is where signed-out customers are sent.
196
+ import type { ReactNode } from 'react';
197
+ import { OpenCloudCmsProvider } from '@opencloudcms/client';
198
+
199
+ export default function Providers({ children }: { children: ReactNode }) {
200
+ return <OpenCloudCmsProvider signInPath="/account/login">{children}</OpenCloudCmsProvider>;
201
+ }
202
+ `;
203
+ exports.providersTsx = providersTsx;
204
+ /** `src/theme.ts` of a new project: the brand colors the site layout uses, one palette (printed with printThemeFile). */
205
+ const defaultTheme = () => ({
206
+ colors: {
207
+ surface: { label: 'Surface' },
208
+ ink: { label: 'Ink' },
209
+ accent: { label: 'Accent' },
210
+ 'accent-ink': { label: 'Text on accent' },
211
+ },
212
+ palettes: {
213
+ default: { label: 'Default', values: { surface: '#ffffff', ink: '#171717', accent: '#171717', 'accent-ink': '#fafafa' } },
214
+ },
215
+ activePalette: 'default',
216
+ });
217
+ exports.defaultTheme = defaultTheme;
218
+ /** Website strings: en-US is required, other locales may be partial (missing keys fall back to en-US). */
219
+ const siteMessagesTs = () => `// Strings of the website. Server components import the helpers from '@opencloudcms/core';
220
+ // client components ('use client') must import them from '@opencloudcms/core/admin' instead.
221
+ import { defineMessages } from '@opencloudcms/core';
222
+
223
+ export const messages = defineMessages({
224
+ // Add strings per language, e.g. 'en-US': { footer: { contact: 'Contact us' } }, 'vi-VN': { footer: { contact: 'Liên hệ' } },
225
+ // and read them with createTranslator(messages, locale)('footer.contact').
226
+ 'en-US': {},
227
+ 'vi-VN': {},
228
+ });
229
+ `;
230
+ exports.siteMessagesTs = siteMessagesTs;
231
+ /** Catch-all website renderer: pages built in /admin/pages (published; drafts in preview), Welcome at `/` until one exists. */
232
+ const siteCatchAllPageTsx = (name) => `// Every website path that no other route of app/(site) handles: the page published at that path in the admin
233
+ // (Pages), rendered with the blocks of src/blocks. Draft mode (website preview) shows drafts to signed-in admins.
234
+ // Until a page is published at /, the home shows a welcome page. A path without a page is a 404 (not-found.tsx).
235
+ import { createCmsPage } from '@opencloudcms/core/blocks/next';
236
+ import blocks from '@/blocks';
237
+
238
+ const cms = createCmsPage({ blocks, siteName: '${name}' });
239
+
240
+ // Next only reads segment config written literally in this file.
241
+ export const dynamic = 'force-dynamic';
242
+ export default cms.Page;
243
+ export const generateMetadata = cms.generateMetadata;
244
+ `;
245
+ exports.siteCatchAllPageTsx = siteCatchAllPageTsx;
246
+ /**
247
+ * Website preview of a draft (\`/__opencloudcms/preview?page=&locale=\`). The folder is \`%5F_opencloudcms\`: Next treats
248
+ * folders starting with \`_\` as private, \`%5F\` is its documented escape for a URL segment starting with \`_\`.
249
+ */
250
+ const previewRouteTs = () => `// Website preview (draft mode) for signed-in admins: /__opencloudcms/preview?page=<documentId>&locale=<locale>.
251
+ // The folder is named %5F_opencloudcms because Next treats folders starting with "_" as private.
252
+ import { createPreviewRoute } from '@opencloudcms/core/blocks/next';
253
+
254
+ export const dynamic = 'force-dynamic';
255
+ export const { GET } = createPreviewRoute();
256
+ `;
257
+ exports.previewRouteTs = previewRouteTs;
258
+ const previewExitRouteTs = () => `// Leaves the website preview: /__opencloudcms/preview/exit (turns draft mode off, back to the published page).
259
+ import { createPreviewExitRoute } from '@opencloudcms/core/blocks/next';
260
+
261
+ export const dynamic = 'force-dynamic';
262
+ export const { GET } = createPreviewExitRoute();
263
+ `;
264
+ exports.previewExitRouteTs = previewExitRouteTs;
265
+ const blocksIndexTs = () => `// Blocks of the page builder (/admin/pages): the core library plus your own.
266
+ // This file is imported by the admin editor, the website renderer and the server (blockManifest in
267
+ // src/app.module.ts), so every block must be isomorphic: no server-only APIs, no data fetching in render
268
+ // (data comes in through b.entry / b.entries / b.link / b.image props), no CSS imports (Tailwind classes only).
269
+ //
270
+ // Blocks made in the admin Block Builder (Settings > Blocks) live in src/blocks/<name>/<name>.block.ts and are
271
+ // listed in ./composed.ts, which the builder rewrites. Keep the import and the spread below.
272
+ import { coreBlocks, defineBlocks } from '@opencloudcms/core/blocks';
273
+ import { composedBlocks } from './composed';
274
+ // import Example from './example/example.block';
275
+
276
+ export default defineBlocks([...coreBlocks, ...composedBlocks]);
277
+ // To add the example: uncomment the import above and use \`defineBlocks([...coreBlocks, ...composedBlocks, Example])\`.
278
+ `;
279
+ exports.blocksIndexTs = blocksIndexTs;
280
+ const exampleBlockTsx = () => `// An example block. To offer it in the page editor, register it in src/blocks/index.ts.
281
+ //
282
+ // - \`name\` is the stable key stored in page data: PascalCase and unique. Renaming it orphans existing pages
283
+ // (publishing them then fails with unknown_block), so treat it like a database column name.
284
+ // - \`fields\` use the b.* builders; \`render\` receives their values (data fields arrive already resolved).
285
+ // - \`render\` runs in the editor (browser) and on the website (server): no server-only APIs, no fetch,
286
+ // no CSS imports. Style with Tailwind classes written out in full (app/globals.css scans src/blocks).
287
+ // - Changing the shape of the props? Bump \`version\` and add a \`migrate\` step (see the README).
288
+ import { b, defineBlock } from '@opencloudcms/core/blocks';
289
+
290
+ const TONE = {
291
+ neutral: 'bg-muted text-foreground',
292
+ primary: 'bg-primary text-primary-foreground',
293
+ } as const;
294
+
295
+ export default defineBlock({
296
+ name: 'Example',
297
+ label: { 'en-US': 'Example', 'vi-VN': 'Ví dụ' },
298
+ category: 'basic',
299
+ icon: 'sparkles',
300
+ fields: {
301
+ title: b.text({ label: 'Title', default: 'Hello from src/blocks' }),
302
+ body: b.longText({ label: 'Body', default: 'Edit this block in src/blocks/example/example.block.tsx.' }),
303
+ tone: b.select({
304
+ label: 'Tone',
305
+ options: [
306
+ { value: 'neutral', label: 'Neutral' },
307
+ { value: 'primary', label: 'Primary' },
308
+ ],
309
+ default: 'neutral',
310
+ }),
311
+ },
312
+ render: ({ title, body, tone }) => (
313
+ <section className={\`rounded-xl px-6 py-8 \${TONE[tone]}\`}>
314
+ <h2 className="text-2xl font-semibold tracking-tight">{title}</h2>
315
+ {body ? <p className="mt-2 opacity-90">{body}</p> : null}
316
+ </section>
317
+ ),
318
+ });
319
+ `;
320
+ exports.exampleBlockTsx = exampleBlockTsx;
321
+ const globalsCss = () => `@import "tailwindcss";
322
+ @import "@opencloudcms/core/admin/theme.css";
323
+ @source "../node_modules/@opencloudcms/core/dist/admin";
324
+ /* Page builder: classes of the core blocks (and the preview bar), and of this project's blocks. */
325
+ @source "../node_modules/@opencloudcms/core/dist/blocks";
326
+ @source "../src/blocks";
327
+ `;
328
+ exports.globalsCss = globalsCss;
329
+ /** `link` (set by `--link`): the core is a symlink outside the project; Turbopack and output tracing only follow files under their root. */
330
+ function nextConfigTs(link) {
331
+ if (!link) {
332
+ return `import type { NextConfig } from 'next';
333
+
334
+ // Server components may import the i18n helpers from @opencloudcms/core: under the \`react-server\` condition the
335
+ // package resolves to a NestJS-free module. Client components ('use client') import them from @opencloudcms/core/admin.
336
+ const nextConfig: NextConfig = {};
337
+
338
+ export default nextConfig;
339
+ `;
340
+ }
341
+ const root = JSON.stringify(link.root);
342
+ return `import type { NextConfig } from 'next';
343
+
344
+ // @opencloudcms/core is linked from outside this directory (opencloudcms init --link); Turbopack and output tracing
345
+ // only follow files under their root, so both point at the common ancestor of the project and the checkout.
346
+ // Server components may import the i18n helpers from @opencloudcms/core: under the \`react-server\` condition the
347
+ // package resolves to a NestJS-free module. Client components ('use client') import them from @opencloudcms/core/admin.
348
+ const nextConfig: NextConfig = {
349
+ turbopack: { root: ${root} },
350
+ outputFileTracingRoot: ${root},
351
+ };
352
+
353
+ export default nextConfig;
354
+ `;
355
+ }
356
+ const postcssConfig = () => `export default {
357
+ plugins: {
358
+ '@tailwindcss/postcss': {},
359
+ },
360
+ };
361
+ `;
362
+ exports.postcssConfig = postcssConfig;
363
+ const nextEnvDts = () => `/// <reference types="next" />
364
+ /// <reference types="next/image-types/global" />
365
+ import "./.next/types/routes.d.ts";
366
+ import "./.next/types/root-params.d.ts";
367
+
368
+ // NOTE: This file should not be edited
369
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
370
+ `;
371
+ exports.nextEnvDts = nextEnvDts;
372
+ const tsconfigNextJson = () => JSON.stringify({
373
+ compilerOptions: {
374
+ target: 'ES2022',
375
+ lib: ['dom', 'dom.iterable', 'esnext'],
376
+ allowJs: true,
377
+ skipLibCheck: true,
378
+ strict: true,
379
+ noEmit: true,
380
+ esModuleInterop: true,
381
+ module: 'esnext',
382
+ moduleResolution: 'bundler',
383
+ resolveJsonModule: true,
384
+ isolatedModules: true,
385
+ jsx: 'react-jsx',
386
+ incremental: true,
387
+ plugins: [{ name: 'next' }],
388
+ // `@/…` = src/… in Next-compiled files (app/**); the NestJS server (src/**) keeps relative imports.
389
+ paths: { '@/*': ['./src/*'] },
390
+ },
391
+ include: ['next-env.d.ts', 'app/**/*', '.next/types/**/*.ts', '.next/dev/types/**/*.ts'],
392
+ exclude: ['node_modules'],
393
+ }, null, 2) + '\n';
394
+ exports.tsconfigNextJson = tsconfigNextJson;
395
+ const extensionsTs = () => 'export const hooks = [];\n';
396
+ exports.extensionsTs = extensionsTs;
397
+ function envFile(opts) {
398
+ return `DATABASE_URL=${opts.dbUrl}
399
+ PORT=${opts.port}
400
+ OPENCLOUDCMS_SECRET=${opts.secret}
401
+ # OPENCLOUDCMS_PUBLIC_URL=https://cms.example.com (required when NODE_ENV=production)
402
+ # OPENCLOUDCMS_ADMIN_EMAIL=
403
+ # OPENCLOUDCMS_ADMIN_PASSWORD= (create the admin without the setup wizard)
404
+ `;
405
+ }
406
+ const gitignore = () => 'node_modules\ndist\n.next/\n.env\n*.log\n';
407
+ exports.gitignore = gitignore;
408
+ function dockerCompose(dbName) {
409
+ return `services:
410
+ postgres:
411
+ image: postgres:16
412
+ restart: unless-stopped
413
+ environment:
414
+ POSTGRES_USER: postgres
415
+ POSTGRES_PASSWORD: postgres
416
+ POSTGRES_DB: ${dbName}
417
+ ports:
418
+ - '5432:5432'
419
+ volumes:
420
+ - pgdata:/var/lib/postgresql/data
421
+
422
+ volumes:
423
+ pgdata:
424
+ `;
425
+ }
426
+ function readme(name, pm, port) {
427
+ return `# ${name}
428
+
429
+ An OpenCloudCMS project: a NestJS backend (\`src/\`) and one Next.js app (\`app/\`) that serves the admin at \`/admin\` and your website everywhere else.
430
+
431
+ ## Structure
432
+
433
+ \`\`\`
434
+ src/ NestJS: main.ts, app.module.ts, content types, hooks, generated code
435
+ blocks/ page-builder blocks (index.ts registers them; example/ is a commented sample;
436
+ composed.ts lists the blocks made in the admin Block Builder)
437
+ locales.ts website languages (managed from Settings > Languages)
438
+ theme.ts brand colors and palettes (managed from Page builder > Theme)
439
+ content-groups.ts sidebar groups of content types (managed from Settings > Content types)
440
+ app/ Next.js App Router: one app for the admin and the website
441
+ (admin)/ root layout + page of the admin (AdminWithBlocks.tsx passes src/blocks to the editor)
442
+ (site)/ root layout and strings (messages.ts) of the website: yours to change
443
+ [[...path]]/ renders the pages built in the admin (Pages)
444
+ %5F_opencloudcms/ website preview routes (/__opencloudcms/preview and /exit)
445
+ globals.css Tailwind v4 + the admin theme (scans the core blocks and src/blocks)
446
+ providers.tsx client providers of the website (OpenCloudCmsProvider from @opencloudcms/client)
447
+ migrations/ SQL migrations (opencloudcms migrate:create / migrate:up)
448
+ next.config.ts Next config
449
+ tsconfig.json for Next (\`@/…\` imports = src/…); tsconfig.server.json is for the NestJS server
450
+ opencloudcms.config.ts database, locales
451
+ .env configuration (see .env.example)
452
+ \`\`\`
453
+
454
+ ## Run it
455
+
456
+ \`\`\`sh
457
+ docker compose up -d # Postgres 16 (skip if you already have a database; edit DATABASE_URL in .env)
458
+ ${pm} run dev # applies migrations, then starts NestJS with Next in dev mode
459
+ \`\`\`
460
+
461
+ Open http://localhost:${port}/admin and create the first administrator. The website is at http://localhost:${port}/.
462
+
463
+ Configuration lives in \`.env\` (see \`.env.example\`). Every \`opencloudcms\` command loads it automatically.
464
+
465
+ ## Scripts
466
+
467
+ - \`${pm} run dev\`: applies migrations, then starts the server with Next in dev mode.
468
+ - \`${pm} run build\`: compiles the server (\`tsc -p tsconfig.server.json\`) and builds the Next app (\`next build\`).
469
+ - \`${pm} run start\`: applies migrations, then starts the production server (\`dist/src/main.js\`) with \`NODE_ENV=production\`.
470
+
471
+ ## Deploy
472
+
473
+ 1. Run \`${pm} run build\` first: without a Next build the server answers \`/admin\` and the website with a 503.
474
+ 2. Set \`NODE_ENV=production\` (the \`start\` script sets it for you; set it as well when you run \`build\` in CI so the environment matches).
475
+ 3. Set \`OPENCLOUDCMS_PUBLIC_URL\` to the public URL of the site (required in production, the server refuses to start without it).
476
+ 4. Set \`OPENCLOUDCMS_SECRET\` (random, at least 32 bytes) and \`DATABASE_URL\`.
477
+ 5. Install with dev dependencies (do not use \`--omit=dev\` / \`--prod\`): \`start\` runs \`opencloudcms migrate:up\`, and \`@opencloudcms/cli\` and \`typescript\` are dev dependencies.
478
+ 6. \`${pm} run start\`.
479
+
480
+ ## Website
481
+
482
+ The website is the \`app/(site)\` route group; edit it like any Next app. Pages built in the admin (\`/admin/pages\`) are
483
+ served by \`app/(site)/[[...path]]/page.tsx\`; until a page is published at \`/\` the home shows a welcome page. A file route
484
+ you add (for example \`app/(site)/blog/page.tsx\`) wins over a page with the same path, and the editor warns about it. To run only the API and no admin or website, set \`web: { enabled: false }\` in \`OpenCloudCmsModule.forRoot({ ... })\` (\`src/app.module.ts\`).
485
+
486
+ Limitation: Next keeps its cache in \`.next/cache\` on disk, so caching is only correct when a single instance runs.
487
+
488
+ ## Page builder
489
+
490
+ - Blocks live in \`src/blocks\` and are registered in \`src/blocks/index.ts\` (\`defineBlocks([...coreBlocks, YourBlock])\`).
491
+ The admin editor, the website and the server all import that file, so \`render\` must be isomorphic: no server-only
492
+ APIs, no data fetching (use \`b.entry\` / \`b.entries\` / \`b.link\` / \`b.image\` fields), no CSS imports (Tailwind classes only).
493
+ - Blocks can also be made without code in the admin Block Builder (\`/admin/settings/blocks\`, in dev): each one is a
494
+ \`src/blocks/<name>/<name>.block.ts\` file (\`defineComposedBlock\`) listed in the managed \`src/blocks/composed.ts\`,
495
+ which \`src/blocks/index.ts\` spreads. Commit these files; "Export as TSX" turns a block into ordinary code.
496
+ - Adding or changing a block is a code change (also from the Block Builder): production needs a rebuild to see it;
497
+ building and publishing pages works in production too.
498
+ - Brand colors live in \`src/theme.ts\` (\`defineTheme\`: named colors, several palettes, one \`activePalette\`). Blocks use
499
+ them as \`brand:<name>\`; \`<ThemeStyle theme={theme} />\` in \`app/(site)/layout.tsx\` writes them as \`--ocms-color-<name>\`
500
+ variables. In dev the admin page Page builder > Theme rewrites the file.
501
+ - "View on website" in the editor opens a draft preview (signed-in admins only; over https in production).
502
+
503
+ ## Languages
504
+
505
+ - Website languages are in \`src/locales.ts\` (\`defaultLocale\`, \`locales\`); \`opencloudcms.config.ts\` spreads it. Supported codes: \`en-US\`, \`vi-VN\`, \`fr-FR\`, \`id-ID\`. In dev the admin page Settings > Languages rewrites the file.
506
+ - Website strings are in \`app/(site)/messages.ts\` (\`defineMessages\`: \`en-US\` required, other languages may be partial). Translate with \`createTranslator(messages, locale)\`; format with \`formatDateTime\` / \`formatNumber\`.
507
+ - Server components import these helpers from \`@opencloudcms/core\` (in a server component it resolves to a small module without NestJS). Client components (\`'use client'\`) must import them from \`@opencloudcms/core/admin\`, which also has \`useLocale\`, \`useTranslator\` and \`useFormat\`.
508
+
509
+ ## Security notes
510
+
511
+ - Keep \`.env\` out of version control (it is in \`.gitignore\`) and never reuse \`OPENCLOUDCMS_SECRET\` between environments.
512
+ - While no user exists, whoever opens \`/admin/setup\` first becomes the super admin (the server logs a WARN at every boot). In production, create the admin from the environment instead (\`OPENCLOUDCMS_ADMIN_EMAIL\` / \`OPENCLOUDCMS_ADMIN_PASSWORD\`).
513
+ - The rate limiter is in-memory: it is only correct with a single instance.
514
+ - Run behind HTTPS in production; the session cookie is only marked secure when \`OPENCLOUDCMS_PUBLIC_URL\` is https.
515
+ - \`OPENCLOUDCMS_ADMIN_EMAIL\` / \`OPENCLOUDCMS_ADMIN_PASSWORD\` create an administrator at start-up. Remove them from the environment once the account exists.
516
+ - The Content Type Builder writes schema files and migrations, so it is disabled when \`NODE_ENV=production\`.
517
+ `;
518
+ }
519
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/init/templates.ts"],"names":[],"mappings":";;;AAIA,kCAuBC;AAsTD,oCAyBC;AAgDD,0BAQC;AAID,sCAiBC;AAED,wBA4FC;AAjhBD,SAAgB,WAAW,CAAC,IAAY,EAAE,IAA4B,EAAE,OAA+B;IACrG,MAAM,IAAI,GAAG,CAAC,CAAyB,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzH,OAAO,CACL,IAAI,CAAC,SAAS,CACZ;QACE,IAAI;QACJ,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE;YACP,GAAG,EAAE,4EAA4E;YACjF,KAAK,EAAE,2CAA2C;YAClD,KAAK,EAAE,8GAA8G;YACrH,YAAY,EAAE,cAAc;SAC7B;QACD,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC;QACxB,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC;QAC9B,qFAAqF;QACrF,IAAI,EAAE,EAAE,qBAAqB,EAAE,CAAC,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;KAChF,EACD,IAAI,EACJ,CAAC,CACF,GAAG,IAAI,CACT,CAAC;AACJ,CAAC;AAEM,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAC7C,IAAI,CAAC,SAAS,CACZ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CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3B,oGAAoG;QACpG,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;KAC9B;IACD,OAAO,EAAE,CAAC,eAAe,EAAE,UAAU,EAAE,qBAAqB,EAAE,yBAAyB,CAAC;IACxF,OAAO,EAAE,CAAC,cAAc,CAAC;CAC1B,EACD,IAAI,EACJ,CAAC,CACF,GAAG,IAAI,CAAC;AA1BE,QAAA,gBAAgB,oBA0BlB;AAEJ,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC,4BAA4B,CAAC;AAA1D,QAAA,YAAY,gBAA8C;AAEvE,SAAgB,OAAO,CAAC,IAAqD;IAC3E,OAAO,gBAAgB,IAAI,CAAC,KAAK;OAC5B,IAAI,CAAC,IAAI;sBACM,IAAI,CAAC,MAAM;;;;CAIhC,CAAC;AACF,CAAC;AAEM,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,2CAA2C,CAAC;AAAtE,QAAA,SAAS,aAA6D;AAEnF,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO;;;;;;;qBAOY,MAAM;;;;;;;;CAQ1B,CAAC;AACF,CAAC;AAED,SAAgB,MAAM,CAAC,IAAY,EAAE,EAAkB,EAAE,IAAY;IACnE,OAAO,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BhB,EAAE;;;wBAGoB,IAAI,iFAAiF,IAAI;;;;;;MAM3G,EAAE;MACF,EAAE;MACF,EAAE;;;;WAIG,EAAE;;;;;OAKN,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCR,CAAC;AACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Version of the installed CLI: read from its package.json (`<pkg>/src` under tests, `<pkg>/dist` when installed). */
2
+ export declare function cliVersion(): string;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.cliVersion = cliVersion;
37
+ const fs = __importStar(require("node:fs"));
38
+ const path = __importStar(require("node:path"));
39
+ /** Version of the installed CLI: read from its package.json (`<pkg>/src` under tests, `<pkg>/dist` when installed). */
40
+ function cliVersion() {
41
+ return JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version;
42
+ }
43
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,gCAEC;AAND,4CAA8B;AAC9B,gDAAkC;AAElC,uHAAuH;AACvH,SAAgB,UAAU;IACxB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AACjG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@opencloudcms/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "OpenCloudCMS command line: generate code, create and run migrations, scaffold content types",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/anhdev97/Open-CMS.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "homepage": "https://github.com/anhdev97/Open-CMS#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/anhdev97/Open-CMS/issues"
14
+ },
15
+ "engines": {
16
+ "node": ">=22"
17
+ },
18
+ "main": "dist/index.js",
19
+ "types": "dist/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "bin"
23
+ ],
24
+ "dependencies": {
25
+ "commander": "^12.1.0",
26
+ "jiti": "^2.4.0",
27
+ "@opencloudcms/schema": "0.1.0",
28
+ "@opencloudcms/codegen": "0.1.0",
29
+ "@opencloudcms/db": "0.1.0",
30
+ "@opencloudcms/oauth2": "0.1.0"
31
+ },
32
+ "bin": {
33
+ "opencloudcms": "bin/opencloudcms.js"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.json",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit"
41
+ }
6
42
  }