@archlinter/cli 0.1.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.
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { platform, arch } = process;
4
+ const { existsSync } = require('fs');
5
+ const { join } = require('path');
6
+ const { spawnSync } = require('child_process');
7
+
8
+ function getBinaryName() {
9
+ return platform === 'win32' ? 'archlint.exe' : 'archlint';
10
+ }
11
+
12
+ function isMusl() {
13
+ if (platform !== 'linux') return false;
14
+ try {
15
+ const { execSync } = require('child_process');
16
+ const output = execSync('ldd --version 2>&1 || true', { encoding: 'utf8' });
17
+ return output.includes('musl');
18
+ } catch {
19
+ try {
20
+ const os = require('fs').readFileSync('/etc/os-release', 'utf8');
21
+ return os.includes('Alpine');
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ }
27
+
28
+ function getPlatformKey() {
29
+ const platformMap = {
30
+ darwin: {
31
+ arm64: 'darwin-arm64',
32
+ x64: 'darwin-x64',
33
+ },
34
+ linux: {
35
+ arm64: 'linux-arm64',
36
+ x64: isMusl() ? 'linux-x64-musl' : 'linux-x64',
37
+ },
38
+ win32: {
39
+ x64: 'win32-x64',
40
+ },
41
+ };
42
+
43
+ const platformArch = platformMap[platform]?.[arch];
44
+ if (!platformArch) {
45
+ throw new Error(
46
+ `Unsupported platform: ${platform}-${arch}. ` +
47
+ `Supported: darwin-arm64, darwin-x64, linux-x64, linux-arm64, linux-x64-musl, win32-x64`
48
+ );
49
+ }
50
+
51
+ return platformArch;
52
+ }
53
+
54
+ function getBinaryPath() {
55
+ const platformKey = getPlatformKey();
56
+ const binaryName = getBinaryName();
57
+
58
+ const possiblePaths = [
59
+ // 1. Local node_modules (npm/pnpm/yarn classic)
60
+ join(__dirname, '..', '..', `cli-${platformKey}`, 'bin', binaryName),
61
+ // 2. pnpm nested structure
62
+ join(__dirname, '..', 'node_modules', '@archlinter', `cli-${platformKey}`, 'bin', binaryName),
63
+ // 3. Development/Monorepo path
64
+ join(__dirname, '..', '..', '..', 'packages', `cli-${platformKey}`, 'bin', binaryName),
65
+ ];
66
+
67
+ for (const p of possiblePaths) {
68
+ if (existsSync(p)) {
69
+ return p;
70
+ }
71
+ }
72
+
73
+ // 4. Try require.resolve for package managers that support it
74
+ try {
75
+ const pkgName = `@archlinter/cli-${platformKey}`;
76
+ // We try to resolve the package directory. Since main/bin might not be index.js,
77
+ // we resolve the package.json path and go from there.
78
+ const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
79
+ const pkgDir = join(pkgJsonPath, '..');
80
+ const p = join(pkgDir, 'bin', binaryName);
81
+ if (existsSync(p)) {
82
+ return p;
83
+ }
84
+ } catch {
85
+ // Package not installed or resolve failed
86
+ }
87
+
88
+ return null;
89
+ }
90
+
91
+ function run() {
92
+ const binaryPath = getBinaryPath();
93
+
94
+ if (!binaryPath) {
95
+ const platformKey = getPlatformKey();
96
+ console.error(`Error: Could not find archlint binary for ${platform}-${arch}`);
97
+ console.error('');
98
+ console.error('This usually means the optional dependency was not installed.');
99
+ console.error('Try running: npm install @archlinter/cli --force');
100
+ console.error('');
101
+ console.error(`Or install the platform-specific package directly:`);
102
+ console.error(` npm install @archlinter/cli-${platformKey}`);
103
+ process.exit(1);
104
+ }
105
+
106
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
107
+ stdio: 'inherit',
108
+ env: process.env,
109
+ });
110
+
111
+ if (result.error) {
112
+ if (result.error.code === 'EACCES') {
113
+ console.error(`Error: Permission denied. Try: chmod +x "${binaryPath}"`);
114
+ } else {
115
+ console.error(`Error running archlint: ${result.error.message}`);
116
+ }
117
+ process.exit(1);
118
+ }
119
+
120
+ process.exit(result.status ?? 0);
121
+ }
122
+
123
+ run();
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@archlinter/cli",
3
+ "version": "0.1.0",
4
+ "description": "Fast architecture smell detector for TypeScript/JavaScript",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/archlinter/archlint.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "homepage": "https://github.com/archlinter/archlint#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/archlinter/archlint/issues"
14
+ },
15
+ "bin": {
16
+ "archlint": "bin/archlint.js"
17
+ },
18
+ "files": [
19
+ "bin",
20
+ "scripts"
21
+ ],
22
+ "optionalDependencies": {
23
+ "@archlinter/cli-darwin-arm64": "workspace:*",
24
+ "@archlinter/cli-darwin-x64": "workspace:*",
25
+ "@archlinter/cli-linux-x64": "workspace:*",
26
+ "@archlinter/cli-linux-arm64": "workspace:*",
27
+ "@archlinter/cli-linux-x64-musl": "workspace:*",
28
+ "@archlinter/cli-win32-x64": "workspace:*"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "keywords": [
34
+ "architecture",
35
+ "lint",
36
+ "typescript",
37
+ "javascript",
38
+ "code-quality",
39
+ "static-analysis",
40
+ "cli"
41
+ ]
42
+ }
@@ -0,0 +1,24 @@
1
+ // CLI platform detection helper
2
+ const { platform, arch } = process;
3
+
4
+ function isMusl() {
5
+ if (platform !== 'linux') return false;
6
+ const { execSync } = require('child_process');
7
+ try {
8
+ const output = execSync('ldd --version 2>&1 || true', { encoding: 'utf8' });
9
+ return output.includes('musl');
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ function getPlatformKey() {
16
+ if (platform === 'darwin' && arch === 'arm64') return 'darwin-arm64';
17
+ if (platform === 'darwin' && arch === 'x64') return 'darwin-x64';
18
+ if (platform === 'linux' && arch === 'x64') return isMusl() ? 'linux-x64-musl' : 'linux-x64';
19
+ if (platform === 'linux' && arch === 'arm64') return 'linux-arm64';
20
+ if (platform === 'win32' && arch === 'x64') return 'win32-x64';
21
+ return null;
22
+ }
23
+
24
+ module.exports = { getPlatformKey };
@@ -0,0 +1,9 @@
1
+ // Postinstall script for @archlinter/cli
2
+ const { getPlatformKey } = require('./platform');
3
+
4
+ const platformKey = getPlatformKey();
5
+ if (platformKey) {
6
+ console.log(`Successfully detected platform: ${platformKey}`);
7
+ } else {
8
+ console.warn('Could not detect platform for @archlinter/cli');
9
+ }