basecampjs 0.0.12 → 0.0.13

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 +26 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -23,10 +23,11 @@ const md = new MarkdownIt({ html: true, linkify: true, typographer: true });
23
23
 
24
24
  const defaultConfig = {
25
25
  siteName: "Campsite",
26
+ siteUrl: "https://example.com",
26
27
  srcDir: "src",
27
28
  outDir: "dist",
28
29
  templateEngine: "nunjucks",
29
- markdown: true,
30
+ frontmatter: true,
30
31
  minifyCSS: false,
31
32
  minifyHTML: false,
32
33
  cacheBustAssets: false,
@@ -38,6 +39,7 @@ const defaultConfig = {
38
39
  inputFormats: [".jpg", ".jpeg", ".png"],
39
40
  preserveOriginal: true
40
41
  },
42
+ port: 4173,
41
43
  integrations: { nunjucks: true, liquid: false, mustache: false, vue: false, alpine: false }
42
44
  };
43
45
 
@@ -627,7 +629,7 @@ async function cacheBustAssets(outDir) {
627
629
  return assetMap;
628
630
  }
629
631
 
630
- async function build(cwdArg = cwd) {
632
+ async function build(cwdArg = cwd, options = {}) {
631
633
  const config = await loadConfig(cwdArg);
632
634
  const srcDir = resolve(cwdArg, config.srcDir || "src");
633
635
  const pagesDir = join(srcDir, "pages");
@@ -660,7 +662,9 @@ async function build(cwdArg = cwd) {
660
662
  await cleanDir(outDir);
661
663
  await copyPublic(publicDir, outDir, config.excludeFiles);
662
664
 
663
- if (config.compressPhotos) {
665
+ // Only compress photos during production builds, not during dev mode
666
+ const shouldCompressPhotos = options.skipImageCompression !== true && config.compressPhotos;
667
+ if (shouldCompressPhotos) {
664
668
  await processImages(outDir, config);
665
669
  }
666
670
 
@@ -672,17 +676,20 @@ async function build(cwdArg = cwd) {
672
676
 
673
677
  await Promise.all(files.map((file) => renderPage(file, { pagesDir, layoutsDir, outDir, env, liquidEnv, config, data, partialsDir })));
674
678
 
675
- if (config.minifyCSS) {
679
+ // Skip minification and cache busting in dev mode for faster rebuilds
680
+ const isDevMode = options.devMode === true;
681
+
682
+ if (!isDevMode && config.minifyCSS) {
676
683
  await minifyCSSFiles(outDir);
677
684
  console.log(kolor.green("CSS minified"));
678
685
  }
679
686
 
680
- if (config.minifyHTML) {
687
+ if (!isDevMode && config.minifyHTML) {
681
688
  await minifyHTMLFiles(outDir, config);
682
689
  console.log(kolor.green("HTML minified"));
683
690
  }
684
691
 
685
- if (config.cacheBustAssets) {
692
+ if (!isDevMode && config.cacheBustAssets) {
686
693
  console.log(kolor.cyan("Cache-busting assets..."));
687
694
  const assetMap = await cacheBustAssets(outDir);
688
695
  const assetCount = Object.keys(assetMap).length;
@@ -693,6 +700,14 @@ async function build(cwdArg = cwd) {
693
700
  }
694
701
  }
695
702
 
703
+ // Generate robots.txt dynamically if it doesn't exist in public directory
704
+ const publicRobotsTxt = join(publicDir, "robots.txt");
705
+ const distRobotsTxt = join(outDir, "robots.txt");
706
+ if (!existsSync(publicRobotsTxt) && !existsSync(distRobotsTxt)) {
707
+ const robotsTxt = `User-agent: *\nAllow: /\n\nSitemap: ${config.siteUrl}/sitemap.xml\n`;
708
+ await writeFile(distRobotsTxt, robotsTxt, "utf8");
709
+ }
710
+
696
711
  console.log(kolor.green(`Built ${files.length} page(s) → ${relative(cwdArg, outDir)}`));
697
712
  }
698
713
 
@@ -765,7 +780,8 @@ async function dev(cwdArg = cwd) {
765
780
  }
766
781
  building = true;
767
782
  try {
768
- await build(cwdArg);
783
+ // Skip image compression, minification, and cache busting during dev mode for faster rebuilds
784
+ await build(cwdArg, { skipImageCompression: true, devMode: true });
769
785
  } catch (err) {
770
786
  console.error(kolor.red(`Build failed: ${err.message}`));
771
787
  } finally {
@@ -792,7 +808,7 @@ async function dev(cwdArg = cwd) {
792
808
  runBuild();
793
809
  });
794
810
 
795
- serve(outDir);
811
+ serve(outDir, config.port || 4173);
796
812
  }
797
813
 
798
814
  function slugify(text) {
@@ -1438,7 +1454,7 @@ async function preview() {
1438
1454
  const config = await loadConfig(cwd);
1439
1455
  const outDir = resolve(cwd, config.outDir || "dist");
1440
1456
  console.log(kolor.cyan(kolor.bold("🔥 Starting preview server...\n")));
1441
- serve(outDir);
1457
+ serve(outDir, config.port || 4173);
1442
1458
  }
1443
1459
 
1444
1460
  async function main() {
@@ -1484,7 +1500,7 @@ async function main() {
1484
1500
  if (!existsSync(outDir)) {
1485
1501
  await build();
1486
1502
  }
1487
- serve(outDir);
1503
+ serve(outDir, config.port || 4173);
1488
1504
  break;
1489
1505
  }
1490
1506
  case "preview":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basecampjs",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "description": "BasecampJS engine for CampsiteJS static site generator.",
6
6
  "bin": {