@masumdev/markforge 0.2.2 → 0.2.3
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/dist/App-DKCNXX3Z.mjs +2437 -0
- package/dist/chunk-ASXSHC6H.mjs +120 -0
- package/dist/chunk-NGC2ZAWZ.mjs +69 -0
- package/dist/chunk-YZHGBG4N.mjs +19 -0
- package/dist/cli.mjs +46 -2551
- package/dist/index.js +64 -13
- package/dist/index.mjs +63 -13
- package/dist/loadConfig-T4ZV6YY2.mjs +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
try {
|
|
3
|
+
if (typeof globalThis !== "undefined" && (!globalThis.localStorage || typeof globalThis.localStorage.getItem !== "function")) {
|
|
4
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
5
|
+
value: { getItem: () => null, setItem: () => {}, removeItem: () => {}, clear: () => {}, key: () => null, length: 0 },
|
|
6
|
+
configurable: true, writable: true,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
} catch {}
|
|
10
|
+
import {
|
|
11
|
+
__require
|
|
12
|
+
} from "./chunk-YZHGBG4N.mjs";
|
|
13
|
+
|
|
14
|
+
// src/config/loadConfig.ts
|
|
15
|
+
import * as fs from "fs";
|
|
16
|
+
import * as path from "path";
|
|
17
|
+
import { pathToFileURL } from "url";
|
|
18
|
+
import * as YAML from "yaml";
|
|
19
|
+
var DEFAULT_CONFIG_FILENAMES = [
|
|
20
|
+
"markforge.config.json",
|
|
21
|
+
".markforgerc.json",
|
|
22
|
+
"markforge.config.yaml",
|
|
23
|
+
"markforge.config.yml",
|
|
24
|
+
".markforgerc.yaml",
|
|
25
|
+
".markforgerc.yml",
|
|
26
|
+
".markforgerc",
|
|
27
|
+
"markforge.config.ts",
|
|
28
|
+
"markforge.config.js",
|
|
29
|
+
"markforge.config.mjs",
|
|
30
|
+
"markforge.config.cjs"
|
|
31
|
+
];
|
|
32
|
+
var DEFAULT_CONFIG = {
|
|
33
|
+
to: ["docx", "pdf"],
|
|
34
|
+
outputDir: void 0,
|
|
35
|
+
theme: "default",
|
|
36
|
+
css: void 0,
|
|
37
|
+
orientation: "portrait",
|
|
38
|
+
paperSize: "A4",
|
|
39
|
+
margins: {
|
|
40
|
+
top: "2.5cm",
|
|
41
|
+
bottom: "2.5cm",
|
|
42
|
+
left: "2.5cm",
|
|
43
|
+
right: "2.5cm"
|
|
44
|
+
},
|
|
45
|
+
header: void 0,
|
|
46
|
+
footer: {
|
|
47
|
+
right: "Page {page} of {pages}"
|
|
48
|
+
},
|
|
49
|
+
toc: false,
|
|
50
|
+
watermark: void 0,
|
|
51
|
+
embedImages: true,
|
|
52
|
+
metadata: void 0,
|
|
53
|
+
watch: false,
|
|
54
|
+
serve: false,
|
|
55
|
+
port: 4e3,
|
|
56
|
+
open: false,
|
|
57
|
+
bundleHtml: true,
|
|
58
|
+
syntaxTheme: "github-dark"
|
|
59
|
+
};
|
|
60
|
+
async function loadConfig(customPath, cwd = process.cwd()) {
|
|
61
|
+
let resolvedPath = null;
|
|
62
|
+
if (customPath) {
|
|
63
|
+
resolvedPath = path.isAbsolute(customPath) ? customPath : path.resolve(cwd, customPath);
|
|
64
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
65
|
+
throw new Error(`Configuration file not found: ${resolvedPath}`);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
for (const filename of DEFAULT_CONFIG_FILENAMES) {
|
|
69
|
+
const candidate = path.resolve(cwd, filename);
|
|
70
|
+
if (fs.existsSync(candidate)) {
|
|
71
|
+
resolvedPath = candidate;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!resolvedPath) {
|
|
77
|
+
return {
|
|
78
|
+
config: { ...DEFAULT_CONFIG },
|
|
79
|
+
configPath: null
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const ext = path.extname(resolvedPath).toLowerCase();
|
|
83
|
+
let userConfig = {};
|
|
84
|
+
if (ext === ".json" || resolvedPath.endsWith(".markforgerc")) {
|
|
85
|
+
const raw = fs.readFileSync(resolvedPath, "utf-8");
|
|
86
|
+
userConfig = JSON.parse(raw);
|
|
87
|
+
} else if (ext === ".yaml" || ext === ".yml") {
|
|
88
|
+
const raw = fs.readFileSync(resolvedPath, "utf-8");
|
|
89
|
+
userConfig = YAML.parse(raw);
|
|
90
|
+
} else if (ext === ".ts" || ext === ".js" || ext === ".mjs" || ext === ".cjs") {
|
|
91
|
+
try {
|
|
92
|
+
const fileUrl = pathToFileURL(resolvedPath).href;
|
|
93
|
+
const mod = await import(fileUrl);
|
|
94
|
+
userConfig = mod.default || mod;
|
|
95
|
+
} catch {
|
|
96
|
+
const required = __require(resolvedPath);
|
|
97
|
+
userConfig = required.default || required;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const mergedConfig = {
|
|
101
|
+
...DEFAULT_CONFIG,
|
|
102
|
+
...userConfig,
|
|
103
|
+
margins: {
|
|
104
|
+
...DEFAULT_CONFIG.margins,
|
|
105
|
+
...userConfig.margins
|
|
106
|
+
},
|
|
107
|
+
header: userConfig.header || DEFAULT_CONFIG.header,
|
|
108
|
+
footer: userConfig.footer || DEFAULT_CONFIG.footer,
|
|
109
|
+
metadata: userConfig.metadata
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
config: mergedConfig,
|
|
113
|
+
configPath: resolvedPath
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
DEFAULT_CONFIG,
|
|
119
|
+
loadConfig
|
|
120
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
try {
|
|
3
|
+
if (typeof globalThis !== "undefined" && (!globalThis.localStorage || typeof globalThis.localStorage.getItem !== "function")) {
|
|
4
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
5
|
+
value: { getItem: () => null, setItem: () => {}, removeItem: () => {}, clear: () => {}, key: () => null, length: 0 },
|
|
6
|
+
configurable: true, writable: true,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
} catch {}
|
|
10
|
+
|
|
11
|
+
// src/version.ts
|
|
12
|
+
import * as fs from "fs";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import { fileURLToPath } from "url";
|
|
15
|
+
try {
|
|
16
|
+
if (typeof globalThis !== "undefined" && (!globalThis.localStorage || typeof globalThis.localStorage.getItem !== "function")) {
|
|
17
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
18
|
+
value: {
|
|
19
|
+
getItem: () => null,
|
|
20
|
+
setItem: () => {
|
|
21
|
+
},
|
|
22
|
+
removeItem: () => {
|
|
23
|
+
},
|
|
24
|
+
clear: () => {
|
|
25
|
+
},
|
|
26
|
+
key: () => null,
|
|
27
|
+
length: 0
|
|
28
|
+
},
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
var FALLBACK_VERSION = "0.2.2";
|
|
36
|
+
function readVersionFromPackageJson(fromDir) {
|
|
37
|
+
let currentDir = fromDir;
|
|
38
|
+
for (let i = 0; i < 6; i++) {
|
|
39
|
+
try {
|
|
40
|
+
const pkgJsonPath = path.join(currentDir, "package.json");
|
|
41
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
42
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
43
|
+
if (pkg.name === "@masumdev/markforge" && pkg.version) {
|
|
44
|
+
return pkg.version;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
const parentDir = path.dirname(currentDir);
|
|
50
|
+
if (parentDir === currentDir) break;
|
|
51
|
+
currentDir = parentDir;
|
|
52
|
+
}
|
|
53
|
+
return FALLBACK_VERSION;
|
|
54
|
+
}
|
|
55
|
+
function getPackageDir() {
|
|
56
|
+
if (typeof __dirname !== "undefined") {
|
|
57
|
+
return __dirname;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
61
|
+
} catch {
|
|
62
|
+
return process.cwd();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var MARKFORGE_VERSION = readVersionFromPackageJson(getPackageDir());
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
MARKFORGE_VERSION
|
|
69
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
try {
|
|
3
|
+
if (typeof globalThis !== "undefined" && (!globalThis.localStorage || typeof globalThis.localStorage.getItem !== "function")) {
|
|
4
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
5
|
+
value: { getItem: () => null, setItem: () => {}, removeItem: () => {}, clear: () => {}, key: () => null, length: 0 },
|
|
6
|
+
configurable: true, writable: true,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
} catch {}
|
|
10
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
12
|
+
}) : x)(function(x) {
|
|
13
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
__require
|
|
19
|
+
};
|