basecampjs 0.0.8 ā 0.0.10
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/index.js +933 -7
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createServer } from "http";
|
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
import { cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "fs/promises";
|
|
6
6
|
import { basename, dirname, extname, join, relative, resolve } from "path";
|
|
7
|
-
import { pathToFileURL } from "url";
|
|
7
|
+
import { pathToFileURL, fileURLToPath } from "url";
|
|
8
8
|
import { createHash } from "crypto";
|
|
9
9
|
import * as kolor from "kolorist";
|
|
10
10
|
import chokidar from "chokidar";
|
|
@@ -15,8 +15,10 @@ import nunjucks from "nunjucks";
|
|
|
15
15
|
import { Liquid } from "liquidjs";
|
|
16
16
|
import { minify as minifyCss } from "csso";
|
|
17
17
|
import { minify as minifyHtml } from "html-minifier-terser";
|
|
18
|
+
import sharp from "sharp";
|
|
18
19
|
|
|
19
20
|
const cwd = process.cwd();
|
|
21
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
22
|
const md = new MarkdownIt({ html: true, linkify: true, typographer: true });
|
|
21
23
|
|
|
22
24
|
const defaultConfig = {
|
|
@@ -28,6 +30,14 @@ const defaultConfig = {
|
|
|
28
30
|
minifyCSS: false,
|
|
29
31
|
minifyHTML: false,
|
|
30
32
|
cacheBustAssets: false,
|
|
33
|
+
excludeFiles: [],
|
|
34
|
+
compressPhotos: false,
|
|
35
|
+
compressionSettings: {
|
|
36
|
+
quality: 80,
|
|
37
|
+
formats: [".webp"],
|
|
38
|
+
inputFormats: [".jpg", ".jpeg", ".png"],
|
|
39
|
+
preserveOriginal: true
|
|
40
|
+
},
|
|
31
41
|
integrations: { nunjucks: true, liquid: false, mustache: false, vue: false, alpine: false }
|
|
32
42
|
};
|
|
33
43
|
|
|
@@ -44,6 +54,75 @@ async function loadConfig(root) {
|
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
|
|
57
|
+
async function getVersion() {
|
|
58
|
+
try {
|
|
59
|
+
const pkgPath = join(__dirname, "package.json");
|
|
60
|
+
const raw = await readFile(pkgPath, "utf8");
|
|
61
|
+
const pkg = JSON.parse(raw);
|
|
62
|
+
return pkg.version || "0.0.0";
|
|
63
|
+
} catch {
|
|
64
|
+
return "0.0.0";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function showHelp() {
|
|
69
|
+
console.log(kolor.cyan(kolor.bold("\nšļø CampsiteJS CLI")));
|
|
70
|
+
console.log(kolor.dim("Build and manage your static campsite.\n"));
|
|
71
|
+
|
|
72
|
+
console.log(kolor.bold("Usage:"));
|
|
73
|
+
console.log(" campsite <command> [arguments] [options]\n");
|
|
74
|
+
|
|
75
|
+
console.log(kolor.bold("Project Commands:"));
|
|
76
|
+
console.log(" " + kolor.cyan("init") + " Initialize a new Campsite project in current directory");
|
|
77
|
+
console.log(" Creates config, folder structure, and starter files\n");
|
|
78
|
+
|
|
79
|
+
console.log(kolor.bold("Development Commands:"));
|
|
80
|
+
console.log(" " + kolor.cyan("dev") + " Start development server with hot reloading");
|
|
81
|
+
console.log(" Watches for file changes and rebuilds automatically");
|
|
82
|
+
console.log(" " + kolor.cyan("build") + " Build your site for production");
|
|
83
|
+
console.log(" Optimizes and outputs to dist/ directory");
|
|
84
|
+
console.log(" " + kolor.cyan("serve") + " Serve the built site locally");
|
|
85
|
+
console.log(" Serves from dist/ folder on http://localhost:4173");
|
|
86
|
+
console.log(" " + kolor.cyan("preview") + " Build and serve in production mode");
|
|
87
|
+
console.log(" Combines build + serve for testing production output\n");
|
|
88
|
+
|
|
89
|
+
console.log(kolor.bold("Utility Commands:"));
|
|
90
|
+
console.log(" " + kolor.cyan("list") + " List all content (pages, layouts, components, etc.)");
|
|
91
|
+
console.log(" Overview of your project structure");
|
|
92
|
+
console.log(" " + kolor.cyan("clean") + " Remove build output directory");
|
|
93
|
+
console.log(" Deletes dist/ folder for a fresh build");
|
|
94
|
+
console.log(" " + kolor.cyan("check") + " Validate config and check for issues");
|
|
95
|
+
console.log(" Diagnoses project structure and dependencies");
|
|
96
|
+
console.log(" " + kolor.cyan("upgrade") + " Update CampsiteJS to the latest version");
|
|
97
|
+
console.log(" Checks and upgrades basecampjs and dependencies\n");
|
|
98
|
+
|
|
99
|
+
console.log(kolor.bold("Make Commands:"));
|
|
100
|
+
console.log(" " + kolor.cyan("make:page") + " " + kolor.dim("<name>") + " Create a new page in src/pages/");
|
|
101
|
+
console.log(" " + kolor.cyan("make:post") + " " + kolor.dim("<name>") + " Create a new blog post in src/pages/blog/");
|
|
102
|
+
console.log(" " + kolor.cyan("make:layout") + " " + kolor.dim("<name>") + " Create a new layout in src/layouts/");
|
|
103
|
+
console.log(" " + kolor.cyan("make:component") + " " + kolor.dim("<name>") + " Create a new component in src/components/");
|
|
104
|
+
console.log(" " + kolor.cyan("make:partial") + " " + kolor.dim("<name>") + " Create a new partial in src/partials/");
|
|
105
|
+
console.log(" " + kolor.cyan("make:collection") + " " + kolor.dim("<name>") + " Create a new JSON collection in src/collections/\n");
|
|
106
|
+
|
|
107
|
+
console.log(kolor.bold("Options:"));
|
|
108
|
+
console.log(" -h, --help Show this help message");
|
|
109
|
+
console.log(" -v, --version Show version number\n");
|
|
110
|
+
|
|
111
|
+
console.log(kolor.bold("Examples:"));
|
|
112
|
+
console.log(" " + kolor.dim("# Initialize a new project"));
|
|
113
|
+
console.log(" campsite init\n");
|
|
114
|
+
console.log(" " + kolor.dim("# Start development"));
|
|
115
|
+
console.log(" campsite dev\n");
|
|
116
|
+
console.log(" " + kolor.dim("# Create new content"));
|
|
117
|
+
console.log(" campsite make:page about");
|
|
118
|
+
console.log(" campsite make:post \"My First Post\"");
|
|
119
|
+
console.log(" campsite make:collection products\n");
|
|
120
|
+
console.log(" " + kolor.dim("# Build and preview"));
|
|
121
|
+
console.log(" campsite preview\n");
|
|
122
|
+
console.log(kolor.dim("For more information, visit: https://campsitejs.dev"));
|
|
123
|
+
console.log();
|
|
124
|
+
}
|
|
125
|
+
|
|
47
126
|
async function ensureDir(dir) {
|
|
48
127
|
await mkdir(dir, { recursive: true });
|
|
49
128
|
}
|
|
@@ -75,12 +154,166 @@ async function cleanDir(dir) {
|
|
|
75
154
|
await mkdir(dir, { recursive: true });
|
|
76
155
|
}
|
|
77
156
|
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
157
|
+
function shouldExcludeFile(filePath, excludePatterns) {
|
|
158
|
+
if (!excludePatterns || excludePatterns.length === 0) return false;
|
|
159
|
+
|
|
160
|
+
const fileName = basename(filePath).toLowerCase();
|
|
161
|
+
const ext = extname(filePath).toLowerCase();
|
|
162
|
+
|
|
163
|
+
return excludePatterns.some(pattern => {
|
|
164
|
+
const normalized = pattern.toLowerCase();
|
|
165
|
+
// Support extension patterns like '.pdf' or 'pdf'
|
|
166
|
+
if (normalized.startsWith('.')) {
|
|
167
|
+
return ext === normalized;
|
|
168
|
+
}
|
|
169
|
+
if (normalized.startsWith('*.')) {
|
|
170
|
+
return ext === normalized.slice(1);
|
|
171
|
+
}
|
|
172
|
+
// Support exact filename matches
|
|
173
|
+
if (fileName === normalized) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
// Support glob-like patterns with wildcards
|
|
177
|
+
if (normalized.includes('*')) {
|
|
178
|
+
const regex = new RegExp('^' + normalized.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
|
|
179
|
+
return regex.test(fileName);
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function copyPublic(publicDir, outDir, excludePatterns = []) {
|
|
186
|
+
if (!existsSync(publicDir)) return;
|
|
187
|
+
|
|
188
|
+
const files = await walkFiles(publicDir);
|
|
189
|
+
for (const file of files) {
|
|
190
|
+
const rel = relative(publicDir, file);
|
|
191
|
+
|
|
192
|
+
// Skip excluded files
|
|
193
|
+
if (shouldExcludeFile(file, excludePatterns)) {
|
|
194
|
+
console.log(kolor.dim(`Skipping excluded file: ${rel}`));
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const destPath = join(outDir, rel);
|
|
199
|
+
await ensureDir(dirname(destPath));
|
|
200
|
+
await cp(file, destPath);
|
|
81
201
|
}
|
|
82
202
|
}
|
|
83
203
|
|
|
204
|
+
function shouldProcessImage(filePath, config) {
|
|
205
|
+
if (!config.compressPhotos) return false;
|
|
206
|
+
const ext = extname(filePath).toLowerCase();
|
|
207
|
+
const inputFormats = config.compressionSettings?.inputFormats || [".jpg", ".jpeg", ".png"];
|
|
208
|
+
return inputFormats.includes(ext);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function processImage(inputPath, outDir, settings) {
|
|
212
|
+
const ext = extname(inputPath);
|
|
213
|
+
const baseName = basename(inputPath, ext);
|
|
214
|
+
const dir = dirname(inputPath);
|
|
215
|
+
const relDir = relative(outDir, dir);
|
|
216
|
+
|
|
217
|
+
const results = [];
|
|
218
|
+
const quality = settings.quality || 80;
|
|
219
|
+
const formats = settings.formats || [".webp"];
|
|
220
|
+
|
|
221
|
+
for (const format of formats) {
|
|
222
|
+
try {
|
|
223
|
+
const outputName = `${baseName}${format}`;
|
|
224
|
+
const outputPath = join(dir, outputName);
|
|
225
|
+
|
|
226
|
+
const sharpInstance = sharp(inputPath);
|
|
227
|
+
|
|
228
|
+
if (format === ".webp") {
|
|
229
|
+
await sharpInstance.webp({ quality }).toFile(outputPath);
|
|
230
|
+
} else if (format === ".avif") {
|
|
231
|
+
await sharpInstance.avif({ quality }).toFile(outputPath);
|
|
232
|
+
} else if (format === ".jpg" || format === ".jpeg") {
|
|
233
|
+
await sharpInstance.jpeg({ quality }).toFile(outputPath);
|
|
234
|
+
} else if (format === ".png") {
|
|
235
|
+
await sharpInstance.png({ quality }).toFile(outputPath);
|
|
236
|
+
} else {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const stats = await stat(outputPath);
|
|
241
|
+
results.push({
|
|
242
|
+
path: outputPath,
|
|
243
|
+
format,
|
|
244
|
+
size: stats.size
|
|
245
|
+
});
|
|
246
|
+
} catch (err) {
|
|
247
|
+
console.error(kolor.red(`Failed to convert ${basename(inputPath)} to ${format}: ${err.message}`));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return results;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function processImages(outDir, config) {
|
|
255
|
+
if (!config.compressPhotos) return;
|
|
256
|
+
|
|
257
|
+
const settings = {
|
|
258
|
+
quality: config.compressionSettings?.quality || 80,
|
|
259
|
+
formats: config.compressionSettings?.formats || [".webp"],
|
|
260
|
+
preserveOriginal: config.compressionSettings?.preserveOriginal !== false
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
console.log(kolor.cyan("š¼ļø Processing images..."));
|
|
264
|
+
|
|
265
|
+
const files = await walkFiles(outDir);
|
|
266
|
+
const imageFiles = files.filter((file) => shouldProcessImage(file, config));
|
|
267
|
+
|
|
268
|
+
if (imageFiles.length === 0) {
|
|
269
|
+
console.log(kolor.dim("No images found to process"));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let totalGenerated = 0;
|
|
274
|
+
let totalOriginalSize = 0;
|
|
275
|
+
let totalConvertedSize = 0;
|
|
276
|
+
|
|
277
|
+
await Promise.all(imageFiles.map(async (file) => {
|
|
278
|
+
const originalStats = await stat(file);
|
|
279
|
+
totalOriginalSize += originalStats.size;
|
|
280
|
+
|
|
281
|
+
const results = await processImage(file, outDir, settings);
|
|
282
|
+
|
|
283
|
+
if (results.length > 0) {
|
|
284
|
+
const formats = results.map(r => r.format.slice(1)).join(", ");
|
|
285
|
+
const rel = relative(outDir, file);
|
|
286
|
+
console.log(kolor.dim(` ${rel} ā ${formats}`));
|
|
287
|
+
|
|
288
|
+
results.forEach(r => {
|
|
289
|
+
totalConvertedSize += r.size;
|
|
290
|
+
totalGenerated++;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Remove original if preserveOriginal is false
|
|
295
|
+
if (!settings.preserveOriginal && results.length > 0) {
|
|
296
|
+
await rm(file, { force: true });
|
|
297
|
+
}
|
|
298
|
+
}));
|
|
299
|
+
|
|
300
|
+
const savedBytes = totalOriginalSize - totalConvertedSize;
|
|
301
|
+
const savedPercent = totalOriginalSize > 0 ? ((savedBytes / totalOriginalSize) * 100).toFixed(1) : 0;
|
|
302
|
+
|
|
303
|
+
console.log(kolor.green(`ā Generated ${totalGenerated} image(s)`));
|
|
304
|
+
if (!settings.preserveOriginal) {
|
|
305
|
+
console.log(kolor.green(` Saved ${formatBytes(savedBytes)} (${savedPercent}% reduction)`));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function formatBytes(bytes) {
|
|
310
|
+
if (bytes === 0) return "0 B";
|
|
311
|
+
const k = 1024;
|
|
312
|
+
const sizes = ["B", "KB", "MB", "GB"];
|
|
313
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
314
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
315
|
+
}
|
|
316
|
+
|
|
84
317
|
async function minifyCSSFiles(outDir) {
|
|
85
318
|
const files = await walkFiles(outDir);
|
|
86
319
|
const cssFiles = files.filter((file) => extname(file).toLowerCase() === ".css");
|
|
@@ -400,7 +633,11 @@ async function build(cwdArg = cwd) {
|
|
|
400
633
|
const data = await loadData([dataDir, collectionsDir]);
|
|
401
634
|
|
|
402
635
|
await cleanDir(outDir);
|
|
403
|
-
await copyPublic(publicDir, outDir);
|
|
636
|
+
await copyPublic(publicDir, outDir, config.excludeFiles);
|
|
637
|
+
|
|
638
|
+
if (config.compressPhotos) {
|
|
639
|
+
await processImages(outDir, config);
|
|
640
|
+
}
|
|
404
641
|
|
|
405
642
|
const files = await walkFiles(pagesDir);
|
|
406
643
|
if (files.length === 0) {
|
|
@@ -533,10 +770,683 @@ async function dev(cwdArg = cwd) {
|
|
|
533
770
|
serve(outDir);
|
|
534
771
|
}
|
|
535
772
|
|
|
773
|
+
function slugify(text) {
|
|
774
|
+
return text
|
|
775
|
+
.toLowerCase()
|
|
776
|
+
.trim()
|
|
777
|
+
.replace(/[^\w\s-]/g, "")
|
|
778
|
+
.replace(/[\s_-]+/g, "-")
|
|
779
|
+
.replace(/^-+|-+$/g, "");
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function formatDate(date) {
|
|
783
|
+
return date.toISOString().split("T")[0];
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
async function makeContent(type) {
|
|
787
|
+
// Get all arguments after the command and join them
|
|
788
|
+
const args = argv.slice(3);
|
|
789
|
+
|
|
790
|
+
if (args.length === 0) {
|
|
791
|
+
console.log(kolor.red("ā Missing name argument"));
|
|
792
|
+
console.log(kolor.dim(`Usage: campsite make:${type} <name> [name2, name3, ...]`));
|
|
793
|
+
console.log(kolor.dim("\nExamples:"));
|
|
794
|
+
console.log(kolor.dim(" campsite make:page about"));
|
|
795
|
+
console.log(kolor.dim(" campsite make:page home, about, contact"));
|
|
796
|
+
console.log(kolor.dim(" campsite make:collection products, categories\n"));
|
|
797
|
+
exit(1);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Join all args and split by comma to support both formats:
|
|
801
|
+
// campsite make:page home about contact
|
|
802
|
+
// campsite make:page home, about, contact
|
|
803
|
+
const namesString = args.join(" ");
|
|
804
|
+
const names = namesString.split(",").map(n => n.trim()).filter(n => n.length > 0);
|
|
805
|
+
|
|
806
|
+
if (names.length === 0) {
|
|
807
|
+
console.log(kolor.red("ā No valid names provided\n"));
|
|
808
|
+
exit(1);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
console.log(kolor.cyan(`\nšļø Creating ${names.length} ${type}(s)...\n`));
|
|
812
|
+
|
|
813
|
+
const config = await loadConfig(cwd);
|
|
814
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
815
|
+
|
|
816
|
+
// Determine file extension based on template engine
|
|
817
|
+
const engineExtMap = {
|
|
818
|
+
nunjucks: ".njk",
|
|
819
|
+
liquid: ".liquid",
|
|
820
|
+
mustache: ".mustache"
|
|
821
|
+
};
|
|
822
|
+
const defaultExt = engineExtMap[config.templateEngine] || ".njk";
|
|
823
|
+
|
|
824
|
+
let successCount = 0;
|
|
825
|
+
let skipCount = 0;
|
|
826
|
+
|
|
827
|
+
for (const name of names) {
|
|
828
|
+
const result = await createSingleContent(type, name, srcDir, config, defaultExt);
|
|
829
|
+
if (result.success) successCount++;
|
|
830
|
+
if (result.skipped) skipCount++;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
console.log();
|
|
834
|
+
if (successCount > 0) {
|
|
835
|
+
console.log(kolor.green(`ā
Created ${successCount} ${type}(s)`));
|
|
836
|
+
}
|
|
837
|
+
if (skipCount > 0) {
|
|
838
|
+
console.log(kolor.yellow(`ā ļø Skipped ${skipCount} existing file(s)`));
|
|
839
|
+
}
|
|
840
|
+
console.log(kolor.dim("\nš² Happy camping!\n"));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
async function createSingleContent(type, name, srcDir, config, defaultExt) {
|
|
844
|
+
// Check if user provided an extension
|
|
845
|
+
const hasExtension = name.includes(".");
|
|
846
|
+
const providedExt = hasExtension ? extname(name) : null;
|
|
847
|
+
const nameWithoutExt = hasExtension ? basename(name, providedExt) : name;
|
|
848
|
+
|
|
849
|
+
const slug = slugify(nameWithoutExt);
|
|
850
|
+
const today = formatDate(new Date());
|
|
851
|
+
const title = nameWithoutExt.charAt(0).toUpperCase() + nameWithoutExt.slice(1);
|
|
852
|
+
|
|
853
|
+
let targetPath;
|
|
854
|
+
let content;
|
|
855
|
+
let fileExt;
|
|
856
|
+
|
|
857
|
+
switch (type.toLowerCase()) {
|
|
858
|
+
case "page": {
|
|
859
|
+
// Priority: provided extension > template engine
|
|
860
|
+
if (providedExt) {
|
|
861
|
+
fileExt = providedExt;
|
|
862
|
+
} else {
|
|
863
|
+
fileExt = defaultExt;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
targetPath = join(srcDir, "pages", `${slug}${fileExt}`);
|
|
867
|
+
|
|
868
|
+
// Determine if we should use markdown content based on extension
|
|
869
|
+
const useMarkdown = fileExt === ".md";
|
|
870
|
+
|
|
871
|
+
if (useMarkdown) {
|
|
872
|
+
content = `---
|
|
873
|
+
layout: base${defaultExt}
|
|
874
|
+
title: ${title}
|
|
875
|
+
---
|
|
876
|
+
|
|
877
|
+
# ${title}
|
|
878
|
+
|
|
879
|
+
Your new page content goes here.
|
|
880
|
+
`;
|
|
881
|
+
} else {
|
|
882
|
+
content = `---
|
|
883
|
+
layout: base${defaultExt}
|
|
884
|
+
title: ${title}
|
|
885
|
+
---
|
|
886
|
+
|
|
887
|
+
<h1>${title}</h1>
|
|
888
|
+
<p>Your new page content goes here.</p>
|
|
889
|
+
`;
|
|
890
|
+
}
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
case "post": {
|
|
895
|
+
const postsDir = join(srcDir, "pages", "blog");
|
|
896
|
+
await ensureDir(postsDir);
|
|
897
|
+
|
|
898
|
+
if (providedExt) {
|
|
899
|
+
fileExt = providedExt;
|
|
900
|
+
} else {
|
|
901
|
+
fileExt = defaultExt;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
targetPath = join(postsDir, `${slug}${fileExt}`);
|
|
905
|
+
|
|
906
|
+
const useMarkdown = fileExt === ".md";
|
|
907
|
+
|
|
908
|
+
if (useMarkdown) {
|
|
909
|
+
content = `---
|
|
910
|
+
layout: base${defaultExt}
|
|
911
|
+
title: ${title}
|
|
912
|
+
date: ${today}
|
|
913
|
+
author: Your Name
|
|
914
|
+
---
|
|
915
|
+
|
|
916
|
+
# ${title}
|
|
917
|
+
|
|
918
|
+
Your blog post content goes here.
|
|
919
|
+
`;
|
|
920
|
+
} else {
|
|
921
|
+
content = `---
|
|
922
|
+
layout: base${defaultExt}
|
|
923
|
+
title: ${title}
|
|
924
|
+
date: ${today}
|
|
925
|
+
author: Your Name
|
|
926
|
+
---
|
|
927
|
+
|
|
928
|
+
<h1>${title}</h1>
|
|
929
|
+
<p>Your blog post content goes here.</p>
|
|
930
|
+
`;
|
|
931
|
+
}
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
case "layout": {
|
|
936
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
937
|
+
await ensureDir(layoutsDir);
|
|
938
|
+
targetPath = join(layoutsDir, `${slug}.njk`);
|
|
939
|
+
fileExt = ".njk";
|
|
940
|
+
content = `<!DOCTYPE html>
|
|
941
|
+
<html lang="en">
|
|
942
|
+
<head>
|
|
943
|
+
<meta charset="UTF-8">
|
|
944
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
945
|
+
<title>{{ title or site.name }}</title>
|
|
946
|
+
<link rel="stylesheet" href="/style.css">
|
|
947
|
+
</head>
|
|
948
|
+
<body>
|
|
949
|
+
<main>
|
|
950
|
+
{% block content %}
|
|
951
|
+
{{ content | safe }}
|
|
952
|
+
{% endblock %}
|
|
953
|
+
</main>
|
|
954
|
+
</body>
|
|
955
|
+
</html>
|
|
956
|
+
`;
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
case "component": {
|
|
961
|
+
const componentsDir = join(srcDir, "components");
|
|
962
|
+
await ensureDir(componentsDir);
|
|
963
|
+
targetPath = join(componentsDir, `${slug}.njk`);
|
|
964
|
+
fileExt = ".njk";
|
|
965
|
+
content = `{# ${title} Component #}
|
|
966
|
+
<div class="${slug}">
|
|
967
|
+
{{ content | safe }}
|
|
968
|
+
</div>
|
|
969
|
+
`;
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
case "partial": {
|
|
974
|
+
const partialsDir = join(srcDir, "partials");
|
|
975
|
+
await ensureDir(partialsDir);
|
|
976
|
+
targetPath = join(partialsDir, `${slug}.njk`);
|
|
977
|
+
fileExt = ".njk";
|
|
978
|
+
content = `{# ${title} Partial #}
|
|
979
|
+
<div class="${slug}">
|
|
980
|
+
{# Your partial content here #}
|
|
981
|
+
</div>
|
|
982
|
+
`;
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
case "collection": {
|
|
987
|
+
const collectionsDir = join(srcDir, "collections");
|
|
988
|
+
await ensureDir(collectionsDir);
|
|
989
|
+
targetPath = join(collectionsDir, `${slug}.json`);
|
|
990
|
+
fileExt = ".json";
|
|
991
|
+
content = `[
|
|
992
|
+
{
|
|
993
|
+
"id": 1,
|
|
994
|
+
"title": "Sample ${title} Item",
|
|
995
|
+
"description": "Add your collection items here"
|
|
996
|
+
}
|
|
997
|
+
]
|
|
998
|
+
`;
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
default:
|
|
1003
|
+
console.log(kolor.red(`ā Unknown content type: ${type}`));
|
|
1004
|
+
console.log(kolor.dim("\nSupported types: page, post, layout, component, partial, collection\n"));
|
|
1005
|
+
return { success: false, skipped: false };
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
if (existsSync(targetPath)) {
|
|
1009
|
+
console.log(kolor.dim(` ā ļø Skipped ${relative(cwd, targetPath)} (already exists)`));
|
|
1010
|
+
return { success: false, skipped: true };
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
await ensureDir(dirname(targetPath));
|
|
1014
|
+
await writeFile(targetPath, content, "utf8");
|
|
1015
|
+
|
|
1016
|
+
console.log(kolor.dim(` ā
${relative(cwd, targetPath)}`));
|
|
1017
|
+
return { success: true, skipped: false };
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
async function init() {
|
|
1021
|
+
const targetDir = cwd;
|
|
1022
|
+
console.log(kolor.cyan(kolor.bold("šļø Initializing Campsite in current directory...")));
|
|
1023
|
+
|
|
1024
|
+
// Check if already initialized
|
|
1025
|
+
if (existsSync(join(targetDir, "campsite.config.js"))) {
|
|
1026
|
+
console.log(kolor.yellow("ā ļø This directory already has a campsite.config.js file."));
|
|
1027
|
+
console.log(kolor.dim("Run 'campsite dev' to start developing.\n"));
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// Create basic structure
|
|
1032
|
+
const dirs = [
|
|
1033
|
+
join(targetDir, "src", "pages"),
|
|
1034
|
+
join(targetDir, "src", "layouts"),
|
|
1035
|
+
join(targetDir, "public")
|
|
1036
|
+
];
|
|
1037
|
+
|
|
1038
|
+
for (const dir of dirs) {
|
|
1039
|
+
await ensureDir(dir);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// Create basic config file
|
|
1043
|
+
const configContent = `export default {
|
|
1044
|
+
siteName: "My Campsite",
|
|
1045
|
+
srcDir: "src",
|
|
1046
|
+
outDir: "dist",
|
|
1047
|
+
templateEngine: "nunjucks",
|
|
1048
|
+
markdown: true,
|
|
1049
|
+
integrations: {
|
|
1050
|
+
nunjucks: true,
|
|
1051
|
+
liquid: false,
|
|
1052
|
+
mustache: false,
|
|
1053
|
+
vue: false,
|
|
1054
|
+
alpine: false
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
`;
|
|
1058
|
+
await writeFile(join(targetDir, "campsite.config.js"), configContent, "utf8");
|
|
1059
|
+
|
|
1060
|
+
// Create basic layout
|
|
1061
|
+
const layoutContent = `<!DOCTYPE html>
|
|
1062
|
+
<html lang="en">
|
|
1063
|
+
<head>
|
|
1064
|
+
<meta charset="UTF-8">
|
|
1065
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1066
|
+
<title>{{ title or site.name }}</title>
|
|
1067
|
+
<link rel="stylesheet" href="/style.css">
|
|
1068
|
+
</head>
|
|
1069
|
+
<body>
|
|
1070
|
+
{% block content %}
|
|
1071
|
+
{{ content | safe }}
|
|
1072
|
+
{% endblock %}
|
|
1073
|
+
</body>
|
|
1074
|
+
</html>
|
|
1075
|
+
`;
|
|
1076
|
+
await writeFile(join(targetDir, "src", "layouts", "base.njk"), layoutContent, "utf8");
|
|
1077
|
+
|
|
1078
|
+
// Create sample page
|
|
1079
|
+
const pageContent = `---
|
|
1080
|
+
layout: base.njk
|
|
1081
|
+
title: Welcome to Campsite
|
|
1082
|
+
---
|
|
1083
|
+
|
|
1084
|
+
# Welcome to Campsite! šļø
|
|
1085
|
+
|
|
1086
|
+
Your cozy static site is ready to build.
|
|
1087
|
+
|
|
1088
|
+
## Get Started
|
|
1089
|
+
|
|
1090
|
+
- Run \`campsite dev\` to start developing
|
|
1091
|
+
- Edit pages in \`src/pages/\`
|
|
1092
|
+
- Customize layouts in \`src/layouts/\`
|
|
1093
|
+
|
|
1094
|
+
Happy camping! š²š¦
|
|
1095
|
+
`;
|
|
1096
|
+
await writeFile(join(targetDir, "src", "pages", "index.md"), pageContent, "utf8");
|
|
1097
|
+
|
|
1098
|
+
// Create basic CSS
|
|
1099
|
+
const cssContent = `* {
|
|
1100
|
+
margin: 0;
|
|
1101
|
+
padding: 0;
|
|
1102
|
+
box-sizing: border-box;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
body {
|
|
1106
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
1107
|
+
line-height: 1.6;
|
|
1108
|
+
padding: 2rem;
|
|
1109
|
+
max-width: 800px;
|
|
1110
|
+
margin: 0 auto;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
h1 { color: #2d5016; margin-bottom: 1rem; }
|
|
1114
|
+
h2 { color: #4a7c2c; margin-top: 1.5rem; }
|
|
1115
|
+
`;
|
|
1116
|
+
await writeFile(join(targetDir, "public", "style.css"), cssContent, "utf8");
|
|
1117
|
+
|
|
1118
|
+
// Create .gitignore
|
|
1119
|
+
const gitignoreContent = `node_modules/
|
|
1120
|
+
dist/
|
|
1121
|
+
.DS_Store
|
|
1122
|
+
`;
|
|
1123
|
+
await writeFile(join(targetDir, ".gitignore"), gitignoreContent, "utf8");
|
|
1124
|
+
|
|
1125
|
+
// Create package.json
|
|
1126
|
+
const packageJson = {
|
|
1127
|
+
name: basename(targetDir),
|
|
1128
|
+
version: "0.0.1",
|
|
1129
|
+
type: "module",
|
|
1130
|
+
scripts: {
|
|
1131
|
+
dev: "campsite dev",
|
|
1132
|
+
build: "campsite build",
|
|
1133
|
+
serve: "campsite serve",
|
|
1134
|
+
preview: "campsite preview"
|
|
1135
|
+
},
|
|
1136
|
+
dependencies: {
|
|
1137
|
+
basecampjs: "^0.0.8"
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
await writeFile(join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2), "utf8");
|
|
1141
|
+
|
|
1142
|
+
console.log(kolor.green("ā
Campsite initialized successfully!\n"));
|
|
1143
|
+
console.log(kolor.bold("Next steps:"));
|
|
1144
|
+
console.log(kolor.dim(" 1. Install dependencies: npm install"));
|
|
1145
|
+
console.log(kolor.dim(" 2. Start developing: campsite dev\n"));
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
async function clean() {
|
|
1149
|
+
const config = await loadConfig(cwd);
|
|
1150
|
+
const outDir = resolve(cwd, config.outDir || "dist");
|
|
1151
|
+
|
|
1152
|
+
if (!existsSync(outDir)) {
|
|
1153
|
+
console.log(kolor.dim(`Nothing to clean. ${outDir} does not exist.`));
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
console.log(kolor.cyan(`š§¹ Cleaning ${relative(cwd, outDir)}...`));
|
|
1158
|
+
await rm(outDir, { recursive: true, force: true });
|
|
1159
|
+
console.log(kolor.green(`ā
Cleaned ${relative(cwd, outDir)}\n`));
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
async function check() {
|
|
1163
|
+
console.log(kolor.cyan(kolor.bold("š Checking Campsite project...\n")));
|
|
1164
|
+
let hasIssues = false;
|
|
1165
|
+
|
|
1166
|
+
// Check if campsite.config.js exists
|
|
1167
|
+
const configPath = join(cwd, "campsite.config.js");
|
|
1168
|
+
if (!existsSync(configPath)) {
|
|
1169
|
+
console.log(kolor.red("ā campsite.config.js not found"));
|
|
1170
|
+
console.log(kolor.dim(" Run 'campsite init' to initialize a project\n"));
|
|
1171
|
+
hasIssues = true;
|
|
1172
|
+
} else {
|
|
1173
|
+
console.log(kolor.green("ā
campsite.config.js found"));
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// Load and validate config
|
|
1177
|
+
const config = await loadConfig(cwd);
|
|
1178
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
1179
|
+
const pagesDir = join(srcDir, "pages");
|
|
1180
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
1181
|
+
const publicDir = resolve(cwd, "public");
|
|
1182
|
+
|
|
1183
|
+
// Check src directory
|
|
1184
|
+
if (!existsSync(srcDir)) {
|
|
1185
|
+
console.log(kolor.red(`ā Source directory not found: ${relative(cwd, srcDir)}`));
|
|
1186
|
+
hasIssues = true;
|
|
1187
|
+
} else {
|
|
1188
|
+
console.log(kolor.green(`ā
Source directory exists: ${relative(cwd, srcDir)}`));
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// Check pages directory
|
|
1192
|
+
if (!existsSync(pagesDir)) {
|
|
1193
|
+
console.log(kolor.yellow(`ā ļø Pages directory not found: ${relative(cwd, pagesDir)}`));
|
|
1194
|
+
hasIssues = true;
|
|
1195
|
+
} else {
|
|
1196
|
+
const files = await walkFiles(pagesDir);
|
|
1197
|
+
if (files.length === 0) {
|
|
1198
|
+
console.log(kolor.yellow(`ā ļø No pages found in ${relative(cwd, pagesDir)}`));
|
|
1199
|
+
hasIssues = true;
|
|
1200
|
+
} else {
|
|
1201
|
+
console.log(kolor.green(`ā
Found ${files.length} page(s) in ${relative(cwd, pagesDir)}`));
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// Check layouts directory
|
|
1206
|
+
if (existsSync(layoutsDir)) {
|
|
1207
|
+
const layouts = await readdir(layoutsDir).catch(() => []);
|
|
1208
|
+
console.log(kolor.green(`ā
Found ${layouts.length} layout(s) in ${relative(cwd, layoutsDir)}`));
|
|
1209
|
+
} else {
|
|
1210
|
+
console.log(kolor.dim(`ā¹ļø No layouts directory (${relative(cwd, layoutsDir)})`));
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// Check public directory
|
|
1214
|
+
if (existsSync(publicDir)) {
|
|
1215
|
+
console.log(kolor.green(`ā
Public directory exists: ${relative(cwd, publicDir)}`));
|
|
1216
|
+
} else {
|
|
1217
|
+
console.log(kolor.dim(`ā¹ļø No public directory (${relative(cwd, publicDir)})`));
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Check for package.json and dependencies
|
|
1221
|
+
const pkgPath = join(cwd, "package.json");
|
|
1222
|
+
if (existsSync(pkgPath)) {
|
|
1223
|
+
try {
|
|
1224
|
+
const pkgRaw = await readFile(pkgPath, "utf8");
|
|
1225
|
+
const pkg = JSON.parse(pkgRaw);
|
|
1226
|
+
if (pkg.dependencies?.basecampjs || pkg.devDependencies?.basecampjs) {
|
|
1227
|
+
console.log(kolor.green("ā
basecampjs dependency found"));
|
|
1228
|
+
} else {
|
|
1229
|
+
console.log(kolor.yellow("ā ļø basecampjs not listed in dependencies"));
|
|
1230
|
+
console.log(kolor.dim(" Consider adding: npm install basecampjs"));
|
|
1231
|
+
}
|
|
1232
|
+
} catch {
|
|
1233
|
+
console.log(kolor.yellow("ā ļø Could not parse package.json"));
|
|
1234
|
+
}
|
|
1235
|
+
} else {
|
|
1236
|
+
console.log(kolor.dim("ā¹ļø No package.json found"));
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
console.log();
|
|
1240
|
+
if (hasIssues) {
|
|
1241
|
+
console.log(kolor.yellow("ā ļø Some issues found. Review the messages above."));
|
|
1242
|
+
} else {
|
|
1243
|
+
console.log(kolor.green(kolor.bold("š Everything looks good! Ready to build.")));
|
|
1244
|
+
}
|
|
1245
|
+
console.log();
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
async function upgrade() {
|
|
1249
|
+
console.log(kolor.cyan(kolor.bold("ā¬ļø Checking for CampsiteJS updates...\n")));
|
|
1250
|
+
|
|
1251
|
+
// Check if package.json exists
|
|
1252
|
+
const pkgPath = join(cwd, "package.json");
|
|
1253
|
+
if (!existsSync(pkgPath)) {
|
|
1254
|
+
console.log(kolor.red("ā package.json not found"));
|
|
1255
|
+
console.log(kolor.dim("This command should be run in a Campsite project directory.\n"));
|
|
1256
|
+
exit(1);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// Read current package.json
|
|
1260
|
+
let pkg;
|
|
1261
|
+
try {
|
|
1262
|
+
const pkgRaw = await readFile(pkgPath, "utf8");
|
|
1263
|
+
pkg = JSON.parse(pkgRaw);
|
|
1264
|
+
} catch {
|
|
1265
|
+
console.log(kolor.red("ā Could not read package.json\n"));
|
|
1266
|
+
exit(1);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
const currentVersion = pkg.dependencies?.basecampjs || pkg.devDependencies?.basecampjs;
|
|
1270
|
+
if (!currentVersion) {
|
|
1271
|
+
console.log(kolor.yellow("ā ļø basecampjs not found in dependencies"));
|
|
1272
|
+
console.log(kolor.dim("Install it with: npm install basecampjs\n"));
|
|
1273
|
+
exit(1);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
console.log(kolor.dim(`Current version: ${currentVersion}`));
|
|
1277
|
+
console.log(kolor.cyan("\nUpgrading basecampjs to latest version...\n"));
|
|
1278
|
+
|
|
1279
|
+
// Use dynamic import to run npm commands
|
|
1280
|
+
const { spawn } = await import("child_process");
|
|
1281
|
+
|
|
1282
|
+
return new Promise((resolve, reject) => {
|
|
1283
|
+
const child = spawn("npm", ["install", "basecampjs@latest"], {
|
|
1284
|
+
cwd,
|
|
1285
|
+
stdio: "inherit",
|
|
1286
|
+
shell: process.platform === "win32"
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
child.on("close", async (code) => {
|
|
1290
|
+
if (code === 0) {
|
|
1291
|
+
console.log();
|
|
1292
|
+
console.log(kolor.green("ā
CampsiteJS updated successfully!"));
|
|
1293
|
+
|
|
1294
|
+
// Read updated version
|
|
1295
|
+
try {
|
|
1296
|
+
const updatedPkgRaw = await readFile(pkgPath, "utf8");
|
|
1297
|
+
const updatedPkg = JSON.parse(updatedPkgRaw);
|
|
1298
|
+
const newVersion = updatedPkg.dependencies?.basecampjs || updatedPkg.devDependencies?.basecampjs;
|
|
1299
|
+
console.log(kolor.dim(`New version: ${newVersion}`));
|
|
1300
|
+
} catch {}
|
|
1301
|
+
|
|
1302
|
+
console.log();
|
|
1303
|
+
console.log(kolor.dim("š² Tip: Run 'campsite dev' to start developing with the latest version\n"));
|
|
1304
|
+
resolve();
|
|
1305
|
+
} else {
|
|
1306
|
+
console.log();
|
|
1307
|
+
console.log(kolor.red(`ā Update failed with code ${code}\n`));
|
|
1308
|
+
reject(new Error(`npm install failed with code ${code}`));
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
child.on("error", (err) => {
|
|
1313
|
+
console.log(kolor.red(`ā Update failed: ${err.message}\n`));
|
|
1314
|
+
reject(err);
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
async function list() {
|
|
1320
|
+
console.log(kolor.cyan(kolor.bold("šŗļø Listing Campsite content...\n")));
|
|
1321
|
+
|
|
1322
|
+
const config = await loadConfig(cwd);
|
|
1323
|
+
const srcDir = resolve(cwd, config.srcDir || "src");
|
|
1324
|
+
const pagesDir = join(srcDir, "pages");
|
|
1325
|
+
const layoutsDir = join(srcDir, "layouts");
|
|
1326
|
+
const componentsDir = join(srcDir, "components");
|
|
1327
|
+
const partialsDir = join(srcDir, "partials");
|
|
1328
|
+
const collectionsDir = join(srcDir, "collections");
|
|
1329
|
+
const dataDir = join(srcDir, "data");
|
|
1330
|
+
|
|
1331
|
+
// List pages
|
|
1332
|
+
if (existsSync(pagesDir)) {
|
|
1333
|
+
const pages = await walkFiles(pagesDir);
|
|
1334
|
+
if (pages.length > 0) {
|
|
1335
|
+
console.log(kolor.bold("š Pages (") + kolor.cyan(pages.length.toString()) + kolor.bold(")"));
|
|
1336
|
+
pages.forEach(page => {
|
|
1337
|
+
const rel = relative(pagesDir, page);
|
|
1338
|
+
console.log(" " + kolor.dim("⢠") + rel);
|
|
1339
|
+
});
|
|
1340
|
+
console.log();
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// List layouts
|
|
1345
|
+
if (existsSync(layoutsDir)) {
|
|
1346
|
+
const layouts = await readdir(layoutsDir).catch(() => []);
|
|
1347
|
+
if (layouts.length > 0) {
|
|
1348
|
+
console.log(kolor.bold("š Layouts (") + kolor.cyan(layouts.length.toString()) + kolor.bold(")"));
|
|
1349
|
+
layouts.forEach(layout => {
|
|
1350
|
+
console.log(" " + kolor.dim("⢠") + layout);
|
|
1351
|
+
});
|
|
1352
|
+
console.log();
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// List components
|
|
1357
|
+
if (existsSync(componentsDir)) {
|
|
1358
|
+
const components = await readdir(componentsDir).catch(() => []);
|
|
1359
|
+
if (components.length > 0) {
|
|
1360
|
+
console.log(kolor.bold("š§© Components (") + kolor.cyan(components.length.toString()) + kolor.bold(")"));
|
|
1361
|
+
components.forEach(component => {
|
|
1362
|
+
console.log(" " + kolor.dim("⢠") + component);
|
|
1363
|
+
});
|
|
1364
|
+
console.log();
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// List partials
|
|
1369
|
+
if (existsSync(partialsDir)) {
|
|
1370
|
+
const partials = await readdir(partialsDir).catch(() => []);
|
|
1371
|
+
if (partials.length > 0) {
|
|
1372
|
+
console.log(kolor.bold("š§° Partials (") + kolor.cyan(partials.length.toString()) + kolor.bold(")"));
|
|
1373
|
+
partials.forEach(partial => {
|
|
1374
|
+
console.log(" " + kolor.dim("⢠") + partial);
|
|
1375
|
+
});
|
|
1376
|
+
console.log();
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// List collections
|
|
1381
|
+
if (existsSync(collectionsDir)) {
|
|
1382
|
+
const collections = await readdir(collectionsDir).catch(() => []);
|
|
1383
|
+
const jsonFiles = collections.filter(f => f.endsWith(".json"));
|
|
1384
|
+
if (jsonFiles.length > 0) {
|
|
1385
|
+
console.log(kolor.bold("š Collections (") + kolor.cyan(jsonFiles.length.toString()) + kolor.bold(")"));
|
|
1386
|
+
jsonFiles.forEach(collection => {
|
|
1387
|
+
console.log(" " + kolor.dim("⢠") + collection);
|
|
1388
|
+
});
|
|
1389
|
+
console.log();
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
// List data files
|
|
1394
|
+
if (existsSync(dataDir)) {
|
|
1395
|
+
const dataFiles = await readdir(dataDir).catch(() => []);
|
|
1396
|
+
const jsonFiles = dataFiles.filter(f => f.endsWith(".json"));
|
|
1397
|
+
if (jsonFiles.length > 0) {
|
|
1398
|
+
console.log(kolor.bold("š Data (") + kolor.cyan(jsonFiles.length.toString()) + kolor.bold(")"));
|
|
1399
|
+
jsonFiles.forEach(dataFile => {
|
|
1400
|
+
console.log(" " + kolor.dim("⢠") + dataFile);
|
|
1401
|
+
});
|
|
1402
|
+
console.log();
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
console.log(kolor.dim("š² Tip: Use 'campsite make:<type> <name>' to create new content\n"));
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
async function preview() {
|
|
1410
|
+
console.log(kolor.cyan(kolor.bold("šļø Building for production preview...\n")));
|
|
1411
|
+
await build();
|
|
1412
|
+
console.log();
|
|
1413
|
+
const config = await loadConfig(cwd);
|
|
1414
|
+
const outDir = resolve(cwd, config.outDir || "dist");
|
|
1415
|
+
console.log(kolor.cyan(kolor.bold("š„ Starting preview server...\n")));
|
|
1416
|
+
serve(outDir);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
536
1419
|
async function main() {
|
|
537
1420
|
const command = argv[2] || "help";
|
|
538
1421
|
|
|
1422
|
+
// Handle flags
|
|
1423
|
+
if (command === "-h" || command === "--help" || command === "help") {
|
|
1424
|
+
showHelp();
|
|
1425
|
+
exit(0);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
if (command === "-v" || command === "--version") {
|
|
1429
|
+
const version = await getVersion();
|
|
1430
|
+
console.log(`v${version}`);
|
|
1431
|
+
exit(0);
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// Handle make:type commands
|
|
1435
|
+
if (command.startsWith("make:")) {
|
|
1436
|
+
const type = command.substring(5); // Remove 'make:' prefix
|
|
1437
|
+
if (!type) {
|
|
1438
|
+
console.log(kolor.red("ā No type specified"));
|
|
1439
|
+
console.log(kolor.dim("Run 'campsite --help' for available make commands.\n"));
|
|
1440
|
+
exit(1);
|
|
1441
|
+
}
|
|
1442
|
+
await makeContent(type);
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
539
1446
|
switch (command) {
|
|
1447
|
+
case "init":
|
|
1448
|
+
await init();
|
|
1449
|
+
break;
|
|
540
1450
|
case "dev":
|
|
541
1451
|
await dev();
|
|
542
1452
|
break;
|
|
@@ -552,9 +1462,25 @@ async function main() {
|
|
|
552
1462
|
serve(outDir);
|
|
553
1463
|
break;
|
|
554
1464
|
}
|
|
1465
|
+
case "preview":
|
|
1466
|
+
await preview();
|
|
1467
|
+
break;
|
|
1468
|
+
case "clean":
|
|
1469
|
+
await clean();
|
|
1470
|
+
break;
|
|
1471
|
+
case "check":
|
|
1472
|
+
await check();
|
|
1473
|
+
break;
|
|
1474
|
+
case "list":
|
|
1475
|
+
await list();
|
|
1476
|
+
break;
|
|
1477
|
+
case "upgrade":
|
|
1478
|
+
await upgrade();
|
|
1479
|
+
break;
|
|
555
1480
|
default:
|
|
556
|
-
console.log(
|
|
557
|
-
|
|
1481
|
+
console.log(kolor.yellow(`Unknown command: ${command}`));
|
|
1482
|
+
console.log(kolor.dim("Run 'campsite --help' for usage information."));
|
|
1483
|
+
exit(1);
|
|
558
1484
|
}
|
|
559
1485
|
}
|
|
560
1486
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basecampjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "BasecampJS engine for CampsiteJS static site generator.",
|
|
6
6
|
"bin": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"liquidjs": "^10.12.0",
|
|
20
20
|
"markdown-it": "^14.1.0",
|
|
21
21
|
"mustache": "^4.2.0",
|
|
22
|
-
"nunjucks": "^3.2.4"
|
|
22
|
+
"nunjucks": "^3.2.4",
|
|
23
|
+
"sharp": "^0.33.5"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=18"
|