basecampjs 0.0.13 → 0.0.14
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/dist/build/assets.d.ts +36 -0
- package/dist/build/assets.d.ts.map +1 -0
- package/dist/build/assets.js +272 -0
- package/dist/build/assets.js.map +1 -0
- package/dist/build/data.d.ts +6 -0
- package/dist/build/data.d.ts.map +1 -0
- package/dist/build/data.js +33 -0
- package/dist/build/data.js.map +1 -0
- package/dist/build/pages.d.ts +19 -0
- package/dist/build/pages.d.ts.map +1 -0
- package/dist/build/pages.js +110 -0
- package/dist/build/pages.js.map +1 -0
- package/dist/build/pipeline.d.ts +6 -0
- package/dist/build/pipeline.d.ts.map +1 -0
- package/dist/build/pipeline.js +98 -0
- package/dist/build/pipeline.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +140 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/dev/server.d.ts +6 -0
- package/dist/dev/server.d.ts.map +1 -0
- package/dist/dev/server.js +64 -0
- package/dist/dev/server.js.map +1 -0
- package/dist/dev/watcher.d.ts +5 -0
- package/dist/dev/watcher.d.ts.map +1 -0
- package/dist/dev/watcher.js +49 -0
- package/dist/dev/watcher.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/render/engines.d.ts +30 -0
- package/dist/render/engines.d.ts.map +1 -0
- package/dist/render/engines.js +102 -0
- package/dist/render/engines.js.map +1 -0
- package/dist/scaffolding.d.ts +25 -0
- package/dist/scaffolding.d.ts.map +1 -0
- package/dist/scaffolding.js +596 -0
- package/dist/scaffolding.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/fs.d.ts +29 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +104 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +21 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +55 -0
- package/dist/utils/paths.js.map +1 -0
- package/package.json +36 -6
- package/src/build/assets.ts +314 -0
- package/src/build/data.ts +32 -0
- package/src/build/pages.ts +143 -0
- package/src/build/pipeline.ts +111 -0
- package/src/cli.ts +155 -0
- package/src/config.ts +61 -0
- package/src/dev/server.ts +66 -0
- package/src/dev/watcher.ts +52 -0
- package/src/index.ts +45 -0
- package/src/render/engines.ts +139 -0
- package/src/scaffolding.ts +656 -0
- package/src/types.ts +110 -0
- package/src/utils/fs.ts +109 -0
- package/src/utils/logger.ts +27 -0
- package/src/utils/paths.ts +56 -0
- package/index.js +0 -1532
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { readFile, readdir, rm, writeFile } from "fs/promises";
|
|
3
|
+
import { basename, dirname, extname, join, relative, resolve } from "path";
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
5
|
+
import { ensureDir, walkFiles, getExt } from "./utils/fs.js";
|
|
6
|
+
import { slugify, formatDate } from "./utils/paths.js";
|
|
7
|
+
import { kolor } from "./utils/logger.js";
|
|
8
|
+
import type { CampsiteConfig, MakeContentResult } from "./types.js";
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Initialize a new Campsite project
|
|
14
|
+
*/
|
|
15
|
+
export async function init(): Promise<void> {
|
|
16
|
+
const targetDir = cwd;
|
|
17
|
+
console.log(kolor.cyan(kolor.bold("🏕️ Initializing Campsite in current directory...")));
|
|
18
|
+
|
|
19
|
+
// Check if already initialized
|
|
20
|
+
if (existsSync(join(targetDir, "campsite.config.js"))) {
|
|
21
|
+
console.log(kolor.yellow("⚠️ This directory already has a campsite.config.js file."));
|
|
22
|
+
console.log(kolor.dim("Run 'camper dev' to start developing.\n"));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Create basic structure
|
|
27
|
+
const dirs = [
|
|
28
|
+
join(targetDir, "src", "pages"),
|
|
29
|
+
join(targetDir, "src", "layouts"),
|
|
30
|
+
join(targetDir, "public")
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
for (const dir of dirs) {
|
|
34
|
+
await ensureDir(dir);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Create basic config file
|
|
38
|
+
const configContent = `export default {
|
|
39
|
+
siteName: "My Campsite",
|
|
40
|
+
srcDir: "src",
|
|
41
|
+
outDir: "dist",
|
|
42
|
+
templateEngine: "nunjucks",
|
|
43
|
+
markdown: true,
|
|
44
|
+
integrations: {
|
|
45
|
+
nunjucks: true,
|
|
46
|
+
liquid: false,
|
|
47
|
+
mustache: false,
|
|
48
|
+
vue: false,
|
|
49
|
+
alpine: false
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
`;
|
|
53
|
+
await writeFile(join(targetDir, "campsite.config.js"), configContent, "utf8");
|
|
54
|
+
|
|
55
|
+
// Create basic layout
|
|
56
|
+
const layoutContent = `<!DOCTYPE html>
|
|
57
|
+
<html lang="en">
|
|
58
|
+
<head>
|
|
59
|
+
<meta charset="UTF-8">
|
|
60
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
61
|
+
<title>{{ title or site.name }}</title>
|
|
62
|
+
<link rel="stylesheet" href="/style.css">
|
|
63
|
+
</head>
|
|
64
|
+
<body>
|
|
65
|
+
{% block content %}
|
|
66
|
+
{{ content | safe }}
|
|
67
|
+
{% endblock %}
|
|
68
|
+
</body>
|
|
69
|
+
</html>
|
|
70
|
+
`;
|
|
71
|
+
await writeFile(join(targetDir, "src", "layouts", "base.njk"), layoutContent, "utf8");
|
|
72
|
+
|
|
73
|
+
// Create sample page
|
|
74
|
+
const pageContent = `---
|
|
75
|
+
layout: base.njk
|
|
76
|
+
title: Welcome to Campsite
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
# Welcome to Campsite! 🏕️
|
|
80
|
+
|
|
81
|
+
Your cozy static site is ready to build.
|
|
82
|
+
|
|
83
|
+
## Get Started
|
|
84
|
+
|
|
85
|
+
- Run \`camper dev\` to start developing
|
|
86
|
+
- Edit pages in \`src/pages/\`
|
|
87
|
+
- Customize layouts in \`src/layouts/\`
|
|
88
|
+
|
|
89
|
+
Happy camping! 🌲🦊
|
|
90
|
+
`;
|
|
91
|
+
await writeFile(join(targetDir, "src", "pages", "index.md"), pageContent, "utf8");
|
|
92
|
+
|
|
93
|
+
// Create basic CSS
|
|
94
|
+
const cssContent = `* {
|
|
95
|
+
margin: 0;
|
|
96
|
+
padding: 0;
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
body {
|
|
101
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
102
|
+
line-height: 1.6;
|
|
103
|
+
padding: 2rem;
|
|
104
|
+
max-width: 800px;
|
|
105
|
+
margin: 0 auto;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
h1 { color: #2d5016; margin-bottom: 1rem; }
|
|
109
|
+
h2 { color: #4a7c2c; margin-top: 1.5rem; }
|
|
110
|
+
`;
|
|
111
|
+
await writeFile(join(targetDir, "public", "style.css"), cssContent, "utf8");
|
|
112
|
+
|
|
113
|
+
// Create .gitignore
|
|
114
|
+
const gitignoreContent = `node_modules/
|
|
115
|
+
dist/
|
|
116
|
+
.DS_Store
|
|
117
|
+
`;
|
|
118
|
+
await writeFile(join(targetDir, ".gitignore"), gitignoreContent, "utf8");
|
|
119
|
+
|
|
120
|
+
// Create package.json
|
|
121
|
+
const packageJson = {
|
|
122
|
+
name: basename(targetDir),
|
|
123
|
+
version: "0.0.1",
|
|
124
|
+
type: "module",
|
|
125
|
+
scripts: {
|
|
126
|
+
dev: "camper dev",
|
|
127
|
+
build: "camper build",
|
|
128
|
+
serve: "camper serve",
|
|
129
|
+
preview: "camper preview"
|
|
130
|
+
},
|
|
131
|
+
dependencies: {
|
|
132
|
+
basecampjs: "^0.0.8"
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
await writeFile(join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2), "utf8");
|
|
136
|
+
|
|
137
|
+
console.log(kolor.green("✅ Campsite initialized successfully!\n"));
|
|
138
|
+
console.log(kolor.bold("Next steps:"));
|
|
139
|
+
console.log(kolor.dim(" 1. Install dependencies: npm install"));
|
|
140
|
+
console.log(kolor.dim(" 2. Start developing: camper dev\n"));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Clean the build output directory
|
|
145
|
+
*/
|
|
146
|
+
export async function clean(): Promise<void> {
|
|
147
|
+
const config = await loadConfig(cwd);
|
|
148
|
+
const outDir = resolve(cwd, config.outDir || "dist");
|
|
149
|
+
|
|
150
|
+
if (!existsSync(outDir)) {
|
|
151
|
+
console.log(kolor.dim(`Nothing to clean. ${outDir} does not exist.`));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
console.log(kolor.cyan(`🧹 Cleaning ${relative(cwd, outDir)}...`));
|
|
156
|
+
await rm(outDir, { recursive: true, force: true });
|
|
157
|
+
console.log(kolor.green(`✅ Cleaned ${relative(cwd, outDir)}\n`));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Check project configuration and structure
|
|
162
|
+
*/
|
|
163
|
+
export async function check(): Promise<void> {
|
|
164
|
+
console.log(kolor.cyan(kolor.bold("🔍 Checking Campsite project...\n")));
|
|
165
|
+
let hasIssues = false;
|
|
166
|
+
|
|
167
|
+
// Check if campsite.config.js exists
|
|
168
|
+
const configPath = join(cwd, "campsite.config.js");
|
|
169
|
+
if (!existsSync(configPath)) {
|
|
170
|
+
console.log(kolor.red("❌ campsite.config.js not found"));
|
|
171
|
+
console.log(kolor.dim(" Run 'camper init' to initialize a project\n"));
|
|
172
|
+
hasIssues = true;
|
|
173
|
+
} else {
|
|
174
|
+
console.log(kolor.green("✅ campsite.config.js found"));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Load and validate config
|
|
178
|
+
const config = await loadConfig(cwd);
|
|
179
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
180
|
+
const pagesDir = join(srcDir, "pages");
|
|
181
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
182
|
+
const publicDir = resolve(cwd, "public");
|
|
183
|
+
|
|
184
|
+
// Check src directory
|
|
185
|
+
if (!existsSync(srcDir)) {
|
|
186
|
+
console.log(kolor.red(`❌ Source directory not found: ${relative(cwd, srcDir)}`));
|
|
187
|
+
hasIssues = true;
|
|
188
|
+
} else {
|
|
189
|
+
console.log(kolor.green(`✅ Source directory exists: ${relative(cwd, srcDir)}`));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Check pages directory
|
|
193
|
+
if (!existsSync(pagesDir)) {
|
|
194
|
+
console.log(kolor.yellow(`⚠️ Pages directory not found: ${relative(cwd, pagesDir)}`));
|
|
195
|
+
hasIssues = true;
|
|
196
|
+
} else {
|
|
197
|
+
const files = await walkFiles(pagesDir);
|
|
198
|
+
if (files.length === 0) {
|
|
199
|
+
console.log(kolor.yellow(`⚠️ No pages found in ${relative(cwd, pagesDir)}`));
|
|
200
|
+
hasIssues = true;
|
|
201
|
+
} else {
|
|
202
|
+
console.log(kolor.green(`✅ Found ${files.length} page(s) in ${relative(cwd, pagesDir)}`));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Check layouts directory
|
|
207
|
+
if (existsSync(layoutsDir)) {
|
|
208
|
+
const layouts = await readdir(layoutsDir).catch(() => [] as string[]);
|
|
209
|
+
console.log(kolor.green(`✅ Found ${layouts.length} layout(s) in ${relative(cwd, layoutsDir)}`));
|
|
210
|
+
} else {
|
|
211
|
+
console.log(kolor.dim(`ℹ️ No layouts directory (${relative(cwd, layoutsDir)})`));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Check public directory
|
|
215
|
+
if (existsSync(publicDir)) {
|
|
216
|
+
console.log(kolor.green(`✅ Public directory exists: ${relative(cwd, publicDir)}`));
|
|
217
|
+
} else {
|
|
218
|
+
console.log(kolor.dim(`ℹ️ No public directory (${relative(cwd, publicDir)})`));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Check for package.json and dependencies
|
|
222
|
+
const pkgPath = join(cwd, "package.json");
|
|
223
|
+
if (existsSync(pkgPath)) {
|
|
224
|
+
try {
|
|
225
|
+
const pkgRaw = await readFile(pkgPath, "utf8");
|
|
226
|
+
const pkg = JSON.parse(pkgRaw) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
227
|
+
if (pkg.dependencies?.basecampjs || pkg.devDependencies?.basecampjs) {
|
|
228
|
+
console.log(kolor.green("✅ basecampjs dependency found"));
|
|
229
|
+
} else {
|
|
230
|
+
console.log(kolor.yellow("⚠️ basecampjs not listed in dependencies"));
|
|
231
|
+
console.log(kolor.dim(" Consider adding: npm install basecampjs"));
|
|
232
|
+
}
|
|
233
|
+
} catch {
|
|
234
|
+
console.log(kolor.yellow("⚠️ Could not parse package.json"));
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
console.log(kolor.dim("ℹ️ No package.json found"));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
console.log();
|
|
241
|
+
if (hasIssues) {
|
|
242
|
+
console.log(kolor.yellow("⚠️ Some issues found. Review the messages above."));
|
|
243
|
+
} else {
|
|
244
|
+
console.log(kolor.green(kolor.bold("🎉 Everything looks good! Ready to build.")));
|
|
245
|
+
}
|
|
246
|
+
console.log();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* List all project content
|
|
251
|
+
*/
|
|
252
|
+
export async function list(): Promise<void> {
|
|
253
|
+
console.log(kolor.cyan(kolor.bold("🗺️ Listing Campsite content...\n")));
|
|
254
|
+
|
|
255
|
+
const config = await loadConfig(cwd);
|
|
256
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
257
|
+
const pagesDir = join(srcDir, "pages");
|
|
258
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
259
|
+
const componentsDir = join(srcDir, "components");
|
|
260
|
+
const partialsDir = join(srcDir, "partials");
|
|
261
|
+
const collectionsDir = join(srcDir, "collections");
|
|
262
|
+
const dataDir = join(srcDir, "data");
|
|
263
|
+
|
|
264
|
+
// List pages
|
|
265
|
+
if (existsSync(pagesDir)) {
|
|
266
|
+
const pages = await walkFiles(pagesDir);
|
|
267
|
+
if (pages.length > 0) {
|
|
268
|
+
console.log(kolor.bold("📄 Pages (") + kolor.cyan(pages.length.toString()) + kolor.bold(")"));
|
|
269
|
+
pages.forEach(page => {
|
|
270
|
+
const rel = relative(pagesDir, page);
|
|
271
|
+
console.log(" " + kolor.dim("• ") + rel);
|
|
272
|
+
});
|
|
273
|
+
console.log();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// List layouts
|
|
278
|
+
if (existsSync(layoutsDir)) {
|
|
279
|
+
const layouts = await readdir(layoutsDir).catch(() => [] as string[]);
|
|
280
|
+
if (layouts.length > 0) {
|
|
281
|
+
console.log(kolor.bold("📝 Layouts (") + kolor.cyan(layouts.length.toString()) + kolor.bold(")"));
|
|
282
|
+
layouts.forEach(layout => {
|
|
283
|
+
console.log(" " + kolor.dim("• ") + layout);
|
|
284
|
+
});
|
|
285
|
+
console.log();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// List components
|
|
290
|
+
if (existsSync(componentsDir)) {
|
|
291
|
+
const components = await readdir(componentsDir).catch(() => [] as string[]);
|
|
292
|
+
if (components.length > 0) {
|
|
293
|
+
console.log(kolor.bold("🧩 Components (") + kolor.cyan(components.length.toString()) + kolor.bold(")"));
|
|
294
|
+
components.forEach(component => {
|
|
295
|
+
console.log(" " + kolor.dim("• ") + component);
|
|
296
|
+
});
|
|
297
|
+
console.log();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// List partials
|
|
302
|
+
if (existsSync(partialsDir)) {
|
|
303
|
+
const partials = await readdir(partialsDir).catch(() => [] as string[]);
|
|
304
|
+
if (partials.length > 0) {
|
|
305
|
+
console.log(kolor.bold("🧰 Partials (") + kolor.cyan(partials.length.toString()) + kolor.bold(")"));
|
|
306
|
+
partials.forEach(partial => {
|
|
307
|
+
console.log(" " + kolor.dim("• ") + partial);
|
|
308
|
+
});
|
|
309
|
+
console.log();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// List collections
|
|
314
|
+
if (existsSync(collectionsDir)) {
|
|
315
|
+
const collections = await readdir(collectionsDir).catch(() => [] as string[]);
|
|
316
|
+
const jsonFiles = collections.filter(f => f.endsWith(".json"));
|
|
317
|
+
if (jsonFiles.length > 0) {
|
|
318
|
+
console.log(kolor.bold("📁 Collections (") + kolor.cyan(jsonFiles.length.toString()) + kolor.bold(")"));
|
|
319
|
+
jsonFiles.forEach(collection => {
|
|
320
|
+
console.log(" " + kolor.dim("• ") + collection);
|
|
321
|
+
});
|
|
322
|
+
console.log();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// List data files
|
|
327
|
+
if (existsSync(dataDir)) {
|
|
328
|
+
const dataFiles = await readdir(dataDir).catch(() => [] as string[]);
|
|
329
|
+
const jsonFiles = dataFiles.filter(f => f.endsWith(".json"));
|
|
330
|
+
if (jsonFiles.length > 0) {
|
|
331
|
+
console.log(kolor.bold("📊 Data (") + kolor.cyan(jsonFiles.length.toString()) + kolor.bold(")"));
|
|
332
|
+
jsonFiles.forEach(dataFile => {
|
|
333
|
+
console.log(" " + kolor.dim("• ") + dataFile);
|
|
334
|
+
});
|
|
335
|
+
console.log();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
console.log(kolor.dim("🌲 Tip: Use 'camper make:<type> <name>' to create new content\n"));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Upgrade CampsiteJS to latest version
|
|
344
|
+
*/
|
|
345
|
+
export async function upgrade(): Promise<void> {
|
|
346
|
+
console.log(kolor.cyan(kolor.bold("⬆️ Checking for CampsiteJS updates...\n")));
|
|
347
|
+
|
|
348
|
+
// Check if package.json exists
|
|
349
|
+
const pkgPath = join(cwd, "package.json");
|
|
350
|
+
if (!existsSync(pkgPath)) {
|
|
351
|
+
console.log(kolor.red("❌ package.json not found"));
|
|
352
|
+
console.log(kolor.dim("This command should be run in a Campsite project directory.\n"));
|
|
353
|
+
process.exit(1);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Read current package.json
|
|
357
|
+
let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
358
|
+
try {
|
|
359
|
+
const pkgRaw = await readFile(pkgPath, "utf8");
|
|
360
|
+
pkg = JSON.parse(pkgRaw);
|
|
361
|
+
} catch {
|
|
362
|
+
console.log(kolor.red("❌ Could not read package.json\n"));
|
|
363
|
+
process.exit(1);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const currentVersion = pkg.dependencies?.basecampjs || pkg.devDependencies?.basecampjs;
|
|
367
|
+
if (!currentVersion) {
|
|
368
|
+
console.log(kolor.yellow("⚠️ basecampjs not found in dependencies"));
|
|
369
|
+
console.log(kolor.dim("Install it with: npm install basecampjs\n"));
|
|
370
|
+
process.exit(1);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
console.log(kolor.dim(`Current version: ${currentVersion}`));
|
|
374
|
+
console.log(kolor.cyan("\nUpgrading basecampjs to latest version...\n"));
|
|
375
|
+
|
|
376
|
+
// Use dynamic import to run npm commands
|
|
377
|
+
const { spawn } = await import("child_process");
|
|
378
|
+
|
|
379
|
+
return new Promise((resolve, reject) => {
|
|
380
|
+
const child = spawn("npm", ["install", "basecampjs@latest"], {
|
|
381
|
+
cwd,
|
|
382
|
+
stdio: "inherit",
|
|
383
|
+
shell: process.platform === "win32"
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
child.on("close", async (code) => {
|
|
387
|
+
if (code === 0) {
|
|
388
|
+
console.log();
|
|
389
|
+
console.log(kolor.green("✅ CampsiteJS updated successfully!"));
|
|
390
|
+
|
|
391
|
+
// Read updated version
|
|
392
|
+
try {
|
|
393
|
+
const updatedPkgRaw = await readFile(pkgPath, "utf8");
|
|
394
|
+
const updatedPkg = JSON.parse(updatedPkgRaw) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
395
|
+
const newVersion = updatedPkg.dependencies?.basecampjs || updatedPkg.devDependencies?.basecampjs;
|
|
396
|
+
console.log(kolor.dim(`New version: ${newVersion}`));
|
|
397
|
+
} catch {
|
|
398
|
+
// Ignore errors reading updated version
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
console.log();
|
|
402
|
+
console.log(kolor.dim("🌲 Tip: Run 'camper dev' to start developing with the latest version\n"));
|
|
403
|
+
resolve();
|
|
404
|
+
} else {
|
|
405
|
+
console.log();
|
|
406
|
+
console.log(kolor.red(`❌ Update failed with code ${code}\n`));
|
|
407
|
+
reject(new Error(`npm install failed with code ${code}`));
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
child.on("error", (err) => {
|
|
412
|
+
console.log(kolor.red(`❌ Update failed: ${err.message}\n`));
|
|
413
|
+
reject(err);
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Create new content (page, post, layout, component, partial, collection)
|
|
420
|
+
*/
|
|
421
|
+
export async function makeContent(type: string, args: string[]): Promise<void> {
|
|
422
|
+
if (!args || args.length === 0) {
|
|
423
|
+
console.log(kolor.red("❌ Missing name argument"));
|
|
424
|
+
console.log(kolor.dim(`Usage: camper make:${type} <name> [name2, name3, ...]`));
|
|
425
|
+
console.log(kolor.dim("\nExamples:"));
|
|
426
|
+
console.log(kolor.dim(" camper make:page about"));
|
|
427
|
+
console.log(kolor.dim(" camper make:page home, about, contact"));
|
|
428
|
+
console.log(kolor.dim(" camper make:collection products, categories\n"));
|
|
429
|
+
process.exit(1);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Join all args and split by comma to support both formats:
|
|
433
|
+
// camper make:page home about contact
|
|
434
|
+
// camper make:page home, about, contact
|
|
435
|
+
const namesString = args.join(" ");
|
|
436
|
+
const names = namesString.split(",").map(n => n.trim()).filter(n => n.length > 0);
|
|
437
|
+
|
|
438
|
+
if (names.length === 0) {
|
|
439
|
+
console.log(kolor.red("❌ No valid names provided\n"));
|
|
440
|
+
process.exit(1);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
console.log(kolor.cyan(`\n🏕️ Creating ${names.length} ${type}(s)...\n`));
|
|
444
|
+
|
|
445
|
+
const config = await loadConfig(cwd);
|
|
446
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
447
|
+
|
|
448
|
+
// Determine file extension based on template engine
|
|
449
|
+
const engineExtMap: Record<string, string> = {
|
|
450
|
+
nunjucks: ".njk",
|
|
451
|
+
liquid: ".liquid",
|
|
452
|
+
mustache: ".mustache"
|
|
453
|
+
};
|
|
454
|
+
const defaultExt = engineExtMap[config.templateEngine] || ".njk";
|
|
455
|
+
|
|
456
|
+
let successCount = 0;
|
|
457
|
+
let skipCount = 0;
|
|
458
|
+
|
|
459
|
+
for (const name of names) {
|
|
460
|
+
const result = await createSingleContent(type, name, srcDir, config, defaultExt);
|
|
461
|
+
if (result.success) successCount++;
|
|
462
|
+
if (result.skipped) skipCount++;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
console.log();
|
|
466
|
+
if (successCount > 0) {
|
|
467
|
+
console.log(kolor.green(`✅ Created ${successCount} ${type}(s)`));
|
|
468
|
+
}
|
|
469
|
+
if (skipCount > 0) {
|
|
470
|
+
console.log(kolor.yellow(`⚠️ Skipped ${skipCount} existing file(s)`));
|
|
471
|
+
}
|
|
472
|
+
console.log(kolor.dim("\n🌲 Happy camping!\n"));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async function createSingleContent(
|
|
476
|
+
type: string,
|
|
477
|
+
name: string,
|
|
478
|
+
srcDir: string,
|
|
479
|
+
config: CampsiteConfig,
|
|
480
|
+
defaultExt: string
|
|
481
|
+
): Promise<MakeContentResult> {
|
|
482
|
+
// Check if user provided an extension
|
|
483
|
+
const hasExtension = name.includes(".");
|
|
484
|
+
const providedExt = hasExtension ? extname(name) : null;
|
|
485
|
+
const nameWithoutExt = hasExtension ? basename(name, providedExt!) : name;
|
|
486
|
+
|
|
487
|
+
const slug = slugify(nameWithoutExt);
|
|
488
|
+
const today = formatDate(new Date());
|
|
489
|
+
const title = nameWithoutExt.charAt(0).toUpperCase() + nameWithoutExt.slice(1);
|
|
490
|
+
|
|
491
|
+
let targetPath: string;
|
|
492
|
+
let content: string;
|
|
493
|
+
let fileExt: string;
|
|
494
|
+
|
|
495
|
+
switch (type.toLowerCase()) {
|
|
496
|
+
case "page": {
|
|
497
|
+
// Priority: provided extension > template engine
|
|
498
|
+
if (providedExt) {
|
|
499
|
+
fileExt = providedExt;
|
|
500
|
+
} else {
|
|
501
|
+
fileExt = defaultExt;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
targetPath = join(srcDir, "pages", `${slug}${fileExt}`);
|
|
505
|
+
|
|
506
|
+
// Determine if we should use markdown content based on extension
|
|
507
|
+
const useMarkdown = fileExt === ".md";
|
|
508
|
+
|
|
509
|
+
if (useMarkdown) {
|
|
510
|
+
content = `---
|
|
511
|
+
layout: base${defaultExt}
|
|
512
|
+
title: ${title}
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
# ${title}
|
|
516
|
+
|
|
517
|
+
Your new page content goes here.
|
|
518
|
+
`;
|
|
519
|
+
} else {
|
|
520
|
+
content = `---
|
|
521
|
+
layout: base${defaultExt}
|
|
522
|
+
title: ${title}
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
<h1>${title}</h1>
|
|
526
|
+
<p>Your new page content goes here.</p>
|
|
527
|
+
`;
|
|
528
|
+
}
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
case "post": {
|
|
533
|
+
const postsDir = join(srcDir, "pages", "blog");
|
|
534
|
+
await ensureDir(postsDir);
|
|
535
|
+
|
|
536
|
+
if (providedExt) {
|
|
537
|
+
fileExt = providedExt;
|
|
538
|
+
} else {
|
|
539
|
+
fileExt = defaultExt;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
targetPath = join(postsDir, `${slug}${fileExt}`);
|
|
543
|
+
|
|
544
|
+
const useMarkdown = fileExt === ".md";
|
|
545
|
+
|
|
546
|
+
if (useMarkdown) {
|
|
547
|
+
content = `---
|
|
548
|
+
layout: base${defaultExt}
|
|
549
|
+
title: ${title}
|
|
550
|
+
date: ${today}
|
|
551
|
+
author: Your Name
|
|
552
|
+
---
|
|
553
|
+
|
|
554
|
+
# ${title}
|
|
555
|
+
|
|
556
|
+
Your blog post content goes here.
|
|
557
|
+
`;
|
|
558
|
+
} else {
|
|
559
|
+
content = `---
|
|
560
|
+
layout: base${defaultExt}
|
|
561
|
+
title: ${title}
|
|
562
|
+
date: ${today}
|
|
563
|
+
author: Your Name
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
<h1>${title}</h1>
|
|
567
|
+
<p>Your blog post content goes here.</p>
|
|
568
|
+
`;
|
|
569
|
+
}
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
case "layout": {
|
|
574
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
575
|
+
await ensureDir(layoutsDir);
|
|
576
|
+
targetPath = join(layoutsDir, `${slug}.njk`);
|
|
577
|
+
fileExt = ".njk";
|
|
578
|
+
content = `<!DOCTYPE html>
|
|
579
|
+
<html lang="en">
|
|
580
|
+
<head>
|
|
581
|
+
<meta charset="UTF-8">
|
|
582
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
583
|
+
<title>{{ title or site.name }}</title>
|
|
584
|
+
<link rel="stylesheet" href="/style.css">
|
|
585
|
+
</head>
|
|
586
|
+
<body>
|
|
587
|
+
<main>
|
|
588
|
+
{% block content %}
|
|
589
|
+
{{ content | safe }}
|
|
590
|
+
{% endblock %}
|
|
591
|
+
</main>
|
|
592
|
+
</body>
|
|
593
|
+
</html>
|
|
594
|
+
`;
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
case "component": {
|
|
599
|
+
const componentsDir = join(srcDir, "components");
|
|
600
|
+
await ensureDir(componentsDir);
|
|
601
|
+
targetPath = join(componentsDir, `${slug}.njk`);
|
|
602
|
+
fileExt = ".njk";
|
|
603
|
+
content = `{# ${title} Component #}
|
|
604
|
+
<div class="${slug}">
|
|
605
|
+
{{ content | safe }}
|
|
606
|
+
</div>
|
|
607
|
+
`;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
case "partial": {
|
|
612
|
+
const partialsDir = join(srcDir, "partials");
|
|
613
|
+
await ensureDir(partialsDir);
|
|
614
|
+
targetPath = join(partialsDir, `${slug}.njk`);
|
|
615
|
+
fileExt = ".njk";
|
|
616
|
+
content = `{# ${title} Partial #}
|
|
617
|
+
<div class="${slug}">
|
|
618
|
+
{# Your partial content here #}
|
|
619
|
+
</div>
|
|
620
|
+
`;
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
case "collection": {
|
|
625
|
+
const collectionsDir = join(srcDir, "collections");
|
|
626
|
+
await ensureDir(collectionsDir);
|
|
627
|
+
targetPath = join(collectionsDir, `${slug}.json`);
|
|
628
|
+
fileExt = ".json";
|
|
629
|
+
content = `[
|
|
630
|
+
{
|
|
631
|
+
"id": 1,
|
|
632
|
+
"title": "Sample ${title} Item",
|
|
633
|
+
"description": "Add your collection items here"
|
|
634
|
+
}
|
|
635
|
+
]
|
|
636
|
+
`;
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
default:
|
|
641
|
+
console.log(kolor.red(`❌ Unknown content type: ${type}`));
|
|
642
|
+
console.log(kolor.dim("\nSupported types: page, post, layout, component, partial, collection\n"));
|
|
643
|
+
return { success: false, skipped: false };
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (existsSync(targetPath)) {
|
|
647
|
+
console.log(kolor.dim(` ⚠️ Skipped ${relative(cwd, targetPath)} (already exists)`));
|
|
648
|
+
return { success: false, skipped: true };
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
await ensureDir(dirname(targetPath));
|
|
652
|
+
await writeFile(targetPath, content, "utf8");
|
|
653
|
+
|
|
654
|
+
console.log(kolor.dim(` ✅ ${relative(cwd, targetPath)}`));
|
|
655
|
+
return { success: true, skipped: false };
|
|
656
|
+
}
|