@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 +30 -15
- package/package.json +1 -1
- package/knip.json +0 -10
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
|
|
29
|
+
return await runPostcss(combinedCss);
|
|
30
30
|
}
|
|
31
31
|
return "";
|
|
32
32
|
} catch (error) {
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
84
|
+
return await runPostcss(combinedCss);
|
|
72
85
|
}
|
|
73
86
|
return "";
|
|
74
87
|
} catch (error) {
|
|
75
|
-
|
|
76
|
-
|
|
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