@vantienkhai/shippage-cli 0.1.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/README.md +16 -0
- package/dist/index.js +160 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Shippage CLI
|
|
2
|
+
|
|
3
|
+
Publish HTML, Markdown, and text files into Shippage from AI agents or scripts.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
export SHIPPAGE_API_URL=http://localhost:3000
|
|
7
|
+
export SHIPPAGE_TOKEN=<supabase-access-token>
|
|
8
|
+
|
|
9
|
+
shippage publish ./out/article.html --title "AI Search Glossary" --visibility unlisted --noindex
|
|
10
|
+
shippage bulk "out/**/*.html" --visibility unlisted --noindex
|
|
11
|
+
shippage list
|
|
12
|
+
shippage share abc123 --visibility private --private-token
|
|
13
|
+
shippage domain add docs.example.com
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For anonymous publishing, omit `SHIPPAGE_TOKEN`. Anonymous pages are ownerless until a later claim flow is added.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
import "dotenv/config";
|
|
24
|
+
import fs from "fs/promises";
|
|
25
|
+
import path from "path";
|
|
26
|
+
import { Command } from "commander";
|
|
27
|
+
import chalk from "chalk";
|
|
28
|
+
import { globby } from "globby";
|
|
29
|
+
var program = new Command();
|
|
30
|
+
function apiUrl() {
|
|
31
|
+
return (process.env.SHIPPAGE_API_URL || "http://localhost:3000").replace(/\/$/, "");
|
|
32
|
+
}
|
|
33
|
+
function apiToken() {
|
|
34
|
+
return process.env.SHIPPAGE_TOKEN;
|
|
35
|
+
}
|
|
36
|
+
async function requestJson(endpoint, init = {}) {
|
|
37
|
+
const headers = new Headers(init.headers);
|
|
38
|
+
if (apiToken()) headers.set("Authorization", `Bearer ${apiToken()}`);
|
|
39
|
+
const response = await fetch(`${apiUrl()}${endpoint}`, __spreadProps(__spreadValues({}, init), {
|
|
40
|
+
headers
|
|
41
|
+
}));
|
|
42
|
+
const text = await response.text();
|
|
43
|
+
const payload = text ? JSON.parse(text) : {};
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw new Error(payload.error || `Request failed with ${response.status}`);
|
|
46
|
+
}
|
|
47
|
+
return payload;
|
|
48
|
+
}
|
|
49
|
+
async function publishFile(filePath, options) {
|
|
50
|
+
const absolute = path.resolve(filePath);
|
|
51
|
+
const buffer = await fs.readFile(absolute);
|
|
52
|
+
const form = new FormData();
|
|
53
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
54
|
+
const type = extension === ".md" || extension === ".mdx" ? "text/markdown" : extension === ".txt" ? "text/plain" : "text/html";
|
|
55
|
+
form.set("file", new Blob([buffer], { type }), path.basename(filePath));
|
|
56
|
+
if (options.title) form.set("title", options.title);
|
|
57
|
+
if (options.description) form.set("description", options.description);
|
|
58
|
+
if (options.slug) form.set("slug", options.slug);
|
|
59
|
+
if (options.domain) form.set("domain", options.domain);
|
|
60
|
+
if (options.visibility) form.set("visibility", options.visibility);
|
|
61
|
+
if (options.noindex) form.set("noindex", "true");
|
|
62
|
+
return requestJson("/api/upload", {
|
|
63
|
+
method: "POST",
|
|
64
|
+
body: form
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
program.name("shippage").description("CLI for Shippage fast HTML publishing").version("0.1.0");
|
|
68
|
+
program.command("login").description("Print shell export instructions for API auth").option("--token <token>", "Supabase access token").option("--api-url <url>", "Shippage API URL").action((options) => {
|
|
69
|
+
if (options.apiUrl) console.log(`export SHIPPAGE_API_URL=${JSON.stringify(options.apiUrl)}`);
|
|
70
|
+
if (options.token) console.log(`export SHIPPAGE_TOKEN=${JSON.stringify(options.token)}`);
|
|
71
|
+
if (!options.apiUrl && !options.token) {
|
|
72
|
+
console.log("Set SHIPPAGE_API_URL and SHIPPAGE_TOKEN in your shell or .env file.");
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
program.command("publish").argument("<file>", "HTML, Markdown, or text file").option("--title <title>", "Page title").option("--description <description>", "Page meta description").option("--slug <slug>", "Custom path slug").option("--domain <domain>", "Verified custom domain").option("--visibility <visibility>", "public, unlisted, or private", "unlisted").option("--noindex", "Keep robots noindex").action(async (file, options) => {
|
|
76
|
+
const result = await publishFile(file, options);
|
|
77
|
+
console.log(chalk.green("Published"));
|
|
78
|
+
console.log(`${result.title}: ${result.shareUrl}`);
|
|
79
|
+
if (result.customUrl) {
|
|
80
|
+
console.log(`Custom URL: ${result.customUrl}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
program.command("bulk").argument("<pattern>", "Glob pattern, for example out/**/*.html").option("--visibility <visibility>", "public, unlisted, or private", "unlisted").option("--noindex", "Keep robots noindex").action(async (pattern, options) => {
|
|
84
|
+
const files = await globby(pattern, { onlyFiles: true });
|
|
85
|
+
if (!files.length) {
|
|
86
|
+
console.log(chalk.yellow("No files matched."));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
for (const file of files) {
|
|
90
|
+
const result = await publishFile(file, __spreadProps(__spreadValues({}, options), {
|
|
91
|
+
title: path.basename(file, path.extname(file))
|
|
92
|
+
}));
|
|
93
|
+
console.log(`${chalk.green("Published")} ${file} -> ${result.shareUrl}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
program.command("list").description("List pages owned by the current token").action(async () => {
|
|
97
|
+
const payload = await requestJson("/api/pages");
|
|
98
|
+
for (const page of payload.pages) {
|
|
99
|
+
console.log(`${page.share_id} ${page.visibility} ${page.noindex ? "noindex" : "index"} ${page.canonical_path} ${page.title}`);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
program.command("share").argument("<shareId>", "Page share id").option("--visibility <visibility>", "public, unlisted, or private").option("--index", "Allow indexing").option("--noindex", "Keep robots noindex").option("--private-token", "Generate a private token").option("--domain <domain>", "Attach to a verified custom domain").option("--slug <slug>", "Custom path slug on the domain").action(async (shareId, options) => {
|
|
103
|
+
const payload = await requestJson(`/api/pages/${shareId}`, {
|
|
104
|
+
method: "PATCH",
|
|
105
|
+
headers: { "content-type": "application/json" },
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
visibility: options.visibility,
|
|
108
|
+
noindex: options.index ? false : options.noindex ? true : void 0,
|
|
109
|
+
privateToken: options.privateToken,
|
|
110
|
+
domain: options.domain,
|
|
111
|
+
slug: options.slug
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
console.log(JSON.stringify(payload.page, null, 2));
|
|
115
|
+
});
|
|
116
|
+
program.command("delete").argument("<shareId>", "Page share id").action(async (shareId) => {
|
|
117
|
+
await requestJson(`/api/pages/${shareId}`, { method: "DELETE" });
|
|
118
|
+
console.log(chalk.green(`Deleted ${shareId}`));
|
|
119
|
+
});
|
|
120
|
+
var domain = program.command("domain").description("Manage custom domains");
|
|
121
|
+
domain.command("add").argument("<domain>", "Domain name").action(async (domainName) => {
|
|
122
|
+
const payload = await requestJson("/api/domains", {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: { "content-type": "application/json" },
|
|
125
|
+
body: JSON.stringify({ domain: domainName })
|
|
126
|
+
});
|
|
127
|
+
console.log(chalk.green(`Added ${payload.domain.domain}`));
|
|
128
|
+
console.log(`TXT record: ${payload.dns.txt.value}`);
|
|
129
|
+
console.log(`CNAME target: ${payload.dns.cname.target}`);
|
|
130
|
+
});
|
|
131
|
+
domain.command("list").action(async () => {
|
|
132
|
+
const payload = await requestJson("/api/domains");
|
|
133
|
+
for (const item of payload.domains) {
|
|
134
|
+
console.log(`${item.domain} ${item.status} ${item.verification_token}`);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
domain.command("verify").argument("<domain>", "Domain name").action(async (domainName) => {
|
|
138
|
+
const payload = await requestJson("/api/domains/verify", {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: { "content-type": "application/json" },
|
|
141
|
+
body: JSON.stringify({ domain: domainName })
|
|
142
|
+
});
|
|
143
|
+
console.log(chalk.green(payload.message));
|
|
144
|
+
console.log(`Status: ${payload.domain.status}`);
|
|
145
|
+
if (!payload.routingReady) {
|
|
146
|
+
console.log(`Add CNAME to: ${payload.dns.cname.target}`);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
domain.command("remove").argument("<domain>", "Domain name").action(async (domainName) => {
|
|
150
|
+
await requestJson("/api/domains", {
|
|
151
|
+
method: "DELETE",
|
|
152
|
+
headers: { "content-type": "application/json" },
|
|
153
|
+
body: JSON.stringify({ domain: domainName })
|
|
154
|
+
});
|
|
155
|
+
console.log(chalk.green(`Removed ${domainName}`));
|
|
156
|
+
});
|
|
157
|
+
program.parseAsync().catch((error) => {
|
|
158
|
+
console.error(chalk.red(error instanceof Error ? error.message : "Command failed"));
|
|
159
|
+
process.exit(1);
|
|
160
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vantienkhai/shippage-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Publish HTML, Markdown, and text files to Shippage from AI agents or scripts.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"shippage": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"shippage",
|
|
16
|
+
"cli",
|
|
17
|
+
"publishing",
|
|
18
|
+
"html",
|
|
19
|
+
"ai",
|
|
20
|
+
"static"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts --format esm --clean",
|
|
30
|
+
"dev": "tsx src/index.ts"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"chalk": "^5.6.2",
|
|
34
|
+
"commander": "^15.0.0",
|
|
35
|
+
"dotenv": "^17.4.2",
|
|
36
|
+
"globby": "^16.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.5.1",
|
|
40
|
+
"tsx": "^4.22.4",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
}
|
|
43
|
+
}
|