@p11-core/cli 0.0.9 → 0.0.10
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/index.js +62 -16
- package/docs/index.md +5 -2
- package/examples/all-components.tsx +3 -3
- package/examples/minimal.tsx +21 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3521,7 +3521,12 @@ var docsTopics = /* @__PURE__ */ new Map([
|
|
|
3521
3521
|
["components", "docs/components.md"],
|
|
3522
3522
|
["sharing", "docs/sharing.md"]
|
|
3523
3523
|
]);
|
|
3524
|
-
var exampleFiles = /* @__PURE__ */ new Map([
|
|
3524
|
+
var exampleFiles = /* @__PURE__ */ new Map([
|
|
3525
|
+
["minimal", "examples/minimal.tsx"],
|
|
3526
|
+
["all", "examples/all-components.tsx"],
|
|
3527
|
+
["all-components", "examples/all-components.tsx"]
|
|
3528
|
+
]);
|
|
3529
|
+
var publicExampleNames = ["minimal", "all"];
|
|
3525
3530
|
var allowedDocumentComponents = /* @__PURE__ */ new Set([
|
|
3526
3531
|
"Document",
|
|
3527
3532
|
"Page",
|
|
@@ -3646,6 +3651,12 @@ function createCliProgram(options = {}) {
|
|
|
3646
3651
|
"after",
|
|
3647
3652
|
`
|
|
3648
3653
|
|
|
3654
|
+
Examples:
|
|
3655
|
+
p11 example minimal --output ./page.tsx
|
|
3656
|
+
p11 example all
|
|
3657
|
+
p11 share ./page.tsx
|
|
3658
|
+
p11 docs components
|
|
3659
|
+
|
|
3649
3660
|
Environment:
|
|
3650
3661
|
P11_API_URL Defaults to ${builtDefaultApiUrl}
|
|
3651
3662
|
P11_BUILD_DIR Directory for temporary share build files. Defaults to the OS temp directory.`
|
|
@@ -3673,7 +3684,7 @@ Environment:
|
|
|
3673
3684
|
await docs(topic);
|
|
3674
3685
|
});
|
|
3675
3686
|
allowLegacyParserBehavior(docsCommand);
|
|
3676
|
-
const exampleCommand = program2.command("example").description("Print or write a p11 example document.").argument("[name]", "Example name: all
|
|
3687
|
+
const exampleCommand = program2.command("example").description("Print or write a p11 example document.").argument("[name]", "Example name: minimal or all.").option("--output [file]", "Write the example to a file.").action(async (name, options2) => {
|
|
3677
3688
|
await example(name, normalizeExampleOptions(options2));
|
|
3678
3689
|
});
|
|
3679
3690
|
allowLegacyParserBehavior(exampleCommand);
|
|
@@ -3749,7 +3760,7 @@ async function publish(input, options) {
|
|
|
3749
3760
|
const url = editTarget ? new URL(`/api/edit/${encodeURIComponent(editTarget.editId)}/page`, apiUrl) : new URL("/api/pages", apiUrl);
|
|
3750
3761
|
const uploadBody = new ArrayBuffer(zipBytes.byteLength);
|
|
3751
3762
|
new Uint8Array(uploadBody).set(zipBytes);
|
|
3752
|
-
const response = await
|
|
3763
|
+
const response = await fetchForOperation("Share", url, {
|
|
3753
3764
|
method: "POST",
|
|
3754
3765
|
headers: {
|
|
3755
3766
|
"content-type": "application/zip"
|
|
@@ -3770,19 +3781,26 @@ async function publish(input, options) {
|
|
|
3770
3781
|
if (options.json) {
|
|
3771
3782
|
console.log(JSON.stringify(data, null, 2));
|
|
3772
3783
|
} else {
|
|
3773
|
-
|
|
3774
|
-
if (data.editUrl) console.log(`editUrl: ${data.editUrl}`);
|
|
3775
|
-
if (data.docId) console.log(`docId: ${data.docId}`);
|
|
3776
|
-
if (data.readId) console.log(`readId: ${data.readId}`);
|
|
3777
|
-
if (data.editId) console.log(`editId: ${data.editId}`);
|
|
3778
|
-
if (data.version) console.log(`version: ${data.version}`);
|
|
3779
|
-
if (data.latestVersion) console.log(`latestVersion: ${data.latestVersion}`);
|
|
3780
|
-
if (data.createdAt) console.log(`createdAt: ${data.createdAt}`);
|
|
3784
|
+
for (const line of publishOutputLines(data)) console.log(line);
|
|
3781
3785
|
}
|
|
3782
3786
|
} finally {
|
|
3783
3787
|
if (cleanupDir) await rm(cleanupDir, { recursive: true, force: true });
|
|
3784
3788
|
}
|
|
3785
3789
|
}
|
|
3790
|
+
function publishOutputLines(data) {
|
|
3791
|
+
const lines = [];
|
|
3792
|
+
const readUrl = data.readUrl ?? data.url;
|
|
3793
|
+
if (readUrl) lines.push(`readUrl: ${readUrl}`);
|
|
3794
|
+
if (data.editUrl) lines.push(`editUrl: ${data.editUrl}`);
|
|
3795
|
+
if (readUrl && data.editUrl) lines.push("Note: share readUrl for comments; keep editUrl private for updates and deletion.");
|
|
3796
|
+
if (data.docId) lines.push(`docId: ${data.docId}`);
|
|
3797
|
+
if (data.readId) lines.push(`readId: ${data.readId}`);
|
|
3798
|
+
if (data.editId) lines.push(`editId: ${data.editId}`);
|
|
3799
|
+
if (data.version) lines.push(`version: ${data.version}`);
|
|
3800
|
+
if (data.latestVersion) lines.push(`latestVersion: ${data.latestVersion}`);
|
|
3801
|
+
if (data.createdAt) lines.push(`createdAt: ${data.createdAt}`);
|
|
3802
|
+
return lines;
|
|
3803
|
+
}
|
|
3786
3804
|
async function history(options) {
|
|
3787
3805
|
const entries = await readHistoryEntries();
|
|
3788
3806
|
if (options.json) {
|
|
@@ -3802,14 +3820,15 @@ async function docs(topic) {
|
|
|
3802
3820
|
async function example(name, options) {
|
|
3803
3821
|
if (!name) {
|
|
3804
3822
|
console.log("Available examples:");
|
|
3805
|
-
for (const exampleName of
|
|
3823
|
+
for (const exampleName of publicExampleNames) console.log(` ${exampleName}`);
|
|
3806
3824
|
console.log("");
|
|
3807
|
-
console.log("Usage: p11 example
|
|
3825
|
+
console.log("Usage: p11 example minimal [--output FILE]");
|
|
3826
|
+
console.log(" p11 example all [--output FILE]");
|
|
3808
3827
|
return;
|
|
3809
3828
|
}
|
|
3810
3829
|
const relativePath = exampleFiles.get(name);
|
|
3811
3830
|
if (!relativePath) {
|
|
3812
|
-
throw new Error(`Unknown example: ${name}. Available examples: ${
|
|
3831
|
+
throw new Error(`Unknown example: ${name}. Available examples: ${publicExampleNames.join(", ")}`);
|
|
3813
3832
|
}
|
|
3814
3833
|
const contents = await readCliAsset(relativePath);
|
|
3815
3834
|
if (options.output) {
|
|
@@ -3827,7 +3846,7 @@ async function comments(target, options) {
|
|
|
3827
3846
|
apiUrl: options.apiUrl,
|
|
3828
3847
|
version
|
|
3829
3848
|
});
|
|
3830
|
-
const response = await
|
|
3849
|
+
const response = await fetchForOperation("Fetch comments", url);
|
|
3831
3850
|
const text = await response.text();
|
|
3832
3851
|
if (!response.ok) {
|
|
3833
3852
|
throw new Error(`Fetch comments failed (${response.status}): ${text}`);
|
|
@@ -3850,7 +3869,7 @@ async function deleteDocument(target, options) {
|
|
|
3850
3869
|
const url = deleteApiUrlForTarget(target, {
|
|
3851
3870
|
apiUrl: options.apiUrl
|
|
3852
3871
|
});
|
|
3853
|
-
const response = await
|
|
3872
|
+
const response = await fetchForOperation("Delete", url, {
|
|
3854
3873
|
method: "DELETE"
|
|
3855
3874
|
});
|
|
3856
3875
|
const text = await response.text();
|
|
@@ -4067,9 +4086,34 @@ function responseErrorMessage(text) {
|
|
|
4067
4086
|
}
|
|
4068
4087
|
return text;
|
|
4069
4088
|
}
|
|
4089
|
+
async function fetchForOperation(operation, url, init) {
|
|
4090
|
+
try {
|
|
4091
|
+
return await fetch(url, init);
|
|
4092
|
+
} catch (error) {
|
|
4093
|
+
throw new Error(formatNetworkError(operation, url, error));
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
function formatNetworkError(operation, url, error) {
|
|
4097
|
+
return `${operation} request failed before receiving a response: ${fetchFailureDetails(error)}. API URL: ${url.origin}. ${networkErrorHint()}`;
|
|
4098
|
+
}
|
|
4099
|
+
function fetchFailureDetails(error) {
|
|
4100
|
+
const message = errorMessage(error);
|
|
4101
|
+
const cause = errorCause(error);
|
|
4102
|
+
if (!cause) return message;
|
|
4103
|
+
const causeCode = errorCode(cause);
|
|
4104
|
+
const causeMessage = errorMessage(cause);
|
|
4105
|
+
const causeDetails = causeCode && !causeMessage.includes(causeCode) ? `${causeCode} ${causeMessage}` : causeMessage;
|
|
4106
|
+
return `${message} (cause: ${causeDetails})`;
|
|
4107
|
+
}
|
|
4108
|
+
function networkErrorHint() {
|
|
4109
|
+
return "If running in an agent sandbox, retry with network access outside the sandbox or with escalated network permissions.";
|
|
4110
|
+
}
|
|
4070
4111
|
function errorMessage(error) {
|
|
4071
4112
|
return error instanceof Error ? error.message : String(error);
|
|
4072
4113
|
}
|
|
4114
|
+
function errorCause(error) {
|
|
4115
|
+
return typeof error === "object" && error !== null && "cause" in error ? error.cause : null;
|
|
4116
|
+
}
|
|
4073
4117
|
async function readCliAsset(relativePath) {
|
|
4074
4118
|
return readFile(path.join(cliPackageRoot, relativePath), "utf8");
|
|
4075
4119
|
}
|
|
@@ -4507,10 +4551,12 @@ export {
|
|
|
4507
4551
|
commentsExportJson,
|
|
4508
4552
|
createCliProgram,
|
|
4509
4553
|
deleteApiUrlForTarget,
|
|
4554
|
+
formatNetworkError,
|
|
4510
4555
|
isNewerVersion,
|
|
4511
4556
|
parseCommentsTarget,
|
|
4512
4557
|
parseEditId,
|
|
4513
4558
|
parseReadId,
|
|
4559
|
+
publishOutputLines,
|
|
4514
4560
|
readHistoryEntries,
|
|
4515
4561
|
resolveBuildParentDir,
|
|
4516
4562
|
validatePageSource
|
package/docs/index.md
CHANGED
|
@@ -5,6 +5,8 @@ p11 shares reviewable, public-but-unlisted document pages from React files.
|
|
|
5
5
|
## Common Commands
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
p11 example minimal --output ./page.tsx
|
|
9
|
+
p11 example all
|
|
8
10
|
p11 share <page.tsx>
|
|
9
11
|
p11 share <page.tsx> --edit-url <editUrl>
|
|
10
12
|
p11 history
|
|
@@ -25,8 +27,9 @@ p11 docs sharing
|
|
|
25
27
|
|
|
26
28
|
```bash
|
|
27
29
|
p11 example
|
|
28
|
-
p11 example
|
|
29
|
-
p11 example all
|
|
30
|
+
p11 example minimal --output ./page.tsx
|
|
31
|
+
p11 example all
|
|
32
|
+
p11 example all --output ./all.tsx
|
|
30
33
|
```
|
|
31
34
|
|
|
32
35
|
Use `p11 share --help`, `p11 comments --help`, `p11 delete --help`, and `p11 history --help` for command-specific flags.
|
|
@@ -271,7 +271,7 @@ export default function All() {
|
|
|
271
271
|
<CodeBlock language="json">
|
|
272
272
|
{code`
|
|
273
273
|
{
|
|
274
|
-
"docId": "all
|
|
274
|
+
"docId": "all",
|
|
275
275
|
"version": 2,
|
|
276
276
|
"comments": true,
|
|
277
277
|
"languages": ["typescript", "javascript", "python", "rust", "html", "css", "json", "yaml", "bash"]
|
|
@@ -285,7 +285,7 @@ export default function All() {
|
|
|
285
285
|
<CodeBlock language="yaml">
|
|
286
286
|
{code`
|
|
287
287
|
document:
|
|
288
|
-
id: all
|
|
288
|
+
id: all
|
|
289
289
|
version: 2
|
|
290
290
|
comments: true
|
|
291
291
|
retentionDays: 7
|
|
@@ -307,7 +307,7 @@ export default function All() {
|
|
|
307
307
|
<Heading>14. Bash</Heading>
|
|
308
308
|
<CodeBlock language="bash">
|
|
309
309
|
{code`
|
|
310
|
-
p11 share ./all
|
|
310
|
+
p11 share ./all.tsx
|
|
311
311
|
p11 comments <readUrl> --version 1
|
|
312
312
|
`}
|
|
313
313
|
</CodeBlock>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Document, Heading, Page, Section, Text } from "@p11-core/components";
|
|
2
|
+
|
|
3
|
+
// For the full component set, run:
|
|
4
|
+
// p11 docs components
|
|
5
|
+
// p11 example all
|
|
6
|
+
|
|
7
|
+
export default function Minimal() {
|
|
8
|
+
return (
|
|
9
|
+
<Document mode="page">
|
|
10
|
+
<Page>
|
|
11
|
+
<Section>
|
|
12
|
+
<Heading level={1}>Review Brief</Heading>
|
|
13
|
+
<Text>
|
|
14
|
+
This is a minimal p11 document. Replace this text with the content
|
|
15
|
+
you want reviewers to read and comment on.
|
|
16
|
+
</Text>
|
|
17
|
+
</Section>
|
|
18
|
+
</Page>
|
|
19
|
+
</Document>
|
|
20
|
+
);
|
|
21
|
+
}
|