@lexho111/plainblog 0.5.20 → 0.5.21

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/build-styles.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "path";
2
+ import { execSync } from "child_process";
2
3
 
3
4
  /**
4
5
  * Compiles CSS styles from file content objects.
@@ -6,9 +7,8 @@ import path from "path";
6
7
  * @returns {Promise<string>} The compiled and minified CSS.
7
8
  */
8
9
  export async function compileStyles(fileData) {
10
+ let combinedCss = "";
9
11
  try {
10
- let combinedCss = "";
11
-
12
12
  // 1. filter out css files
13
13
  if (fileData) {
14
14
  const scssFiles = fileData.filter(
@@ -26,16 +26,18 @@ export async function compileStyles(fileData) {
26
26
 
27
27
  // 2. minify and uglify with PostCSS
28
28
  if (combinedCss) {
29
- return postcss2(combinedCss);
29
+ return await runPostcss(combinedCss);
30
30
  }
31
31
  return "";
32
32
  } catch (error) {
33
- console.error("Build failed:", error);
34
- return "";
33
+ if (error.message !== "Missing optional dependencies") {
34
+ console.error("Build failed:", error);
35
+ }
36
+ return combinedCss;
35
37
  }
36
38
  }
37
39
 
38
- async function postcss2(css) {
40
+ async function runPostcss(css) {
39
41
  let postcss, autoprefixer, cssnano;
40
42
 
41
43
  try {
@@ -43,12 +45,23 @@ async function postcss2(css) {
43
45
  autoprefixer = (await import("autoprefixer")).default;
44
46
  cssnano = (await import("cssnano")).default;
45
47
  } catch (error) {
46
- console.error("Missing CSS processing dependencies.");
47
- console.error(
48
- "To use this feature, please install the following packages manually:"
49
- );
50
- console.error("\n npm install postcss autoprefixer cssnano\n");
51
- throw new Error("Missing optional dependencies");
48
+ if (
49
+ error.code === "ERR_MODULE_NOT_FOUND" ||
50
+ error.code === "MODULE_NOT_FOUND"
51
+ ) {
52
+ try {
53
+ const packageName = "postcss autoprefixer cssnano";
54
+ console.log(`Installing ${packageName}...`);
55
+ execSync(`npm install ${packageName} --no-save`, { stdio: "inherit" });
56
+ postcss = (await import("postcss")).default;
57
+ autoprefixer = (await import("autoprefixer")).default;
58
+ cssnano = (await import("cssnano")).default;
59
+ } catch (e) {
60
+ throw new Error("Missing optional dependencies");
61
+ }
62
+ } else {
63
+ throw new Error("Missing optional dependencies");
64
+ }
52
65
  }
53
66
 
54
67
  const plugins = [autoprefixer(), cssnano()];
@@ -68,11 +81,13 @@ export async function mergeStyles(...cssContents) {
68
81
  const combinedCss = cssContents.join("\n");
69
82
 
70
83
  if (combinedCss) {
71
- return postcss2(combinedCss);
84
+ return await runPostcss(combinedCss);
72
85
  }
73
86
  return "";
74
87
  } catch (error) {
75
- console.error("Merge failed:", error);
76
- return "";
88
+ if (error.message !== "Missing optional dependencies") {
89
+ console.error("Merge failed:", error);
90
+ }
91
+ return cssContents.join("\n"); // fallback: return unminified css
77
92
  }
78
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexho111/plainblog",
3
- "version": "0.5.20",
3
+ "version": "0.5.21",
4
4
  "description": "A tool for creating and serving a minimalist, single-page blog.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/knip.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/knip@5/schema.json",
3
- "ignoreExportsUsedInFile": {
4
- "interface": true,
5
- "type": true
6
- },
7
- "tags": [
8
- "-lintignore"
9
- ]
10
- }