@goliapkg/sentori-cli 1.5.0 → 1.6.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.
@@ -1,193 +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
- import { spawnSync } from 'node:child_process';
17
- import { mkdtemp, readFile, readdir, stat, writeFile } from 'node:fs/promises';
18
- import { tmpdir } from 'node:os';
19
- import { join, relative, sep as pathSep } from 'node:path';
20
- const PLATFORMS = new Set(['ios', 'android']);
21
- /** v1.2 W3.d — per-platform file extensions the CLI bundles when
22
- * `--from-dir` mode picks files from a project tree. Kept narrow on
23
- * purpose: source-bundle is only useful for native source viewing,
24
- * and including non-source files would balloon the archive without
25
- * helping the lookup path. */
26
- const EXTENSIONS = {
27
- android: ['.kt', '.java'],
28
- ios: ['.swift', '.m', '.mm', '.h', '.hpp'],
29
- };
30
- const SKIP_DIRS = new Set([
31
- '.git',
32
- 'node_modules',
33
- 'Pods',
34
- 'build',
35
- 'DerivedData',
36
- '.gradle',
37
- '.build',
38
- 'target',
39
- ]);
40
- export async function uploadSourceBundle(opts) {
41
- if (!PLATFORMS.has(opts.platform)) {
42
- throw new Error(`--platform must be 'ios' or 'android' (got '${opts.platform}')`);
43
- }
44
- if (!opts.release) {
45
- throw new Error('--release is required for source-bundle uploads');
46
- }
47
- // v1.2 W3.d: when `opts.path` is a directory, bundle it on the fly
48
- // instead of requiring the operator to pre-build the archive.
49
- let archivePath = opts.path;
50
- let cleanup;
51
- try {
52
- const st = await stat(opts.path);
53
- if (st.isDirectory()) {
54
- const built = await buildSourceBundleFromDir(opts.path, opts.platform);
55
- archivePath = built.path;
56
- cleanup = built.cleanup;
57
- }
58
- }
59
- catch (e) {
60
- if (e.code !== 'ENOENT')
61
- throw e;
62
- throw new Error(`source path not found: ${opts.path}`);
63
- }
64
- try {
65
- return await uploadPrebuiltTarGz({ ...opts, path: archivePath });
66
- }
67
- finally {
68
- if (cleanup)
69
- await cleanup();
70
- }
71
- }
72
- async function uploadPrebuiltTarGz(opts) {
73
- const body = await readFile(opts.path);
74
- if (body.length === 0)
75
- throw new Error(`empty archive: ${opts.path}`);
76
- // Same gzip magic check the server enforces. Failing early here
77
- // saves a network round-trip when an operator accidentally points
78
- // at a raw .tar.
79
- if (body.length < 2 || body[0] !== 0x1f || body[1] !== 0x8b) {
80
- throw new Error(`${opts.path} does not look like a gzip stream (expected 1f 8b magic) — ` +
81
- `did you mean to gzip it first? \`tar -czf <out>.tar.gz <dir>/\``);
82
- }
83
- if (!opts.release)
84
- throw new Error('--release is required for source-bundle uploads');
85
- const base = opts.apiUrl.replace(/\/+$/, '');
86
- const q = new URLSearchParams();
87
- q.set('release', opts.release);
88
- q.set('platform', opts.platform);
89
- if (opts.module)
90
- q.set('module', opts.module);
91
- const url = `${base}/admin/api/projects/${encodeURIComponent(opts.projectId)}/source-bundles?${q.toString()}`;
92
- const resp = await fetch(url, {
93
- body,
94
- headers: {
95
- Authorization: `Bearer ${opts.token}`,
96
- 'Content-Type': 'application/gzip',
97
- },
98
- method: 'POST',
99
- });
100
- if (!resp.ok) {
101
- let detail = '';
102
- try {
103
- detail = await resp.text();
104
- }
105
- catch {
106
- // ignore
107
- }
108
- throw new Error(`${resp.status} ${resp.statusText}${detail ? ` — ${detail.slice(0, 300)}` : ''}`);
109
- }
110
- const parsed = await resp.json();
111
- if (!parsed ||
112
- typeof parsed !== 'object' ||
113
- typeof parsed.contentHash !== 'string') {
114
- throw new Error(`unexpected response shape: ${JSON.stringify(parsed)}`);
115
- }
116
- const r = parsed;
117
- return { contentHash: r.contentHash, kind: r.kind, sizeBytes: r.sizeBytes };
118
- }
119
- /** Walk `dir`, pick platform-relevant source files, and tar.gz them
120
- * into a temp file. Caller is responsible for invoking `cleanup()`.
121
- * Uses the system `tar` binary; that's portable enough on macOS +
122
- * Linux + WSL, which covers every realistic CI environment Sentori
123
- * ships to. Native Windows CI without WSL would need to gzip the
124
- * archive themselves (the pre-built-path mode still works). */
125
- export async function buildSourceBundleFromDir(dir, platform) {
126
- const exts = EXTENSIONS[platform];
127
- const files = [];
128
- await walk(dir, dir, exts, files);
129
- if (files.length === 0) {
130
- throw new Error(`no ${platform} source files (${exts.join(', ')}) found under ${dir} — ` +
131
- `pass --platform with the right value or check your source layout`);
132
- }
133
- files.sort();
134
- // Write the file list to a temp file, then have tar consume it via
135
- // -T —. Avoids the per-arg shell length cap on huge projects.
136
- const tmp = await mkdtemp(join(tmpdir(), 'sentori-srcbun-'));
137
- const listPath = join(tmp, 'files.txt');
138
- const archivePath = join(tmp, `${platform}-source.tar.gz`);
139
- await writeFile(listPath, files.join('\n'));
140
- const r = spawnSync('tar', ['-czf', archivePath, '-C', dir, '-T', listPath]);
141
- if (r.status !== 0) {
142
- throw new Error(`tar failed (status ${r.status}): ${(r.stderr ?? '').toString().slice(0, 300)}`);
143
- }
144
- return {
145
- cleanup: async () => {
146
- try {
147
- await readdir(tmp).then(async (entries) => {
148
- for (const e of entries) {
149
- await unlinkIfExists(join(tmp, e));
150
- }
151
- });
152
- await unlinkIfExists(tmp, true);
153
- }
154
- catch {
155
- // best-effort cleanup
156
- }
157
- },
158
- path: archivePath,
159
- };
160
- }
161
- async function walk(root, dir, exts, out) {
162
- const entries = await readdir(dir, { withFileTypes: true });
163
- for (const e of entries) {
164
- if (e.name.startsWith('.') && e.isDirectory() && e.name !== '.') {
165
- // Hidden directory: skip (.git, .gradle, .build…). The known
166
- // ones are listed in SKIP_DIRS for clarity, but any leading-dot
167
- // dir is also skipped as a safety net.
168
- continue;
169
- }
170
- if (SKIP_DIRS.has(e.name))
171
- continue;
172
- const full = join(dir, e.name);
173
- if (e.isDirectory()) {
174
- await walk(root, full, exts, out);
175
- }
176
- else if (e.isFile()) {
177
- const lower = e.name.toLowerCase();
178
- if (exts.some((ext) => lower.endsWith(ext))) {
179
- out.push(relative(root, full).split(pathSep).join('/'));
180
- }
181
- }
182
- }
183
- }
184
- async function unlinkIfExists(path, isDir = false) {
185
- const { rm } = await import('node:fs/promises');
186
- try {
187
- await rm(path, { force: true, recursive: isDir });
188
- }
189
- catch {
190
- // ignore
191
- }
192
- }
193
- //# sourceMappingURL=source-bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"source-bundle.js","sourceRoot":"","sources":["../src/source-bundle.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,sEAAsE;AACtE,2CAA2C;AAC3C,iEAAiE;AACjE,oEAAoE;AACpE,qDAAqD;AACrD,EAAE;AACF,iEAAiE;AACjE,wDAAwD;AACxD,mDAAmD;AACnD,EAAE;AACF,wCAAwC;AACxC,wDAAwD;AACxD,oEAAoE;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAI1D,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA;AAE7C;;;;+BAI+B;AAC/B,MAAM,UAAU,GAAwC;IACtD,OAAO,EAAE,CAAC,KA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