@daz4126/swifty 2.3.0 → 2.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/swifty",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
package/src/init.js CHANGED
@@ -42,7 +42,7 @@ dateFormat:
42
42
  <link rel="apple-touch-icon" href="path/to/apple-touch-icon.png">
43
43
  <link rel="icon" sizes="192x192" href="android-chrome-192x19.png">
44
44
  <link rel="icon" sizes="512x512" href="android-chrome-512x512.png">
45
- <title>{{sitename}}</title>
45
+ <title>{{ sitename }} || {{ title }}</title>
46
46
  </head>
47
47
  <body>
48
48
  <header>
package/src/pages.js CHANGED
@@ -177,7 +177,7 @@ const generatePages = async (sourceDir, baseDir = sourceDir, parent) => {
177
177
  const generateLinkList = async (name, pages) => {
178
178
  const partial = `${name}.md`;
179
179
  const partialPath = path.join(dirs.partials, partial);
180
- const linksPath = path.join(dirs.partials, defaultConfig.default_link_name);
180
+ const linksPath = path.join(dirs.partials, defaultConfig.default_link_name || "links");
181
181
  // Check if either file exists in the 'partials' folder
182
182
  const fileExists = await fsExtra.pathExists(partialPath);
183
183
  const defaultExists = await fsExtra.pathExists(linksPath);
package/src/watcher.js CHANGED
@@ -1,43 +1,50 @@
1
1
  import chokidar from "chokidar";
2
+ import { exec } from "child_process";
3
+ import path from "path";
2
4
 
3
- export default async function startWatcher(outDir = "dist") {
4
- const filesToWatch = [
5
- "pages/**/*.{md,html}",
6
- "layouts/**/*.{html}",
7
- "images/**/*",
8
- "css/**/*.{css}",
9
- "js/**/*.{js}",
10
- "partials/**/*.{md,html}",
11
- "template.html",
12
- "config.yaml",
13
- "config.yml",
14
- "config.json",
15
- ];
5
+ // Define files to watch, resolving relative to the current working directory
6
+ const filesToWatch = [
7
+ "pages/**/*.{md,html}",
8
+ "layouts/**/*.html",
9
+ "images/**/*",
10
+ "css/**/*.css",
11
+ "js/**/*.js",
12
+ "partials/**/*.{md,html}",
13
+ "template.html",
14
+ "config.yaml",
15
+ "config.yml",
16
+ "config.json",
17
+ ].map((pattern) => path.join(process.cwd(), pattern));
16
18
 
17
- const watcher = chokidar.watch(filesToWatch, {
18
- persistent: true,
19
- ignoreInitial: true,
20
- awaitWriteFinish: { stabilityThreshold: 100 },
21
- debounceDelay: 200,
22
- });
23
-
24
- const buildModule = await import("./build.js");
25
- const build = buildModule.default;
19
+ const buildScript = "npm run build";
26
20
 
27
- if (typeof build !== "function") {
28
- console.error("❌ build.js does not export a default function.");
29
- return;
30
- }
21
+ // Initialize watcher
22
+ const watcher = chokidar.watch(filesToWatch, {
23
+ persistent: true,
24
+ ignoreInitial: true,
25
+ awaitWriteFinish: {
26
+ stabilityThreshold: 200,
27
+ pollInterval: 100,
28
+ },
29
+ });
31
30
 
32
- watcher.on("change", async (path) => {
33
- console.log(`📄 File changed: ${path}`);
34
- try {
35
- await build(outDir);
36
- console.log("✅ Build completed");
37
- } catch (error) {
38
- console.error(`❌ Build failed: ${error.message}`);
31
+ // Rebuild function
32
+ function triggerBuild(event, filePath) {
33
+ console.log(`File ${event}: ${filePath}. Running build...`);
34
+ exec(buildScript, (error, stdout, stderr) => {
35
+ if (error) {
36
+ console.error(`Build failed: ${error.message}`);
37
+ return;
39
38
  }
39
+ if (stderr) console.error(`stderr: ${stderr}`);
40
+ if (stdout) console.log(stdout);
40
41
  });
41
-
42
- console.log(`👀 Watching for changes...`);
43
42
  }
43
+
44
+ // Set up event listeners
45
+ watcher
46
+ .on("change", (filePath) => triggerBuild("changed", filePath))
47
+ .on("add", (filePath) => triggerBuild("added", filePath))
48
+ .on("unlink", (filePath) => triggerBuild("deleted", filePath));
49
+
50
+ console.log("Watching for file changes...");