@apexacc/cli 1.4.1 → 1.4.4
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/apex.cjs +21 -30
- package/bin/apex +12 -29
- package/install.cjs +10 -40
- package/package.json +1 -1
package/apex.cjs
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
const { spawnSync } = require('child_process')
|
|
3
3
|
const { join } = require('path')
|
|
4
4
|
const { existsSync, mkdirSync, createWriteStream } = require('fs')
|
|
5
|
-
const https = require('https')
|
|
6
5
|
const os = require('os')
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
7
|
const REPO = 'Apex-Accelerator/apexcli'
|
|
13
8
|
const VERSION = require('./package.json').version
|
|
14
9
|
const isWin = process.platform === 'win32'
|
|
@@ -17,10 +12,10 @@ const BIN_PATH = join(BIN_DIR, isWin ? 'apex.exe' : 'apex')
|
|
|
17
12
|
|
|
18
13
|
function getPlatformTarget() {
|
|
19
14
|
const p = process.platform, a = process.arch
|
|
20
|
-
if (p === 'linux' && a === 'x64') return 'linux-x64'
|
|
21
15
|
if (p === 'darwin' && a === 'arm64') return 'darwin-arm64'
|
|
22
16
|
if (p === 'darwin' && a === 'x64') return 'darwin-x64'
|
|
23
17
|
if (p === 'win32' && a === 'x64') return 'windows-x64'
|
|
18
|
+
if (p === 'linux' && a === 'x64') return 'linux-x64'
|
|
24
19
|
throw new Error(`Unsupported: ${p}-${a}`)
|
|
25
20
|
}
|
|
26
21
|
|
|
@@ -28,8 +23,11 @@ function download(url, dest) {
|
|
|
28
23
|
return new Promise((resolve, reject) => {
|
|
29
24
|
const file = createWriteStream(dest)
|
|
30
25
|
const req = (u) => {
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const lib = u.startsWith('https') ? require('https') : require('http')
|
|
27
|
+
lib.get(u, { headers: { 'User-Agent': 'apex-installer' } }, (res) => {
|
|
28
|
+
if ([301,302,307,308].includes(res.statusCode)) {
|
|
29
|
+
req(new URL(res.headers.location, u).href); return
|
|
30
|
+
}
|
|
33
31
|
if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}`)); return }
|
|
34
32
|
res.pipe(file)
|
|
35
33
|
file.on('finish', () => { file.close(); resolve() })
|
|
@@ -41,19 +39,12 @@ function download(url, dest) {
|
|
|
41
39
|
|
|
42
40
|
async function ensureBinary() {
|
|
43
41
|
if (existsSync(BIN_PATH)) return
|
|
44
|
-
|
|
45
42
|
console.log('Downloading Apex Copilot (~150MB), please wait...')
|
|
46
43
|
const target = getPlatformTarget()
|
|
47
44
|
const assetName = isWin ? `apex-${target}.exe` : `apex-${target}`
|
|
48
|
-
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`
|
|
49
|
-
|
|
50
45
|
mkdirSync(BIN_DIR, { recursive: true })
|
|
51
|
-
await download(
|
|
52
|
-
|
|
53
|
-
const { chmodSync } = require('fs')
|
|
54
|
-
if (!isWin) chmodSync(BIN_PATH, 0o755)
|
|
55
|
-
|
|
56
|
-
// Windows: download native addon
|
|
46
|
+
await download(`https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`, BIN_PATH)
|
|
47
|
+
if (!isWin) require('fs').chmodSync(BIN_PATH, 0o755)
|
|
57
48
|
if (isWin) {
|
|
58
49
|
const nativesDir = join(os.homedir(), '.apex', 'natives', '16.3.6')
|
|
59
50
|
const nodeFile = 'pi_natives.win32-x64-baseline.node'
|
|
@@ -63,17 +54,13 @@ async function ensureBinary() {
|
|
|
63
54
|
mkdirSync(nativesDir, { recursive: true })
|
|
64
55
|
await download(`https://github.com/${REPO}/releases/download/v${VERSION}/${nodeFile}`, nodePath)
|
|
65
56
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Windows: download apex-verify
|
|
69
|
-
if (isWin) {
|
|
70
57
|
const verifyPath = join(os.homedir(), '.apex', 'apex-verify.exe')
|
|
71
58
|
const verifyVersionPath = join(os.homedir(), '.apex', '.verify-version')
|
|
72
59
|
let needsUpdate = !existsSync(verifyPath)
|
|
73
60
|
if (!needsUpdate) {
|
|
74
61
|
try {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
62
|
+
const saved = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
|
|
63
|
+
if (saved !== VERSION) needsUpdate = true
|
|
77
64
|
} catch { needsUpdate = true }
|
|
78
65
|
}
|
|
79
66
|
if (needsUpdate) {
|
|
@@ -82,24 +69,28 @@ async function ensureBinary() {
|
|
|
82
69
|
require('fs').writeFileSync(verifyVersionPath, VERSION)
|
|
83
70
|
}
|
|
84
71
|
}
|
|
85
|
-
|
|
86
|
-
// Mac: download apex-verify
|
|
87
72
|
if (process.platform === 'darwin') {
|
|
88
73
|
const verifyPath = join(os.homedir(), '.apex', 'apex-verify')
|
|
89
|
-
|
|
74
|
+
const verifyVersionPath = join(os.homedir(), '.apex', '.verify-version')
|
|
75
|
+
let needsUpdate = !existsSync(verifyPath)
|
|
76
|
+
if (!needsUpdate) {
|
|
77
|
+
try {
|
|
78
|
+
const saved = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
|
|
79
|
+
if (saved !== VERSION) needsUpdate = true
|
|
80
|
+
} catch { needsUpdate = true }
|
|
81
|
+
}
|
|
82
|
+
if (needsUpdate) {
|
|
90
83
|
mkdirSync(join(os.homedir(), '.apex'), { recursive: true })
|
|
91
84
|
await download(`https://github.com/${REPO}/releases/download/v${VERSION}/apex-verify-darwin`, verifyPath)
|
|
92
85
|
require('fs').chmodSync(verifyPath, 0o755)
|
|
86
|
+
require('fs').writeFileSync(verifyVersionPath, VERSION)
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
|
-
|
|
96
89
|
console.log('Done!')
|
|
97
90
|
}
|
|
98
91
|
|
|
99
92
|
ensureBinary().then(() => {
|
|
100
|
-
const result = spawnSync(BIN_PATH, process.argv.slice(2), {
|
|
101
|
-
stdio: 'inherit', env: process.env
|
|
102
|
-
})
|
|
93
|
+
const result = spawnSync(BIN_PATH, process.argv.slice(2), { stdio: 'inherit', env: process.env })
|
|
103
94
|
process.exit(result.status ?? 0)
|
|
104
95
|
}).catch(err => {
|
|
105
96
|
console.error('Failed to download Apex:', err.message)
|
package/bin/apex
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { spawnSync } = require('child_process')
|
|
3
3
|
const { join } = require('path')
|
|
4
|
-
const { existsSync, mkdirSync, createWriteStream
|
|
5
|
-
const https = require('https')
|
|
4
|
+
const { existsSync, mkdirSync, createWriteStream } = require('fs')
|
|
6
5
|
const os = require('os')
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
7
|
const REPO = 'Apex-Accelerator/apexcli'
|
|
12
8
|
const VERSION = require('../package.json').version
|
|
13
9
|
const isWin = process.platform === 'win32'
|
|
@@ -28,9 +24,8 @@ function download(url, dest) {
|
|
|
28
24
|
const req = (u) => {
|
|
29
25
|
const lib = u.startsWith('https') ? require('https') : require('http')
|
|
30
26
|
lib.get(u, { headers: { 'User-Agent': 'apex-installer' } }, (res) => {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
req(absoluteUrl); return
|
|
27
|
+
if ([301,302,307,308].includes(res.statusCode)) {
|
|
28
|
+
req(new URL(res.headers.location, u).href); return
|
|
34
29
|
}
|
|
35
30
|
if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}`)); return }
|
|
36
31
|
res.pipe(file)
|
|
@@ -45,9 +40,8 @@ async function verifySha256(filePath, hashUrl) {
|
|
|
45
40
|
try {
|
|
46
41
|
const hashPath = filePath + '.sha256'
|
|
47
42
|
await download(hashUrl, hashPath)
|
|
48
|
-
const { createHash
|
|
49
|
-
const
|
|
50
|
-
const expectedHash = expectedLine.split(/\s+/)[0]
|
|
43
|
+
const { createHash } = require('crypto'), fs = require('fs')
|
|
44
|
+
const expectedHash = fs.readFileSync(hashPath, 'utf8').trim().split(/\s+/)[0]
|
|
51
45
|
const actualHash = createHash('sha256').update(fs.readFileSync(filePath)).digest('hex')
|
|
52
46
|
fs.unlinkSync(hashPath)
|
|
53
47
|
if (actualHash !== expectedHash) {
|
|
@@ -56,21 +50,19 @@ async function verifySha256(filePath, hashUrl) {
|
|
|
56
50
|
}
|
|
57
51
|
} catch (e) {
|
|
58
52
|
if (e.message.includes('hash mismatch')) throw e
|
|
59
|
-
// hash file unavailable — warn but continue
|
|
60
53
|
console.warn('Warning: could not verify binary hash:', e.message)
|
|
61
54
|
}
|
|
62
55
|
}
|
|
63
56
|
|
|
64
57
|
async function ensureVerify() {
|
|
65
|
-
// Windows: download apex-verify
|
|
66
58
|
if (isWin) {
|
|
67
59
|
const verifyPath = join(os.homedir(), '.apex', 'apex-verify.exe')
|
|
68
60
|
const verifyVersionPath = join(os.homedir(), '.apex', '.verify-version')
|
|
69
61
|
let needsUpdate = !existsSync(verifyPath)
|
|
70
62
|
if (!needsUpdate) {
|
|
71
63
|
try {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
64
|
+
const saved = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
|
|
65
|
+
if (saved !== VERSION) needsUpdate = true
|
|
74
66
|
} catch { needsUpdate = true }
|
|
75
67
|
}
|
|
76
68
|
if (needsUpdate) {
|
|
@@ -87,14 +79,10 @@ async function ensureBinary() {
|
|
|
87
79
|
console.log('Downloading Apex Copilot (~150MB), please wait...')
|
|
88
80
|
const target = getPlatformTarget()
|
|
89
81
|
const assetName = isWin ? `apex-${target}.exe` : `apex-${target}`
|
|
90
|
-
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`
|
|
91
82
|
mkdirSync(BIN_DIR, { recursive: true })
|
|
92
|
-
await download(
|
|
83
|
+
await download(`https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`, BIN_PATH)
|
|
93
84
|
await verifySha256(BIN_PATH, `https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}.sha256`)
|
|
94
|
-
|
|
95
|
-
if (!isWin) chmodSync(BIN_PATH, 0o755)
|
|
96
|
-
|
|
97
|
-
// Windows: download native addon
|
|
85
|
+
if (!isWin) require('fs').chmodSync(BIN_PATH, 0o755)
|
|
98
86
|
if (isWin) {
|
|
99
87
|
const nativesDir = join(os.homedir(), '.apex', 'natives', '16.3.6')
|
|
100
88
|
const nodeFile = 'pi_natives.win32-x64-baseline.node'
|
|
@@ -105,16 +93,14 @@ async function ensureBinary() {
|
|
|
105
93
|
await download(`https://github.com/${REPO}/releases/download/v${VERSION}/${nodeFile}`, nodePath)
|
|
106
94
|
}
|
|
107
95
|
}
|
|
108
|
-
|
|
109
|
-
// Mac: download apex-verify
|
|
110
96
|
if (process.platform === 'darwin') {
|
|
111
97
|
const verifyPath = join(os.homedir(), '.apex', 'apex-verify')
|
|
112
98
|
const verifyVersionPath = join(os.homedir(), '.apex', '.verify-version')
|
|
113
99
|
let needsUpdate = !existsSync(verifyPath)
|
|
114
100
|
if (!needsUpdate) {
|
|
115
101
|
try {
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
102
|
+
const saved = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
|
|
103
|
+
if (saved !== VERSION) needsUpdate = true
|
|
118
104
|
} catch { needsUpdate = true }
|
|
119
105
|
}
|
|
120
106
|
if (needsUpdate) {
|
|
@@ -125,14 +111,11 @@ async function ensureBinary() {
|
|
|
125
111
|
require('fs').writeFileSync(verifyVersionPath, VERSION)
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
|
-
|
|
129
114
|
console.log('Done!')
|
|
130
115
|
}
|
|
131
116
|
|
|
132
117
|
ensureVerify().then(() => ensureBinary()).then(() => {
|
|
133
|
-
const result = spawnSync(BIN_PATH, process.argv.slice(2), {
|
|
134
|
-
stdio: 'inherit', env: process.env
|
|
135
|
-
})
|
|
118
|
+
const result = spawnSync(BIN_PATH, process.argv.slice(2), { stdio: 'inherit', env: process.env })
|
|
136
119
|
process.exit(result.status ?? 0)
|
|
137
120
|
}).catch(err => {
|
|
138
121
|
console.error('Failed to download Apex:', err.message)
|
package/install.cjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
2
|
const { existsSync, mkdirSync, chmodSync, createWriteStream } = require('fs')
|
|
4
3
|
const { join } = require('path')
|
|
5
4
|
const { homedir } = require('os')
|
|
6
|
-
const https = require('https')
|
|
7
5
|
|
|
8
6
|
if (process.env.CI || process.env.SKIP_APEX_INSTALL) {
|
|
9
7
|
console.log('Skipping install in CI.')
|
|
10
8
|
process.exit(0)
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
const _pkg = require('./package.json')
|
|
11
|
+
const _pkg = require('./package.json')
|
|
14
12
|
const RELEASE_VERSION = (process.env.npm_package_version || _pkg.version || '1.0.0').replace(/^v/, '')
|
|
15
13
|
const REPO = 'Apex-Accelerator/apexcli'
|
|
16
14
|
const BIN_DIR = join(__dirname, 'bin')
|
|
@@ -32,9 +30,8 @@ function download(url, dest) {
|
|
|
32
30
|
const req = (u) => {
|
|
33
31
|
const lib = u.startsWith('https') ? require('https') : require('http')
|
|
34
32
|
lib.get(u, { headers: { 'User-Agent': 'apex-installer' } }, (res) => {
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
req(absoluteUrl); return
|
|
33
|
+
if ([301,302,307,308].includes(res.statusCode)) {
|
|
34
|
+
req(new URL(res.headers.location, u).href); return
|
|
38
35
|
}
|
|
39
36
|
if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode} ${u}`)); return }
|
|
40
37
|
res.pipe(file)
|
|
@@ -49,30 +46,23 @@ async function install() {
|
|
|
49
46
|
const target = getPlatformTarget()
|
|
50
47
|
const isWin = process.platform === 'win32'
|
|
51
48
|
const assetName = isWin ? `apex-${target}.exe` : `apex-${target}`
|
|
52
|
-
const url = `https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${assetName}`
|
|
53
|
-
|
|
54
49
|
if (!existsSync(BIN_DIR)) mkdirSync(BIN_DIR, { recursive: true })
|
|
55
|
-
|
|
56
50
|
console.log(`Downloading Apex Copilot for ${target}...`)
|
|
57
51
|
try {
|
|
58
|
-
await download(
|
|
52
|
+
await download(`https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${assetName}`, BIN_PATH)
|
|
59
53
|
if (!isWin) chmodSync(BIN_PATH, 0o755)
|
|
60
|
-
// Verify binary integrity via SHA256
|
|
61
|
-
const hashUrl = `https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${assetName}.sha256`
|
|
62
|
-
const hashPath = BIN_PATH + '.sha256'
|
|
63
54
|
try {
|
|
64
|
-
|
|
55
|
+
const hashPath = BIN_PATH + '.sha256'
|
|
56
|
+
await download(`https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${assetName}.sha256`, hashPath)
|
|
65
57
|
const { createHash } = require('crypto')
|
|
66
58
|
const { readFileSync, unlinkSync } = require('fs')
|
|
67
|
-
const
|
|
68
|
-
const expectedHash = expectedLine.split(/\s+/)[0]
|
|
59
|
+
const expectedHash = readFileSync(hashPath, 'utf8').trim().split(/\s+/)[0]
|
|
69
60
|
const actualHash = createHash('sha256').update(readFileSync(BIN_PATH)).digest('hex')
|
|
70
61
|
unlinkSync(hashPath)
|
|
71
62
|
if (actualHash !== expectedHash) {
|
|
72
63
|
console.error('Security: binary hash mismatch! Aborting.')
|
|
73
64
|
process.exit(1)
|
|
74
65
|
}
|
|
75
|
-
console.log('Binary verified.')
|
|
76
66
|
} catch (err) {
|
|
77
67
|
console.warn('Warning: could not verify binary hash:', err.message)
|
|
78
68
|
}
|
|
@@ -80,40 +70,20 @@ async function install() {
|
|
|
80
70
|
console.error(`Failed: ${err.message}`)
|
|
81
71
|
process.exit(1)
|
|
82
72
|
}
|
|
83
|
-
|
|
84
|
-
if (isWin) {
|
|
73
|
+
if (process.platform === 'win32') {
|
|
85
74
|
const nativesDir = join(homedir(), '.apex', 'natives', VERSION)
|
|
86
75
|
const nodeFile = 'pi_natives.win32-x64-baseline.node'
|
|
87
|
-
const nodeUrl = `https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${nodeFile}`
|
|
88
76
|
const nodePath = join(nativesDir, nodeFile)
|
|
89
|
-
|
|
90
77
|
if (!existsSync(nodePath)) {
|
|
91
|
-
console.log(
|
|
78
|
+
console.log('Downloading native addon...')
|
|
92
79
|
mkdirSync(nativesDir, { recursive: true })
|
|
93
80
|
try {
|
|
94
|
-
await download(
|
|
95
|
-
console.log('Native addon downloaded.')
|
|
81
|
+
await download(`https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/${nodeFile}`, nodePath)
|
|
96
82
|
} catch (err) {
|
|
97
83
|
console.error(`Failed to download native addon: ${err.message}`)
|
|
98
84
|
}
|
|
99
85
|
}
|
|
100
86
|
}
|
|
101
|
-
|
|
102
|
-
// Mac: download apex-verify binary
|
|
103
|
-
if (process.platform === 'darwin') {
|
|
104
|
-
const { chmodSync } = require('fs')
|
|
105
|
-
const verifyPath = join(homedir(), '.apex', 'apex-verify')
|
|
106
|
-
const verifyUrl = `https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}/apex-verify-darwin`
|
|
107
|
-
console.log('Downloading apex-verify from ' + verifyUrl)
|
|
108
|
-
try {
|
|
109
|
-
mkdirSync(join(homedir(), '.apex'), { recursive: true })
|
|
110
|
-
await download(verifyUrl, verifyPath)
|
|
111
|
-
chmodSync(verifyPath, 0o755)
|
|
112
|
-
console.log('Apex verify tool downloaded successfully.')
|
|
113
|
-
} catch (err) {
|
|
114
|
-
console.error('Failed to download apex-verify:', err.message)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
87
|
console.log('Done!')
|
|
118
88
|
}
|
|
119
89
|
|