@apexacc/cli 1.4.0 → 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.
Files changed (4) hide show
  1. package/apex.cjs +21 -34
  2. package/bin/apex +12 -29
  3. package/install.cjs +10 -40
  4. package/package.json +1 -1
package/apex.cjs CHANGED
@@ -2,17 +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
- if (process.platform === 'linux') {
10
- console.error('Apex Copilot is not supported on Linux. Please use macOS or Windows.');
11
- process.exit(1);
12
- }
13
-
14
-
15
-
16
7
  const REPO = 'Apex-Accelerator/apexcli'
17
8
  const VERSION = require('./package.json').version
18
9
  const isWin = process.platform === 'win32'
@@ -21,10 +12,10 @@ const BIN_PATH = join(BIN_DIR, isWin ? 'apex.exe' : 'apex')
21
12
 
22
13
  function getPlatformTarget() {
23
14
  const p = process.platform, a = process.arch
24
- if (p === 'linux' && a === 'x64') return 'linux-x64'
25
15
  if (p === 'darwin' && a === 'arm64') return 'darwin-arm64'
26
16
  if (p === 'darwin' && a === 'x64') return 'darwin-x64'
27
17
  if (p === 'win32' && a === 'x64') return 'windows-x64'
18
+ if (p === 'linux' && a === 'x64') return 'linux-x64'
28
19
  throw new Error(`Unsupported: ${p}-${a}`)
29
20
  }
30
21
 
@@ -32,8 +23,11 @@ function download(url, dest) {
32
23
  return new Promise((resolve, reject) => {
33
24
  const file = createWriteStream(dest)
34
25
  const req = (u) => {
35
- https.get(u, { headers: { 'User-Agent': 'apex-installer' } }, (res) => {
36
- if (res.statusCode === 301 || res.statusCode === 302) { req(res.headers.location); return }
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
+ }
37
31
  if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}`)); return }
38
32
  res.pipe(file)
39
33
  file.on('finish', () => { file.close(); resolve() })
@@ -45,19 +39,12 @@ function download(url, dest) {
45
39
 
46
40
  async function ensureBinary() {
47
41
  if (existsSync(BIN_PATH)) return
48
-
49
42
  console.log('Downloading Apex Copilot (~150MB), please wait...')
50
43
  const target = getPlatformTarget()
51
44
  const assetName = isWin ? `apex-${target}.exe` : `apex-${target}`
52
- const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`
53
-
54
45
  mkdirSync(BIN_DIR, { recursive: true })
55
- await download(url, BIN_PATH)
56
-
57
- const { chmodSync } = require('fs')
58
- if (!isWin) chmodSync(BIN_PATH, 0o755)
59
-
60
- // 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)
61
48
  if (isWin) {
62
49
  const nativesDir = join(os.homedir(), '.apex', 'natives', '16.3.6')
63
50
  const nodeFile = 'pi_natives.win32-x64-baseline.node'
@@ -67,17 +54,13 @@ async function ensureBinary() {
67
54
  mkdirSync(nativesDir, { recursive: true })
68
55
  await download(`https://github.com/${REPO}/releases/download/v${VERSION}/${nodeFile}`, nodePath)
69
56
  }
70
- }
71
-
72
- // Windows: download apex-verify
73
- if (isWin) {
74
57
  const verifyPath = join(os.homedir(), '.apex', 'apex-verify.exe')
75
58
  const verifyVersionPath = join(os.homedir(), '.apex', '.verify-version')
76
59
  let needsUpdate = !existsSync(verifyPath)
77
60
  if (!needsUpdate) {
78
61
  try {
79
- const savedVersion = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
80
- if (savedVersion !== VERSION) needsUpdate = true
62
+ const saved = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
63
+ if (saved !== VERSION) needsUpdate = true
81
64
  } catch { needsUpdate = true }
82
65
  }
83
66
  if (needsUpdate) {
@@ -86,24 +69,28 @@ async function ensureBinary() {
86
69
  require('fs').writeFileSync(verifyVersionPath, VERSION)
87
70
  }
88
71
  }
89
-
90
- // Mac: download apex-verify
91
72
  if (process.platform === 'darwin') {
92
73
  const verifyPath = join(os.homedir(), '.apex', 'apex-verify')
93
- if (!existsSync(verifyPath)) {
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) {
94
83
  mkdirSync(join(os.homedir(), '.apex'), { recursive: true })
95
84
  await download(`https://github.com/${REPO}/releases/download/v${VERSION}/apex-verify-darwin`, verifyPath)
96
85
  require('fs').chmodSync(verifyPath, 0o755)
86
+ require('fs').writeFileSync(verifyVersionPath, VERSION)
97
87
  }
98
88
  }
99
-
100
89
  console.log('Done!')
101
90
  }
102
91
 
103
92
  ensureBinary().then(() => {
104
- const result = spawnSync(BIN_PATH, process.argv.slice(2), {
105
- stdio: 'inherit', env: process.env
106
- })
93
+ const result = spawnSync(BIN_PATH, process.argv.slice(2), { stdio: 'inherit', env: process.env })
107
94
  process.exit(result.status ?? 0)
108
95
  }).catch(err => {
109
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, unlinkSync } = require('fs')
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 (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
32
- const absoluteUrl = new URL(res.headers.location, u).href
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, readFileSync } = require('crypto'), fs = require('fs')
49
- const expectedLine = fs.readFileSync(hashPath, 'utf8').trim()
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 savedVersion = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
73
- if (savedVersion !== VERSION) needsUpdate = true
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(url, BIN_PATH)
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
- const { chmodSync } = require('fs')
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 savedVersion = require('fs').readFileSync(verifyVersionPath, 'utf8').trim()
117
- if (savedVersion !== VERSION) needsUpdate = true
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 (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
36
- const absoluteUrl = new URL(res.headers.location, u).href
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(url, BIN_PATH)
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
- await download(hashUrl, hashPath)
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 expectedLine = readFileSync(hashPath, 'utf8').trim()
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(`Downloading native addon...`)
78
+ console.log('Downloading native addon...')
92
79
  mkdirSync(nativesDir, { recursive: true })
93
80
  try {
94
- await download(nodeUrl, nodePath)
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexacc/cli",
3
- "version": "1.4.0",
3
+ "version": "1.4.4",
4
4
  "description": "Apex Copilot CLI — Due diligence toolkit for founders",
5
5
  "author": {
6
6
  "name": "Apex Accelerator",