mehen 0.0.1

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.
Files changed (2) hide show
  1. package/bin/mehen.js +139 -0
  2. package/package.json +52 -0
package/bin/mehen.js ADDED
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require('child_process');
4
+ const { existsSync } = require('fs');
5
+ const path = require('path');
6
+
7
+ /**
8
+ * Detect if we're running on musl libc (like Alpine Linux)
9
+ * @returns {boolean} true if musl is detected
10
+ */
11
+ function detectMusl() {
12
+ try {
13
+ if (existsSync('/lib/ld-musl-x86_64.so.1') ||
14
+ existsSync('/lib/ld-musl-aarch64.so.1') ||
15
+ existsSync('/usr/lib/libc.musl-x86_64.so.1') ||
16
+ existsSync('/usr/lib/libc.musl-aarch64.so.1')) {
17
+ return true;
18
+ }
19
+
20
+ if (existsSync('/proc/version')) {
21
+ const fs = require('fs');
22
+ const version = fs.readFileSync('/proc/version', 'utf8');
23
+ if (version.includes('musl')) {
24
+ return true;
25
+ }
26
+ }
27
+
28
+ return false;
29
+ } catch (error) {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Get the platform-specific package name for the current system
36
+ * @returns {string} the npm package name for this platform
37
+ */
38
+ function getPlatformPackageName() {
39
+ const platform = process.platform;
40
+ const arch = process.arch;
41
+
42
+ let pkgPlatform;
43
+ let pkgArch;
44
+ let suffix = '';
45
+
46
+ switch (platform) {
47
+ case 'linux':
48
+ pkgPlatform = 'linux';
49
+ suffix = detectMusl() ? '-musl' : '-gnu';
50
+ break;
51
+ case 'darwin':
52
+ pkgPlatform = 'darwin';
53
+ break;
54
+ case 'win32':
55
+ pkgPlatform = 'win32';
56
+ break;
57
+ default:
58
+ throw new Error(`Unsupported platform: ${platform}`);
59
+ }
60
+
61
+ switch (arch) {
62
+ case 'x64':
63
+ pkgArch = 'x64';
64
+ break;
65
+ case 'arm64':
66
+ pkgArch = 'arm64';
67
+ break;
68
+ default:
69
+ throw new Error(`Unsupported architecture: ${arch}`);
70
+ }
71
+
72
+ return `@mehen/${pkgPlatform}-${pkgArch}${suffix}`;
73
+ }
74
+
75
+ /**
76
+ * Find and execute the platform-specific mehen binary
77
+ */
78
+ function main() {
79
+ try {
80
+ const pkgName = getPlatformPackageName();
81
+ const binName = process.platform === 'win32' ? 'mehen.exe' : 'mehen';
82
+
83
+ let binPath;
84
+ try {
85
+ binPath = require.resolve(`${pkgName}/bin/${binName}`);
86
+ } catch (resolveError) {
87
+ console.error(`Error: Could not find mehen binary for your platform (${pkgName}).`);
88
+ console.error('');
89
+ console.error('This usually means:');
90
+ console.error('1. Optional dependencies were disabled during installation');
91
+ console.error('2. Your platform is not supported');
92
+ console.error('');
93
+ console.error('To fix this:');
94
+ console.error('1. Reinstall with optional dependencies enabled:');
95
+ console.error(' npm install mehen');
96
+ console.error(' # or');
97
+ console.error(' yarn add mehen');
98
+ console.error('');
99
+ console.error('2. If you disabled optional dependencies, re-enable them:');
100
+ console.error(' npm install --include=optional');
101
+ console.error('');
102
+ console.error(`Expected package: ${pkgName}`);
103
+ console.error(`Platform: ${process.platform} ${process.arch}`);
104
+ process.exit(1);
105
+ }
106
+
107
+ if (!existsSync(binPath)) {
108
+ console.error(`Error: Binary not found at ${binPath}`);
109
+ console.error('The platform package was installed but the binary is missing.');
110
+ console.error('Please try reinstalling mehen.');
111
+ process.exit(1);
112
+ }
113
+
114
+ const args = process.argv.slice(2);
115
+
116
+ try {
117
+ execFileSync(binPath, args, {
118
+ stdio: 'inherit',
119
+ windowsHide: false
120
+ });
121
+ } catch (execError) {
122
+ if (execError.status !== undefined) {
123
+ process.exit(execError.status);
124
+ }
125
+ console.error(`Error executing mehen binary: ${execError.message}`);
126
+ process.exit(1);
127
+ }
128
+
129
+ } catch (error) {
130
+ console.error(`Error: ${error.message}`);
131
+ process.exit(1);
132
+ }
133
+ }
134
+
135
+ if (require.main === module) {
136
+ main();
137
+ }
138
+
139
+ module.exports = { getPlatformPackageName, detectMusl };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "mehen",
3
+ "version": "0.0.1",
4
+ "description": "Tool to compute and export code metrics",
5
+ "keywords": [
6
+ "metrics",
7
+ "code-analysis",
8
+ "complexity",
9
+ "cyclomatic",
10
+ "halstead",
11
+ "rust",
12
+ "go",
13
+ "typescript",
14
+ "cli"
15
+ ],
16
+ "homepage": "https://github.com/ophidiarium/mehen",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/ophidiarium/mehen.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/ophidiarium/mehen/issues"
23
+ },
24
+ "license": "MPL-2.0",
25
+ "author": {
26
+ "name": "Konstantin Vyatkin",
27
+ "email": "tino@vtkn.io"
28
+ },
29
+ "bin": {
30
+ "mehen": "./bin/mehen.js"
31
+ },
32
+ "files": [
33
+ "bin/",
34
+ "README.md"
35
+ ],
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "optionalDependencies": {
40
+ "@mehen/linux-x64-gnu": "0.0.1",
41
+ "@mehen/linux-x64-musl": "0.0.1",
42
+ "@mehen/linux-arm64-gnu": "0.0.1",
43
+ "@mehen/linux-arm64-musl": "0.0.1",
44
+ "@mehen/darwin-x64": "0.0.1",
45
+ "@mehen/darwin-arm64": "0.0.1",
46
+ "@mehen/win32-x64": "0.0.1",
47
+ "@mehen/win32-arm64": "0.0.1"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }