@fedify/cli 2.0.0-pr.479.1922 → 2.0.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/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/cache.js +17 -3
- package/dist/config.js +105 -0
- package/dist/deno.js +18 -8
- package/dist/generate-vocab/action.js +1 -1
- package/dist/imagerenderer.js +1 -1
- package/dist/inbox/rendercode.js +11 -21
- package/dist/inbox.js +162 -132
- package/dist/init/mod.js +3 -3
- package/dist/log.js +35 -1
- package/dist/lookup.js +55 -23
- package/dist/mod.js +95 -18
- package/dist/nodeinfo.js +39 -22
- package/dist/options.js +84 -0
- package/dist/relay.js +136 -0
- package/dist/tempserver.js +15 -8
- package/dist/tunnel.js +6 -10
- package/dist/utils.js +19 -108
- package/dist/webfinger/action.js +1 -1
- package/dist/webfinger/command.js +17 -9
- package/dist/webfinger/lib.js +3 -3
- package/package.json +50 -28
- package/deno.json +0 -71
- package/dist/globals.js +0 -49
- package/dist/init/action/configs.js +0 -91
- package/dist/init/action/const.js +0 -10
- package/dist/init/action/deps.js +0 -50
- package/dist/init/action/dir.js +0 -16
- package/dist/init/action/env.js +0 -13
- package/dist/init/action/install.js +0 -20
- package/dist/init/action/mod.js +0 -39
- package/dist/init/action/notice.js +0 -55
- package/dist/init/action/patch.js +0 -147
- package/dist/init/action/precommand.js +0 -28
- package/dist/init/action/recommend.js +0 -24
- package/dist/init/action/set.js +0 -31
- package/dist/init/action/templates.js +0 -58
- package/dist/init/action/utils.js +0 -50
- package/dist/init/ask/dir.js +0 -82
- package/dist/init/ask/kv.js +0 -44
- package/dist/init/ask/mod.js +0 -16
- package/dist/init/ask/mq.js +0 -46
- package/dist/init/ask/pm.js +0 -49
- package/dist/init/ask/wf.js +0 -29
- package/dist/init/command.js +0 -50
- package/dist/init/const.js +0 -31
- package/dist/init/json/biome.js +0 -24
- package/dist/init/json/kv.js +0 -53
- package/dist/init/json/mq.js +0 -72
- package/dist/init/json/pm.js +0 -44
- package/dist/init/json/rt.js +0 -39
- package/dist/init/json/vscode-settings-for-deno.js +0 -53
- package/dist/init/json/vscode-settings.js +0 -49
- package/dist/init/lib.js +0 -136
- package/dist/init/templates/defaults/federation.ts.tpl +0 -23
- package/dist/init/templates/defaults/logging.ts.tpl +0 -23
- package/dist/init/templates/express/app.ts.tpl +0 -16
- package/dist/init/templates/express/index.ts.tpl +0 -6
- package/dist/init/templates/hono/app.tsx.tpl +0 -14
- package/dist/init/templates/hono/index/bun.ts.tpl +0 -10
- package/dist/init/templates/hono/index/deno.ts.tpl +0 -13
- package/dist/init/templates/hono/index/node.ts.tpl +0 -14
- package/dist/init/templates/next/middleware.ts.tpl +0 -45
- package/dist/init/templates/nitro/.env.test.tpl +0 -1
- package/dist/init/templates/nitro/nitro.config.ts.tpl +0 -14
- package/dist/init/templates/nitro/server/error.ts.tpl +0 -3
- package/dist/init/templates/nitro/server/middleware/federation.ts.tpl +0 -8
- package/dist/init/test/action.js +0 -17
- package/dist/init/test/create.js +0 -100
- package/dist/init/test/fill.js +0 -32
- package/dist/init/test/lookup.js +0 -190
- package/dist/init/test/run.js +0 -25
- package/dist/init/test/utils.js +0 -17
- package/dist/init/webframeworks.js +0 -136
- package/scripts/pack.ts +0 -71
- package/src/cache.ts +0 -17
- package/src/docloader.ts +0 -67
- package/src/generate-vocab/action.ts +0 -17
- package/src/generate-vocab/command.ts +0 -44
- package/src/generate-vocab/mod.ts +0 -2
- package/src/globals.ts +0 -43
- package/src/imagerenderer.ts +0 -149
- package/src/inbox/entry.ts +0 -10
- package/src/inbox/rendercode.ts +0 -68
- package/src/inbox/view.tsx +0 -598
- package/src/inbox.tsx +0 -536
- package/src/init/action/configs.ts +0 -133
- package/src/init/action/const.ts +0 -9
- package/src/init/action/deps.ts +0 -161
- package/src/init/action/dir.ts +0 -11
- package/src/init/action/env.ts +0 -14
- package/src/init/action/install.ts +0 -24
- package/src/init/action/mod.ts +0 -66
- package/src/init/action/notice.ts +0 -103
- package/src/init/action/patch.ts +0 -233
- package/src/init/action/precommand.ts +0 -29
- package/src/init/action/recommend.ts +0 -38
- package/src/init/action/set.ts +0 -65
- package/src/init/action/templates.ts +0 -96
- package/src/init/action/utils.ts +0 -64
- package/src/init/ask/dir.ts +0 -98
- package/src/init/ask/kv.ts +0 -82
- package/src/init/ask/mod.ts +0 -23
- package/src/init/ask/mq.ts +0 -86
- package/src/init/ask/pm.ts +0 -58
- package/src/init/ask/wf.ts +0 -27
- package/src/init/command.ts +0 -135
- package/src/init/const.ts +0 -4
- package/src/init/json/biome.json +0 -17
- package/src/init/json/kv.json +0 -39
- package/src/init/json/mq.json +0 -95
- package/src/init/json/pm.json +0 -47
- package/src/init/json/rt.json +0 -42
- package/src/init/json/vscode-settings-for-deno.json +0 -43
- package/src/init/json/vscode-settings.json +0 -41
- package/src/init/lib.ts +0 -223
- package/src/init/mod.ts +0 -3
- package/src/init/templates/defaults/federation.ts.tpl +0 -23
- package/src/init/templates/defaults/logging.ts.tpl +0 -23
- package/src/init/templates/express/app.ts.tpl +0 -16
- package/src/init/templates/express/index.ts.tpl +0 -6
- package/src/init/templates/hono/app.tsx.tpl +0 -14
- package/src/init/templates/hono/index/bun.ts.tpl +0 -10
- package/src/init/templates/hono/index/deno.ts.tpl +0 -13
- package/src/init/templates/hono/index/node.ts.tpl +0 -14
- package/src/init/templates/next/middleware.ts.tpl +0 -45
- package/src/init/templates/nitro/.env.test.tpl +0 -1
- package/src/init/templates/nitro/nitro.config.ts.tpl +0 -14
- package/src/init/templates/nitro/server/error.ts.tpl +0 -3
- package/src/init/templates/nitro/server/middleware/federation.ts.tpl +0 -8
- package/src/init/test/action.ts +0 -28
- package/src/init/test/create.ts +0 -137
- package/src/init/test/fill.ts +0 -67
- package/src/init/test/lookup.ts +0 -254
- package/src/init/test/run.ts +0 -39
- package/src/init/test/types.ts +0 -27
- package/src/init/test/utils.ts +0 -21
- package/src/init/types.ts +0 -89
- package/src/init/webframeworks.ts +0 -168
- package/src/kv.bun.ts +0 -12
- package/src/kv.node.ts +0 -11
- package/src/log.ts +0 -64
- package/src/lookup.test.ts +0 -182
- package/src/lookup.ts +0 -563
- package/src/mod.ts +0 -62
- package/src/nodeinfo.test.ts +0 -229
- package/src/nodeinfo.ts +0 -454
- package/src/table.ts +0 -17
- package/src/tempserver.ts +0 -87
- package/src/tunnel.test.ts +0 -157
- package/src/tunnel.ts +0 -94
- package/src/utils.ts +0 -254
- package/src/webfinger/action.ts +0 -50
- package/src/webfinger/command.ts +0 -64
- package/src/webfinger/error.ts +0 -47
- package/src/webfinger/lib.ts +0 -37
- package/src/webfinger/mod.test.ts +0 -79
- package/src/webfinger/mod.ts +0 -2
- package/tsdown.config.ts +0 -35
package/dist/init/test/run.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
-
|
|
4
|
-
import { printMessage } from "../../utils.js";
|
|
5
|
-
import create_default, { filterOptions, generateTestCases } from "./create.js";
|
|
6
|
-
import { runServerAndLookupUser } from "./lookup.js";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { optionNames } from "@optique/core";
|
|
9
|
-
import { always, filter, map as map$1, pipe, tap, unless } from "@fxts/core";
|
|
10
|
-
|
|
11
|
-
//#region src/init/test/run.ts
|
|
12
|
-
const runTests = (dry) => ({ testDirPrefix, dryRun, hydRun,...options }) => pipe(options, printStartMessage(dry), generateTestCases, filter(filterOptions), map$1(create_default(join(testDirPrefix, getMid(dryRun, hydRun, dry)), dry)), Array.fromAsync, unless(always(dry), runServerAndLookupUser));
|
|
13
|
-
var run_default = runTests;
|
|
14
|
-
const printStartMessage = (dry) => tap(() => printMessage`\n
|
|
15
|
-
Init ${dry ? "Dry" : "Hyd"} Test start!
|
|
16
|
-
Options: ${optionNames([
|
|
17
|
-
"Web Framework",
|
|
18
|
-
"Package Manager",
|
|
19
|
-
"KV Store",
|
|
20
|
-
"Message Queue"
|
|
21
|
-
])}`);
|
|
22
|
-
const getMid = (dryRun, hydRun, dry) => dryRun === hydRun ? dry ? "dry" : "hyd" : "";
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { run_default as default };
|
package/dist/init/test/utils.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
-
|
|
4
|
-
import { printMessage } from "../../utils.js";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
|
|
8
|
-
//#region src/init/test/utils.ts
|
|
9
|
-
const genRunId = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
10
|
-
const genTestDirPrefix = ({ runId }) => join(tmpdir(), "fedify-init", runId);
|
|
11
|
-
const emptyTestDir = ({ testDirPrefix }) => Deno.remove(testDirPrefix, { recursive: true }).catch(() => {});
|
|
12
|
-
const logTestDir = ({ runId, testDirPrefix }) => printMessage`Test run completed.
|
|
13
|
-
Run ID: ${runId}
|
|
14
|
-
Path: ${testDirPrefix}`;
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { emptyTestDir, genRunId, genTestDirPrefix, logTestDir };
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
-
|
|
4
|
-
import { replace } from "../utils.js";
|
|
5
|
-
import { PACKAGE_MANAGER } from "./const.js";
|
|
6
|
-
import { PACKAGE_VERSION, getInstruction, getNextInitCommand, getNitroInitCommand, packageManagerToRuntime, readTemplate } from "./lib.js";
|
|
7
|
-
import { pipe } from "@fxts/core";
|
|
8
|
-
|
|
9
|
-
//#region src/init/webframeworks.ts
|
|
10
|
-
const webFrameworks = {
|
|
11
|
-
hono: {
|
|
12
|
-
label: "Hono",
|
|
13
|
-
packageManagers: PACKAGE_MANAGER,
|
|
14
|
-
init: ({ projectName, packageManager: pm }) => ({
|
|
15
|
-
dependencies: pm === "deno" ? {
|
|
16
|
-
"@std/dotenv": "^0.225.2",
|
|
17
|
-
"@hono/hono": "^4.5.0",
|
|
18
|
-
"@hongminhee/x-forwarded-fetch": "^0.2.0",
|
|
19
|
-
"@fedify/hono": PACKAGE_VERSION
|
|
20
|
-
} : pm === "bun" ? {
|
|
21
|
-
hono: "^4.5.0",
|
|
22
|
-
"x-forwarded-fetch": "^0.2.0",
|
|
23
|
-
"@fedify/hono": PACKAGE_VERSION
|
|
24
|
-
} : {
|
|
25
|
-
"@dotenvx/dotenvx": "^1.14.1",
|
|
26
|
-
hono: "^4.5.0",
|
|
27
|
-
"@hono/node-server": "^1.12.0",
|
|
28
|
-
tsx: "^4.17.0",
|
|
29
|
-
"x-forwarded-fetch": "^0.2.0",
|
|
30
|
-
"@fedify/hono": PACKAGE_VERSION
|
|
31
|
-
},
|
|
32
|
-
devDependencies: pm === "bun" ? { "@types/bun": "^1.1.6" } : {},
|
|
33
|
-
federationFile: "src/federation.ts",
|
|
34
|
-
loggingFile: "src/logging.ts",
|
|
35
|
-
files: {
|
|
36
|
-
"src/app.tsx": pipe("hono/app.tsx", readTemplate, replace(/\/\* hono \*\//, pm === "deno" ? "@hono/hono" : "hono"), replace(/\/\* logger \*\//, projectName)),
|
|
37
|
-
"src/index.ts": readTemplate(`hono/index/${packageManagerToRuntime(pm)}.ts`)
|
|
38
|
-
},
|
|
39
|
-
compilerOptions: pm === "deno" ? void 0 : {
|
|
40
|
-
"lib": ["ESNext", "DOM"],
|
|
41
|
-
"target": "ESNext",
|
|
42
|
-
"module": "NodeNext",
|
|
43
|
-
"moduleResolution": "NodeNext",
|
|
44
|
-
"allowImportingTsExtensions": true,
|
|
45
|
-
"verbatimModuleSyntax": true,
|
|
46
|
-
"noEmit": true,
|
|
47
|
-
"strict": true,
|
|
48
|
-
"jsx": "react-jsx",
|
|
49
|
-
"jsxImportSource": "hono/jsx"
|
|
50
|
-
},
|
|
51
|
-
tasks: {
|
|
52
|
-
"dev": pm === "deno" ? "deno run -A --watch ./src/index.ts" : pm === "bun" ? "bun run --hot ./src/index.ts" : "dotenvx run -- tsx watch ./src/index.ts",
|
|
53
|
-
"prod": pm === "deno" ? "deno run -A ./src/index.ts" : pm === "bun" ? "bun run ./src/index.ts" : "dotenvx run -- node --import tsx ./src/index.ts"
|
|
54
|
-
},
|
|
55
|
-
instruction: getInstruction(pm, 8e3)
|
|
56
|
-
}),
|
|
57
|
-
defaultPort: 8e3
|
|
58
|
-
},
|
|
59
|
-
express: {
|
|
60
|
-
label: "Express",
|
|
61
|
-
packageManagers: PACKAGE_MANAGER,
|
|
62
|
-
init: ({ projectName, packageManager: pm }) => ({
|
|
63
|
-
dependencies: {
|
|
64
|
-
"npm:express": "^4.19.2",
|
|
65
|
-
"@fedify/express": PACKAGE_VERSION,
|
|
66
|
-
...pm !== "deno" && pm !== "bun" ? {
|
|
67
|
-
"@dotenvx/dotenvx": "^1.14.1",
|
|
68
|
-
tsx: "^4.17.0"
|
|
69
|
-
} : {}
|
|
70
|
-
},
|
|
71
|
-
devDependencies: {
|
|
72
|
-
"@types/express": "^4.17.21",
|
|
73
|
-
...pm === "bun" ? { "@types/bun": "^1.1.6" } : {}
|
|
74
|
-
},
|
|
75
|
-
federationFile: "src/federation.ts",
|
|
76
|
-
loggingFile: "src/logging.ts",
|
|
77
|
-
files: {
|
|
78
|
-
"src/app.ts": readTemplate("express/app.ts").replace(/\/\* logger \*\//, projectName),
|
|
79
|
-
"src/index.ts": readTemplate("express/index.ts")
|
|
80
|
-
},
|
|
81
|
-
compilerOptions: pm === "deno" ? void 0 : {
|
|
82
|
-
"lib": ["ESNext", "DOM"],
|
|
83
|
-
"target": "ESNext",
|
|
84
|
-
"module": "NodeNext",
|
|
85
|
-
"moduleResolution": "NodeNext",
|
|
86
|
-
"allowImportingTsExtensions": true,
|
|
87
|
-
"verbatimModuleSyntax": true,
|
|
88
|
-
"noEmit": true,
|
|
89
|
-
"strict": true
|
|
90
|
-
},
|
|
91
|
-
tasks: {
|
|
92
|
-
"dev": pm === "bun" ? "bun run --hot ./src/index.ts" : pm === "deno" ? "deno run --allow-net --allow-env --allow-sys --watch ./src/index.ts" : "dotenvx run -- tsx watch ./src/index.ts",
|
|
93
|
-
"prod": pm === "bun" ? "bun run ./src/index.ts" : pm === "deno" ? "deno run --allow-net --allow-env --allow-sys ./src/index.ts" : "dotenvx run -- node --import tsx ./src/index.ts"
|
|
94
|
-
},
|
|
95
|
-
instruction: getInstruction(pm, 8e3)
|
|
96
|
-
}),
|
|
97
|
-
defaultPort: 8e3
|
|
98
|
-
},
|
|
99
|
-
nitro: {
|
|
100
|
-
label: "Nitro",
|
|
101
|
-
packageManagers: PACKAGE_MANAGER,
|
|
102
|
-
init: ({ packageManager: pm, testMode }) => ({
|
|
103
|
-
command: getNitroInitCommand(pm),
|
|
104
|
-
dependencies: { "@fedify/h3": PACKAGE_VERSION },
|
|
105
|
-
federationFile: "server/federation.ts",
|
|
106
|
-
loggingFile: "server/logging.ts",
|
|
107
|
-
files: {
|
|
108
|
-
"server/middleware/federation.ts": readTemplate("nitro/server/middleware/federation.ts"),
|
|
109
|
-
"server/error.ts": readTemplate("nitro/server/error.ts"),
|
|
110
|
-
"nitro.config.ts": readTemplate("nitro/nitro.config.ts"),
|
|
111
|
-
...testMode ? { ".env": readTemplate("nitro/.env.test") } : {}
|
|
112
|
-
},
|
|
113
|
-
instruction: getInstruction(pm, 3e3)
|
|
114
|
-
}),
|
|
115
|
-
defaultPort: 3e3
|
|
116
|
-
},
|
|
117
|
-
next: {
|
|
118
|
-
label: "Next.js",
|
|
119
|
-
packageManagers: PACKAGE_MANAGER,
|
|
120
|
-
init: ({ packageManager: pm }) => ({
|
|
121
|
-
label: "Next.js",
|
|
122
|
-
command: getNextInitCommand(pm),
|
|
123
|
-
dependencies: { "@fedify/next": PACKAGE_VERSION },
|
|
124
|
-
devDependencies: { "@types/node": "^20.11.2" },
|
|
125
|
-
federationFile: "federation/index.ts",
|
|
126
|
-
loggingFile: "logging.ts",
|
|
127
|
-
files: { "middleware.ts": readTemplate("next/middleware.ts") },
|
|
128
|
-
instruction: getInstruction(pm, 3e3)
|
|
129
|
-
}),
|
|
130
|
-
defaultPort: 3e3
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var webframeworks_default = webFrameworks;
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
export { webframeworks_default as default };
|
package/scripts/pack.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import $ from "@david/dax";
|
|
2
|
-
import { dirname, join } from "@std/path";
|
|
3
|
-
import metadata from "../deno.json" with { type: "json" };
|
|
4
|
-
|
|
5
|
-
type OS = "linux" | "macos" | "windows";
|
|
6
|
-
type Arch = "x86_64" | "aarch64";
|
|
7
|
-
|
|
8
|
-
const triplets: Record<OS, Partial<Record<Arch, string>>> = {
|
|
9
|
-
linux: {
|
|
10
|
-
x86_64: "x86_64-unknown-linux-gnu",
|
|
11
|
-
aarch64: "aarch64-unknown-linux-gnu",
|
|
12
|
-
},
|
|
13
|
-
macos: {
|
|
14
|
-
x86_64: "x86_64-apple-darwin",
|
|
15
|
-
aarch64: "aarch64-apple-darwin",
|
|
16
|
-
},
|
|
17
|
-
windows: {
|
|
18
|
-
x86_64: "x86_64-pc-windows-msvc",
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
async function compile(os: OS, arch: Arch, into: string): Promise<void> {
|
|
23
|
-
const target = triplets[os][arch];
|
|
24
|
-
if (!target) {
|
|
25
|
-
throw new Error(`Unsupported os/arch: ${os}/${arch}`);
|
|
26
|
-
}
|
|
27
|
-
await $`deno compile --allow-all --include=${
|
|
28
|
-
join("src", "init", "templates")
|
|
29
|
-
} --target=${target} --output=${into} ${
|
|
30
|
-
join(dirname(import.meta.dirname!), "src", "mod.ts")
|
|
31
|
-
}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function pack(os: OS, arch: Arch): Promise<void> {
|
|
35
|
-
const dir = await Deno.makeTempDir();
|
|
36
|
-
await compile(os, arch, join(dir, "fedify"));
|
|
37
|
-
await Deno.copyFile(
|
|
38
|
-
join(dirname(import.meta.dirname!), "README.md"),
|
|
39
|
-
join(dir, "README.md"),
|
|
40
|
-
);
|
|
41
|
-
await Deno.copyFile(
|
|
42
|
-
join(dirname(dirname(dirname(import.meta.dirname!))), "LICENSE"),
|
|
43
|
-
join(dir, "LICENSE"),
|
|
44
|
-
);
|
|
45
|
-
if (os === "windows") {
|
|
46
|
-
const zipName = `fedify-cli-${metadata.version}-${os}-${arch}.zip`;
|
|
47
|
-
await $`7z a ${zipName} fedify.exe README.md LICENSE`.cwd(dir);
|
|
48
|
-
await Deno.copyFile(join(dir, zipName), zipName);
|
|
49
|
-
} else {
|
|
50
|
-
const tarName = `fedify-cli-${metadata.version}-${os}-${arch}.tar.xz`;
|
|
51
|
-
await $`tar cfvJ ${tarName} fedify README.md LICENSE`.cwd(dir);
|
|
52
|
-
await Deno.copyFile(join(dir, tarName), tarName);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const osFilter = Deno.env.get("OS")?.toLowerCase();
|
|
57
|
-
const archFilter = Deno.env.get("ARCH")?.toLowerCase();
|
|
58
|
-
|
|
59
|
-
const promises: Promise<void>[] = [];
|
|
60
|
-
for (const osKey in triplets) {
|
|
61
|
-
const os = osKey as OS;
|
|
62
|
-
if (osFilter != null && osFilter !== os) continue;
|
|
63
|
-
for (const arch in triplets[os]) {
|
|
64
|
-
if (archFilter != null && archFilter !== arch) continue;
|
|
65
|
-
const promise = pack(os, arch as Arch);
|
|
66
|
-
promises.push(promise);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
await Promise.all(promises);
|
|
70
|
-
|
|
71
|
-
// cSpell: ignore cfvz
|
package/src/cache.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import envPaths from "env-paths";
|
|
2
|
-
import { mkdir } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
const paths = envPaths("fedify", { suffix: "" });
|
|
5
|
-
export const DEFAULT_CACHE_DIR = paths.cache;
|
|
6
|
-
|
|
7
|
-
let currentCacheDir: string = DEFAULT_CACHE_DIR;
|
|
8
|
-
|
|
9
|
-
export async function getCacheDir(): Promise<string> {
|
|
10
|
-
await mkdir(currentCacheDir, { recursive: true });
|
|
11
|
-
return currentCacheDir;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function setCacheDir(dir: string): Promise<void> {
|
|
15
|
-
currentCacheDir = dir;
|
|
16
|
-
return Promise.resolve();
|
|
17
|
-
}
|
package/src/docloader.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { kvCache } from "@fedify/fedify";
|
|
2
|
-
import {
|
|
3
|
-
type DocumentLoader,
|
|
4
|
-
getDocumentLoader as getDefaultDocumentLoader,
|
|
5
|
-
} from "@fedify/vocab-runtime";
|
|
6
|
-
import { getKvStore } from "#kv";
|
|
7
|
-
|
|
8
|
-
const documentLoaders: Record<string, DocumentLoader> = {};
|
|
9
|
-
|
|
10
|
-
export interface DocumentLoaderOptions {
|
|
11
|
-
userAgent?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getDocumentLoader(
|
|
15
|
-
{ userAgent }: DocumentLoaderOptions = {},
|
|
16
|
-
): Promise<DocumentLoader> {
|
|
17
|
-
if (documentLoaders[userAgent ?? ""]) return documentLoaders[userAgent ?? ""];
|
|
18
|
-
const kv = await getKvStore();
|
|
19
|
-
return documentLoaders[userAgent ?? ""] = kvCache({
|
|
20
|
-
kv,
|
|
21
|
-
rules: [
|
|
22
|
-
[
|
|
23
|
-
new URLPattern({
|
|
24
|
-
protocol: "http{s}?",
|
|
25
|
-
hostname: "localhost",
|
|
26
|
-
port: "*",
|
|
27
|
-
pathname: "/*",
|
|
28
|
-
search: "*",
|
|
29
|
-
hash: "*",
|
|
30
|
-
}),
|
|
31
|
-
{ seconds: 0 },
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
new URLPattern({
|
|
35
|
-
protocol: "http{s}?",
|
|
36
|
-
hostname: "127.0.0.1",
|
|
37
|
-
port: "*",
|
|
38
|
-
pathname: "/*",
|
|
39
|
-
search: "*",
|
|
40
|
-
hash: "*",
|
|
41
|
-
}),
|
|
42
|
-
{ seconds: 0 },
|
|
43
|
-
],
|
|
44
|
-
[
|
|
45
|
-
new URLPattern({
|
|
46
|
-
protocol: "http{s}?",
|
|
47
|
-
hostname: "\\[\\:\\:1\\]",
|
|
48
|
-
port: "*",
|
|
49
|
-
pathname: "/*",
|
|
50
|
-
search: "*",
|
|
51
|
-
hash: "*",
|
|
52
|
-
}),
|
|
53
|
-
{ seconds: 0 },
|
|
54
|
-
],
|
|
55
|
-
],
|
|
56
|
-
loader: getDefaultDocumentLoader({
|
|
57
|
-
allowPrivateAddress: true,
|
|
58
|
-
userAgent,
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function getContextLoader(
|
|
64
|
-
options: DocumentLoaderOptions = {},
|
|
65
|
-
): Promise<DocumentLoader> {
|
|
66
|
-
return getDocumentLoader(options);
|
|
67
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { generateVocab } from "@fedify/vocab-tools";
|
|
2
|
-
import { message } from "@optique/core/message";
|
|
3
|
-
import { printError } from "@optique/run";
|
|
4
|
-
import { stat } from "node:fs/promises";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
import type { GenerateVocabCommand } from "./command.ts";
|
|
7
|
-
|
|
8
|
-
export default async function runGenerateVocab(
|
|
9
|
-
{ schemaDir, generatedPath }: GenerateVocabCommand,
|
|
10
|
-
) {
|
|
11
|
-
if (!(await stat(schemaDir)).isDirectory()) {
|
|
12
|
-
printError(message`${schemaDir} is not a directory.`);
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
await generateVocab(schemaDir, generatedPath);
|
|
17
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
argument,
|
|
3
|
-
command,
|
|
4
|
-
constant,
|
|
5
|
-
type InferValue,
|
|
6
|
-
message,
|
|
7
|
-
object,
|
|
8
|
-
option,
|
|
9
|
-
withDefault,
|
|
10
|
-
} from "@optique/core";
|
|
11
|
-
import { path } from "@optique/run";
|
|
12
|
-
|
|
13
|
-
const schemaDir = withDefault(
|
|
14
|
-
option(
|
|
15
|
-
"-i",
|
|
16
|
-
"--input",
|
|
17
|
-
path({ metavar: "DIR", type: "directory", mustExist: true }),
|
|
18
|
-
{ description: message`Directory containing schema files.` },
|
|
19
|
-
),
|
|
20
|
-
".",
|
|
21
|
-
);
|
|
22
|
-
const generatedPath = argument(
|
|
23
|
-
path({ metavar: "PATH", type: "file", allowCreate: true }),
|
|
24
|
-
{
|
|
25
|
-
description:
|
|
26
|
-
message`Path to output the generated vocabulary classes. Should end with ${".ts"} suffix.`,
|
|
27
|
-
},
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const generateVocabCommand = command(
|
|
31
|
-
"generate-vocab",
|
|
32
|
-
object("Generation options", {
|
|
33
|
-
command: constant("generate-vocab"),
|
|
34
|
-
schemaDir,
|
|
35
|
-
generatedPath,
|
|
36
|
-
}),
|
|
37
|
-
{
|
|
38
|
-
description: message`Generate vocabulary classes from schema files.`,
|
|
39
|
-
},
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
export default generateVocabCommand;
|
|
43
|
-
|
|
44
|
-
export type GenerateVocabCommand = InferValue<typeof generateVocabCommand>;
|
package/src/globals.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getFileSink } from "@logtape/file";
|
|
2
|
-
import { configure, getConsoleSink } from "@logtape/logtape";
|
|
3
|
-
import { message, object, option } from "@optique/core";
|
|
4
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
import { recordingSink } from "./log.ts";
|
|
7
|
-
|
|
8
|
-
export const debugOption = object("Global options", {
|
|
9
|
-
debug: option("-d", "--debug", {
|
|
10
|
-
description: message`Enable debug mode.`,
|
|
11
|
-
}),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export async function configureLogging() {
|
|
15
|
-
const logFile = process.env["FEDIFY_LOG_FILE"];
|
|
16
|
-
await configure({
|
|
17
|
-
sinks: {
|
|
18
|
-
console: getConsoleSink(),
|
|
19
|
-
recording: recordingSink,
|
|
20
|
-
file: logFile == null ? () => undefined : getFileSink(logFile),
|
|
21
|
-
},
|
|
22
|
-
filters: {},
|
|
23
|
-
loggers: [
|
|
24
|
-
{
|
|
25
|
-
category: "fedify",
|
|
26
|
-
lowestLevel: "debug",
|
|
27
|
-
sinks: ["console", "recording", "file"],
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
category: "localtunnel",
|
|
31
|
-
lowestLevel: "debug",
|
|
32
|
-
sinks: ["console", "file"],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
category: ["logtape", "meta"],
|
|
36
|
-
lowestLevel: "warning",
|
|
37
|
-
sinks: ["console", "file"],
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
reset: true,
|
|
41
|
-
contextLocalStorage: new AsyncLocalStorage(),
|
|
42
|
-
});
|
|
43
|
-
}
|
package/src/imagerenderer.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { encodeBase64 } from "byte-encodings/base64";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
import { Jimp } from "./nodeinfo.ts";
|
|
7
|
-
|
|
8
|
-
export type TerminalType = "kitty" | "iterm2" | "none";
|
|
9
|
-
|
|
10
|
-
const KITTY_IDENTIFIERS: string[] = [
|
|
11
|
-
"kitty",
|
|
12
|
-
"wezterm",
|
|
13
|
-
"konsole",
|
|
14
|
-
"warp",
|
|
15
|
-
"wayst",
|
|
16
|
-
"st",
|
|
17
|
-
"ghostty",
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
type KittyCommand = Record<string, string | number>;
|
|
21
|
-
|
|
22
|
-
export function detectTerminalCapabilities(): TerminalType {
|
|
23
|
-
const termProgram = (process.env.TERM_PROGRAM || "").toLowerCase();
|
|
24
|
-
|
|
25
|
-
if (KITTY_IDENTIFIERS.includes(termProgram)) return "kitty";
|
|
26
|
-
|
|
27
|
-
if (termProgram === "iterm.app") return "iterm2";
|
|
28
|
-
|
|
29
|
-
return "none";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function serializeGrCommand(
|
|
33
|
-
cmd: KittyCommand,
|
|
34
|
-
payload?: string,
|
|
35
|
-
): Uint8Array {
|
|
36
|
-
const cmdString = Object.entries(cmd)
|
|
37
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
38
|
-
.join(",");
|
|
39
|
-
|
|
40
|
-
const encoder = new TextEncoder();
|
|
41
|
-
const parts: Uint8Array[] = [];
|
|
42
|
-
|
|
43
|
-
parts.push(encoder.encode("\x1b_G"));
|
|
44
|
-
parts.push(encoder.encode(cmdString));
|
|
45
|
-
|
|
46
|
-
if (payload) {
|
|
47
|
-
parts.push(encoder.encode(";"));
|
|
48
|
-
parts.push(encoder.encode(payload));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
parts.push(encoder.encode("\x1b\\"));
|
|
52
|
-
|
|
53
|
-
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
54
|
-
const result = new Uint8Array(totalLength);
|
|
55
|
-
let offset = 0;
|
|
56
|
-
|
|
57
|
-
for (const part of parts) {
|
|
58
|
-
result.set(part, offset);
|
|
59
|
-
offset += part.length;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function renderImageKitty(
|
|
66
|
-
imagePath: string,
|
|
67
|
-
cmd: KittyCommand,
|
|
68
|
-
): Promise<void> {
|
|
69
|
-
const imageData = await fs.readFile(imagePath);
|
|
70
|
-
const base64Data = encodeBase64(imageData);
|
|
71
|
-
let remaining = base64Data;
|
|
72
|
-
let isFirst = true;
|
|
73
|
-
|
|
74
|
-
while (remaining.length > 0) {
|
|
75
|
-
const chunk = remaining.slice(0, 4096);
|
|
76
|
-
remaining = remaining.slice(4096);
|
|
77
|
-
|
|
78
|
-
const chunkCmd = {
|
|
79
|
-
...(isFirst ? cmd : {}),
|
|
80
|
-
m: remaining.length > 0 ? 1 : 0,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const command = serializeGrCommand(chunkCmd, chunk);
|
|
84
|
-
|
|
85
|
-
process.stderr.write(command);
|
|
86
|
-
|
|
87
|
-
isFirst = false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function renderImageITerm2(
|
|
92
|
-
imagePath: string,
|
|
93
|
-
): Promise<void> {
|
|
94
|
-
const imageData = await fs.readFile(imagePath);
|
|
95
|
-
const base64Data = encodeBase64(imageData);
|
|
96
|
-
|
|
97
|
-
const encoder = new TextEncoder();
|
|
98
|
-
const command = encoder.encode(
|
|
99
|
-
`\x1b]1337;File=inline=1preserveAspectRatio=1:${base64Data}\x07\n`,
|
|
100
|
-
);
|
|
101
|
-
process.stderr.write(command);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function downloadImage(url: string): Promise<string | null> {
|
|
105
|
-
try {
|
|
106
|
-
const response = await fetch(url);
|
|
107
|
-
const imageData = new Uint8Array(await response.arrayBuffer());
|
|
108
|
-
const extension = new URL(url).pathname.split(".").pop() || "jpg";
|
|
109
|
-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "fedify"));
|
|
110
|
-
const tempPath = path.join(tempDir, `image.${extension}`);
|
|
111
|
-
|
|
112
|
-
await fs.writeFile(tempPath, imageData);
|
|
113
|
-
|
|
114
|
-
return tempPath;
|
|
115
|
-
} catch (_error) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export async function renderImages(
|
|
121
|
-
imageUrls: URL[],
|
|
122
|
-
): Promise<void> {
|
|
123
|
-
const graphicsProtocol = detectTerminalCapabilities();
|
|
124
|
-
for (const url of imageUrls) {
|
|
125
|
-
const tempPath = await downloadImage(url.href);
|
|
126
|
-
if (!tempPath) continue;
|
|
127
|
-
|
|
128
|
-
const convertedImagePath: `${string}.png` = `${tempPath}.converted.png`;
|
|
129
|
-
const image = await Jimp.read(tempPath);
|
|
130
|
-
await image.write(convertedImagePath);
|
|
131
|
-
await fs.rm(tempPath);
|
|
132
|
-
|
|
133
|
-
console.error(); // clear the line before rendering image
|
|
134
|
-
|
|
135
|
-
if (graphicsProtocol === "kitty") {
|
|
136
|
-
await renderImageKitty(convertedImagePath, {
|
|
137
|
-
a: "T",
|
|
138
|
-
f: 100, // specify the image format is png
|
|
139
|
-
});
|
|
140
|
-
} else if (graphicsProtocol === "iterm2") {
|
|
141
|
-
await renderImageITerm2(convertedImagePath);
|
|
142
|
-
} else {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
console.error(); // clear the line after rendering image
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// cSpell: ignore ghostty iterm konsole magick wezterm wayst
|
package/src/inbox/entry.ts
DELETED
package/src/inbox/rendercode.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { Activity } from "@fedify/fedify";
|
|
2
|
-
import { getStatusText } from "@poppanator/http-constants";
|
|
3
|
-
import { getContextLoader } from "../docloader.ts";
|
|
4
|
-
|
|
5
|
-
export async function renderRequest(request: Request): Promise<string> {
|
|
6
|
-
// @ts-ignore: Work around `deno publish --dry-run` bug
|
|
7
|
-
request = request.clone();
|
|
8
|
-
const url = new URL(request.url);
|
|
9
|
-
let code = `${request.method} ${url.pathname + url.search}\n`;
|
|
10
|
-
for (const [key, value] of request.headers.entries()) {
|
|
11
|
-
code += `${capitalize(key)}: ${value}\n`;
|
|
12
|
-
}
|
|
13
|
-
let body: string;
|
|
14
|
-
try {
|
|
15
|
-
body = await request.text();
|
|
16
|
-
} catch (_) {
|
|
17
|
-
body = "[Failed to decode body; it may be binary.]";
|
|
18
|
-
}
|
|
19
|
-
code += `\n${body}`;
|
|
20
|
-
return code;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function renderResponse(response: Response): Promise<string> {
|
|
24
|
-
response = response.clone();
|
|
25
|
-
let code = `${response.status} ${
|
|
26
|
-
response.statusText === ""
|
|
27
|
-
? getStatusText(response.status)
|
|
28
|
-
: response.statusText
|
|
29
|
-
}\n`;
|
|
30
|
-
for (const [key, value] of response.headers.entries()) {
|
|
31
|
-
code += `${capitalize(key)}: ${value}\n`;
|
|
32
|
-
}
|
|
33
|
-
let body: string;
|
|
34
|
-
try {
|
|
35
|
-
body = await response.text();
|
|
36
|
-
} catch (_) {
|
|
37
|
-
body = "[Failed to decode body; it may be binary.]";
|
|
38
|
-
}
|
|
39
|
-
code += `\n${body}`;
|
|
40
|
-
return code;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function renderRawActivity(request: Request): Promise<string> {
|
|
44
|
-
// @ts-ignore: Work around `deno publish --dry-run` bug
|
|
45
|
-
request = request.clone();
|
|
46
|
-
try {
|
|
47
|
-
const activity = await request.json();
|
|
48
|
-
return JSON.stringify(activity, null, 2);
|
|
49
|
-
} catch {
|
|
50
|
-
return "[Failed to decode body; it may not be JSON.]";
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function renderActivity(
|
|
55
|
-
activity: Activity,
|
|
56
|
-
expand: boolean = false,
|
|
57
|
-
): Promise<string> {
|
|
58
|
-
const contextLoader = await getContextLoader();
|
|
59
|
-
const jsonLd = await activity.toJsonLd({
|
|
60
|
-
contextLoader,
|
|
61
|
-
format: expand ? "expand" : "compact",
|
|
62
|
-
});
|
|
63
|
-
return JSON.stringify(jsonLd, null, 2);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function capitalize(name: string): string {
|
|
67
|
-
return name.replace(/(^|-)./g, (match) => match.toUpperCase());
|
|
68
|
-
}
|