@goliapkg/sentori-cli 0.6.0 → 1.0.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/lib/index.js +268 -340
- package/lib/index.js.map +1 -1
- package/lib/issue.d.ts +16 -18
- package/lib/issue.d.ts.map +1 -1
- package/lib/issue.js +29 -32
- package/lib/issue.js.map +1 -1
- package/lib/lenient.d.ts +13 -0
- package/lib/lenient.d.ts.map +1 -0
- package/lib/lenient.js +25 -0
- package/lib/lenient.js.map +1 -0
- package/lib/mcp.d.ts +4 -2
- package/lib/mcp.d.ts.map +1 -1
- package/lib/mcp.js +43 -220
- package/lib/mcp.js.map +1 -1
- package/lib/native-artifacts.d.ts +0 -1
- package/lib/native-artifacts.d.ts.map +1 -1
- package/lib/native-artifacts.js +30 -41
- package/lib/native-artifacts.js.map +1 -1
- package/lib/probes.d.ts +10 -0
- package/lib/probes.d.ts.map +1 -0
- package/lib/probes.js +75 -0
- package/lib/probes.js.map +1 -0
- package/lib/react-native.d.ts.map +1 -1
- package/lib/react-native.js +17 -9
- package/lib/react-native.js.map +1 -1
- package/lib/upload.d.ts +10 -21
- package/lib/upload.d.ts.map +1 -1
- package/lib/upload.js +20 -57
- package/lib/upload.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/lenient.test.ts +32 -0
- package/src/__tests__/mcp.test.ts +20 -112
- package/src/__tests__/native-artifacts.test.ts +5 -12
- package/src/__tests__/probes.test.ts +41 -0
- package/src/index.ts +290 -362
- package/src/issue.ts +47 -46
- package/src/lenient.ts +39 -0
- package/src/mcp.ts +46 -215
- package/src/native-artifacts.ts +37 -44
- package/src/probes.ts +75 -0
- package/src/react-native.ts +16 -9
- package/src/upload.ts +30 -71
- package/src/__tests__/issue.test.ts +0 -95
- package/src/__tests__/source-bundle-from-dir.test.ts +0 -85
- package/src/__tests__/source-bundle.test.ts +0 -105
- package/src/__tests__/upload.test.ts +0 -121
- package/src/source-bundle.ts +0 -234
package/src/source-bundle.ts
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
// v1.2 W3.a — `sentori-cli upload source-bundle`.
|
|
2
|
-
//
|
|
3
|
-
// Uploads a pre-built `*.tar.gz` archive of the project's source tree
|
|
4
|
-
// for one platform. Server stores it under
|
|
5
|
-
// `release_artifacts` with `kind = source_bundle_<platform>`; on
|
|
6
|
-
// click-frame, the dashboard's FrameSourceDrawer pulls the matching
|
|
7
|
-
// source file out of the archive and shows ±N lines.
|
|
8
|
-
//
|
|
9
|
-
// We intentionally keep the CLI side small: the operator (or CI)
|
|
10
|
-
// already knows how to build a tarball. v1.3 may add an
|
|
11
|
-
// auto-bundle-from-directory mode; for now you do:
|
|
12
|
-
//
|
|
13
|
-
// tar -czf ios-source.tar.gz Sources/
|
|
14
|
-
// sentori-cli upload source-bundle --project <uuid> \
|
|
15
|
-
// --release myapp@1.0.0 --platform ios --path ios-source.tar.gz
|
|
16
|
-
|
|
17
|
-
import { spawnSync } from 'node:child_process'
|
|
18
|
-
import { mkdtemp, readFile, readdir, stat, writeFile } from 'node:fs/promises'
|
|
19
|
-
import { tmpdir } from 'node:os'
|
|
20
|
-
import { join, relative, sep as pathSep } from 'node:path'
|
|
21
|
-
|
|
22
|
-
import type { AdminUpload } from './native-artifacts.js'
|
|
23
|
-
|
|
24
|
-
const PLATFORMS = new Set(['ios', 'android'])
|
|
25
|
-
|
|
26
|
-
/** v1.2 W3.d — per-platform file extensions the CLI bundles when
|
|
27
|
-
* `--from-dir` mode picks files from a project tree. Kept narrow on
|
|
28
|
-
* purpose: source-bundle is only useful for native source viewing,
|
|
29
|
-
* and including non-source files would balloon the archive without
|
|
30
|
-
* helping the lookup path. */
|
|
31
|
-
const EXTENSIONS: Record<'android' | 'ios', string[]> = {
|
|
32
|
-
android: ['.kt', '.java'],
|
|
33
|
-
ios: ['.swift', '.m', '.mm', '.h', '.hpp'],
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const SKIP_DIRS = new Set([
|
|
37
|
-
'.git',
|
|
38
|
-
'node_modules',
|
|
39
|
-
'Pods',
|
|
40
|
-
'build',
|
|
41
|
-
'DerivedData',
|
|
42
|
-
'.gradle',
|
|
43
|
-
'.build',
|
|
44
|
-
'target',
|
|
45
|
-
])
|
|
46
|
-
|
|
47
|
-
export type SourceBundleUploadOptions = AdminUpload & {
|
|
48
|
-
/** v1.4 W26 — optional module label so polyrepo apps (main +
|
|
49
|
-
* watch ext + share ext etc.) can upload multiple bundles per
|
|
50
|
-
* (release, platform). Empty/undefined → unlabelled single
|
|
51
|
-
* bundle (v1.3 W15 behaviour). */
|
|
52
|
-
module?: string
|
|
53
|
-
/** Pre-built tar.gz archive of the project's source tree. */
|
|
54
|
-
path: string
|
|
55
|
-
platform: 'android' | 'ios'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type SourceBundleUploadResult = {
|
|
59
|
-
contentHash: string
|
|
60
|
-
kind: string
|
|
61
|
-
sizeBytes: number
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function uploadSourceBundle(
|
|
65
|
-
opts: SourceBundleUploadOptions,
|
|
66
|
-
): Promise<SourceBundleUploadResult> {
|
|
67
|
-
if (!PLATFORMS.has(opts.platform)) {
|
|
68
|
-
throw new Error(`--platform must be 'ios' or 'android' (got '${opts.platform}')`)
|
|
69
|
-
}
|
|
70
|
-
if (!opts.release) {
|
|
71
|
-
throw new Error('--release is required for source-bundle uploads')
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// v1.2 W3.d: when `opts.path` is a directory, bundle it on the fly
|
|
75
|
-
// instead of requiring the operator to pre-build the archive.
|
|
76
|
-
let archivePath = opts.path
|
|
77
|
-
let cleanup: undefined | (() => Promise<void>)
|
|
78
|
-
try {
|
|
79
|
-
const st = await stat(opts.path)
|
|
80
|
-
if (st.isDirectory()) {
|
|
81
|
-
const built = await buildSourceBundleFromDir(opts.path, opts.platform)
|
|
82
|
-
archivePath = built.path
|
|
83
|
-
cleanup = built.cleanup
|
|
84
|
-
}
|
|
85
|
-
} catch (e) {
|
|
86
|
-
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e
|
|
87
|
-
throw new Error(`source path not found: ${opts.path}`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
return await uploadPrebuiltTarGz({ ...opts, path: archivePath })
|
|
92
|
-
} finally {
|
|
93
|
-
if (cleanup) await cleanup()
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function uploadPrebuiltTarGz(
|
|
98
|
-
opts: SourceBundleUploadOptions,
|
|
99
|
-
): Promise<SourceBundleUploadResult> {
|
|
100
|
-
const body = await readFile(opts.path)
|
|
101
|
-
if (body.length === 0) throw new Error(`empty archive: ${opts.path}`)
|
|
102
|
-
// Same gzip magic check the server enforces. Failing early here
|
|
103
|
-
// saves a network round-trip when an operator accidentally points
|
|
104
|
-
// at a raw .tar.
|
|
105
|
-
if (body.length < 2 || body[0] !== 0x1f || body[1] !== 0x8b) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`${opts.path} does not look like a gzip stream (expected 1f 8b magic) — ` +
|
|
108
|
-
`did you mean to gzip it first? \`tar -czf <out>.tar.gz <dir>/\``,
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
if (!opts.release) throw new Error('--release is required for source-bundle uploads')
|
|
112
|
-
const base = opts.apiUrl.replace(/\/+$/, '')
|
|
113
|
-
const q = new URLSearchParams()
|
|
114
|
-
q.set('release', opts.release)
|
|
115
|
-
q.set('platform', opts.platform)
|
|
116
|
-
if (opts.module) q.set('module', opts.module)
|
|
117
|
-
const url = `${base}/admin/api/projects/${encodeURIComponent(opts.projectId)}/source-bundles?${q.toString()}`
|
|
118
|
-
|
|
119
|
-
const resp = await fetch(url, {
|
|
120
|
-
body,
|
|
121
|
-
headers: {
|
|
122
|
-
Authorization: `Bearer ${opts.token}`,
|
|
123
|
-
'Content-Type': 'application/gzip',
|
|
124
|
-
},
|
|
125
|
-
method: 'POST',
|
|
126
|
-
})
|
|
127
|
-
if (!resp.ok) {
|
|
128
|
-
let detail = ''
|
|
129
|
-
try {
|
|
130
|
-
detail = await resp.text()
|
|
131
|
-
} catch {
|
|
132
|
-
// ignore
|
|
133
|
-
}
|
|
134
|
-
throw new Error(
|
|
135
|
-
`${resp.status} ${resp.statusText}${detail ? ` — ${detail.slice(0, 300)}` : ''}`,
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
const parsed: unknown = await resp.json()
|
|
139
|
-
if (
|
|
140
|
-
!parsed ||
|
|
141
|
-
typeof parsed !== 'object' ||
|
|
142
|
-
typeof (parsed as { contentHash?: unknown }).contentHash !== 'string'
|
|
143
|
-
) {
|
|
144
|
-
throw new Error(`unexpected response shape: ${JSON.stringify(parsed)}`)
|
|
145
|
-
}
|
|
146
|
-
const r = parsed as { contentHash: string; kind: string; sizeBytes: number }
|
|
147
|
-
return { contentHash: r.contentHash, kind: r.kind, sizeBytes: r.sizeBytes }
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Walk `dir`, pick platform-relevant source files, and tar.gz them
|
|
151
|
-
* into a temp file. Caller is responsible for invoking `cleanup()`.
|
|
152
|
-
* Uses the system `tar` binary; that's portable enough on macOS +
|
|
153
|
-
* Linux + WSL, which covers every realistic CI environment Sentori
|
|
154
|
-
* ships to. Native Windows CI without WSL would need to gzip the
|
|
155
|
-
* archive themselves (the pre-built-path mode still works). */
|
|
156
|
-
export async function buildSourceBundleFromDir(
|
|
157
|
-
dir: string,
|
|
158
|
-
platform: 'android' | 'ios',
|
|
159
|
-
): Promise<{ cleanup: () => Promise<void>; path: string }> {
|
|
160
|
-
const exts = EXTENSIONS[platform]
|
|
161
|
-
const files: string[] = []
|
|
162
|
-
await walk(dir, dir, exts, files)
|
|
163
|
-
if (files.length === 0) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
`no ${platform} source files (${exts.join(', ')}) found under ${dir} — ` +
|
|
166
|
-
`pass --platform with the right value or check your source layout`,
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
files.sort()
|
|
170
|
-
|
|
171
|
-
// Write the file list to a temp file, then have tar consume it via
|
|
172
|
-
// -T —. Avoids the per-arg shell length cap on huge projects.
|
|
173
|
-
const tmp = await mkdtemp(join(tmpdir(), 'sentori-srcbun-'))
|
|
174
|
-
const listPath = join(tmp, 'files.txt')
|
|
175
|
-
const archivePath = join(tmp, `${platform}-source.tar.gz`)
|
|
176
|
-
await writeFile(listPath, files.join('\n'))
|
|
177
|
-
const r = spawnSync('tar', ['-czf', archivePath, '-C', dir, '-T', listPath])
|
|
178
|
-
if (r.status !== 0) {
|
|
179
|
-
throw new Error(
|
|
180
|
-
`tar failed (status ${r.status}): ${(r.stderr ?? '').toString().slice(0, 300)}`,
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
cleanup: async () => {
|
|
185
|
-
try {
|
|
186
|
-
await readdir(tmp).then(async (entries) => {
|
|
187
|
-
for (const e of entries) {
|
|
188
|
-
await unlinkIfExists(join(tmp, e))
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
await unlinkIfExists(tmp, true)
|
|
192
|
-
} catch {
|
|
193
|
-
// best-effort cleanup
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
path: archivePath,
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async function walk(
|
|
201
|
-
root: string,
|
|
202
|
-
dir: string,
|
|
203
|
-
exts: string[],
|
|
204
|
-
out: string[],
|
|
205
|
-
): Promise<void> {
|
|
206
|
-
const entries = await readdir(dir, { withFileTypes: true })
|
|
207
|
-
for (const e of entries) {
|
|
208
|
-
if (e.name.startsWith('.') && e.isDirectory() && e.name !== '.') {
|
|
209
|
-
// Hidden directory: skip (.git, .gradle, .build…). The known
|
|
210
|
-
// ones are listed in SKIP_DIRS for clarity, but any leading-dot
|
|
211
|
-
// dir is also skipped as a safety net.
|
|
212
|
-
continue
|
|
213
|
-
}
|
|
214
|
-
if (SKIP_DIRS.has(e.name)) continue
|
|
215
|
-
const full = join(dir, e.name)
|
|
216
|
-
if (e.isDirectory()) {
|
|
217
|
-
await walk(root, full, exts, out)
|
|
218
|
-
} else if (e.isFile()) {
|
|
219
|
-
const lower = e.name.toLowerCase()
|
|
220
|
-
if (exts.some((ext) => lower.endsWith(ext))) {
|
|
221
|
-
out.push(relative(root, full).split(pathSep).join('/'))
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function unlinkIfExists(path: string, isDir = false): Promise<void> {
|
|
228
|
-
const { rm } = await import('node:fs/promises')
|
|
229
|
-
try {
|
|
230
|
-
await rm(path, { force: true, recursive: isDir })
|
|
231
|
-
} catch {
|
|
232
|
-
// ignore
|
|
233
|
-
}
|
|
234
|
-
}
|