@goliapkg/sentori-cli 0.5.3 → 0.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.
- package/README.md +27 -32
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +795 -0
- package/lib/index.js.map +1 -0
- package/lib/issue.d.ts +28 -0
- package/lib/issue.d.ts.map +1 -0
- package/lib/issue.js +53 -0
- package/lib/issue.js.map +1 -0
- package/lib/mcp.d.ts +14 -0
- package/lib/mcp.d.ts.map +1 -0
- package/lib/mcp.js +371 -0
- package/lib/mcp.js.map +1 -0
- package/lib/native-artifacts.d.ts +43 -0
- package/lib/native-artifacts.d.ts.map +1 -0
- package/lib/native-artifacts.js +148 -0
- package/lib/native-artifacts.js.map +1 -0
- package/lib/push.d.ts +42 -0
- package/lib/push.d.ts.map +1 -0
- package/lib/push.js +92 -0
- package/lib/push.js.map +1 -0
- package/lib/react-native.d.ts +25 -0
- package/lib/react-native.d.ts.map +1 -0
- package/lib/react-native.js +74 -0
- package/lib/react-native.js.map +1 -0
- package/lib/source-bundle.d.ts +28 -0
- package/lib/source-bundle.d.ts.map +1 -0
- package/lib/source-bundle.js +193 -0
- package/lib/source-bundle.js.map +1 -0
- package/lib/upload.d.ts +24 -0
- package/lib/upload.d.ts.map +1 -0
- package/lib/upload.js +65 -0
- package/lib/upload.js.map +1 -0
- package/package.json +23 -13
- package/src/__tests__/issue.test.ts +95 -0
- package/src/__tests__/mcp.test.ts +124 -0
- package/src/__tests__/native-artifacts.test.ts +132 -0
- package/src/__tests__/react-native.test.ts +37 -0
- package/src/__tests__/source-bundle-from-dir.test.ts +85 -0
- package/src/__tests__/source-bundle.test.ts +105 -0
- package/src/__tests__/upload.test.ts +121 -0
- package/src/index.ts +799 -0
- package/src/issue.ts +81 -0
- package/src/mcp.ts +399 -0
- package/src/native-artifacts.ts +182 -0
- package/src/push.ts +174 -0
- package/src/react-native.ts +87 -0
- package/src/source-bundle.ts +234 -0
- package/src/upload.ts +85 -0
- package/bin/sentori-cli.js +0 -32
- package/scripts/postinstall.js +0 -90
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// `sentori-cli upload dsym` (iOS) + `sentori-cli upload mapping` (Android).
|
|
2
|
+
// Both endpoints take the raw artifact bytes (NOT multipart) with a few
|
|
3
|
+
// headers / query params.
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { basename, extname, join } from 'node:path';
|
|
7
|
+
import { statSync, readdirSync } from 'node:fs';
|
|
8
|
+
async function postBytes(url, body, token, headers = {}) {
|
|
9
|
+
const resp = await fetch(url, {
|
|
10
|
+
body,
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: `Bearer ${token}`,
|
|
13
|
+
'Content-Type': 'application/octet-stream',
|
|
14
|
+
...headers,
|
|
15
|
+
},
|
|
16
|
+
method: 'POST',
|
|
17
|
+
});
|
|
18
|
+
if (!resp.ok) {
|
|
19
|
+
let detail = '';
|
|
20
|
+
try {
|
|
21
|
+
detail = await resp.text();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// ignore
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`${resp.status} ${resp.statusText}${detail ? ` — ${detail.slice(0, 300)}` : ''}`);
|
|
27
|
+
}
|
|
28
|
+
const txt = await resp.text();
|
|
29
|
+
return txt ? JSON.parse(txt) : null;
|
|
30
|
+
}
|
|
31
|
+
const ARCHES = new Set([
|
|
32
|
+
'arm64',
|
|
33
|
+
'arm64_32',
|
|
34
|
+
'arm64e',
|
|
35
|
+
'armv7',
|
|
36
|
+
'armv7k',
|
|
37
|
+
'armv7s',
|
|
38
|
+
'i386',
|
|
39
|
+
'x86_64',
|
|
40
|
+
'x86_64h',
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Use `dwarfdump --uuid <path>` to enumerate `(arch, debug_id, file)`
|
|
44
|
+
* for each Mach-O slice. Returns [] if dwarfdump isn't installed or the
|
|
45
|
+
* output couldn't be parsed; callers should fall back to explicit
|
|
46
|
+
* `--debug-id` / `--arch` flags in that case.
|
|
47
|
+
*/
|
|
48
|
+
export function dsymSlicesFromDwarfdump(path) {
|
|
49
|
+
const r = spawnSync('dwarfdump', ['--uuid', path]);
|
|
50
|
+
if (r.status !== 0 || !r.stdout)
|
|
51
|
+
return [];
|
|
52
|
+
const out = [];
|
|
53
|
+
// Output lines look like:
|
|
54
|
+
// UUID: 1234ABCD-... (arm64) /path/to/Foo.dSYM/Contents/Resources/DWARF/Foo
|
|
55
|
+
const re = /^UUID:\s+([0-9A-Fa-f-]{32,36})\s+\(([^)]+)\)\s+(.+)\s*$/m;
|
|
56
|
+
for (const line of r.stdout.toString().split('\n')) {
|
|
57
|
+
const m = re.exec(line);
|
|
58
|
+
if (!m)
|
|
59
|
+
continue;
|
|
60
|
+
const [, debugId, arch, file] = m;
|
|
61
|
+
if (!ARCHES.has(arch))
|
|
62
|
+
continue;
|
|
63
|
+
out.push({ arch, debugId: debugId.toUpperCase(), file: file.trim() });
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** Walk a `.dSYM` bundle and return the DWARF binary files inside
|
|
68
|
+
* `Contents/Resources/DWARF/`. If `path` already points at a binary
|
|
69
|
+
* (not a bundle), returns `[path]`. */
|
|
70
|
+
export function dwarfBinariesIn(path) {
|
|
71
|
+
let st;
|
|
72
|
+
try {
|
|
73
|
+
st = statSync(path);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
if (st.isFile())
|
|
79
|
+
return [path];
|
|
80
|
+
const dwarfDir = join(path, 'Contents/Resources/DWARF');
|
|
81
|
+
try {
|
|
82
|
+
return readdirSync(dwarfDir)
|
|
83
|
+
.filter((n) => !n.startsWith('.'))
|
|
84
|
+
.map((n) => join(dwarfDir, n));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// not a .dSYM bundle layout — try the top-level path
|
|
88
|
+
return [path];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function uploadDsym(opts) {
|
|
92
|
+
const slices = [];
|
|
93
|
+
if (opts.debugId && opts.arch) {
|
|
94
|
+
// Explicit single-slice upload — no parsing needed.
|
|
95
|
+
const binaries = dwarfBinariesIn(opts.path);
|
|
96
|
+
if (binaries.length === 0)
|
|
97
|
+
throw new Error(`no DWARF binary at: ${opts.path}`);
|
|
98
|
+
slices.push({ arch: opts.arch, debugId: opts.debugId.toUpperCase(), file: binaries[0] });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Auto-discover via dwarfdump.
|
|
102
|
+
const found = dsymSlicesFromDwarfdump(opts.path);
|
|
103
|
+
if (found.length === 0) {
|
|
104
|
+
throw new Error('couldn’t enumerate dSYM slices — install Xcode command-line tools ' +
|
|
105
|
+
'(for `dwarfdump`), or pass --debug-id and --arch explicitly');
|
|
106
|
+
}
|
|
107
|
+
slices.push(...found);
|
|
108
|
+
}
|
|
109
|
+
const base = opts.apiUrl.replace(/\/+$/, '');
|
|
110
|
+
const q = new URLSearchParams();
|
|
111
|
+
if (opts.release)
|
|
112
|
+
q.set('release', opts.release);
|
|
113
|
+
if (opts.objectName ?? basename(opts.path).replace(/\.dSYM$/, ''))
|
|
114
|
+
q.set('objectName', opts.objectName ?? basename(opts.path).replace(/\.dSYM$/, ''));
|
|
115
|
+
const qs = q.toString();
|
|
116
|
+
const url = `${base}/admin/api/projects/${encodeURIComponent(opts.projectId)}/dsyms${qs ? '?' + qs : ''}`;
|
|
117
|
+
const uploaded = [];
|
|
118
|
+
for (const s of slices) {
|
|
119
|
+
const body = await readFile(s.file);
|
|
120
|
+
await postBytes(url, body, opts.token, {
|
|
121
|
+
'x-sentori-arch': s.arch,
|
|
122
|
+
'x-sentori-debug-id': s.debugId,
|
|
123
|
+
});
|
|
124
|
+
uploaded.push({ arch: s.arch, debugId: s.debugId });
|
|
125
|
+
}
|
|
126
|
+
return { slices: uploaded };
|
|
127
|
+
}
|
|
128
|
+
export async function uploadMapping(opts) {
|
|
129
|
+
const ext = extname(opts.path).toLowerCase();
|
|
130
|
+
if (ext && ext !== '.txt' && ext !== '.map') {
|
|
131
|
+
// R8 emits `mapping.txt` by default; accept anything but warn.
|
|
132
|
+
console.warn(`[sentori-cli] upload mapping: unexpected extension ${ext} — uploading anyway`);
|
|
133
|
+
}
|
|
134
|
+
const body = await readFile(opts.path);
|
|
135
|
+
if (body.length === 0)
|
|
136
|
+
throw new Error(`empty mapping file: ${opts.path}`);
|
|
137
|
+
const base = opts.apiUrl.replace(/\/+$/, '');
|
|
138
|
+
const q = new URLSearchParams();
|
|
139
|
+
if (opts.release)
|
|
140
|
+
q.set('release', opts.release);
|
|
141
|
+
const qs = q.toString();
|
|
142
|
+
const url = `${base}/admin/api/projects/${encodeURIComponent(opts.projectId)}/mappings${qs ? '?' + qs : ''}`;
|
|
143
|
+
const headers = {};
|
|
144
|
+
if (opts.debugId)
|
|
145
|
+
headers['x-sentori-debug-id'] = opts.debugId;
|
|
146
|
+
await postBytes(url, body, opts.token, headers);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=native-artifacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-artifacts.js","sourceRoot":"","sources":["../src/native-artifacts.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wEAAwE;AACxE,0BAA0B;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAS/C,KAAK,UAAU,SAAS,CACtB,GAAW,EACX,IAAY,EACZ,KAAa,EACb,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,CAAC,IAAI,CAAC,sDAAsD,GAAG,qBAAqB,CAAC,CAAA;IAC9F,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACtC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAE1E,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC5C,MAAM,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IAC/B,IAAI,IAAI,CAAC,OAAO;QAAE,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IAChD,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;IACvB,MAAM,GAAG,GAAG,GAAG,IAAI,uBAAuB,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAC5G,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;IAC9D,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AACjD,CAAC"}
|
package/lib/push.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type PushClientConfig = {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
projectId: string;
|
|
4
|
+
token: string;
|
|
5
|
+
};
|
|
6
|
+
type AdminCredentialRow = {
|
|
7
|
+
provider: string;
|
|
8
|
+
config: Record<string, unknown>;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
};
|
|
11
|
+
type Ticket = {
|
|
12
|
+
id: string;
|
|
13
|
+
status: 'queued' | 'sent' | 'failed';
|
|
14
|
+
providerOutcome?: string | null;
|
|
15
|
+
error?: string | null;
|
|
16
|
+
retryCount: number;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
sentAt?: string | null;
|
|
19
|
+
};
|
|
20
|
+
/** Parse a CLI flag value that may be `@file.json` (read from disk
|
|
21
|
+
* and parse) or a literal JSON string. */
|
|
22
|
+
export declare function parseJsonArg(raw: string, kind: string): unknown;
|
|
23
|
+
export declare function pushCredsList(cfg: PushClientConfig): Promise<AdminCredentialRow[]>;
|
|
24
|
+
export declare function pushCredsSet(cfg: PushClientConfig, provider: string, config: unknown, secret: unknown): Promise<{
|
|
25
|
+
ok: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function pushCredsDelete(cfg: PushClientConfig, provider: string): Promise<void>;
|
|
28
|
+
export type SendOpts = {
|
|
29
|
+
to: string;
|
|
30
|
+
title?: string;
|
|
31
|
+
body?: string;
|
|
32
|
+
data?: unknown;
|
|
33
|
+
priority?: 'high' | 'normal';
|
|
34
|
+
ttl?: number;
|
|
35
|
+
idempotencyKey?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function pushSend(cfg: PushClientConfig, opts: SendOpts): Promise<Ticket>;
|
|
38
|
+
export declare function pushReceipt(cfg: PushClientConfig, sendId: string): Promise<{
|
|
39
|
+
ticket: Ticket;
|
|
40
|
+
}>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,C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QAAQ,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBrF;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAK7B"}
|
package/lib/push.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// v2.12 — `sentori-cli push *` commands.
|
|
2
|
+
//
|
|
3
|
+
// Wraps the v2.7 admin REST + v2.7 ingest endpoints so operators can
|
|
4
|
+
// drive credential CRUD, ad-hoc sends, and receipt lookups from the
|
|
5
|
+
// terminal without touching curl.
|
|
6
|
+
//
|
|
7
|
+
// `push send` POST /v1/push/send (ingest Bearer)
|
|
8
|
+
// `push receipt` GET /v1/push/receipts/:id (ingest Bearer)
|
|
9
|
+
// `push creds list` GET /admin/api/projects/:id/push/credentials (admin Bearer)
|
|
10
|
+
// `push creds set` PUT /admin/api/projects/:id/push/credentials (admin Bearer)
|
|
11
|
+
// `push creds delete` DELETE /admin/api/projects/:id/push/credentials/:provider
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
const VALID_PROVIDERS = new Set(['apns', 'fcm', 'webpush', 'hcm', 'mipush']);
|
|
14
|
+
function joinUrl(base, path) {
|
|
15
|
+
return `${base.replace(/\/+$/, '')}${path}`;
|
|
16
|
+
}
|
|
17
|
+
async function bearerFetch(url, token, init) {
|
|
18
|
+
const resp = await fetch(url, {
|
|
19
|
+
...init,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${token}`,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
...(init?.headers ?? {}),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!resp.ok) {
|
|
27
|
+
const detail = await resp.text().catch(() => '');
|
|
28
|
+
throw new Error(`${resp.status} ${resp.statusText}${detail ? ` — ${detail.slice(0, 300)}` : ''}`);
|
|
29
|
+
}
|
|
30
|
+
const txt = await resp.text();
|
|
31
|
+
return (txt ? JSON.parse(txt) : null);
|
|
32
|
+
}
|
|
33
|
+
/** Parse a CLI flag value that may be `@file.json` (read from disk
|
|
34
|
+
* and parse) or a literal JSON string. */
|
|
35
|
+
export function parseJsonArg(raw, kind) {
|
|
36
|
+
if (raw.startsWith('@')) {
|
|
37
|
+
const path = raw.slice(1);
|
|
38
|
+
const body = readFileSync(path, 'utf-8');
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(body);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw new Error(`${kind} file ${path} is not valid JSON: ${e.message}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(raw);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw new Error(`${kind} arg is not valid JSON: ${e.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ── credential CRUD ───────────────────────────────────────────────
|
|
54
|
+
export async function pushCredsList(cfg) {
|
|
55
|
+
return bearerFetch(joinUrl(cfg.apiUrl, `/admin/api/projects/${cfg.projectId}/push/credentials`), cfg.token);
|
|
56
|
+
}
|
|
57
|
+
export async function pushCredsSet(cfg, provider, config, secret) {
|
|
58
|
+
if (!VALID_PROVIDERS.has(provider)) {
|
|
59
|
+
throw new Error(`invalid provider '${provider}'; expected one of ${[...VALID_PROVIDERS].join('/')}`);
|
|
60
|
+
}
|
|
61
|
+
return bearerFetch(joinUrl(cfg.apiUrl, `/admin/api/projects/${cfg.projectId}/push/credentials`), cfg.token, {
|
|
62
|
+
body: JSON.stringify({ provider, config, secret }),
|
|
63
|
+
method: 'PUT',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export async function pushCredsDelete(cfg, provider) {
|
|
67
|
+
await bearerFetch(joinUrl(cfg.apiUrl, `/admin/api/projects/${cfg.projectId}/push/credentials/${provider}`), cfg.token, { method: 'DELETE' });
|
|
68
|
+
}
|
|
69
|
+
export async function pushSend(cfg, opts) {
|
|
70
|
+
const payload = {
|
|
71
|
+
to: opts.to,
|
|
72
|
+
title: opts.title,
|
|
73
|
+
body: opts.body,
|
|
74
|
+
data: opts.data,
|
|
75
|
+
idempotencyKey: opts.idempotencyKey,
|
|
76
|
+
};
|
|
77
|
+
if (opts.priority || opts.ttl != null) {
|
|
78
|
+
payload.options = { priority: opts.priority, ttl: opts.ttl };
|
|
79
|
+
}
|
|
80
|
+
const resp = await bearerFetch(joinUrl(cfg.apiUrl, '/v1/push/send'), cfg.token, {
|
|
81
|
+
body: JSON.stringify(payload),
|
|
82
|
+
method: 'POST',
|
|
83
|
+
});
|
|
84
|
+
if (!resp.tickets?.length) {
|
|
85
|
+
throw new Error('server returned no tickets');
|
|
86
|
+
}
|
|
87
|
+
return resp.tickets[0];
|
|
88
|
+
}
|
|
89
|
+
export async function pushReceipt(cfg, sendId) {
|
|
90
|
+
return bearerFetch(joinUrl(cfg.apiUrl, `/v1/push/receipts/${encodeURIComponent(sendId)}`), cfg.token);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=push.js.map
|
package/lib/push.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.js","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,qEAAqE;AACrE,oEAAoE;AACpE,kCAAkC;AAClC,EAAE;AACF,6DAA6D;AAC7D,6DAA6D;AAC7D,wFAAwF;AACxF,wFAAwF;AACxF,iFAAiF;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAwBtC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE5E,SAAS,OAAO,CAAC,IAAY,EAAE,IAAY;IACzC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,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,EACtE,GAAG,CAAC,KAAK,CACV,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Resolve `react-native/scripts/compose-source-maps.js` from the
|
|
2
|
+
* current project's node_modules. Returns null if react-native isn't
|
|
3
|
+
* installed or the version doesn't ship that script. */
|
|
4
|
+
export declare function resolveComposeScript(fromDir?: string): null | string;
|
|
5
|
+
/** Compose a Metro packager source map + a Hermes source map into a
|
|
6
|
+
* single map (a temp file the caller is responsible for deleting).
|
|
7
|
+
* Throws if react-native's compose script can't be found or fails. */
|
|
8
|
+
export declare function composeSourceMaps(metroMap: string, hermesMap: string): string;
|
|
9
|
+
export type RnUploadOptions = {
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
/** Optional bundle file (.jsbundle / .bundle) to upload alongside the map. */
|
|
12
|
+
bundle?: string;
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
hermesMap: string;
|
|
15
|
+
metroMap: string;
|
|
16
|
+
release: string;
|
|
17
|
+
token: string;
|
|
18
|
+
};
|
|
19
|
+
/** Compose the Metro + Hermes maps, then upload the result (and the
|
|
20
|
+
* bundle, if given). Cleans up the temp composed map. */
|
|
21
|
+
export declare function reactNativeUpload(opts: RnUploadOptions): Promise<{
|
|
22
|
+
files: string[];
|
|
23
|
+
uploaded?: number;
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAQA;;yDAEyD;AACzD,wBAAgB,oBAAoB,CAAC,OAAO,SAAgB,GAAG,IAAI,GAAG,MAAM,CAc3E;AAED;;uEAEuE;AACvE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAkB7E;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;0DAC0D;AAC1D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC;IACtE,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAC,CAoBD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { uploadSourcemaps } from './upload.js';
|
|
7
|
+
/** Resolve `react-native/scripts/compose-source-maps.js` from the
|
|
8
|
+
* current project's node_modules. Returns null if react-native isn't
|
|
9
|
+
* installed or the version doesn't ship that script. */
|
|
10
|
+
export function resolveComposeScript(fromDir = process.cwd()) {
|
|
11
|
+
const req = createRequire(join(fromDir, 'noop.js'));
|
|
12
|
+
for (const id of [
|
|
13
|
+
'react-native/scripts/compose-source-maps.js',
|
|
14
|
+
'@react-native/community-cli-plugin/dist/utils/composeSourceMaps.js',
|
|
15
|
+
]) {
|
|
16
|
+
try {
|
|
17
|
+
const p = req.resolve(id);
|
|
18
|
+
if (existsSync(p))
|
|
19
|
+
return p;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// try next
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/** Compose a Metro packager source map + a Hermes source map into a
|
|
28
|
+
* single map (a temp file the caller is responsible for deleting).
|
|
29
|
+
* Throws if react-native's compose script can't be found or fails. */
|
|
30
|
+
export function composeSourceMaps(metroMap, hermesMap) {
|
|
31
|
+
for (const p of [metroMap, hermesMap]) {
|
|
32
|
+
if (!existsSync(p))
|
|
33
|
+
throw new Error(`no such file: ${p}`);
|
|
34
|
+
}
|
|
35
|
+
const script = resolveComposeScript();
|
|
36
|
+
if (!script) {
|
|
37
|
+
throw new Error("couldn't find react-native's compose-source-maps.js — install react-native, or " +
|
|
38
|
+
'compose the maps yourself and use `sentori-cli upload sourcemap <composed.map>`');
|
|
39
|
+
}
|
|
40
|
+
const out = join(mkdtempSync(join(tmpdir(), 'sentori-rn-')), 'composed.map');
|
|
41
|
+
const r = spawnSync('node', [script, metroMap, hermesMap, '-o', out], { stdio: 'inherit' });
|
|
42
|
+
if (r.status !== 0) {
|
|
43
|
+
throw new Error(`compose-source-maps.js exited with ${r.status ?? 'signal'}`);
|
|
44
|
+
}
|
|
45
|
+
if (!existsSync(out))
|
|
46
|
+
throw new Error('compose-source-maps.js produced no output');
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** Compose the Metro + Hermes maps, then upload the result (and the
|
|
50
|
+
* bundle, if given). Cleans up the temp composed map. */
|
|
51
|
+
export async function reactNativeUpload(opts) {
|
|
52
|
+
const composed = composeSourceMaps(opts.metroMap, opts.hermesMap);
|
|
53
|
+
try {
|
|
54
|
+
const paths = [composed, ...(opts.bundle ? [opts.bundle] : [])];
|
|
55
|
+
const r = await uploadSourcemaps({
|
|
56
|
+
apiUrl: opts.apiUrl,
|
|
57
|
+
dryRun: opts.dryRun,
|
|
58
|
+
paths,
|
|
59
|
+
release: opts.release,
|
|
60
|
+
token: opts.token,
|
|
61
|
+
});
|
|
62
|
+
return { files: r.files, uploaded: r.uploaded };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
try {
|
|
66
|
+
rmSync(composed, { force: true });
|
|
67
|
+
rmSync(join(composed, '..'), { force: true, recursive: true });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// best-effort cleanup
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C;;yDAEyD;AACzD,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE;IAC1D,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAA;IACnD,KAAK,MAAM,EAAE,IAAI;QACf,6CAA6C;QAC7C,oEAAoE;KACrE,EAAE,CAAC;QACF,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YACzB,IAAI,UAAU,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAA;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;uEAEuE;AACvE,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,SAAiB;IACnE,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,CAAC,CA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nB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAA;QACF,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;IACjD,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YACjC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,sBAAsB;QACxB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AdminUpload } from './native-artifacts.js';
|
|
2
|
+
export type SourceBundleUploadOptions = AdminUpload & {
|
|
3
|
+
/** v1.4 W26 — optional module label so polyrepo apps (main +
|
|
4
|
+
* watch ext + share ext etc.) can upload multiple bundles per
|
|
5
|
+
* (release, platform). Empty/undefined → unlabelled single
|
|
6
|
+
* bundle (v1.3 W15 behaviour). */
|
|
7
|
+
module?: string;
|
|
8
|
+
/** Pre-built tar.gz archive of the project's source tree. */
|
|
9
|
+
path: string;
|
|
10
|
+
platform: 'android' | 'ios';
|
|
11
|
+
};
|
|
12
|
+
export type SourceBundleUploadResult = {
|
|
13
|
+
contentHash: string;
|
|
14
|
+
kind: string;
|
|
15
|
+
sizeBytes: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function uploadSourceBundle(opts: SourceBundleUploadOptions): Promise<SourceBundleUploadResult>;
|
|
18
|
+
/** Walk `dir`, pick platform-relevant source files, and tar.gz them
|
|
19
|
+
* into a temp file. Caller is responsible for invoking `cleanup()`.
|
|
20
|
+
* Uses the system `tar` binary; that's portable enough on macOS +
|
|
21
|
+
* Linux + WSL, which covers every realistic CI environment Sentori
|
|
22
|
+
* ships to. Native Windows CI without WSL would need to gzip the
|
|
23
|
+
* archive themselves (the pre-built-path mode still works). */
|
|
24
|
+
export declare function buildSourceBundleFromDir(dir: string, platform: 'android' | 'ios'): Promise<{
|
|
25
|
+
cleanup: () => Promise<void>;
|
|
26
|
+
path: string;
|
|
27
|
+
}>;
|
|
28
|
+
//# sourceMappingURL=source-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-bundle.d.ts","sourceRoot":"","sources":["../src/source-bundle.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAyBxD,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG;IACpD;;;uCAGmC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,SAAS,GAAG,KAAK,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,wBAAwB,CAAC,CA6BnC;AAuDD;;;;;gEAKgE;AAChE,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,GAAG,KAAK,GAC1B,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAuCzD"}
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|