@superdoc-dev/visual-benchmarks 0.2.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 SuperDoc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # superdoc-benchmark (npm wrapper)
2
+
3
+ This npm package installs a lightweight wrapper that downloads the macOS
4
+ binary from GitHub Releases on install.
5
+
6
+ ## Requirements
7
+
8
+ - macOS
9
+ - Microsoft Word
10
+ - Node.js (npm)
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install -g @superdoc-dev/visual-benchmarks
16
+ ```
17
+
18
+ ## Run
19
+
20
+ ```bash
21
+ superdoc-benchmark
22
+ superdoc-benchmark compare ./docs/
23
+ ```
24
+
25
+ ## Update
26
+
27
+ ```bash
28
+ npm update -g @superdoc-dev/visual-benchmarks
29
+ ```
30
+
31
+ ## Publish (maintainers)
32
+
33
+ From the `npm/` folder:
34
+
35
+ ```bash
36
+ npm run publish
37
+ ```
38
+
39
+ ## Troubleshooting
40
+
41
+ If the download fails, you can run from source instead:
42
+
43
+ ```bash
44
+ git clone https://github.com/superdoc-dev/superdoc-visual-benchmarks
45
+ cd superdoc-visual-benchmarks
46
+ uv run superdoc-benchmark
47
+ ```
package/bin/cli.js ADDED
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawn, execSync } = require("child_process");
5
+ const path = require("path");
6
+ const fs = require("fs");
7
+ const os = require("os");
8
+ const http = require("http");
9
+ const https = require("https");
10
+ const readline = require("readline");
11
+
12
+ const PACKAGE_NAME = "@superdoc-dev/visual-benchmarks";
13
+ const CURRENT_VERSION = require("../package.json").version;
14
+ const BIN_CACHE = path.join(__dirname, "..", ".bin-cache");
15
+ const USER_CACHE_DIR = (() => {
16
+ const home = os.homedir();
17
+ if (!home) return BIN_CACHE;
18
+ const base =
19
+ process.env.XDG_CACHE_HOME ||
20
+ (process.platform === "darwin"
21
+ ? path.join(home, "Library", "Caches")
22
+ : path.join(home, ".cache"));
23
+ return path.join(base, "superdoc-benchmark");
24
+ })();
25
+ const CACHE_FILE = path.join(USER_CACHE_DIR, "update-check.json");
26
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
27
+ const REGISTRY = (process.env.npm_config_registry || "https://registry.npmjs.org")
28
+ .replace(/\/$/, "");
29
+ const PACKAGE_NAME_ENCODED = encodeURIComponent(PACKAGE_NAME);
30
+
31
+ function getLatestVersion() {
32
+ return new Promise((resolve, reject) => {
33
+ const url = `${REGISTRY}/${PACKAGE_NAME_ENCODED}/latest`;
34
+ const client = url.startsWith("http:") ? http : https;
35
+ const req = client.get(
36
+ url,
37
+ { headers: { Accept: "application/json" } },
38
+ (res) => {
39
+ if (!res || res.statusCode < 200 || res.statusCode >= 300) {
40
+ res.resume();
41
+ reject(new Error("Failed to fetch npm metadata"));
42
+ return;
43
+ }
44
+
45
+ let data = "";
46
+ res.on("data", (chunk) => (data += chunk));
47
+ res.on("end", () => {
48
+ try {
49
+ resolve(JSON.parse(data).version);
50
+ } catch {
51
+ reject(new Error("Failed to parse npm response"));
52
+ }
53
+ });
54
+ }
55
+ );
56
+
57
+ req.setTimeout(2000, () => {
58
+ req.destroy(new Error("npm registry request timed out"));
59
+ });
60
+ req.on("error", reject);
61
+ });
62
+ }
63
+
64
+ function shouldCheckForUpdate() {
65
+ try {
66
+ if (!fs.existsSync(CACHE_FILE)) return true;
67
+ const cache = JSON.parse(fs.readFileSync(CACHE_FILE, "utf8"));
68
+ return Date.now() - cache.lastCheck > CHECK_INTERVAL_MS;
69
+ } catch {
70
+ return true;
71
+ }
72
+ }
73
+
74
+ function cacheUpdateCheck(latestVersion) {
75
+ try {
76
+ fs.mkdirSync(USER_CACHE_DIR, { recursive: true });
77
+ fs.writeFileSync(
78
+ CACHE_FILE,
79
+ JSON.stringify({ lastCheck: Date.now(), latestVersion }),
80
+ "utf8"
81
+ );
82
+ } catch {
83
+ // Ignore cache write failures
84
+ }
85
+ }
86
+
87
+ function compareVersions(a, b) {
88
+ const pa = a.split(".").map(Number);
89
+ const pb = b.split(".").map(Number);
90
+ for (let i = 0; i < 3; i++) {
91
+ if (pa[i] > pb[i]) return 1;
92
+ if (pa[i] < pb[i]) return -1;
93
+ }
94
+ return 0;
95
+ }
96
+
97
+ function isGlobalInstall() {
98
+ try {
99
+ const globalRoot = execSync("npm root -g", {
100
+ stdio: ["ignore", "pipe", "ignore"],
101
+ })
102
+ .toString()
103
+ .trim();
104
+ return __dirname.startsWith(globalRoot);
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+
110
+ function promptForUpdate(latestVersion) {
111
+ const rl = readline.createInterface({
112
+ input: process.stdin,
113
+ output: process.stderr,
114
+ });
115
+
116
+ return new Promise((resolve) => {
117
+ console.error(
118
+ `\nA new version of ${PACKAGE_NAME} is available: ${latestVersion} (current: ${CURRENT_VERSION})`
119
+ );
120
+ rl.question(" Would you like to update now? (Y/n) ", (answer) => {
121
+ rl.close();
122
+ resolve(answer.toLowerCase() !== "n");
123
+ });
124
+ });
125
+ }
126
+
127
+ function performUpdate() {
128
+ console.error(`\n Updating ${PACKAGE_NAME}...`);
129
+ try {
130
+ execSync(`npm update -g ${PACKAGE_NAME}`, { stdio: "inherit" });
131
+ console.error("\n Updated successfully. Please re-run your command.\n");
132
+ process.exit(0);
133
+ } catch {
134
+ console.error(
135
+ `\n Update failed. Run manually: npm update -g ${PACKAGE_NAME}\n`
136
+ );
137
+ }
138
+ }
139
+
140
+ async function checkForUpdates() {
141
+ if (process.env.SUPERDOC_BENCHMARK_SKIP_UPDATE_CHECK === "1") return;
142
+ if (!process.stdin.isTTY || !process.stderr.isTTY) return;
143
+ if (!shouldCheckForUpdate()) return;
144
+
145
+ try {
146
+ const latestVersion = await getLatestVersion();
147
+ cacheUpdateCheck(latestVersion);
148
+
149
+ if (compareVersions(latestVersion, CURRENT_VERSION) > 0) {
150
+ if (!isGlobalInstall()) {
151
+ console.error(
152
+ `\nA new version of ${PACKAGE_NAME} is available: ${latestVersion} (current: ${CURRENT_VERSION})`
153
+ );
154
+ console.error(
155
+ " Update with your package manager (e.g., npm update @superdoc-dev/visual-benchmarks).\n"
156
+ );
157
+ return;
158
+ }
159
+
160
+ const shouldUpdate = await promptForUpdate(latestVersion);
161
+ if (shouldUpdate) {
162
+ performUpdate();
163
+ } else {
164
+ console.error(
165
+ " Skipped. Run `npm update -g @superdoc-dev/visual-benchmarks` anytime.\n"
166
+ );
167
+ }
168
+ }
169
+ } catch {
170
+ // Silently ignore update check failures
171
+ }
172
+ }
173
+
174
+ async function main() {
175
+ await checkForUpdates();
176
+
177
+ const binaryPath = path.join(BIN_CACHE, "superdoc-benchmark");
178
+
179
+ if (!fs.existsSync(binaryPath)) {
180
+ console.error("Binary not found. Try reinstalling:");
181
+ console.error(
182
+ " npm uninstall -g @superdoc-dev/visual-benchmarks && npm install -g @superdoc-dev/visual-benchmarks"
183
+ );
184
+ process.exit(1);
185
+ }
186
+
187
+ const child = spawn(binaryPath, process.argv.slice(2), {
188
+ stdio: "inherit",
189
+ env: process.env,
190
+ });
191
+
192
+ child.on("error", (err) => {
193
+ console.error(`Failed to run superdoc-benchmark: ${err.message}`);
194
+ process.exit(1);
195
+ });
196
+
197
+ child.on("exit", (code) => {
198
+ process.exit(code ?? 0);
199
+ });
200
+ }
201
+
202
+ main();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@superdoc-dev/visual-benchmarks",
3
+ "version": "0.2.8",
4
+ "description": "Visual comparison tool for SuperDoc document rendering",
5
+ "bin": {
6
+ "superdoc-benchmark": "bin/cli.js"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "scripts/",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "postinstall": "node scripts/postinstall.js",
16
+ "publish": "node scripts/publish.js"
17
+ },
18
+ "os": ["darwin"],
19
+ "cpu": ["arm64", "x64"],
20
+ "engines": {
21
+ "node": ">=16"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/superdoc-dev/superdoc-visual-benchmarks"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "keywords": [
31
+ "superdoc",
32
+ "benchmark",
33
+ "docx",
34
+ "word",
35
+ "visual-testing",
36
+ "document-comparison"
37
+ ],
38
+ "license": "MIT"
39
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const { execSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+
7
+ const VERSION = require("../package.json").version;
8
+ const REPO = "superdoc-dev/superdoc-visual-benchmarks";
9
+ const LOCAL_TARBALL = process.env.SUPERDOC_BENCHMARK_BINARY_TARBALL;
10
+
11
+ const platform = process.platform;
12
+ const arch = process.arch;
13
+
14
+ if (platform !== "darwin") {
15
+ console.error("superdoc-benchmark only supports macOS");
16
+ process.exit(1);
17
+ }
18
+
19
+ const archMap = { arm64: "arm64", x64: "x64" };
20
+ const binaryArch = archMap[arch];
21
+
22
+ if (!binaryArch) {
23
+ console.error(`Unsupported architecture: ${arch}`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const binDir = path.join(__dirname, "..", ".bin-cache");
28
+ const binaryPath = path.join(binDir, "superdoc-benchmark");
29
+
30
+ const downloadUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/superdoc-benchmark-darwin-${binaryArch}.tar.gz`;
31
+
32
+ function extractTarball(tarballPath) {
33
+ execSync(`tar -xzf "${tarballPath}" -C "${binDir}"`, {
34
+ stdio: "inherit",
35
+ });
36
+ }
37
+
38
+ function download() {
39
+ if (fs.existsSync(binaryPath)) {
40
+ console.log("superdoc-benchmark binary already installed");
41
+ return;
42
+ }
43
+
44
+ console.log(
45
+ `Downloading superdoc-benchmark v${VERSION} for darwin-${binaryArch}...`
46
+ );
47
+
48
+ fs.mkdirSync(binDir, { recursive: true });
49
+
50
+ try {
51
+ if (LOCAL_TARBALL) {
52
+ const resolvedTarball = path.resolve(LOCAL_TARBALL);
53
+ if (!fs.existsSync(resolvedTarball)) {
54
+ throw new Error(`Local tarball not found: ${resolvedTarball}`);
55
+ }
56
+ extractTarball(resolvedTarball);
57
+ } else {
58
+ const tarPath = path.join(binDir, "download.tar.gz");
59
+ execSync(`curl -fsSL "${downloadUrl}" -o "${tarPath}"`, {
60
+ stdio: "inherit",
61
+ });
62
+ extractTarball(tarPath);
63
+ fs.unlinkSync(tarPath);
64
+ }
65
+
66
+ if (!fs.existsSync(binaryPath)) {
67
+ throw new Error("Binary was not found after extraction");
68
+ }
69
+
70
+ fs.chmodSync(binaryPath, 0o755);
71
+ console.log("superdoc-benchmark installed successfully");
72
+ } catch (err) {
73
+ console.error(`Failed to download binary: ${err.message}`);
74
+ console.error(`URL: ${downloadUrl}`);
75
+ console.error("\nYou can install from source instead:");
76
+ console.error(
77
+ " git clone https://github.com/superdoc-dev/superdoc-visual-benchmarks"
78
+ );
79
+ console.error(" cd superdoc-visual-benchmarks && uv run superdoc-benchmark");
80
+ process.exit(1);
81
+ }
82
+ }
83
+
84
+ download();
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const { execSync } = require("child_process");
4
+
5
+ function isLifecycleFromPublish() {
6
+ const argv = process.env.npm_config_argv;
7
+ if (argv) {
8
+ try {
9
+ const parsed = JSON.parse(argv);
10
+ const original = parsed.original || [];
11
+ if (original[0] === "publish") {
12
+ return true;
13
+ }
14
+ if (original[0] === "run" || original[0] === "run-script") {
15
+ return false;
16
+ }
17
+ } catch {
18
+ // Fall through to npm_command check.
19
+ }
20
+ }
21
+
22
+ return process.env.npm_command === "publish";
23
+ }
24
+
25
+ if (isLifecycleFromPublish()) {
26
+ process.exit(0);
27
+ }
28
+
29
+ execSync("npm publish --access public", { stdio: "inherit" });