@masumdev/markforge 0.2.2 → 0.2.4

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.
@@ -0,0 +1,165 @@
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
+ function discoverConfigFile(startDir) {
61
+ const dirsToCheck = [];
62
+ let curr = path.resolve(startDir);
63
+ while (curr) {
64
+ dirsToCheck.push(curr);
65
+ const parent = path.dirname(curr);
66
+ if (parent === curr) break;
67
+ curr = parent;
68
+ }
69
+ const cwd = path.resolve(process.cwd());
70
+ if (!dirsToCheck.includes(cwd)) {
71
+ dirsToCheck.push(cwd);
72
+ }
73
+ for (const dir of dirsToCheck) {
74
+ for (const filename of DEFAULT_CONFIG_FILENAMES) {
75
+ const candidate = path.join(dir, filename);
76
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
77
+ return candidate;
78
+ }
79
+ }
80
+ }
81
+ return null;
82
+ }
83
+ async function loadConfig(customPath, startDir = process.cwd()) {
84
+ let resolvedPath = null;
85
+ if (customPath) {
86
+ resolvedPath = path.isAbsolute(customPath) ? customPath : path.resolve(process.cwd(), customPath);
87
+ if (!fs.existsSync(resolvedPath)) {
88
+ const altPath = path.resolve(startDir, customPath);
89
+ if (fs.existsSync(altPath)) {
90
+ resolvedPath = altPath;
91
+ } else {
92
+ throw new Error(`Configuration file not found: ${resolvedPath}`);
93
+ }
94
+ }
95
+ } else {
96
+ resolvedPath = discoverConfigFile(startDir);
97
+ }
98
+ if (!resolvedPath) {
99
+ return {
100
+ config: { ...DEFAULT_CONFIG },
101
+ configPath: null
102
+ };
103
+ }
104
+ const ext = path.extname(resolvedPath).toLowerCase();
105
+ let userConfig = {};
106
+ try {
107
+ if (ext === ".json" || ext === "" || resolvedPath.endsWith(".markforgerc")) {
108
+ const raw = fs.readFileSync(resolvedPath, "utf-8").trim();
109
+ try {
110
+ userConfig = JSON.parse(raw);
111
+ } catch {
112
+ userConfig = YAML.parse(raw) || {};
113
+ }
114
+ } else if (ext === ".yaml" || ext === ".yml") {
115
+ const raw = fs.readFileSync(resolvedPath, "utf-8");
116
+ userConfig = YAML.parse(raw) || {};
117
+ } else if (ext === ".ts" || ext === ".js" || ext === ".mjs" || ext === ".cjs") {
118
+ try {
119
+ const fileUrl = `${pathToFileURL(resolvedPath).href}?t=${Date.now()}`;
120
+ const mod = await import(fileUrl);
121
+ const rawExport = mod.default ?? mod.config ?? mod;
122
+ userConfig = (typeof rawExport === "function" ? await rawExport() : rawExport) || {};
123
+ } catch (importErr) {
124
+ try {
125
+ const mod = __require(resolvedPath);
126
+ const rawExport = mod.default ?? mod.config ?? mod;
127
+ userConfig = (typeof rawExport === "function" ? await rawExport() : rawExport) || {};
128
+ } catch {
129
+ throw importErr;
130
+ }
131
+ }
132
+ }
133
+ } catch (err) {
134
+ throw new Error(
135
+ `Failed to parse configuration file at ${resolvedPath}: ${err instanceof Error ? err.message : String(err)}`
136
+ );
137
+ }
138
+ if (userConfig && typeof userConfig === "object" && "$schema" in userConfig) {
139
+ delete userConfig.$schema;
140
+ }
141
+ const parsedConfig = userConfig;
142
+ const mergedConfig = {
143
+ ...DEFAULT_CONFIG,
144
+ ...parsedConfig,
145
+ margins: {
146
+ ...DEFAULT_CONFIG.margins,
147
+ ...parsedConfig.margins || {}
148
+ },
149
+ header: parsedConfig.header !== void 0 ? parsedConfig.header : DEFAULT_CONFIG.header,
150
+ footer: parsedConfig.footer !== void 0 ? parsedConfig.footer : DEFAULT_CONFIG.footer,
151
+ metadata: {
152
+ ...DEFAULT_CONFIG.metadata || {},
153
+ ...parsedConfig.metadata || {}
154
+ }
155
+ };
156
+ return {
157
+ config: mergedConfig,
158
+ configPath: resolvedPath
159
+ };
160
+ }
161
+
162
+ export {
163
+ DEFAULT_CONFIG,
164
+ loadConfig
165
+ };
@@ -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
+ };