@ohos-ports/graphviz 0.0.9-beta.0

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/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@ohos-ports/graphviz",
3
+ "version": "0.0.9-beta.0",
4
+ "author": "Gregoire Lejeune <gregoire.lejeune@free.fr> (http://algorithmique.net/)",
5
+ "description": "Node.js interface to the GraphViz graphing tool (OpenHarmony/HarmonyOS port: bundles openharmony-arm64 GraphViz 12.2.1 dot/gvpr binaries)",
6
+ "homepage": "http://algorithmique.net/",
7
+ "license": "GPL-3.0",
8
+ "contributors": [
9
+ "Gregoire Lejeune (http://algorithmique.net)",
10
+ "Mathieu Ravaux (http://mathieuravaux.com)"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
15
+ "directory": "ports/graphviz/0.0.9"
16
+ },
17
+ "keywords": [
18
+ "graphviz",
19
+ "dot"
20
+ ],
21
+ "directories": {
22
+ "lib": "./lib"
23
+ },
24
+ "main": "lib/graphviz",
25
+ "engines": {
26
+ "node": ">=0.6.8"
27
+ },
28
+ "dependencies": {
29
+ "temp": "^0.4.0"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
33
+ },
34
+ "scripts": {
35
+ "postinstall": "node scripts/install-binaries.js"
36
+ },
37
+ "files": [
38
+ "lib/",
39
+ "bin/",
40
+ "scripts/",
41
+ "README.md",
42
+ "LICENCE.txt",
43
+ "CHANGELOG.md"
44
+ ]
45
+ }
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * postinstall: install bundled ohos-arm64 GraphViz binaries (dot, gvpr)
4
+ * into ~/.harmonybrew/bin so `require('graphviz')` finds them on PATH.
5
+ *
6
+ * The package ships prebuilt GraphViz 12.2.1 binaries for
7
+ * openharmony-arm64 only. On any other platform this script is a no-op
8
+ * and users must provide their own graphviz installation on PATH.
9
+ */
10
+ 'use strict';
11
+
12
+ const fs = require('fs');
13
+ const os = require('os');
14
+ const path = require('path');
15
+ const { execFileSync } = require('child_process');
16
+
17
+ const ENGINES = ['neato', 'fdp', 'sfdp', 'twopi', 'circo', 'osage', 'patchwork'];
18
+
19
+ function isOhosArm64() {
20
+ if (process.platform === 'openharmony' && os.arch() === 'arm64') return true;
21
+ // Some HarmonyOS Node.js builds still report 'linux'
22
+ if (process.platform === 'linux' && os.arch() === 'arm64') {
23
+ try {
24
+ const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
25
+ if (/openharmony|harmonyos/i.test(osRelease)) return true;
26
+ } catch (_) { /* ignore */ }
27
+ try {
28
+ const ver = fs.readFileSync('/proc/version', 'utf8').toLowerCase();
29
+ if (ver.includes('ohos') || ver.includes('harmonyos')) return true;
30
+ } catch (_) { /* ignore */ }
31
+ }
32
+ return false;
33
+ }
34
+
35
+ function main() {
36
+ const srcDir = path.join(__dirname, '..', 'bin', 'openharmony-arm64');
37
+ if (!isOhosArm64()) {
38
+ console.log('[ohos-ports/graphviz] not openharmony-arm64, skipping bundled binary install (use system graphviz).');
39
+ return;
40
+ }
41
+ if (!fs.existsSync(path.join(srcDir, 'dot'))) {
42
+ console.log('[ohos-ports/graphviz] bundled binaries missing, skipping.');
43
+ return;
44
+ }
45
+
46
+ const destDir = path.join(os.homedir(), '.harmonybrew', 'bin');
47
+ fs.mkdirSync(destDir, { recursive: true });
48
+
49
+ const install = (name, target) => {
50
+ const dest = path.join(destDir, target);
51
+ fs.rmSync(dest, { force: true }); // overwrite: unlink first (EPERM on copy over existing file)
52
+ fs.copyFileSync(path.join(srcDir, name), dest);
53
+ fs.chmodSync(dest, 0o755);
54
+ };
55
+
56
+ install('dot', 'dot');
57
+ install('gvpr', 'gvpr');
58
+
59
+ // GraphViz layout engines are symlinks to the dot multi-call binary
60
+ for (const engine of ENGINES) {
61
+ const link = path.join(destDir, engine);
62
+ try {
63
+ fs.rmSync(link, { force: true });
64
+ fs.symlinkSync('dot', link);
65
+ } catch (err) {
66
+ console.warn(`[ohos-ports/graphviz] could not link ${engine}: ${err.message}`);
67
+ }
68
+ }
69
+
70
+ console.log(`[ohos-ports/graphviz] installed GraphViz 12.2.1 (dot, gvpr) to ${destDir}`);
71
+ try {
72
+ execFileSync(path.join(destDir, 'dot'), ['-V'], { stdio: 'ignore' });
73
+ console.log('[ohos-ports/graphviz] dot -V OK');
74
+ } catch (_) {
75
+ console.warn('[ohos-ports/graphviz] warning: dot -V verification failed; ensure libc++_shared.so is available');
76
+ }
77
+ }
78
+
79
+ main();