@p11-core/cli 0.0.7 → 0.0.9
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 +68 -35
- 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";
|
|
@@ -3625,6 +3625,11 @@ async function main() {
|
|
|
3625
3625
|
return;
|
|
3626
3626
|
}
|
|
3627
3627
|
const command = process.argv[2];
|
|
3628
|
+
if (isVersionFlag(command)) {
|
|
3629
|
+
await warnIfUpdateAvailable({ force: true });
|
|
3630
|
+
console.log(packageJson.version);
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3628
3633
|
if (!isKnownTopLevelCommand(program2, command)) throw new Error(`Unknown command: ${command}`);
|
|
3629
3634
|
await program2.parseAsync(process.argv);
|
|
3630
3635
|
}
|
|
@@ -3632,7 +3637,9 @@ function createCliProgram(options = {}) {
|
|
|
3632
3637
|
const program2 = new Command();
|
|
3633
3638
|
const warnBeforeAction = options.warnIfUpdateAvailable ?? warnIfUpdateAvailable;
|
|
3634
3639
|
program2.name("p11").description("Share and inspect p11 document pages.");
|
|
3635
|
-
program2.
|
|
3640
|
+
program2.version(packageJson.version);
|
|
3641
|
+
program2.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
3642
|
+
if (actionCommand.name() === "version") return;
|
|
3636
3643
|
await warnBeforeAction();
|
|
3637
3644
|
});
|
|
3638
3645
|
program2.addHelpText(
|
|
@@ -3640,9 +3647,10 @@ function createCliProgram(options = {}) {
|
|
|
3640
3647
|
`
|
|
3641
3648
|
|
|
3642
3649
|
Environment:
|
|
3643
|
-
P11_API_URL
|
|
3650
|
+
P11_API_URL Defaults to ${builtDefaultApiUrl}
|
|
3651
|
+
P11_BUILD_DIR Directory for temporary share build files. Defaults to the OS temp directory.`
|
|
3644
3652
|
);
|
|
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) => {
|
|
3653
|
+
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
3654
|
await publish(input, normalizePublishOptions(options2));
|
|
3647
3655
|
});
|
|
3648
3656
|
allowLegacyParserBehavior(shareCommand);
|
|
@@ -3654,6 +3662,10 @@ Environment:
|
|
|
3654
3662
|
await deleteDocument(target, normalizeDeleteOptions(options2));
|
|
3655
3663
|
});
|
|
3656
3664
|
allowLegacyParserBehavior(deleteCommand);
|
|
3665
|
+
program2.command("version").description("Print the p11 CLI version.").action(async () => {
|
|
3666
|
+
await warnBeforeAction({ force: true });
|
|
3667
|
+
console.log(packageJson.version);
|
|
3668
|
+
});
|
|
3657
3669
|
program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options2) => {
|
|
3658
3670
|
await history(normalizeHistoryOptions(options2));
|
|
3659
3671
|
});
|
|
@@ -3668,7 +3680,10 @@ Environment:
|
|
|
3668
3680
|
return program2;
|
|
3669
3681
|
}
|
|
3670
3682
|
function isKnownTopLevelCommand(program2, command) {
|
|
3671
|
-
return command === "--help" || command === "-h" || command === "help" || program2.commands.some((subcommand) => subcommand.name() === command);
|
|
3683
|
+
return command === "--help" || command === "-h" || isVersionFlag(command) || command === "help" || program2.commands.some((subcommand) => subcommand.name() === command);
|
|
3684
|
+
}
|
|
3685
|
+
function isVersionFlag(command) {
|
|
3686
|
+
return command === "--version" || command === "-V";
|
|
3672
3687
|
}
|
|
3673
3688
|
function allowLegacyParserBehavior(command) {
|
|
3674
3689
|
return command.allowUnknownOption().allowExcessArguments();
|
|
@@ -3677,7 +3692,8 @@ function normalizePublishOptions(options) {
|
|
|
3677
3692
|
return {
|
|
3678
3693
|
json: options.json,
|
|
3679
3694
|
editUrl: optionString(options.editUrl, "--edit-url requires a URL or edit id."),
|
|
3680
|
-
apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
|
|
3695
|
+
apiUrl: optionString(options.apiUrl, "--api-url requires a URL."),
|
|
3696
|
+
buildDir: optionString(options.buildDir, "--build-dir requires a directory path.")
|
|
3681
3697
|
};
|
|
3682
3698
|
}
|
|
3683
3699
|
function normalizeCommentsOptions(options) {
|
|
@@ -3719,10 +3735,12 @@ async function publish(input, options) {
|
|
|
3719
3735
|
if (!/\.[cm]?[tj]sx?$/.test(resolvedInput)) {
|
|
3720
3736
|
throw new Error("File input must be a .tsx, .jsx, .ts, or .js page file.");
|
|
3721
3737
|
}
|
|
3722
|
-
const
|
|
3738
|
+
const buildParentDir = resolveBuildParentDir(options.buildDir);
|
|
3739
|
+
await mkdir(buildParentDir, { recursive: true });
|
|
3740
|
+
const cleanupDir = await mkdtemp(path.join(buildParentDir, "p11-build-"));
|
|
3723
3741
|
const distDir = path.join(cleanupDir, "dist");
|
|
3724
|
-
await buildPageModule(resolvedInput, distDir);
|
|
3725
3742
|
try {
|
|
3743
|
+
await buildPageModule(resolvedInput, distDir);
|
|
3726
3744
|
await ensureIndexHtml(distDir);
|
|
3727
3745
|
const zipBytes = await zipDirectory(distDir);
|
|
3728
3746
|
const editUrl = options.editUrl ?? "";
|
|
@@ -4107,34 +4125,48 @@ async function buildPageModule(inputFile, outDir) {
|
|
|
4107
4125
|
"</html>"
|
|
4108
4126
|
].join("\n")
|
|
4109
4127
|
);
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4128
|
+
const previousCwd = process.cwd();
|
|
4129
|
+
try {
|
|
4130
|
+
process.chdir(tempDir);
|
|
4131
|
+
await build({
|
|
4132
|
+
root: ".",
|
|
4133
|
+
base: "./",
|
|
4134
|
+
configFile: false,
|
|
4135
|
+
logLevel: "warn",
|
|
4136
|
+
plugins: [react(), tailwindcss()],
|
|
4137
|
+
resolve: {
|
|
4138
|
+
alias: {
|
|
4139
|
+
"@p11-core/components/styles.css": componentStyles,
|
|
4140
|
+
"@p11-core/components": componentEntry,
|
|
4141
|
+
"@recogito/text-annotator/text-annotator.css": textAnnotatorStyles,
|
|
4142
|
+
"@recogito/text-annotator": textAnnotatorEntry,
|
|
4143
|
+
"react/jsx-runtime": nodeRequire.resolve("react/jsx-runtime"),
|
|
4144
|
+
"react/jsx-dev-runtime": nodeRequire.resolve("react/jsx-dev-runtime"),
|
|
4145
|
+
"react-dom/client": nodeRequire.resolve("react-dom/client"),
|
|
4146
|
+
"react-dom": nodeRequire.resolve("react-dom"),
|
|
4147
|
+
react: nodeRequire.resolve("react")
|
|
4148
|
+
},
|
|
4149
|
+
dedupe: ["react", "react-dom"]
|
|
4127
4150
|
},
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4151
|
+
build: {
|
|
4152
|
+
outDir: path.relative(tempDir, outDir),
|
|
4153
|
+
emptyOutDir: true,
|
|
4154
|
+
assetsDir: "assets",
|
|
4155
|
+
rollupOptions: {
|
|
4156
|
+
input: {
|
|
4157
|
+
index: "index.html"
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
});
|
|
4162
|
+
} finally {
|
|
4163
|
+
process.chdir(previousCwd);
|
|
4164
|
+
}
|
|
4136
4165
|
await writeFile(path.join(outDir, P11_MANIFEST_FILE), JSON.stringify({ runtimeVersion: P11_RUNTIME_VERSION }, null, 2));
|
|
4137
4166
|
}
|
|
4167
|
+
function resolveBuildParentDir(buildDir) {
|
|
4168
|
+
return path.resolve(buildDir || process.env.P11_BUILD_DIR || tmpdir());
|
|
4169
|
+
}
|
|
4138
4170
|
function validatePageSource(code, inputFile = "page.tsx") {
|
|
4139
4171
|
validatePageAst(parsePageSource(code), inputFile);
|
|
4140
4172
|
}
|
|
@@ -4399,12 +4431,12 @@ function validateAccessTarget(target, expected) {
|
|
|
4399
4431
|
function normalizeApiUrl(value) {
|
|
4400
4432
|
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
4401
4433
|
}
|
|
4402
|
-
async function warnIfUpdateAvailable() {
|
|
4434
|
+
async function warnIfUpdateAvailable(options = {}) {
|
|
4403
4435
|
if (process.env.P11_DISABLE_UPDATE_CHECK) return;
|
|
4404
4436
|
try {
|
|
4405
4437
|
const cachePath = updateCheckCachePath();
|
|
4406
4438
|
const checkedAt = await readUpdateCheckTime(cachePath);
|
|
4407
|
-
if (checkedAt && Date.now() - checkedAt.getTime() < updateCheckIntervalMs) return;
|
|
4439
|
+
if (!options.force && checkedAt && Date.now() - checkedAt.getTime() < updateCheckIntervalMs) return;
|
|
4408
4440
|
await writeUpdateCheckTime(cachePath);
|
|
4409
4441
|
const latestVersion = await fetchLatestVersion();
|
|
4410
4442
|
if (!latestVersion || !isNewerVersion(latestVersion, packageJson.version)) return;
|
|
@@ -4480,5 +4512,6 @@ export {
|
|
|
4480
4512
|
parseEditId,
|
|
4481
4513
|
parseReadId,
|
|
4482
4514
|
readHistoryEntries,
|
|
4515
|
+
resolveBuildParentDir,
|
|
4483
4516
|
validatePageSource
|
|
4484
4517
|
};
|
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.
|