basecampjs 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +20 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -48,18 +48,23 @@ async function ensureDir(dir) {
48
48
  await mkdir(dir, { recursive: true });
49
49
  }
50
50
 
51
- async function loadData(dataDir) {
51
+ async function loadData(dataDirs) {
52
52
  const collections = {};
53
- if (!existsSync(dataDir)) return collections;
54
- const files = await walkFiles(dataDir);
55
- for (const file of files) {
56
- if (extname(file).toLowerCase() !== ".json") continue;
57
- const name = basename(file, ".json");
58
- try {
59
- const raw = await readFile(file, "utf8");
60
- collections[name] = JSON.parse(raw);
61
- } catch (err) {
62
- console.error(kolor.red(`Failed to load data ${relative(dataDir, file)}: ${err.message}`));
53
+ // Support both string and array input
54
+ const dirs = Array.isArray(dataDirs) ? dataDirs : [dataDirs];
55
+
56
+ for (const dataDir of dirs) {
57
+ if (!existsSync(dataDir)) continue;
58
+ const files = await walkFiles(dataDir);
59
+ for (const file of files) {
60
+ if (extname(file).toLowerCase() !== ".json") continue;
61
+ const name = basename(file, ".json");
62
+ try {
63
+ const raw = await readFile(file, "utf8");
64
+ collections[name] = JSON.parse(raw);
65
+ } catch (err) {
66
+ console.error(kolor.red(`Failed to load data ${relative(dataDir, file)}: ${err.message}`));
67
+ }
63
68
  }
64
69
  }
65
70
  return collections;
@@ -371,6 +376,7 @@ async function build(cwdArg = cwd) {
371
376
  const layoutsDir = join(srcDir, "layouts");
372
377
  const partialsDir = join(srcDir, "partials");
373
378
  const dataDir = join(srcDir, "data");
379
+ const collectionsDir = join(srcDir, "collections");
374
380
  const publicDir = resolve(cwdArg, "public");
375
381
  const outDir = resolve(cwdArg, config.outDir || "dist");
376
382
  const env = createNunjucksEnv(layoutsDir, pagesDir, srcDir, partialsDir);
@@ -391,7 +397,7 @@ async function build(cwdArg = cwd) {
391
397
  console.error(kolor.red(`Failed to apply liquidEnv hook: ${err.message}`));
392
398
  }
393
399
  }
394
- const data = await loadData(dataDir);
400
+ const data = await loadData([dataDir, collectionsDir]);
395
401
 
396
402
  await cleanDir(outDir);
397
403
  await copyPublic(publicDir, outDir);
@@ -514,9 +520,10 @@ async function dev(cwdArg = cwd) {
514
520
  const config = await loadConfig(cwdArg);
515
521
  const srcDir = resolve(cwdArg, config.srcDir || "src");
516
522
  const dataDir = join(srcDir, "data");
523
+ const collectionsDir = join(srcDir, "collections");
517
524
  const publicDir = resolve(cwdArg, "public");
518
525
  const outDir = resolve(cwdArg, config.outDir || "dist");
519
- const watcher = chokidar.watch([srcDir, publicDir, dataDir], { ignoreInitial: true });
526
+ const watcher = chokidar.watch([srcDir, publicDir, dataDir, collectionsDir], { ignoreInitial: true });
520
527
 
521
528
  watcher.on("all", (event, path) => {
522
529
  console.log(kolor.cyan(`↻ ${event}: ${relative(cwdArg, path)}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basecampjs",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "description": "BasecampJS engine for CampsiteJS static site generator.",
6
6
  "bin": {