@paragraph-com/cli 0.0.3 → 0.0.4
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 +1 -1
- package/dist/index.js +81 -7
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -42837,9 +42837,11 @@ async function createPost(params) {
|
|
|
42837
42837
|
const body = {
|
|
42838
42838
|
title: params.title,
|
|
42839
42839
|
markdown: params.markdown,
|
|
42840
|
-
status: "draft",
|
|
42840
|
+
status: params.scheduledAt ? void 0 : "draft",
|
|
42841
42841
|
subtitle: params.subtitle,
|
|
42842
|
-
categories: params.tags
|
|
42842
|
+
categories: params.tags,
|
|
42843
|
+
scheduledAt: params.scheduledAt,
|
|
42844
|
+
sendNewsletter: params.sendNewsletter
|
|
42843
42845
|
};
|
|
42844
42846
|
createPostBody.parse(body);
|
|
42845
42847
|
const client = createClient2(params.apiKey);
|
|
@@ -42887,6 +42889,31 @@ async function updatePostStatus(idOrSlug, status, apiKey, sendNewsletter) {
|
|
|
42887
42889
|
}
|
|
42888
42890
|
await client.posts.update({ slug: idOrSlug, ...body });
|
|
42889
42891
|
}
|
|
42892
|
+
async function schedulePost(idOrSlug, scheduledAt, apiKey, sendNewsletter) {
|
|
42893
|
+
const client = createClient2(apiKey);
|
|
42894
|
+
const body = {
|
|
42895
|
+
scheduledAt,
|
|
42896
|
+
sendNewsletter: sendNewsletter || void 0
|
|
42897
|
+
};
|
|
42898
|
+
try {
|
|
42899
|
+
await client.posts.update({ id: idOrSlug, ...body });
|
|
42900
|
+
return;
|
|
42901
|
+
} catch {
|
|
42902
|
+
if (!isSlug(idOrSlug)) throw new Error(`Post not found: ${idOrSlug}`);
|
|
42903
|
+
}
|
|
42904
|
+
await client.posts.update({ slug: idOrSlug, ...body });
|
|
42905
|
+
}
|
|
42906
|
+
async function cancelSchedule(idOrSlug, apiKey) {
|
|
42907
|
+
const client = createClient2(apiKey);
|
|
42908
|
+
const body = { scheduledAt: null };
|
|
42909
|
+
try {
|
|
42910
|
+
await client.posts.update({ id: idOrSlug, ...body });
|
|
42911
|
+
return;
|
|
42912
|
+
} catch {
|
|
42913
|
+
if (!isSlug(idOrSlug)) throw new Error(`Post not found: ${idOrSlug}`);
|
|
42914
|
+
}
|
|
42915
|
+
await client.posts.update({ slug: idOrSlug, ...body });
|
|
42916
|
+
}
|
|
42890
42917
|
var init_posts = __esm({
|
|
42891
42918
|
"src/services/posts.ts"() {
|
|
42892
42919
|
"use strict";
|
|
@@ -42980,6 +43007,17 @@ var init_args = __esm({
|
|
|
42980
43007
|
|
|
42981
43008
|
// src/cli/commands/post.ts
|
|
42982
43009
|
import * as fs2 from "fs";
|
|
43010
|
+
function parseScheduleTime(value) {
|
|
43011
|
+
const asNum = Number(value);
|
|
43012
|
+
if (Number.isFinite(asNum) && asNum > 1e12) return asNum;
|
|
43013
|
+
const date = new Date(value);
|
|
43014
|
+
if (isNaN(date.getTime())) {
|
|
43015
|
+
throw new Error(
|
|
43016
|
+
`Invalid schedule time: "${value}". Use ISO 8601 (e.g. "2026-05-01T09:00:00Z") or Unix ms.`
|
|
43017
|
+
);
|
|
43018
|
+
}
|
|
43019
|
+
return date.getTime();
|
|
43020
|
+
}
|
|
42983
43021
|
async function resolveMarkdown(opts) {
|
|
42984
43022
|
if (opts.text) return opts.text;
|
|
42985
43023
|
if (opts.file) {
|
|
@@ -42993,11 +43031,12 @@ async function resolveMarkdown(opts) {
|
|
|
42993
43031
|
}
|
|
42994
43032
|
function registerPostCommands(program2) {
|
|
42995
43033
|
const post = program2.command("post").description("Manage posts");
|
|
42996
|
-
const createCmd = (parent) => parent.command("create").description("Create a new post").requiredOption("--title <title>", "Post title").option("--text <markdown>", "Post content as markdown string").option("--file <path>", "Read post content from a file").option("--subtitle <subtitle>", "Post subtitle").option("--tags <tags>", "Comma-separated tags").addHelpText("after", `
|
|
43034
|
+
const createCmd = (parent) => parent.command("create").description("Create a new post").requiredOption("--title <title>", "Post title").option("--text <markdown>", "Post content as markdown string").option("--file <path>", "Read post content from a file").option("--subtitle <subtitle>", "Post subtitle").option("--tags <tags>", "Comma-separated tags").option("--schedule-at <time>", "Schedule publish at a future time (ISO 8601 or Unix ms)").option("--newsletter", "Also send as newsletter email to subscribers").addHelpText("after", `
|
|
42997
43035
|
Examples:
|
|
42998
43036
|
$ paragraph post create --title "My Post" --file ./post.md
|
|
42999
43037
|
$ paragraph post create --title "My Post" --text "# Hello World"
|
|
43000
43038
|
$ paragraph post create --title "My Post" --tags "web3,defi" --file ./post.md
|
|
43039
|
+
$ paragraph post create --title "My Post" --schedule-at "2026-05-01T09:00:00Z"
|
|
43001
43040
|
$ cat draft.md | paragraph post create --title "My Post"`).action(async function(opts) {
|
|
43002
43041
|
try {
|
|
43003
43042
|
const apiKey = requireApiKey();
|
|
@@ -43006,19 +43045,24 @@ Examples:
|
|
|
43006
43045
|
throw new Error(
|
|
43007
43046
|
"Provide content via --text, --file, or pipe to stdin."
|
|
43008
43047
|
);
|
|
43048
|
+
const scheduledAt = opts.scheduleAt ? parseScheduleTime(opts.scheduleAt) : void 0;
|
|
43009
43049
|
const data = await createPost({
|
|
43010
43050
|
apiKey,
|
|
43011
43051
|
title: opts.title,
|
|
43012
43052
|
markdown,
|
|
43013
43053
|
subtitle: opts.subtitle,
|
|
43014
|
-
tags: opts.tags?.split(",").map((t) => t.trim())
|
|
43054
|
+
tags: opts.tags?.split(",").map((t) => t.trim()),
|
|
43055
|
+
scheduledAt,
|
|
43056
|
+
sendNewsletter: opts.newsletter
|
|
43015
43057
|
});
|
|
43016
|
-
|
|
43058
|
+
const label = scheduledAt ? "Post scheduled" : "Post created";
|
|
43059
|
+
writeSuccess(`${label}: ${opts.title}`);
|
|
43017
43060
|
outputData(
|
|
43018
43061
|
this,
|
|
43019
43062
|
{
|
|
43020
43063
|
ID: data.id,
|
|
43021
|
-
Title: opts.title
|
|
43064
|
+
Title: opts.title,
|
|
43065
|
+
Status: data.status
|
|
43022
43066
|
},
|
|
43023
43067
|
data
|
|
43024
43068
|
);
|
|
@@ -43323,6 +43367,36 @@ Examples:
|
|
|
43323
43367
|
handleError(err);
|
|
43324
43368
|
}
|
|
43325
43369
|
});
|
|
43370
|
+
post.command("schedule [id-or-slug]").description("Schedule a draft post for future publication").option("--id <id-or-slug>", "Post ID or slug").requiredOption("--at <time>", "Publish time (ISO 8601 or Unix ms)").option("--newsletter", "Also send as newsletter email to subscribers").addHelpText("after", `
|
|
43371
|
+
Examples:
|
|
43372
|
+
$ paragraph post schedule my-post --at "2026-05-01T09:00:00Z"
|
|
43373
|
+
$ paragraph post schedule my-post --at 1746090000000
|
|
43374
|
+
$ paragraph post schedule my-post --at "2026-05-01T09:00:00Z" --newsletter`).action(async function(idOrSlug, opts) {
|
|
43375
|
+
try {
|
|
43376
|
+
const id = requireArg(idOrSlug, opts.id, "post ID or slug");
|
|
43377
|
+
const apiKey = requireApiKey();
|
|
43378
|
+
const scheduledAt = parseScheduleTime(opts.at);
|
|
43379
|
+
await schedulePost(id, scheduledAt, apiKey, opts.newsletter);
|
|
43380
|
+
writeSuccess(`Post scheduled: ${id} at ${new Date(scheduledAt).toISOString()}`);
|
|
43381
|
+
outputData(this, { ID: id, Status: "scheduled", ScheduledAt: new Date(scheduledAt).toISOString() }, { id, status: "scheduled", scheduledAt });
|
|
43382
|
+
} catch (err) {
|
|
43383
|
+
handleError(err);
|
|
43384
|
+
}
|
|
43385
|
+
});
|
|
43386
|
+
post.command("unschedule [id-or-slug]").description("Cancel a scheduled post publication").option("--id <id-or-slug>", "Post ID or slug").addHelpText("after", `
|
|
43387
|
+
Examples:
|
|
43388
|
+
$ paragraph post unschedule my-post
|
|
43389
|
+
$ paragraph post unschedule --id my-post`).action(async function(idOrSlug, opts) {
|
|
43390
|
+
try {
|
|
43391
|
+
const id = requireArg(idOrSlug, opts.id, "post ID or slug");
|
|
43392
|
+
const apiKey = requireApiKey();
|
|
43393
|
+
await cancelSchedule(id, apiKey);
|
|
43394
|
+
writeSuccess(`Schedule cancelled: ${id}`);
|
|
43395
|
+
outputData(this, { ID: id, Status: "draft" }, { id, status: "draft" });
|
|
43396
|
+
} catch (err) {
|
|
43397
|
+
handleError(err);
|
|
43398
|
+
}
|
|
43399
|
+
});
|
|
43326
43400
|
createCmd(post);
|
|
43327
43401
|
updateCmd(post);
|
|
43328
43402
|
deleteCmd(post);
|
|
@@ -43789,7 +43863,7 @@ var init_user = __esm({
|
|
|
43789
43863
|
// src/cli/program.ts
|
|
43790
43864
|
function createProgram() {
|
|
43791
43865
|
const program2 = new Command();
|
|
43792
|
-
program2.name("paragraph").description("CLI for Paragraph").version("0.0.
|
|
43866
|
+
program2.name("paragraph").description("CLI for Paragraph").version("0.0.4", "-v, --version").option("--json", "Output as JSON").option("--verbose", "Show detailed output for debugging").exitOverride().configureOutput({
|
|
43793
43867
|
writeOut: (str) => process.stdout.write(str),
|
|
43794
43868
|
writeErr: (str) => {
|
|
43795
43869
|
if (process.argv.includes("--json")) {
|