@parall/cli 1.66.0 → 1.68.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/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/apps-db.d.ts +8 -0
- package/dist/commands/apps-db.d.ts.map +1 -0
- package/dist/commands/apps-db.js +17 -0
- package/dist/commands/apps-publish.d.ts +23 -0
- package/dist/commands/apps-publish.d.ts.map +1 -0
- package/dist/commands/apps-publish.js +288 -0
- package/dist/commands/apps-scaffold.d.ts +9 -0
- package/dist/commands/apps-scaffold.d.ts.map +1 -0
- package/dist/commands/apps-scaffold.js +379 -0
- package/dist/commands/apps.d.ts +12 -0
- package/dist/commands/apps.d.ts.map +1 -0
- package/dist/commands/apps.js +172 -0
- package/dist/commands/clip.d.ts.map +1 -1
- package/dist/commands/clip.js +55 -10
- package/dist/commands/db-plane.d.ts +41 -0
- package/dist/commands/db-plane.d.ts.map +1 -0
- package/dist/commands/db-plane.js +237 -0
- package/dist/commands/dbs.d.ts +16 -0
- package/dist/commands/dbs.d.ts.map +1 -0
- package/dist/commands/dbs.js +147 -0
- package/dist/commands/triggers.d.ts +14 -1
- package/dist/commands/triggers.d.ts.map +1 -1
- package/dist/commands/triggers.js +64 -0
- package/dist/commands/watch.d.ts +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +21 -11
- package/dist/commands/wiki-changesets.d.ts +3 -0
- package/dist/commands/wiki-changesets.d.ts.map +1 -0
- package/dist/commands/wiki-changesets.js +176 -0
- package/dist/commands/wiki.d.ts.map +1 -1
- package/dist/commands/wiki.js +4 -173
- package/dist/index.js +20 -16
- package/dist/lib/wiki-tool-definition.d.ts +23 -0
- package/dist/lib/wiki-tool-definition.d.ts.map +1 -0
- package/dist/lib/wiki-tool-definition.js +17 -0
- package/dist/lib/wiki-tools.d.ts +2 -24
- package/dist/lib/wiki-tools.d.ts.map +1 -1
- package/dist/lib/wiki-tools.js +11 -16
- package/package.json +6 -4
|
@@ -36,6 +36,8 @@ export declare function redactCreateAgentResponse(result: CreateAgentResponse, o
|
|
|
36
36
|
api_key_discarded: boolean | undefined;
|
|
37
37
|
user: import("@parall/sdk").User;
|
|
38
38
|
machine?: Machine;
|
|
39
|
+
teams?: import("@parall/sdk").CreateAgentMembershipOutcome[];
|
|
40
|
+
chats?: import("@parall/sdk").CreateAgentMembershipOutcome[];
|
|
39
41
|
}>;
|
|
40
42
|
export declare class ProvisioningWaitError extends Error {
|
|
41
43
|
readonly phase: 'machine' | 'agent_online';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAEV,aAAa,EAEb,mBAAmB,EACnB,OAAO,EACP,YAAY,EAEb,MAAM,aAAa,CAAC;AAuCrB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAMnF;AAED;0EAC0E;AAC1E,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGzF;AAYD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,GAAG,SAAS,CAQrB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,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M,EACb,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC7C,OAAO,CAAC,aAAa,CAAC,CASxB;AA6CD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QA+brD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
export { parseParams } from './db-plane.js';
|
|
3
|
+
/** `parall app db …`: the app alias of the data plane — the same operations
|
|
4
|
+
* as `parall db …` on the app's Database, with the app recorded on every
|
|
5
|
+
* log row; the same construction-surface rule applies (attached-app author
|
|
6
|
+
* or org owner/admin). Writes through an archived app are refused. */
|
|
7
|
+
export declare function registerAppDBCommands(app: Command): void;
|
|
8
|
+
//# sourceMappingURL=apps-db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-db.d.ts","sourceRoot":"","sources":["../../src/commands/apps-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;sEAGsE;AACtE,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,QASjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { stripPrllScheme } from '../lib/output.js';
|
|
2
|
+
import { registerDataPlaneCommands } from './db-plane.js';
|
|
3
|
+
export { parseParams } from './db-plane.js';
|
|
4
|
+
/** `parall app db …`: the app alias of the data plane — the same operations
|
|
5
|
+
* as `parall db …` on the app's Database, with the app recorded on every
|
|
6
|
+
* log row; the same construction-surface rule applies (attached-app author
|
|
7
|
+
* or org owner/admin). Writes through an archived app are refused. */
|
|
8
|
+
export function registerAppDBCommands(app) {
|
|
9
|
+
const db = app
|
|
10
|
+
.command('db')
|
|
11
|
+
.description("Query and change an app's Database (alias of `parall db`)");
|
|
12
|
+
registerDataPlaneCommands(db, {
|
|
13
|
+
flag: '--app <appId>',
|
|
14
|
+
flagHelp: 'App ID (app_… or prll://app_…)',
|
|
15
|
+
resolve: async (_ctx, opts) => ({ kind: 'app', id: stripPrllScheme(opts.app ?? '') }),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/** `parall app publish / versions / rollback / pull` (design §7.3): the
|
|
3
|
+
* agent's machine builds, the platform accepts. publish = tar the dist and
|
|
4
|
+
* the source, reserve a seq, PUT both content-addressed tarballs, finalize
|
|
5
|
+
* (server-side acceptance). Versions are immutable; rollback only moves
|
|
6
|
+
* the served pointer. */
|
|
7
|
+
export declare function registerAppPublishCommands(app: Command): void;
|
|
8
|
+
interface Packed {
|
|
9
|
+
tarPath: string;
|
|
10
|
+
sha256: string;
|
|
11
|
+
/** Uncompressed file bytes (what the server re-counts at acceptance). */
|
|
12
|
+
totalSize: number;
|
|
13
|
+
fileCount: number;
|
|
14
|
+
}
|
|
15
|
+
/** packDirectory writes dir as a deterministic tar.gz (sorted paths, fixed
|
|
16
|
+
* mtime/uid so the same tree always hashes the same → content addressing
|
|
17
|
+
* can reuse uploads). */
|
|
18
|
+
declare function packDirectory(dir: string, opts: {
|
|
19
|
+
excludeDefaults: boolean;
|
|
20
|
+
}): Promise<Packed>;
|
|
21
|
+
declare function extractTarGz(bytes: Buffer, out: string): Promise<void>;
|
|
22
|
+
export { extractTarGz, packDirectory };
|
|
23
|
+
//# sourceMappingURL=apps-publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-publish.d.ts","sourceRoot":"","sources":["../../src/commands/apps-publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC;;;;yBAIyB;AACzB,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,QA4ItD;AAgCD,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;yBAEyB;AACzB,iBAAe,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,eAAe,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA8D7F;AA4BD,iBAAe,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCrE;AAGD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { once } from 'node:events';
|
|
3
|
+
import { createReadStream, createWriteStream, promises as fs } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
import { createGunzip, createGzip } from 'node:zlib';
|
|
8
|
+
import * as tar from 'tar-stream';
|
|
9
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
10
|
+
import { printError, printJson, stripPrllScheme } from '../lib/output.js';
|
|
11
|
+
/** `parall app publish / versions / rollback / pull` (design §7.3): the
|
|
12
|
+
* agent's machine builds, the platform accepts. publish = tar the dist and
|
|
13
|
+
* the source, reserve a seq, PUT both content-addressed tarballs, finalize
|
|
14
|
+
* (server-side acceptance). Versions are immutable; rollback only moves
|
|
15
|
+
* the served pointer. */
|
|
16
|
+
export function registerAppPublishCommands(app) {
|
|
17
|
+
app
|
|
18
|
+
.command('publish')
|
|
19
|
+
.description("Publish a built bundle directory as a new version (the app's author or an org owner/admin)")
|
|
20
|
+
.argument('<dir>', 'The built bundle directory (index.html + manifest.json at its root)')
|
|
21
|
+
.requiredOption('--app <appId>', 'App ID')
|
|
22
|
+
.option('--source <dir>', 'Source directory to archive for `app pull` (default: the bundle dir)')
|
|
23
|
+
.option('--notes <text>', 'Version notes')
|
|
24
|
+
.option('--preview', 'Become ready without moving the served pointer')
|
|
25
|
+
.action(async (dir, opts) => {
|
|
26
|
+
try {
|
|
27
|
+
const ctx = resolveCredentials();
|
|
28
|
+
const appId = stripPrllScheme(opts.app);
|
|
29
|
+
const dist = resolve(dir);
|
|
30
|
+
await assertBundleRoot(dist);
|
|
31
|
+
const srcDir = resolve(opts.source ?? dir);
|
|
32
|
+
const bundle = await packDirectory(dist, { excludeDefaults: false });
|
|
33
|
+
// Everything after the first archive exists runs inside the cleanup
|
|
34
|
+
// scope, so a failure packing the source cannot leave the bundle
|
|
35
|
+
// archive behind in the temp directory.
|
|
36
|
+
let source;
|
|
37
|
+
try {
|
|
38
|
+
source = await packDirectory(srcDir, { excludeDefaults: true });
|
|
39
|
+
// The server refuses these at finalize (the presigned PUT cannot
|
|
40
|
+
// bound a size); failing here saves the upload and a seq.
|
|
41
|
+
await assertArchiveSize('bundle', bundle.tarPath, BUNDLE_ARCHIVE_MAX_BYTES);
|
|
42
|
+
await assertArchiveSize('source', source.tarPath, SOURCE_ARCHIVE_MAX_BYTES);
|
|
43
|
+
const begin = await ctx.client.beginMiniAppPublish(ctx.orgId, appId, {
|
|
44
|
+
bundle_sha256: bundle.sha256,
|
|
45
|
+
source_sha256: source.sha256,
|
|
46
|
+
size_bytes: bundle.totalSize,
|
|
47
|
+
file_count: bundle.fileCount,
|
|
48
|
+
notes: opts.notes,
|
|
49
|
+
preview: Boolean(opts.preview),
|
|
50
|
+
});
|
|
51
|
+
console.error(`Reserved version ${begin.seq} (bundle ${bundle.fileCount} files / ${bundle.totalSize} bytes)`);
|
|
52
|
+
await uploadArtifact('bundle', begin.bundle, bundle.tarPath);
|
|
53
|
+
await uploadArtifact('source', begin.source, source.tarPath);
|
|
54
|
+
const version = await ctx.client.finalizeMiniAppPublish(ctx.orgId, appId, begin.seq);
|
|
55
|
+
printJson(version);
|
|
56
|
+
console.error(version.is_preview
|
|
57
|
+
? `Preview version ${version.seq} is ready (the served pointer did not move)`
|
|
58
|
+
: version.current
|
|
59
|
+
? `Version ${version.seq} is ready and serving`
|
|
60
|
+
: `Version ${version.seq} is ready but not serving (a newer version, or an explicit rollback made while it was in flight, holds the pointer); \`parall app rollback --app ${appId} --to ${version.seq}\` serves it`);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await fs.rm(bundle.tarPath, { force: true });
|
|
64
|
+
if (source)
|
|
65
|
+
await fs.rm(source.tarPath, { force: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
printError(err);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
app
|
|
73
|
+
.command('versions')
|
|
74
|
+
.description("List an app's versions, newest first")
|
|
75
|
+
.argument('<appId>', 'App ID')
|
|
76
|
+
.option('--limit <n>', 'Versions to return (default 50)')
|
|
77
|
+
.action(async (appId, opts) => {
|
|
78
|
+
try {
|
|
79
|
+
const { client, orgId } = resolveCredentials();
|
|
80
|
+
printJson(await client.getMiniAppVersions(orgId, stripPrllScheme(appId), opts.limit ? Number(opts.limit) : undefined));
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
printError(err);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
app
|
|
87
|
+
.command('rollback')
|
|
88
|
+
.description("Point the app back at an existing ready version (the app's author or an org owner/admin)")
|
|
89
|
+
.requiredOption('--app <appId>', 'App ID')
|
|
90
|
+
.requiredOption('--to <seq>', 'Version seq to serve')
|
|
91
|
+
.action(async (opts) => {
|
|
92
|
+
try {
|
|
93
|
+
const { client, orgId } = resolveCredentials();
|
|
94
|
+
printJson(await client.rollbackMiniApp(orgId, stripPrllScheme(opts.app), Number(opts.to)));
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
printError(err);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
app
|
|
101
|
+
.command('pull')
|
|
102
|
+
.description("Download a version's source tarball and unpack it (the app's author or an org owner/admin)")
|
|
103
|
+
.argument('<appId>', 'App ID')
|
|
104
|
+
.option('--v <seq>', 'Version seq (default: the current served version)')
|
|
105
|
+
.requiredOption('--out <dir>', 'Directory to unpack into (created; must be empty or absent)')
|
|
106
|
+
.action(async (appId, opts) => {
|
|
107
|
+
try {
|
|
108
|
+
const ctx = resolveCredentials();
|
|
109
|
+
const id = stripPrllScheme(appId);
|
|
110
|
+
let seq = opts.v ? Number(opts.v) : 0;
|
|
111
|
+
if (!seq) {
|
|
112
|
+
const appInfo = await ctx.client.getMiniApp(ctx.orgId, id);
|
|
113
|
+
seq = appInfo.current_version_seq;
|
|
114
|
+
if (!seq)
|
|
115
|
+
throw new Error('The app has no published version yet; pass --v <seq>');
|
|
116
|
+
}
|
|
117
|
+
const { url, source_sha256 } = await ctx.client.getMiniAppVersionSource(ctx.orgId, id, seq);
|
|
118
|
+
const out = resolve(opts.out);
|
|
119
|
+
await fs.mkdir(out, { recursive: true });
|
|
120
|
+
if ((await fs.readdir(out)).length > 0) {
|
|
121
|
+
throw new Error(`--out ${out} is not empty`);
|
|
122
|
+
}
|
|
123
|
+
const response = await fetch(url);
|
|
124
|
+
if (!response.ok || !response.body) {
|
|
125
|
+
throw new Error(`source download failed: ${response.status} ${response.statusText}`);
|
|
126
|
+
}
|
|
127
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
128
|
+
const digest = createHash('sha256').update(bytes).digest('hex');
|
|
129
|
+
if (digest !== source_sha256) {
|
|
130
|
+
throw new Error(`source tarball digest ${digest} does not match the recorded ${source_sha256}`);
|
|
131
|
+
}
|
|
132
|
+
await extractTarGz(bytes, out);
|
|
133
|
+
console.error(`Pulled version ${seq} source into ${out}`);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
printError(err);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function assertBundleRoot(dist) {
|
|
141
|
+
for (const required of ['index.html', 'manifest.json']) {
|
|
142
|
+
try {
|
|
143
|
+
await fs.access(join(dist, required));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
throw new Error(`${dist} has no ${required} at its root — publish the BUILT bundle directory`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Anything a source tree drags along that is never source. */
|
|
151
|
+
const sourceExcludes = new Set(['node_modules', '.git', 'dist', '.DS_Store']);
|
|
152
|
+
// Mirrors the server's archive caps (model.MiniAppBundleArchiveMaxBytes /
|
|
153
|
+
// MiniAppSourceArchiveMaxBytes).
|
|
154
|
+
const BUNDLE_ARCHIVE_MAX_BYTES = 22 * 1024 * 1024;
|
|
155
|
+
const SOURCE_ARCHIVE_MAX_BYTES = 50 * 1024 * 1024;
|
|
156
|
+
async function assertArchiveSize(kind, tarPath, max) {
|
|
157
|
+
const { size } = await fs.stat(tarPath);
|
|
158
|
+
if (size > max) {
|
|
159
|
+
throw new Error(`${kind} archive is ${size} bytes, over the ${max}-byte cap` +
|
|
160
|
+
(kind === 'source' ? ' — pass --source <dir> to archive only the app source' : ''));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** packDirectory writes dir as a deterministic tar.gz (sorted paths, fixed
|
|
164
|
+
* mtime/uid so the same tree always hashes the same → content addressing
|
|
165
|
+
* can reuse uploads). */
|
|
166
|
+
async function packDirectory(dir, opts) {
|
|
167
|
+
const files = [];
|
|
168
|
+
const walk = async (current) => {
|
|
169
|
+
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
170
|
+
if (opts.excludeDefaults && sourceExcludes.has(entry.name))
|
|
171
|
+
continue;
|
|
172
|
+
const full = join(current, entry.name);
|
|
173
|
+
if (entry.isDirectory()) {
|
|
174
|
+
await walk(full);
|
|
175
|
+
}
|
|
176
|
+
else if (entry.isFile()) {
|
|
177
|
+
files.push(full);
|
|
178
|
+
}
|
|
179
|
+
else if (entry.isSymbolicLink()) {
|
|
180
|
+
throw new Error(`symlinks are not allowed in a bundle/source archive: ${full}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
await walk(dir);
|
|
185
|
+
files.sort();
|
|
186
|
+
if (files.length === 0) {
|
|
187
|
+
throw new Error(`${dir} is empty`);
|
|
188
|
+
}
|
|
189
|
+
const pack = tar.pack();
|
|
190
|
+
const tarPath = join(tmpdir(), `parall-app-${Date.now()}-${Math.random().toString(36).slice(2)}.tar.gz`);
|
|
191
|
+
const hash = createHash('sha256');
|
|
192
|
+
let totalSize = 0;
|
|
193
|
+
// The archive file exists once the stream is open. From there every
|
|
194
|
+
// failure removes it: neither tar-stream nor pipeline deletes the file they
|
|
195
|
+
// were writing, and each failed publish would leave up to 22 MiB behind.
|
|
196
|
+
const out = createWriteStream(tarPath);
|
|
197
|
+
await once(out, 'open');
|
|
198
|
+
const done = pipeline(pack, createGzip({ level: 9, mtime: 0 }), async function* (chunks) {
|
|
199
|
+
for await (const chunk of chunks) {
|
|
200
|
+
hash.update(chunk);
|
|
201
|
+
yield chunk;
|
|
202
|
+
}
|
|
203
|
+
}, out);
|
|
204
|
+
// Awaited below; a write failure while entries are still being fed must
|
|
205
|
+
// not surface as an unhandled rejection first.
|
|
206
|
+
done.catch(() => { });
|
|
207
|
+
try {
|
|
208
|
+
for (const full of files) {
|
|
209
|
+
const rel = relative(dir, full).split(sep).join('/');
|
|
210
|
+
const body = await fs.readFile(full);
|
|
211
|
+
totalSize += body.length;
|
|
212
|
+
pack.entry({ name: rel, size: body.length, mode: 0o644, mtime: new Date(0) }, body);
|
|
213
|
+
}
|
|
214
|
+
pack.finalize();
|
|
215
|
+
await done;
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
pack.destroy(err);
|
|
219
|
+
await done.catch(() => { });
|
|
220
|
+
await fs.rm(tarPath, { force: true, maxRetries: 3 });
|
|
221
|
+
throw err;
|
|
222
|
+
}
|
|
223
|
+
return { tarPath, sha256: hash.digest('hex'), totalSize, fileCount: files.length };
|
|
224
|
+
}
|
|
225
|
+
async function uploadArtifact(label, upload, tarPath) {
|
|
226
|
+
if (upload.exists || !upload.url) {
|
|
227
|
+
console.error(`${label}: content already stored (same digest), skipping upload`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const body = await fs.readFile(tarPath);
|
|
231
|
+
const response = await fetch(upload.url, {
|
|
232
|
+
method: 'PUT',
|
|
233
|
+
headers: { 'Content-Type': 'application/gzip', ...(upload.headers ?? {}) },
|
|
234
|
+
body,
|
|
235
|
+
});
|
|
236
|
+
// 412 = the conditional create lost to an identical object: content
|
|
237
|
+
// addressing makes that success.
|
|
238
|
+
if (!response.ok && response.status !== 412) {
|
|
239
|
+
const text = await response.text().catch(() => '');
|
|
240
|
+
throw new Error(`${label} upload failed: ${response.status} ${response.statusText} ${text.slice(0, 300)}`);
|
|
241
|
+
}
|
|
242
|
+
console.error(`${label}: uploaded ${body.length} bytes`);
|
|
243
|
+
}
|
|
244
|
+
async function extractTarGz(bytes, out) {
|
|
245
|
+
const extract = tar.extract();
|
|
246
|
+
const donePromise = new Promise((resolveDone, rejectDone) => {
|
|
247
|
+
extract.on('entry', (header, stream, next) => {
|
|
248
|
+
void (async () => {
|
|
249
|
+
try {
|
|
250
|
+
const name = header.name.replace(/^\.\//, '');
|
|
251
|
+
const target = resolve(out, name);
|
|
252
|
+
if (!target.startsWith(out + sep) && target !== out) {
|
|
253
|
+
throw new Error(`archive entry escapes the target directory: ${header.name}`);
|
|
254
|
+
}
|
|
255
|
+
if (header.type === 'directory') {
|
|
256
|
+
await fs.mkdir(target, { recursive: true });
|
|
257
|
+
stream.resume();
|
|
258
|
+
}
|
|
259
|
+
else if (header.type === 'file') {
|
|
260
|
+
await fs.mkdir(resolve(target, '..'), { recursive: true });
|
|
261
|
+
const chunks = [];
|
|
262
|
+
for await (const chunk of stream)
|
|
263
|
+
chunks.push(chunk);
|
|
264
|
+
await fs.writeFile(target, Buffer.concat(chunks));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
throw new Error(`archive entry ${header.name} is not a regular file`);
|
|
268
|
+
}
|
|
269
|
+
next();
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
rejectDone(err);
|
|
273
|
+
stream.resume();
|
|
274
|
+
}
|
|
275
|
+
})();
|
|
276
|
+
});
|
|
277
|
+
extract.on('finish', () => resolveDone());
|
|
278
|
+
extract.on('error', rejectDone);
|
|
279
|
+
});
|
|
280
|
+
const gunzip = createGunzip();
|
|
281
|
+
gunzip.end(bytes);
|
|
282
|
+
await Promise.all([pipeline(gunzip, extract), donePromise]);
|
|
283
|
+
}
|
|
284
|
+
// Re-exported for `app pull` tests.
|
|
285
|
+
export { extractTarGz, packDirectory };
|
|
286
|
+
// createReadStream is imported for future streaming uploads of large
|
|
287
|
+
// bundles; the 20 MiB cap makes buffering acceptable today.
|
|
288
|
+
void createReadStream;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/** `parall app init` (the fixed scaffold, design §7.4 v1) and `parall app
|
|
3
|
+
* dev` (a local host page speaking the same bridge shell, for自测 by eye).
|
|
4
|
+
* The scaffold is Vite + React + TS with the bridge shell wired; Tailwind /
|
|
5
|
+
* shadcn presets arrive with the authoring-skill slice. The shell is
|
|
6
|
+
* vendored into the scaffold (src/parall.ts) until @parall/miniapp-sdk is
|
|
7
|
+
* on npm; it is the same code, @parall/miniapp-sdk stays the SSOT. */
|
|
8
|
+
export declare function registerAppScaffoldCommands(app: Command): void;
|
|
9
|
+
//# sourceMappingURL=apps-scaffold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/apps-scaffold.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC;;;;;sEAKsE;AACtE,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,QAkEvD"}
|