@digitalygo/create-diggocms-app 0.1.0 → 0.1.2
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 +94 -23
- package/bin/cli.js +58 -94
- package/package.json +5 -2
- package/templates/full/README.md +66 -25
- package/templates/full/components/ExtendedCard.tsx +17 -5
- package/templates/full/components/ExtendedGallery.tsx +43 -0
- package/templates/full/components/ExtendedText.tsx +16 -0
- package/templates/full/components/ExtendedVideo.tsx +27 -0
- package/templates/full/components/server-components.ts +3 -3
- package/templates/full/lib/diggo-config.ts +9 -6
- package/templates/full/package.json +3 -0
- package/templates/full/pages/[...slug].tsx +82 -0
- package/templates/full/pages/_app.tsx +11 -0
- package/templates/full/pages/index.tsx +14 -0
- package/templates/full/postcss.config.js +6 -0
- package/templates/full/styles/globals.css +81 -0
- package/templates/full/tailwind.config.ts +14 -0
- package/templates/full/tsconfig.json +2 -1
- package/templates/minimal/README.md +39 -9
- package/templates/minimal/lib/data-fetching.ts +0 -2
- package/templates/minimal/lib/diggo-config.ts +0 -3
- package/templates/minimal/package.json +3 -0
- package/templates/minimal/pages/[...slug].tsx +73 -0
- package/templates/minimal/pages/_app.tsx +11 -0
- package/templates/minimal/pages/index.tsx +14 -0
- package/templates/minimal/postcss.config.js +6 -0
- package/templates/minimal/{app → styles}/globals.css +4 -0
- package/templates/minimal/tailwind.config.ts +14 -0
- package/templates/minimal/tsconfig.json +2 -1
- package/templates/with-mock/README.md +64 -36
- package/templates/with-mock/components/ExtendedCard.tsx +17 -5
- package/templates/with-mock/components/ExtendedGallery.tsx +43 -0
- package/templates/with-mock/components/ExtendedText.tsx +16 -0
- package/templates/with-mock/components/ExtendedVideo.tsx +27 -0
- package/templates/with-mock/components/server-components.ts +3 -3
- package/templates/with-mock/fixtures/collection.json +59 -18
- package/templates/with-mock/fixtures/pages/chi-siamo.json +9 -8
- package/templates/with-mock/fixtures/pages/contatti.json +10 -7
- package/templates/with-mock/fixtures/pages/home.json +71 -22
- package/templates/with-mock/lib/data-fetching.ts +1 -1
- package/templates/with-mock/lib/diggo-config.ts +9 -6
- package/templates/with-mock/package.json +7 -2
- package/templates/with-mock/pages/[...slug].tsx +103 -0
- package/templates/with-mock/pages/_app.tsx +11 -0
- package/templates/with-mock/pages/index.tsx +14 -0
- package/templates/with-mock/postcss.config.js +6 -0
- package/templates/with-mock/scripts/mock-server.ts +0 -6
- package/templates/with-mock/styles/globals.css +86 -0
- package/templates/with-mock/tailwind.config.ts +14 -0
- package/templates/with-mock/tsconfig.json +2 -1
- package/templates/full/app/[...slug]/page.tsx +0 -115
- package/templates/full/app/globals.css +0 -187
- package/templates/full/app/layout.tsx +0 -25
- package/templates/full/app/page.tsx +0 -6
- package/templates/full/components/ExtendedRichtext.tsx +0 -15
- package/templates/full/components/ExtendedSubtitle.tsx +0 -10
- package/templates/minimal/app/[...slug]/page.tsx +0 -56
- package/templates/minimal/app/layout.tsx +0 -22
- package/templates/minimal/app/page.tsx +0 -6
- package/templates/with-mock/app/[...slug]/page.tsx +0 -115
- package/templates/with-mock/app/globals.css +0 -187
- package/templates/with-mock/app/layout.tsx +0 -25
- package/templates/with-mock/app/page.tsx +0 -6
- package/templates/with-mock/components/ExtendedRichtext.tsx +0 -15
- package/templates/with-mock/components/ExtendedSubtitle.tsx +0 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Create DiggoCMS App
|
|
2
2
|
|
|
3
|
-
A CLI tool to scaffold new DiggoCMS projects with Next.js and the DiggoCMS SDK.
|
|
3
|
+
A CLI tool to scaffold new DiggoCMS projects with Next.js Pages Router and the DiggoCMS SDK.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ A CLI tool to scaffold new DiggoCMS projects with Next.js and the DiggoCMS SDK.
|
|
|
10
10
|
npx create-diggocms-app@latest
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
### With bun
|
|
13
|
+
### With bun (recommended)
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
bun x create-diggocms-app
|
|
@@ -29,41 +29,53 @@ The CLI will guide you through the setup process:
|
|
|
29
29
|
|
|
30
30
|
1. **Project name** - Name of your new project directory
|
|
31
31
|
2. **Template** - Choose from:
|
|
32
|
-
- `full` - Complete setup with all
|
|
33
|
-
- `with-mock` - Full setup + mock API server +
|
|
32
|
+
- `full` - Complete setup with all components, SSG-ready with Pages Router (recommended)
|
|
33
|
+
- `with-mock` - Full setup + mock API server + optional fixtures
|
|
34
34
|
- `minimal` - Basic setup, add components yourself
|
|
35
|
-
3. **
|
|
35
|
+
3. **Fixtures** (with-mock only) - Include sample fixtures for development
|
|
36
|
+
4. **Package manager** - Choose your preferred package manager (bun, npm, yarn, pnpm)
|
|
36
37
|
|
|
37
38
|
## Templates
|
|
38
39
|
|
|
39
40
|
### Minimal
|
|
40
41
|
|
|
41
42
|
A bare-bones setup with just the SDK installed. You'll need to:
|
|
43
|
+
|
|
42
44
|
- Create your own extended components
|
|
43
45
|
- Configure the SDK manually
|
|
44
46
|
- Set up data fetching
|
|
45
47
|
|
|
48
|
+
**Features:**
|
|
49
|
+
|
|
50
|
+
- Next.js 16 with Pages Router
|
|
51
|
+
- Tailwind CSS configured
|
|
52
|
+
- SSG structure with `getStaticProps`/`getStaticPaths`
|
|
53
|
+
- Hot reload via `next dev`
|
|
54
|
+
|
|
46
55
|
Best for: Experienced developers who want full control.
|
|
47
56
|
|
|
48
57
|
### Full
|
|
49
58
|
|
|
50
59
|
Complete setup including:
|
|
51
|
-
|
|
60
|
+
|
|
61
|
+
- Extended templates for all supported component types (title, image, text, video, gallery, card)
|
|
52
62
|
- Navigation components with dropdown support
|
|
53
|
-
- Dynamic routing with `[...slug]`
|
|
54
|
-
- Data fetching helpers
|
|
63
|
+
- Dynamic routing with `[...slug]` using Pages Router
|
|
64
|
+
- Data fetching helpers with SSG
|
|
55
65
|
- Error handling and mock indicators
|
|
56
|
-
-
|
|
66
|
+
- Tailwind CSS with component styles
|
|
57
67
|
|
|
58
68
|
Best for: Most users starting a new project.
|
|
59
69
|
|
|
60
70
|
### With Mock
|
|
61
71
|
|
|
62
72
|
Everything from the full template, plus:
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
73
|
+
|
|
74
|
+
- Standalone mock API server (`scripts/mock-server.ts`) using tsx (works with any package manager)
|
|
75
|
+
- Optional sample fixtures (pages, menu, collection) aligned with SDK payload model
|
|
76
|
+
- Scripts: `mock:api` and `dev:mock` (uses `concurrently` for cross-platform parallel execution)
|
|
66
77
|
- Pre-configured `.env.local` for mock mode
|
|
78
|
+
- Mock mode indicator in UI
|
|
67
79
|
|
|
68
80
|
Best for: Developing without a real CMS API, testing, or learning.
|
|
69
81
|
|
|
@@ -71,13 +83,12 @@ Best for: Developing without a real CMS API, testing, or learning.
|
|
|
71
83
|
|
|
72
84
|
After scaffolding, your project will have this structure:
|
|
73
85
|
|
|
74
|
-
```
|
|
86
|
+
```text
|
|
75
87
|
my-app/
|
|
76
|
-
├──
|
|
77
|
-
│ ├── [...slug]
|
|
78
|
-
│ ├──
|
|
79
|
-
│ ├──
|
|
80
|
-
│ └── globals.css
|
|
88
|
+
├── pages/ # Next.js pages (Pages Router)
|
|
89
|
+
│ ├── [...slug].tsx # Dynamic routes
|
|
90
|
+
│ ├── _app.tsx # App wrapper
|
|
91
|
+
│ ├── index.tsx # Home redirect
|
|
81
92
|
├── components/ # React components
|
|
82
93
|
│ ├── DiggoProvider.tsx
|
|
83
94
|
│ ├── server-components.ts
|
|
@@ -85,10 +96,14 @@ my-app/
|
|
|
85
96
|
├── lib/ # Utilities
|
|
86
97
|
│ ├── diggo-config.ts
|
|
87
98
|
│ └── data-fetching.ts
|
|
88
|
-
├── fixtures/ # Mock data (with-mock only)
|
|
99
|
+
├── fixtures/ # Mock data (with-mock only, optional)
|
|
89
100
|
├── scripts/ # Mock server (with-mock only)
|
|
101
|
+
├── styles/ # Global styles
|
|
102
|
+
│ └── globals.css # Tailwind + custom styles
|
|
90
103
|
├── .env.local.example
|
|
91
104
|
├── next.config.ts
|
|
105
|
+
├── tailwind.config.ts # Tailwind configuration
|
|
106
|
+
├── postcss.config.js # PostCSS configuration
|
|
92
107
|
├── package.json
|
|
93
108
|
├── tsconfig.json
|
|
94
109
|
└── README.md
|
|
@@ -108,6 +123,17 @@ MOCK=1
|
|
|
108
123
|
MOCK_API_URL=http://localhost:3001
|
|
109
124
|
```
|
|
110
125
|
|
|
126
|
+
## Package Manager Support
|
|
127
|
+
|
|
128
|
+
The CLI supports multiple package managers:
|
|
129
|
+
|
|
130
|
+
- **bun** (default if available) - Fast, all-in-one JavaScript runtime
|
|
131
|
+
- **npm** - Node.js default package manager
|
|
132
|
+
- **yarn** - Fast, reliable, and secure dependency management
|
|
133
|
+
- **pnpm** - Fast, disk space efficient package manager
|
|
134
|
+
|
|
135
|
+
Scripts in `package.json` are automatically adjusted for your chosen package manager.
|
|
136
|
+
|
|
111
137
|
## Requirements
|
|
112
138
|
|
|
113
139
|
- Node.js >= 18.0.0 or Bun >= 1.1.0
|
|
@@ -115,22 +141,63 @@ MOCK_API_URL=http://localhost:3001
|
|
|
115
141
|
|
|
116
142
|
## Options
|
|
117
143
|
|
|
118
|
-
|
|
144
|
+
### Default path
|
|
145
|
+
|
|
146
|
+
You can pass the project name as an argument to skip the prompt:
|
|
119
147
|
|
|
120
148
|
```bash
|
|
121
149
|
npx create-diggocms-app@latest my-project
|
|
122
150
|
```
|
|
123
151
|
|
|
124
|
-
|
|
152
|
+
### With fixtures toggle (with-mock template)
|
|
153
|
+
|
|
154
|
+
When selecting the `with-mock` template, you'll be prompted to include fixtures:
|
|
155
|
+
|
|
156
|
+
- **Yes** (default) - Includes sample pages, menu, and collection fixtures
|
|
157
|
+
- **No** - Sets up the mock server infrastructure without sample data
|
|
158
|
+
|
|
159
|
+
## SSG (Static Site Generation)
|
|
160
|
+
|
|
161
|
+
All templates use Next.js Pages Router with SSG-first approach:
|
|
162
|
+
|
|
163
|
+
- `getStaticProps` - Fetches page data at build time
|
|
164
|
+
- `getStaticPaths` - Pre-generates pages (configure for your CMS)
|
|
165
|
+
- ISR (Incremental Static Regeneration) - Enabled with 60s revalidation by default
|
|
166
|
+
|
|
167
|
+
To pre-generate specific pages at build time, update `getStaticPaths` in `pages/[...slug].tsx`.
|
|
168
|
+
|
|
169
|
+
## Commands Reference
|
|
170
|
+
|
|
171
|
+
Commands work with any package manager (bun, npm, yarn, pnpm). Examples use `bun`:
|
|
172
|
+
|
|
173
|
+
### All Templates
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
bun run dev # Start development server with hot reload
|
|
177
|
+
bun run build # Build for production
|
|
178
|
+
bun run start # Start production server
|
|
179
|
+
bun run lint # Run ESLint
|
|
180
|
+
bun run typecheck # Run TypeScript check
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### With-Mock Template Only
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
bun run mock:api # Start the mock API server
|
|
187
|
+
bun run dev:mock # Start mock API and dev server together
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
With yarn, omit `run` (for example: `yarn dev`, `yarn mock:api`).
|
|
125
191
|
|
|
126
192
|
## Troubleshooting
|
|
127
193
|
|
|
128
194
|
### Permission denied
|
|
129
195
|
|
|
130
|
-
If you get a permission error, try:
|
|
196
|
+
If you get a permission error with npx, try:
|
|
131
197
|
|
|
132
198
|
```bash
|
|
133
|
-
|
|
199
|
+
npm install -g create-diggocms-app
|
|
200
|
+
create-diggocms-app
|
|
134
201
|
```
|
|
135
202
|
|
|
136
203
|
Or use a Node version manager like nvm/fnm.
|
|
@@ -143,6 +210,10 @@ If the mock API server fails to start due to port conflicts, set a different por
|
|
|
143
210
|
PORT=3002 bun run mock:api
|
|
144
211
|
```
|
|
145
212
|
|
|
213
|
+
### Hot reload not working
|
|
214
|
+
|
|
215
|
+
Ensure you're using `next dev` (via `bun run dev`, `npm run dev`, `yarn dev`, or `pnpm run dev`). Hot reload is enabled by default in development mode.
|
|
216
|
+
|
|
146
217
|
## Contributing
|
|
147
218
|
|
|
148
219
|
This CLI is part of the DiggoCMS SDK monorepo. See the main repository for contribution guidelines.
|
package/bin/cli.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Create DiggoCMS App - CLI tool to scaffold new DiggoCMS projects
|
|
4
|
-
* Inspired by create-next-app and create-vite
|
|
5
|
-
*/
|
|
6
2
|
|
|
7
3
|
import { createRequire } from 'module';
|
|
8
4
|
import { fileURLToPath } from 'url';
|
|
9
5
|
import { dirname, join } from 'path';
|
|
10
|
-
import { cp, mkdir, readFile, writeFile, access, stat } from 'fs/promises';
|
|
6
|
+
import { cp, mkdir, readFile, writeFile, access, stat, readdir, rm } from 'fs/promises';
|
|
11
7
|
import { execSync } from 'child_process';
|
|
12
8
|
import process from 'process';
|
|
13
9
|
import prompts from 'prompts';
|
|
@@ -31,11 +27,6 @@ const PACKAGE_MANAGERS = ['bun', 'npm', 'yarn', 'pnpm'];
|
|
|
31
27
|
|
|
32
28
|
const DEFAULT_PROJECT_NAME = 'my-diggocms-app';
|
|
33
29
|
|
|
34
|
-
/**
|
|
35
|
-
* Validates project name (no spaces, special chars, etc.)
|
|
36
|
-
* @param {string} name
|
|
37
|
-
* @returns {string | true} Error message or true if valid
|
|
38
|
-
*/
|
|
39
30
|
function validateProjectName(name) {
|
|
40
31
|
if (!name || name.trim().length === 0) {
|
|
41
32
|
return 'Project name is required';
|
|
@@ -52,11 +43,6 @@ function validateProjectName(name) {
|
|
|
52
43
|
return true;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
/**
|
|
56
|
-
* Checks if directory exists and is not empty
|
|
57
|
-
* @param {string} dir
|
|
58
|
-
* @returns {Promise<boolean>}
|
|
59
|
-
*/
|
|
60
46
|
async function isDirectoryEmpty(dir) {
|
|
61
47
|
try {
|
|
62
48
|
const stats = await stat(dir);
|
|
@@ -70,11 +56,6 @@ async function isDirectoryEmpty(dir) {
|
|
|
70
56
|
}
|
|
71
57
|
}
|
|
72
58
|
|
|
73
|
-
/**
|
|
74
|
-
* Checks if a command exists
|
|
75
|
-
* @param {string} cmd
|
|
76
|
-
* @returns {boolean}
|
|
77
|
-
*/
|
|
78
59
|
function commandExists(cmd) {
|
|
79
60
|
try {
|
|
80
61
|
execSync(`${cmd} --version`, { stdio: 'ignore' });
|
|
@@ -84,11 +65,6 @@ function commandExists(cmd) {
|
|
|
84
65
|
}
|
|
85
66
|
}
|
|
86
67
|
|
|
87
|
-
/**
|
|
88
|
-
* Gets the version of Node.js or Bun
|
|
89
|
-
* @param {string} runtime
|
|
90
|
-
* @returns {string | null}
|
|
91
|
-
*/
|
|
92
68
|
function getRuntimeVersion(runtime) {
|
|
93
69
|
try {
|
|
94
70
|
const version = execSync(`${runtime} --version`, { encoding: 'utf-8' }).trim();
|
|
@@ -98,10 +74,6 @@ function getRuntimeVersion(runtime) {
|
|
|
98
74
|
}
|
|
99
75
|
}
|
|
100
76
|
|
|
101
|
-
/**
|
|
102
|
-
* Checks version requirements
|
|
103
|
-
* @returns {{ node: string | null, bun: string | null }}
|
|
104
|
-
*/
|
|
105
77
|
function checkRuntimeVersions() {
|
|
106
78
|
return {
|
|
107
79
|
node: getRuntimeVersion('node'),
|
|
@@ -109,12 +81,7 @@ function checkRuntimeVersions() {
|
|
|
109
81
|
};
|
|
110
82
|
}
|
|
111
83
|
|
|
112
|
-
|
|
113
|
-
* Copies template files to target directory
|
|
114
|
-
* @param {string} template
|
|
115
|
-
* @param {string} targetDir
|
|
116
|
-
*/
|
|
117
|
-
async function copyTemplate(template, targetDir) {
|
|
84
|
+
async function copyTemplate(template, targetDir, includeFixtures = true) {
|
|
118
85
|
const templateDir = join(__dirname, '..', 'templates', template);
|
|
119
86
|
|
|
120
87
|
async function copyRecursive(src, dest) {
|
|
@@ -124,6 +91,11 @@ async function copyTemplate(template, targetDir) {
|
|
|
124
91
|
const srcPath = join(src, entry.name);
|
|
125
92
|
const destPath = join(dest, entry.name);
|
|
126
93
|
|
|
94
|
+
// Skip fixtures if not included (for with-mock template)
|
|
95
|
+
if (entry.name === 'fixtures' && !includeFixtures) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
127
99
|
if (entry.isDirectory()) {
|
|
128
100
|
await mkdir(destPath, { recursive: true });
|
|
129
101
|
await copyRecursive(srcPath, destPath);
|
|
@@ -136,26 +108,42 @@ async function copyTemplate(template, targetDir) {
|
|
|
136
108
|
await copyRecursive(templateDir, targetDir);
|
|
137
109
|
}
|
|
138
110
|
|
|
139
|
-
|
|
140
|
-
* Updates package.json with project name
|
|
141
|
-
* @param {string} targetDir
|
|
142
|
-
* @param {string} projectName
|
|
143
|
-
*/
|
|
144
|
-
async function updatePackageJson(targetDir, projectName) {
|
|
111
|
+
async function updatePackageJson(targetDir, projectName, packageManager) {
|
|
145
112
|
const packageJsonPath = join(targetDir, 'package.json');
|
|
146
113
|
const content = await readFile(packageJsonPath, 'utf-8');
|
|
147
114
|
const packageJson = JSON.parse(content);
|
|
148
115
|
|
|
149
116
|
packageJson.name = projectName;
|
|
150
117
|
|
|
118
|
+
const scripts = packageJson.scripts;
|
|
119
|
+
|
|
120
|
+
if (packageManager === 'bun') {
|
|
121
|
+
scripts.dev = scripts.dev.replace('next dev', 'bunx next dev');
|
|
122
|
+
scripts.build = scripts.build.replace('next build', 'bunx next build');
|
|
123
|
+
scripts.start = scripts.start.replace('next start', 'bunx next start');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (scripts['dev:mock']) {
|
|
127
|
+
const mockCmd = {
|
|
128
|
+
bun: 'bun run mock:api',
|
|
129
|
+
npm: 'npm run mock:api',
|
|
130
|
+
yarn: 'yarn mock:api',
|
|
131
|
+
pnpm: 'pnpm run mock:api',
|
|
132
|
+
}[packageManager];
|
|
133
|
+
|
|
134
|
+
const devCmd = {
|
|
135
|
+
bun: 'bun run dev',
|
|
136
|
+
npm: 'npm run dev',
|
|
137
|
+
yarn: 'yarn dev',
|
|
138
|
+
pnpm: 'pnpm run dev',
|
|
139
|
+
}[packageManager];
|
|
140
|
+
|
|
141
|
+
scripts['dev:mock'] = `concurrently "${mockCmd}" "${devCmd}"`;
|
|
142
|
+
}
|
|
143
|
+
|
|
151
144
|
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
152
145
|
}
|
|
153
146
|
|
|
154
|
-
/**
|
|
155
|
-
* Installs dependencies using specified package manager
|
|
156
|
-
* @param {string} packageManager
|
|
157
|
-
* @param {string} cwd
|
|
158
|
-
*/
|
|
159
147
|
function installDependencies(packageManager, cwd) {
|
|
160
148
|
const installCmd = {
|
|
161
149
|
bun: 'bun install',
|
|
@@ -168,10 +156,6 @@ function installDependencies(packageManager, cwd) {
|
|
|
168
156
|
execSync(installCmd, { cwd, stdio: 'inherit' });
|
|
169
157
|
}
|
|
170
158
|
|
|
171
|
-
/**
|
|
172
|
-
* Initializes git repository
|
|
173
|
-
* @param {string} cwd
|
|
174
|
-
*/
|
|
175
159
|
function initGit(cwd) {
|
|
176
160
|
try {
|
|
177
161
|
execSync('git init', { cwd, stdio: 'ignore' });
|
|
@@ -186,14 +170,7 @@ function initGit(cwd) {
|
|
|
186
170
|
}
|
|
187
171
|
}
|
|
188
172
|
|
|
189
|
-
|
|
190
|
-
* Shows the final success message with next steps
|
|
191
|
-
* @param {string} projectName
|
|
192
|
-
* @param {string} targetDir
|
|
193
|
-
* @param {string} packageManager
|
|
194
|
-
* @param {string} template
|
|
195
|
-
*/
|
|
196
|
-
function showSuccessMessage(projectName, targetDir, packageManager, template) {
|
|
173
|
+
function showSuccessMessage(projectName, targetDir, packageManager, template, includeFixtures) {
|
|
197
174
|
const runCmd = {
|
|
198
175
|
bun: 'bun run',
|
|
199
176
|
npm: 'npm run',
|
|
@@ -202,6 +179,13 @@ function showSuccessMessage(projectName, targetDir, packageManager, template) {
|
|
|
202
179
|
}[packageManager];
|
|
203
180
|
|
|
204
181
|
console.log(`\n${green('✔')} Successfully created ${cyan(projectName)}`);
|
|
182
|
+
console.log(`\n${lightGray('Configuration:')}`);
|
|
183
|
+
console.log(` Template: ${cyan(template)}`);
|
|
184
|
+
console.log(` Package manager: ${cyan(packageManager)}`);
|
|
185
|
+
if (template === 'with-mock') {
|
|
186
|
+
console.log(` Fixtures: ${includeFixtures ? cyan('included') : dim('excluded')}`);
|
|
187
|
+
}
|
|
188
|
+
|
|
205
189
|
console.log(`\n${lightGray('Next steps:')}`);
|
|
206
190
|
console.log(` ${cyan('cd')} ${projectName}`);
|
|
207
191
|
|
|
@@ -227,13 +211,9 @@ function showSuccessMessage(projectName, targetDir, packageManager, template) {
|
|
|
227
211
|
console.log(`\n${blue('Happy coding with DiggoCMS!')} ${magenta('🚀')}\n`);
|
|
228
212
|
}
|
|
229
213
|
|
|
230
|
-
/**
|
|
231
|
-
* Main CLI function
|
|
232
|
-
*/
|
|
233
214
|
async function main() {
|
|
234
215
|
console.log(`\n${cyan('◆')} ${bold('DiggoCMS')} ${lightGray('– Create a new CMS-powered app')}\n`);
|
|
235
216
|
|
|
236
|
-
// Check runtime versions
|
|
237
217
|
const versions = checkRuntimeVersions();
|
|
238
218
|
|
|
239
219
|
if (!versions.node && !versions.bun) {
|
|
@@ -241,7 +221,6 @@ async function main() {
|
|
|
241
221
|
process.exit(1);
|
|
242
222
|
}
|
|
243
223
|
|
|
244
|
-
// Get project name from command line or prompt
|
|
245
224
|
let projectName = process.argv[2];
|
|
246
225
|
|
|
247
226
|
if (!projectName) {
|
|
@@ -267,7 +246,6 @@ async function main() {
|
|
|
267
246
|
process.exit(1);
|
|
268
247
|
}
|
|
269
248
|
|
|
270
|
-
// Check if directory exists
|
|
271
249
|
const targetDir = join(process.cwd(), projectName);
|
|
272
250
|
|
|
273
251
|
try {
|
|
@@ -297,18 +275,16 @@ async function main() {
|
|
|
297
275
|
}
|
|
298
276
|
}
|
|
299
277
|
} catch {
|
|
300
|
-
// Directory doesn't exist, create it
|
|
301
278
|
await mkdir(targetDir, { recursive: true });
|
|
302
279
|
}
|
|
303
280
|
|
|
304
|
-
// Choose template
|
|
305
281
|
const { template } = await prompts({
|
|
306
282
|
type: 'select',
|
|
307
283
|
name: 'template',
|
|
308
284
|
message: 'Choose a template:',
|
|
309
285
|
choices: [
|
|
310
|
-
{ title: green('full'), value: 'full', description: 'Complete setup with all components' },
|
|
311
|
-
{ title: blue('with-mock'), value: 'with-mock', description: 'Full setup + mock API server' },
|
|
286
|
+
{ title: green('full'), value: 'full', description: 'Complete setup with all components (SSG, Pages Router)' },
|
|
287
|
+
{ title: blue('with-mock'), value: 'with-mock', description: 'Full setup + mock API server + optional fixtures' },
|
|
312
288
|
{ title: yellow('minimal'), value: 'minimal', description: 'Basic setup, add components yourself' },
|
|
313
289
|
],
|
|
314
290
|
initial: 0,
|
|
@@ -319,7 +295,17 @@ async function main() {
|
|
|
319
295
|
process.exit(1);
|
|
320
296
|
}
|
|
321
297
|
|
|
322
|
-
|
|
298
|
+
let includeFixtures = true;
|
|
299
|
+
if (template === 'with-mock') {
|
|
300
|
+
const { fixtures } = await prompts({
|
|
301
|
+
type: 'confirm',
|
|
302
|
+
name: 'fixtures',
|
|
303
|
+
message: 'Include sample fixtures (pages, menu, collection)?',
|
|
304
|
+
initial: true,
|
|
305
|
+
});
|
|
306
|
+
includeFixtures = fixtures;
|
|
307
|
+
}
|
|
308
|
+
|
|
323
309
|
const availableManagers = PACKAGE_MANAGERS.filter(commandExists);
|
|
324
310
|
const defaultManager = availableManagers.includes('bun') ? 'bun' : 'npm';
|
|
325
311
|
|
|
@@ -340,24 +326,14 @@ async function main() {
|
|
|
340
326
|
process.exit(1);
|
|
341
327
|
}
|
|
342
328
|
|
|
343
|
-
// Scaffold project
|
|
344
329
|
console.log(dim(`\nScaffolding project in ${targetDir}...`));
|
|
345
330
|
|
|
346
331
|
try {
|
|
347
|
-
|
|
348
|
-
await
|
|
349
|
-
|
|
350
|
-
// Update package.json
|
|
351
|
-
await updatePackageJson(targetDir, projectName);
|
|
352
|
-
|
|
353
|
-
// Initialize git
|
|
332
|
+
await copyTemplate(template, targetDir, includeFixtures);
|
|
333
|
+
await updatePackageJson(targetDir, projectName, packageManager);
|
|
354
334
|
const gitInitialized = initGit(targetDir);
|
|
355
|
-
|
|
356
|
-
// Install dependencies
|
|
357
335
|
installDependencies(packageManager, targetDir);
|
|
358
|
-
|
|
359
|
-
// Show success message
|
|
360
|
-
showSuccessMessage(projectName, targetDir, packageManager, template);
|
|
336
|
+
showSuccessMessage(projectName, targetDir, packageManager, template, includeFixtures);
|
|
361
337
|
|
|
362
338
|
if (gitInitialized) {
|
|
363
339
|
console.log(`${green('✔')} Git repository initialized\n`);
|
|
@@ -369,22 +345,10 @@ async function main() {
|
|
|
369
345
|
}
|
|
370
346
|
}
|
|
371
347
|
|
|
372
|
-
// Helper functions
|
|
373
348
|
function bold(str) {
|
|
374
349
|
return `\x1b[1m${str}\x1b[0m`;
|
|
375
350
|
}
|
|
376
351
|
|
|
377
|
-
async function readdir(path, options) {
|
|
378
|
-
const fs = await import('fs/promises');
|
|
379
|
-
return fs.readdir(path, options);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async function rm(path, options) {
|
|
383
|
-
const fs = await import('fs/promises');
|
|
384
|
-
return fs.rm(path, options);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Run main function
|
|
388
352
|
main().catch((error) => {
|
|
389
353
|
console.error(red('\nUnexpected error:'));
|
|
390
354
|
console.error(error);
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalygo/create-diggocms-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "CLI tool to scaffold a new DiggoCMS project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-diggocms-app": "./bin/cli.js"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"templates"
|
|
12
|
+
],
|
|
10
13
|
"scripts": {
|
|
11
14
|
"prepublishOnly": "echo 'No build step needed'"
|
|
12
15
|
},
|
package/templates/full/README.md
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
# My DiggoCMS App
|
|
2
2
|
|
|
3
|
-
A complete DiggoCMS application built with Next.js and the DiggoCMS SDK.
|
|
3
|
+
A complete DiggoCMS application built with Next.js Pages Router and the DiggoCMS SDK.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- Next.js 16 with Pages Router
|
|
8
|
+
- Static Site Generation (SSG) with `getStaticProps`/`getStaticPaths`
|
|
9
|
+
- Tailwind CSS for styling
|
|
10
|
+
- Hot reload via `next dev`
|
|
11
|
+
- Extended components for all supported types: title, image, text, video, gallery, and card
|
|
12
|
+
- Navigation components with dropdown support
|
|
13
|
+
- Error handling and mock indicators
|
|
12
14
|
|
|
13
15
|
## Getting Started
|
|
14
16
|
|
|
15
17
|
1. Copy `.env.local.example` to `.env.local` and configure:
|
|
18
|
+
|
|
16
19
|
```bash
|
|
17
20
|
cp .env.local.example .env.local
|
|
18
21
|
```
|
|
19
22
|
|
|
20
23
|
2. Install dependencies:
|
|
24
|
+
|
|
21
25
|
```bash
|
|
22
|
-
npm install
|
|
23
|
-
# or
|
|
24
26
|
bun install
|
|
27
|
+
# or
|
|
28
|
+
npm install
|
|
25
29
|
```
|
|
26
30
|
|
|
27
31
|
3. Run the development server:
|
|
32
|
+
|
|
28
33
|
```bash
|
|
29
|
-
npm run dev
|
|
30
|
-
# or
|
|
31
34
|
bun run dev
|
|
35
|
+
# or
|
|
36
|
+
npm run dev
|
|
32
37
|
```
|
|
33
38
|
|
|
34
39
|
4. Open [http://localhost:3000](http://localhost:3000) in your browser.
|
|
@@ -38,6 +43,7 @@ A complete DiggoCMS application built with Next.js and the DiggoCMS SDK.
|
|
|
38
43
|
### Using a Real CMS API
|
|
39
44
|
|
|
40
45
|
Set your CMS API base URL:
|
|
46
|
+
|
|
41
47
|
```env
|
|
42
48
|
BASE_URL=https://your-cms-api.com
|
|
43
49
|
MOCK=0
|
|
@@ -46,6 +52,7 @@ MOCK=0
|
|
|
46
52
|
### Using Mock Mode
|
|
47
53
|
|
|
48
54
|
Enable mock mode for development without a real API:
|
|
55
|
+
|
|
49
56
|
```env
|
|
50
57
|
MOCK=1
|
|
51
58
|
MOCK_API_URL=http://localhost:3001
|
|
@@ -53,20 +60,15 @@ MOCK_API_URL=http://localhost:3001
|
|
|
53
60
|
|
|
54
61
|
## Project Structure
|
|
55
62
|
|
|
56
|
-
```
|
|
57
|
-
app/ # Next.js app router
|
|
58
|
-
├── [...slug]/ # Dynamic catch-all route
|
|
59
|
-
├── layout.tsx # Root layout with DiggoProvider
|
|
60
|
-
├── page.tsx # Home redirect
|
|
61
|
-
└── globals.css # Global styles
|
|
62
|
-
|
|
63
|
+
```text
|
|
63
64
|
components/ # React components
|
|
64
65
|
├── DiggoProvider.tsx # SDK provider wrapper
|
|
65
66
|
├── server-components.ts # Server-safe component exports
|
|
66
67
|
├── ExtendedTitle.tsx
|
|
67
|
-
├── ExtendedSubtitle.tsx
|
|
68
68
|
├── ExtendedImage.tsx
|
|
69
|
-
├──
|
|
69
|
+
├── ExtendedText.tsx
|
|
70
|
+
├── ExtendedVideo.tsx
|
|
71
|
+
├── ExtendedGallery.tsx
|
|
70
72
|
├── ExtendedCard.tsx
|
|
71
73
|
├── ExtendedMenuItem.tsx
|
|
72
74
|
└── ExtendedMenuContainer.tsx
|
|
@@ -74,23 +76,61 @@ components/ # React components
|
|
|
74
76
|
lib/ # Utility functions
|
|
75
77
|
├── diggo-config.ts # SDK configuration
|
|
76
78
|
└── data-fetching.ts # Data fetching helpers
|
|
79
|
+
|
|
80
|
+
pages/ # Next.js pages (Pages Router)
|
|
81
|
+
├── _app.tsx # App wrapper with DiggoProvider
|
|
82
|
+
├── index.tsx # Home redirect
|
|
83
|
+
└── [...slug].tsx # Dynamic catch-all route
|
|
84
|
+
|
|
85
|
+
public/ # Static assets
|
|
86
|
+
styles/ # Global styles
|
|
87
|
+
└── globals.css # Tailwind + component styles
|
|
77
88
|
```
|
|
78
89
|
|
|
90
|
+
## Scripts
|
|
91
|
+
|
|
92
|
+
| Script | Description |
|
|
93
|
+
|--------|-------------|
|
|
94
|
+
| `bun run dev` | Start development server with hot reload |
|
|
95
|
+
| `bun run build` | Build for static export |
|
|
96
|
+
| `bun run start` | Start production server |
|
|
97
|
+
| `bun run lint` | Run ESLint |
|
|
98
|
+
| `bun run typecheck` | Run TypeScript check |
|
|
99
|
+
|
|
79
100
|
## Extended Components
|
|
80
101
|
|
|
81
|
-
This template includes extended versions of all
|
|
102
|
+
This template includes extended versions of all SDK-supported component types:
|
|
82
103
|
|
|
83
104
|
- **ExtendedTitle** - Styled H1 heading
|
|
84
|
-
- **ExtendedSubtitle** - Styled H2 heading
|
|
85
105
|
- **ExtendedImage** - Responsive image with shadow
|
|
86
|
-
- **
|
|
87
|
-
- **
|
|
106
|
+
- **ExtendedText** - Styled paragraph content
|
|
107
|
+
- **ExtendedVideo** - Styled video wrapper for CMS media payloads
|
|
108
|
+
- **ExtendedGallery** - Ordered gallery renderer for image and video items
|
|
109
|
+
- **ExtendedCard** - Card layout with title, media, body copy, and CTA support
|
|
88
110
|
- **ExtendedMenuItem** - Navigation item with active state
|
|
89
111
|
- **ExtendedMenuContainer** - Navigation wrapper
|
|
90
112
|
|
|
113
|
+
Page payloads should use only the supported types above. Card payloads can include card-specific fields such as `richtext` when provided by the CMS.
|
|
114
|
+
|
|
115
|
+
## SSG Configuration
|
|
116
|
+
|
|
117
|
+
By default, pages are generated on-demand. To pre-generate pages at build time, modify `getStaticPaths` in `pages/[...slug].tsx`:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
export const getStaticPaths: GetStaticPaths = async () => {
|
|
121
|
+
// Fetch all page slugs from your CMS
|
|
122
|
+
const pages = await fetchAllPages();
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
paths: pages.map(page => ({ params: { slug: page.slug.split('/') } })),
|
|
126
|
+
fallback: 'blocking',
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
91
131
|
## Customization
|
|
92
132
|
|
|
93
|
-
1. Edit styles in `
|
|
133
|
+
1. Edit styles in `styles/globals.css`
|
|
94
134
|
2. Modify components in `components/`
|
|
95
135
|
3. Update configuration in `lib/diggo-config.ts`
|
|
96
136
|
4. Add more data fetching functions in `lib/data-fetching.ts`
|
|
@@ -98,4 +138,5 @@ This template includes extended versions of all base components:
|
|
|
98
138
|
## Documentation
|
|
99
139
|
|
|
100
140
|
- [DiggoCMS SDK Documentation](https://github.com/digitalygo/diggocms-sdk)
|
|
101
|
-
- [Next.js Documentation](https://nextjs.org/docs)
|
|
141
|
+
- [Next.js Pages Router Documentation](https://nextjs.org/docs/pages)
|
|
142
|
+
- [Tailwind CSS Documentation](https://tailwindcss.com/docs)
|