clovie 0.1.4 → 0.1.5

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/lib/core/write.js CHANGED
@@ -13,7 +13,10 @@ export default function write (pages, outputDir, keys = Object.keys(pages), accu
13
13
  fs.mkdirSync(dir, { recursive: true })
14
14
  }
15
15
 
16
- fs.writeFileSync(dest, value, err => {
16
+ // Check if the value is a Buffer (binary data) or string
17
+ const options = Buffer.isBuffer(value) ? {} : { encoding: 'utf8' };
18
+
19
+ fs.writeFileSync(dest, value, options, err => {
17
20
  if (err) {
18
21
  console.log(err)
19
22
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { isText } from 'istextorbinary';
3
4
 
4
5
  /**
5
6
  * Reads multiple files and returns a map of file paths to file contents
@@ -15,7 +16,18 @@ export function readFilesToMap(files, src, accumulator = {}) {
15
16
  if (!file) return accumulator;
16
17
 
17
18
  let key = file.substring(path.join(src).length);
18
- accumulator[key] = fs.readFileSync(file).toString('utf8');
19
+
20
+ // Read file as buffer first
21
+ const buffer = fs.readFileSync(file);
22
+
23
+ // Use istextorbinary to detect if file is text or binary
24
+ if (isText(file, buffer)) {
25
+ // Read text files as UTF-8 string
26
+ accumulator[key] = buffer.toString('utf8');
27
+ } else {
28
+ // Keep binary files as Buffer
29
+ accumulator[key] = buffer;
30
+ }
19
31
 
20
32
  return files.length ? readFilesToMap(files, src, accumulator) : accumulator;
21
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clovie",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Vintage web dev tooling with modern quality of life",
5
5
  "keywords": [
6
6
  "static-site-generator",
@@ -55,15 +55,16 @@
55
55
  "dependencies": {
56
56
  "@babel/core": "^7.23.7",
57
57
  "@babel/preset-env": "^7.23.7",
58
- "esbuild": "^0.19.11",
58
+ "babelify": "^10.0.0",
59
59
  "chokidar": "^3.5.3",
60
60
  "command-line-args": "^5.2.1",
61
+ "esbuild": "^0.19.11",
61
62
  "express": "^4.18.2",
62
63
  "handlebars": "^4.7.8",
64
+ "istextorbinary": "^9.5.0",
63
65
  "sass": "^1.69.5",
64
66
  "socket.io": "^4.7.4",
65
- "type-detect": "^4.0.8",
66
- "babelify": "^10.0.0"
67
+ "type-detect": "^4.0.8"
67
68
  },
68
69
  "devDependencies": {
69
70
  "vitest": "^1.0.4"