@lexho111/plainblog 0.5.20 → 0.5.22
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/model/PostgresAdapter.js +27 -1
- package/model/SequelizeAdapter.js +25 -9
- package/model/SqliteAdapter.js +23 -0
- 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/model/PostgresAdapter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import SequelizeAdapter from "./SequelizeAdapter.js";
|
|
2
|
+
import { execSync } from "child_process";
|
|
2
3
|
|
|
3
4
|
export default class PostgresAdapter extends SequelizeAdapter {
|
|
4
5
|
dbtype = "postgres";
|
|
@@ -21,6 +22,28 @@ export default class PostgresAdapter extends SequelizeAdapter {
|
|
|
21
22
|
|
|
22
23
|
async initialize() {
|
|
23
24
|
console.log("initialize database");
|
|
25
|
+
let pgPkg;
|
|
26
|
+
try {
|
|
27
|
+
await import("sequelize");
|
|
28
|
+
pgPkg = await import("pg");
|
|
29
|
+
await import("pg-hstore");
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (
|
|
32
|
+
error.code === "ERR_MODULE_NOT_FOUND" ||
|
|
33
|
+
error.code === "MODULE_NOT_FOUND"
|
|
34
|
+
) {
|
|
35
|
+
try {
|
|
36
|
+
const packageName = "sequelize pg pg-hstore";
|
|
37
|
+
console.log(`Installing ${packageName}...`);
|
|
38
|
+
execSync(`npm install ${packageName} --no-save`, {
|
|
39
|
+
stdio: "inherit",
|
|
40
|
+
});
|
|
41
|
+
pgPkg = await import("pg");
|
|
42
|
+
} catch (e) {
|
|
43
|
+
throw new Error("Missing optional dependencies");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
24
47
|
await this.loadSequelize();
|
|
25
48
|
const maxRetries = 10;
|
|
26
49
|
const retryDelay = 3000;
|
|
@@ -33,7 +56,10 @@ export default class PostgresAdapter extends SequelizeAdapter {
|
|
|
33
56
|
|
|
34
57
|
this.sequelize = new this.Sequelize(
|
|
35
58
|
`postgres://${this.username}:${this.password}@${this.host}:${this.dbport}/${this.dbname}`,
|
|
36
|
-
{
|
|
59
|
+
{
|
|
60
|
+
logging: false,
|
|
61
|
+
dialectModule: pgPkg.default || pgPkg,
|
|
62
|
+
}
|
|
37
63
|
);
|
|
38
64
|
await this.sequelize.authenticate();
|
|
39
65
|
await this.initializeModels();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
|
|
1
3
|
export default class SequelizeAdapter {
|
|
2
4
|
username;
|
|
3
5
|
password;
|
|
@@ -20,17 +22,31 @@ export default class SequelizeAdapter {
|
|
|
20
22
|
|
|
21
23
|
async loadSequelize() {
|
|
22
24
|
if (this.Sequelize) return;
|
|
25
|
+
let sequelizePkg;
|
|
23
26
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
sequelizePkg = await import("sequelize");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (
|
|
30
|
+
error.code === "ERR_MODULE_NOT_FOUND" ||
|
|
31
|
+
error.code === "MODULE_NOT_FOUND"
|
|
32
|
+
) {
|
|
33
|
+
try {
|
|
34
|
+
const packageName = "sequelize";
|
|
35
|
+
console.log(`Installing ${packageName}...`);
|
|
36
|
+
execSync(`npm install ${packageName} --no-save`, {
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
});
|
|
39
|
+
sequelizePkg = await import("sequelize");
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new Error("Missing optional dependencies");
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error("Missing optional dependencies");
|
|
45
|
+
}
|
|
33
46
|
}
|
|
47
|
+
this.Sequelize = sequelizePkg.Sequelize;
|
|
48
|
+
this.DataTypes = sequelizePkg.DataTypes;
|
|
49
|
+
this.Op = sequelizePkg.Op;
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
async initializeModels() {
|
package/model/SqliteAdapter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import SequelizeAdapter from "./SequelizeAdapter.js";
|
|
2
|
+
import { execSync } from "child_process";
|
|
2
3
|
|
|
3
4
|
export default class SqliteAdapter extends SequelizeAdapter {
|
|
4
5
|
constructor(options = {}) {
|
|
@@ -10,12 +11,34 @@ export default class SqliteAdapter extends SequelizeAdapter {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
async initialize() {
|
|
14
|
+
let sqlite3Pkg;
|
|
15
|
+
try {
|
|
16
|
+
await import("sequelize");
|
|
17
|
+
sqlite3Pkg = await import("sqlite3");
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (
|
|
20
|
+
error.code === "ERR_MODULE_NOT_FOUND" ||
|
|
21
|
+
error.code === "MODULE_NOT_FOUND"
|
|
22
|
+
) {
|
|
23
|
+
try {
|
|
24
|
+
const packageName = "sequelize sqlite3";
|
|
25
|
+
console.log(`Installing ${packageName}...`);
|
|
26
|
+
execSync(`npm install ${packageName} --no-save`, {
|
|
27
|
+
stdio: "inherit",
|
|
28
|
+
});
|
|
29
|
+
sqlite3Pkg = await import("sqlite3");
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error("Missing optional dependencies");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
13
35
|
await this.loadSequelize();
|
|
14
36
|
try {
|
|
15
37
|
this.sequelize = new this.Sequelize({
|
|
16
38
|
dialect: "sqlite",
|
|
17
39
|
storage: this.dbname + ".db",
|
|
18
40
|
logging: false,
|
|
41
|
+
dialectModule: sqlite3Pkg.default || sqlite3Pkg,
|
|
19
42
|
});
|
|
20
43
|
await this.initializeModels();
|
|
21
44
|
} catch (err) {
|
package/package.json
CHANGED