@daz4126/swifty 2.4.1 → 2.5.0
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 +2 -1
- package/src/partials.js +2 -1
- package/src/watcher.js +26 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daz4126/swifty",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"description": "Super Speedy Static Site Generator",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"chokidar": "^4.0.0",
|
|
28
29
|
"fs-extra": "^11.2.0",
|
|
29
30
|
"gray-matter": "^4.0.3",
|
|
30
31
|
"highlight.js": "^11.11.1",
|
package/src/partials.js
CHANGED
|
@@ -45,8 +45,9 @@ const replacePlaceholders = async (template, values) => {
|
|
|
45
45
|
},
|
|
46
46
|
);
|
|
47
47
|
// Replace other placeholders **only outside of code blocks**
|
|
48
|
+
// Fenced blocks require closing ``` to be at start of line (after newline)
|
|
48
49
|
const codeBlockRegex =
|
|
49
|
-
/```[\s\S]
|
|
50
|
+
/```[\s\S]*?\n```|`[^`\n]+`|<(pre|code)[^>]*>[\s\S]*?<\/\1>/g;
|
|
50
51
|
const codeBlocks = [];
|
|
51
52
|
template = template.replace(codeBlockRegex, (match) => {
|
|
52
53
|
codeBlocks.push(match);
|
package/src/watcher.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import chokidar from "chokidar";
|
|
2
|
-
import { exec } from "child_process";
|
|
3
2
|
import path from "path";
|
|
4
3
|
|
|
5
4
|
// Define files to watch, resolving relative to the current working directory
|
|
@@ -16,35 +15,35 @@ const filesToWatch = [
|
|
|
16
15
|
"config.json",
|
|
17
16
|
].map((pattern) => path.join(process.cwd(), pattern));
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
export default async function watch(outDir = "dist") {
|
|
19
|
+
const build = await import("./build.js");
|
|
20
20
|
|
|
21
|
-
// Initialize watcher
|
|
22
|
-
const watcher = chokidar.watch(filesToWatch, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
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
|
+
});
|
|
30
30
|
|
|
31
|
-
// Rebuild function
|
|
32
|
-
function triggerBuild(event, filePath) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// Rebuild function
|
|
32
|
+
async function triggerBuild(event, filePath) {
|
|
33
|
+
console.log(`File ${event}: ${filePath}. Running build...`);
|
|
34
|
+
try {
|
|
35
|
+
await build.default(outDir);
|
|
36
|
+
console.log("Build complete.");
|
|
37
|
+
} catch (error) {
|
|
36
38
|
console.error(`Build failed: ${error.message}`);
|
|
37
|
-
return;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
if (stdout) console.log(stdout);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
40
|
+
}
|
|
43
41
|
|
|
44
|
-
// Set up event listeners
|
|
45
|
-
watcher
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
// Set up event listeners
|
|
43
|
+
watcher
|
|
44
|
+
.on("change", (filePath) => triggerBuild("changed", filePath))
|
|
45
|
+
.on("add", (filePath) => triggerBuild("added", filePath))
|
|
46
|
+
.on("unlink", (filePath) => triggerBuild("deleted", filePath));
|
|
49
47
|
|
|
50
|
-
console.log("Watching for file changes...");
|
|
48
|
+
console.log("Watching for file changes...");
|
|
49
|
+
}
|