@p11-core/cli 0.0.7 → 0.0.8
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 +50 -31
- package/docs/sharing.md +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3469,7 +3469,7 @@ var require_commander = __commonJS({
|
|
|
3469
3469
|
import { realpathSync } from "fs";
|
|
3470
3470
|
import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from "fs/promises";
|
|
3471
3471
|
import { createRequire } from "module";
|
|
3472
|
-
import { homedir } from "os";
|
|
3472
|
+
import { homedir, tmpdir } from "os";
|
|
3473
3473
|
import path from "path";
|
|
3474
3474
|
import { fileURLToPath } from "url";
|
|
3475
3475
|
import process from "process";
|
|
@@ -3640,9 +3640,10 @@ function createCliProgram(options = {}) {
|
|
|
3640
3640
|
`
|
|
3641
3641
|
|
|
3642
3642
|
Environment:
|
|
3643
|
-
P11_API_URL
|
|
3643
|
+
P11_API_URL Defaults to ${builtDefaultApiUrl}
|
|
3644
|
+
P11_BUILD_DIR Directory for temporary share build files. Defaults to the OS temp directory.`
|
|
3644
3645
|
);
|
|
3645
|
-
const shareCommand = program2.command("share").description("Share a review link for a page.").argument("[page.tsx]").option("--json", "Print the API response as JSON.").option("--edit-url [url]", "Share a new version using an edit URL or edit id.").option("--api-url [url]", "Override the p11 API URL.").action(async (input, options2) => {
|
|
3646
|
+
const shareCommand = program2.command("share").description("Share a review link for a page.").argument("[page.tsx]").option("--json", "Print the API response as JSON.").option("--edit-url [url]", "Share a new version using an edit URL or edit id.").option("--api-url [url]", "Override the p11 API URL.").option("--build-dir [dir]", "Directory for temporary build files.").action(async (input, options2) => {
|
|
3646
3647
|
await publish(input, normalizePublishOptions(options2));
|
|
3647
3648
|
});
|
|
3648
3649
|
allowLegacyParserBehavior(shareCommand);
|
|
@@ -3677,7 +3678,8 @@ function normalizePublishOptions(options) {
|
|
|
3677
3678
|
return {
|
|
3678
3679
|
json: options.json,
|
|
3679
3680
|
editUrl: optionString(options.editUrl, "--edit-url requires a URL or edit id."),
|
|
3680
|
-
apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
|
|
3681
|
+
apiUrl: optionString(options.apiUrl, "--api-url requires a URL."),
|
|
3682
|
+
buildDir: optionString(options.buildDir, "--build-dir requires a directory path.")
|
|
3681
3683
|
};
|
|
3682
3684
|
}
|
|
3683
3685
|
function normalizeCommentsOptions(options) {
|
|
@@ -3719,10 +3721,12 @@ async function publish(input, options) {
|
|
|
3719
3721
|
if (!/\.[cm]?[tj]sx?$/.test(resolvedInput)) {
|
|
3720
3722
|
throw new Error("File input must be a .tsx, .jsx, .ts, or .js page file.");
|
|
3721
3723
|
}
|
|
3722
|
-
const
|
|
3724
|
+
const buildParentDir = resolveBuildParentDir(options.buildDir);
|
|
3725
|
+
await mkdir(buildParentDir, { recursive: true });
|
|
3726
|
+
const cleanupDir = await mkdtemp(path.join(buildParentDir, "p11-build-"));
|
|
3723
3727
|
const distDir = path.join(cleanupDir, "dist");
|
|
3724
|
-
await buildPageModule(resolvedInput, distDir);
|
|
3725
3728
|
try {
|
|
3729
|
+
await buildPageModule(resolvedInput, distDir);
|
|
3726
3730
|
await ensureIndexHtml(distDir);
|
|
3727
3731
|
const zipBytes = await zipDirectory(distDir);
|
|
3728
3732
|
const editUrl = options.editUrl ?? "";
|
|
@@ -4107,34 +4111,48 @@ async function buildPageModule(inputFile, outDir) {
|
|
|
4107
4111
|
"</html>"
|
|
4108
4112
|
].join("\n")
|
|
4109
4113
|
);
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4114
|
+
const previousCwd = process.cwd();
|
|
4115
|
+
try {
|
|
4116
|
+
process.chdir(tempDir);
|
|
4117
|
+
await build({
|
|
4118
|
+
root: ".",
|
|
4119
|
+
base: "./",
|
|
4120
|
+
configFile: false,
|
|
4121
|
+
logLevel: "warn",
|
|
4122
|
+
plugins: [react(), tailwindcss()],
|
|
4123
|
+
resolve: {
|
|
4124
|
+
alias: {
|
|
4125
|
+
"@p11-core/components/styles.css": componentStyles,
|
|
4126
|
+
"@p11-core/components": componentEntry,
|
|
4127
|
+
"@recogito/text-annotator/text-annotator.css": textAnnotatorStyles,
|
|
4128
|
+
"@recogito/text-annotator": textAnnotatorEntry,
|
|
4129
|
+
"react/jsx-runtime": nodeRequire.resolve("react/jsx-runtime"),
|
|
4130
|
+
"react/jsx-dev-runtime": nodeRequire.resolve("react/jsx-dev-runtime"),
|
|
4131
|
+
"react-dom/client": nodeRequire.resolve("react-dom/client"),
|
|
4132
|
+
"react-dom": nodeRequire.resolve("react-dom"),
|
|
4133
|
+
react: nodeRequire.resolve("react")
|
|
4134
|
+
},
|
|
4135
|
+
dedupe: ["react", "react-dom"]
|
|
4127
4136
|
},
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4137
|
+
build: {
|
|
4138
|
+
outDir: path.relative(tempDir, outDir),
|
|
4139
|
+
emptyOutDir: true,
|
|
4140
|
+
assetsDir: "assets",
|
|
4141
|
+
rollupOptions: {
|
|
4142
|
+
input: {
|
|
4143
|
+
index: "index.html"
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
});
|
|
4148
|
+
} finally {
|
|
4149
|
+
process.chdir(previousCwd);
|
|
4150
|
+
}
|
|
4136
4151
|
await writeFile(path.join(outDir, P11_MANIFEST_FILE), JSON.stringify({ runtimeVersion: P11_RUNTIME_VERSION }, null, 2));
|
|
4137
4152
|
}
|
|
4153
|
+
function resolveBuildParentDir(buildDir) {
|
|
4154
|
+
return path.resolve(buildDir || process.env.P11_BUILD_DIR || tmpdir());
|
|
4155
|
+
}
|
|
4138
4156
|
function validatePageSource(code, inputFile = "page.tsx") {
|
|
4139
4157
|
validatePageAst(parsePageSource(code), inputFile);
|
|
4140
4158
|
}
|
|
@@ -4480,5 +4498,6 @@ export {
|
|
|
4480
4498
|
parseEditId,
|
|
4481
4499
|
parseReadId,
|
|
4482
4500
|
readHistoryEntries,
|
|
4501
|
+
resolveBuildParentDir,
|
|
4483
4502
|
validatePageSource
|
|
4484
4503
|
};
|
package/docs/sharing.md
CHANGED
|
@@ -35,5 +35,6 @@ p11 delete <editUrl|editId>
|
|
|
35
35
|
Add `--json` when scripting or when exact structured fields are needed.
|
|
36
36
|
|
|
37
37
|
`P11_API_URL` overrides the default API URL. `--api-url <url>` can override it per command.
|
|
38
|
+
Temporary share builds are created under the OS temp directory by default. Use `P11_BUILD_DIR` or `--build-dir <dir>` only when you need to inspect or redirect the transient build workspace.
|
|
38
39
|
|
|
39
40
|
Edit URLs are bearer credentials for updating or deleting a document. Keep them private.
|