@maratus/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.
- package/bin/maratus.mjs +81 -0
- package/package.json +21 -0
package/bin/maratus.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'node:child_process'
|
|
4
|
+
import { constants as fsConstants } from 'node:fs'
|
|
5
|
+
import { access } from 'node:fs/promises'
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
import { dirname, join } from 'node:path'
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
9
|
+
|
|
10
|
+
function platformPackageName() {
|
|
11
|
+
const key = `${process.platform}-${process.arch}`
|
|
12
|
+
|
|
13
|
+
switch (key) {
|
|
14
|
+
case 'darwin-arm64':
|
|
15
|
+
return '@maratus/cli-darwin-arm64'
|
|
16
|
+
case 'darwin-x64':
|
|
17
|
+
return '@maratus/cli-darwin-x64'
|
|
18
|
+
case 'linux-x64':
|
|
19
|
+
return '@maratus/cli-linux-x64'
|
|
20
|
+
case 'win32-x64':
|
|
21
|
+
return '@maratus/cli-win32-x64'
|
|
22
|
+
default:
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const packageName = platformPackageName()
|
|
28
|
+
if (!packageName) {
|
|
29
|
+
console.error(
|
|
30
|
+
`Maratus CLI does not support ${process.platform}-${process.arch}.`,
|
|
31
|
+
)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let binaryPath
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
39
|
+
const binaryName = process.platform === 'win32' ? 'maratus.exe' : 'maratus'
|
|
40
|
+
binaryPath = join(dirname(packageJsonPath), 'bin', binaryName)
|
|
41
|
+
} catch {
|
|
42
|
+
console.error(
|
|
43
|
+
[
|
|
44
|
+
`Maratus CLI not installed for ${process.platform}-${process.arch}.`,
|
|
45
|
+
`Expected package: ${packageName}`,
|
|
46
|
+
].join('\n'),
|
|
47
|
+
)
|
|
48
|
+
process.exit(1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const accessMode =
|
|
53
|
+
process.platform === 'win32' ? fsConstants.F_OK : fsConstants.X_OK
|
|
54
|
+
await access(binaryPath, accessMode)
|
|
55
|
+
} catch {
|
|
56
|
+
console.error(
|
|
57
|
+
[
|
|
58
|
+
'Maratus CLI binary is not packaged yet for this platform.',
|
|
59
|
+
`Expected package: ${packageName}`,
|
|
60
|
+
`Expected executable at: ${binaryPath}`,
|
|
61
|
+
].join('\n'),
|
|
62
|
+
)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
67
|
+
stdio: 'inherit',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
child.on('exit', (code, signal) => {
|
|
71
|
+
if (signal) {
|
|
72
|
+
process.kill(process.pid, signal)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
process.exit(code ?? 1)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
child.on('error', (error) => {
|
|
79
|
+
console.error(error.message)
|
|
80
|
+
process.exit(1)
|
|
81
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maratus/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"bin": {
|
|
6
|
+
"maratus": "./bin/maratus.mjs"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@maratus/codemod-runner": "workspace:*"
|
|
14
|
+
},
|
|
15
|
+
"optionalDependencies": {
|
|
16
|
+
"@maratus/cli-darwin-arm64": "workspace:*",
|
|
17
|
+
"@maratus/cli-darwin-x64": "workspace:*",
|
|
18
|
+
"@maratus/cli-linux-x64": "workspace:*",
|
|
19
|
+
"@maratus/cli-win32-x64": "workspace:*"
|
|
20
|
+
}
|
|
21
|
+
}
|