@fedify/cli 1.8.12 → 2.0.0-dev.1761
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/deno.json +71 -0
- package/dist/cache.js +17 -0
- package/dist/deno.js +71 -0
- package/dist/docloader.js +52 -0
- package/dist/globals.js +49 -0
- package/dist/imagerenderer.js +105 -0
- package/dist/inbox/rendercode.js +57 -0
- package/dist/inbox/view.js +508 -0
- package/dist/inbox.js +315 -0
- package/dist/init/action/configs.js +81 -0
- package/dist/init/action/deps.js +52 -0
- package/dist/init/action/dir.js +16 -0
- package/dist/init/action/env.js +13 -0
- package/dist/init/action/install.js +22 -0
- package/dist/init/action/mod.js +39 -0
- package/dist/init/action/notice.js +62 -0
- package/dist/init/action/patch.js +141 -0
- package/dist/init/action/precommand.js +23 -0
- package/dist/init/action/recommend.js +24 -0
- package/dist/init/action/set.js +31 -0
- package/dist/init/action/templates.js +57 -0
- package/dist/init/action/utils.js +50 -0
- package/dist/init/ask/dir.js +82 -0
- package/dist/init/ask/kv.js +33 -0
- package/dist/init/ask/mod.js +16 -0
- package/dist/init/ask/mq.js +33 -0
- package/dist/init/ask/pm.js +49 -0
- package/dist/init/ask/wf.js +29 -0
- package/dist/init/command.js +25 -0
- package/dist/init/const.js +31 -0
- package/dist/init/json/biome.js +24 -0
- package/dist/init/json/kv.js +53 -0
- package/dist/init/json/mq.js +72 -0
- package/dist/init/json/pm.js +44 -0
- package/dist/init/json/rt.js +39 -0
- package/dist/init/json/vscode-settings-for-deno.js +53 -0
- package/dist/init/json/vscode-settings.js +49 -0
- package/dist/init/lib.js +129 -0
- package/dist/init/mod.js +5 -0
- package/dist/init/webframeworks.js +133 -0
- package/dist/kv.bun.js +17 -0
- package/dist/kv.node.js +17 -0
- package/dist/log.js +52 -0
- package/dist/lookup.js +287 -0
- package/dist/mod.js +34 -0
- package/dist/nodeinfo.js +261 -0
- package/dist/table.js +24 -0
- package/dist/tempserver.js +71 -0
- package/dist/tunnel.js +21 -0
- package/dist/utils.js +67 -0
- package/dist/webfinger/action.js +44 -0
- package/dist/webfinger/command.js +20 -0
- package/dist/webfinger/error.js +47 -0
- package/dist/webfinger/lib.js +45 -0
- package/dist/webfinger/mod.js +5 -0
- package/package.json +64 -24
- package/scripts/pack.ts +64 -0
- package/src/cache.ts +17 -0
- package/src/docloader.ts +67 -0
- package/src/globals.ts +43 -0
- package/src/imagerenderer.ts +149 -0
- package/src/inbox/entry.ts +10 -0
- package/src/inbox/rendercode.ts +68 -0
- package/src/inbox/view.tsx +598 -0
- package/src/inbox.tsx +535 -0
- package/src/init/action/configs.ts +88 -0
- package/src/init/action/deps.ts +93 -0
- package/src/init/action/dir.ts +11 -0
- package/src/init/action/env.ts +14 -0
- package/src/init/action/install.ts +59 -0
- package/src/init/action/mod.ts +66 -0
- package/src/init/action/notice.ts +101 -0
- package/src/init/action/patch.ts +212 -0
- package/src/init/action/precommand.ts +22 -0
- package/src/init/action/recommend.ts +38 -0
- package/src/init/action/set.ts +78 -0
- package/src/init/action/templates.ts +95 -0
- package/src/init/action/utils.ts +64 -0
- package/src/init/ask/dir.ts +98 -0
- package/src/init/ask/kv.ts +39 -0
- package/src/init/ask/mod.ts +23 -0
- package/src/init/ask/mq.ts +37 -0
- package/src/init/ask/pm.ts +58 -0
- package/src/init/ask/wf.ts +27 -0
- package/src/init/command.ts +64 -0
- package/src/init/const.ts +4 -0
- package/src/init/json/biome.json +17 -0
- package/src/init/json/kv.json +39 -0
- package/src/init/json/mq.json +95 -0
- package/src/init/json/pm.json +47 -0
- package/src/init/json/rt.json +42 -0
- package/src/init/json/vscode-settings-for-deno.json +43 -0
- package/src/init/json/vscode-settings.json +41 -0
- package/src/init/lib.ts +220 -0
- package/src/init/mod.ts +2 -0
- package/src/init/templates/defaults/federation.ts.tpl +23 -0
- package/src/init/templates/defaults/logging.ts.tpl +23 -0
- package/src/init/templates/express/app.ts.tpl +16 -0
- package/src/init/templates/express/index.ts.tpl +6 -0
- package/src/init/templates/hono/app.tsx.tpl +14 -0
- package/src/init/templates/hono/index/bun.ts.tpl +10 -0
- package/src/init/templates/hono/index/deno.ts.tpl +13 -0
- package/src/init/templates/hono/index/node.ts.tpl +14 -0
- package/src/init/templates/next/middleware.ts.tpl +45 -0
- package/src/init/templates/nitro/nitro.config.ts.tpl +5 -0
- package/src/init/templates/nitro/server/error.ts.tpl +3 -0
- package/src/init/templates/nitro/server/middleware/federation.ts.tpl +8 -0
- package/src/init/types.ts +88 -0
- package/src/init/webframeworks.ts +151 -0
- package/src/kv.bun.ts +12 -0
- package/src/kv.node.ts +11 -0
- package/src/log.ts +64 -0
- package/src/lookup.test.ts +182 -0
- package/src/lookup.ts +558 -0
- package/src/mod.ts +45 -0
- package/src/nodeinfo.test.ts +229 -0
- package/src/nodeinfo.ts +447 -0
- package/src/table.ts +17 -0
- package/src/tempserver.ts +87 -0
- package/src/tunnel.ts +32 -0
- package/src/utils.ts +136 -0
- package/src/webfinger/action.ts +50 -0
- package/src/webfinger/command.ts +59 -0
- package/src/webfinger/error.ts +47 -0
- package/src/webfinger/lib.ts +37 -0
- package/src/webfinger/mod.test.ts +79 -0
- package/src/webfinger/mod.ts +2 -0
- package/tsdown.config.ts +24 -0
- package/src/install.mjs +0 -189
- package/src/run.mjs +0 -22
package/dist/tunnel.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { debugOption } from "./globals.js";
|
|
5
|
+
import { argument, command, constant, integer, merge, message, object } from "@optique/core";
|
|
6
|
+
|
|
7
|
+
//#region src/tunnel.ts
|
|
8
|
+
const tunnelCommand = command("tunnel", merge(object({
|
|
9
|
+
command: constant("tunnel"),
|
|
10
|
+
port: argument(integer({
|
|
11
|
+
metavar: "PORT",
|
|
12
|
+
min: 0,
|
|
13
|
+
max: 65535
|
|
14
|
+
}))
|
|
15
|
+
}), debugOption), { description: message`Expose a local HTTP server to the public internet using a secure tunnel.` });
|
|
16
|
+
function runTunnel(command$1) {
|
|
17
|
+
console.debug(command$1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { runTunnel, tunnelCommand };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { writeFile } from "node:fs/promises";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import util from "node:util";
|
|
7
|
+
import { isObject } from "@fxts/core";
|
|
8
|
+
import { Chalk } from "chalk";
|
|
9
|
+
import { highlight } from "cli-highlight";
|
|
10
|
+
import { toMerged } from "es-toolkit";
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
|
|
13
|
+
//#region src/utils.ts
|
|
14
|
+
const colorEnabled = process.stdout.isTTY && !("NO_COLOR" in process.env && process.env.NO_COLOR !== "");
|
|
15
|
+
const colors = new Chalk(colorEnabled ? {} : { level: 0 });
|
|
16
|
+
function formatObject(obj, colors$1, json) {
|
|
17
|
+
const enableColors = colors$1 ?? colorEnabled;
|
|
18
|
+
if (!json) return util.inspect(obj, { colors: enableColors });
|
|
19
|
+
const formatted = JSON.stringify(obj, null, 2);
|
|
20
|
+
if (enableColors) return highlight(formatted, { language: "json" });
|
|
21
|
+
return formatted;
|
|
22
|
+
}
|
|
23
|
+
const isPromise = (a) => a instanceof Promise;
|
|
24
|
+
function set(key, f) {
|
|
25
|
+
return (obj) => {
|
|
26
|
+
const result = f(obj);
|
|
27
|
+
if (isPromise(result)) return result.then((value) => ({
|
|
28
|
+
...obj,
|
|
29
|
+
[key]: value
|
|
30
|
+
}));
|
|
31
|
+
return {
|
|
32
|
+
...obj,
|
|
33
|
+
[key]: result
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const merge = (source = {}) => (target = {}) => toMerged(target, source);
|
|
38
|
+
const isNotFoundError = (e) => isObject(e) && "code" in e && e.code === "ENOENT";
|
|
39
|
+
const runSubCommand = (command, options) => new Promise((resolve, reject) => {
|
|
40
|
+
const child = spawn(command[0], command.slice(1), options);
|
|
41
|
+
let stdout = "";
|
|
42
|
+
let stderr = "";
|
|
43
|
+
child.stdout?.on("data", (data) => {
|
|
44
|
+
stdout += data.toString();
|
|
45
|
+
});
|
|
46
|
+
child.stderr?.on("data", (data) => {
|
|
47
|
+
stderr += data.toString();
|
|
48
|
+
});
|
|
49
|
+
child.on("close", () => {
|
|
50
|
+
resolve({
|
|
51
|
+
stdout: stdout.trim(),
|
|
52
|
+
stderr: stderr.trim()
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
child.on("error", (error) => {
|
|
56
|
+
reject(error);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
const getCwd = () => process.cwd();
|
|
60
|
+
const replace = (pattern, replacement) => (text) => text.replace(pattern, replacement);
|
|
61
|
+
const getOsType = () => process.platform;
|
|
62
|
+
const formatJson = (obj) => JSON.stringify(obj, null, 2) + "\n";
|
|
63
|
+
const notEmpty = (s) => s.length > 0;
|
|
64
|
+
const exit = (code) => process.exit(code);
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { colorEnabled, colors, exit, formatJson, formatObject, getCwd, getOsType, isNotFoundError, merge, notEmpty, replace, runSubCommand, set };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { formatObject } from "../utils.js";
|
|
5
|
+
import { NotFoundError, getErrorMessage } from "./error.js";
|
|
6
|
+
import { convertUrlIfHandle } from "./lib.js";
|
|
7
|
+
import { print } from "@optique/run";
|
|
8
|
+
import ora from "ora";
|
|
9
|
+
import { formatMessage, message } from "@optique/core/message";
|
|
10
|
+
import { lookupWebFinger } from "@fedify/fedify/webfinger";
|
|
11
|
+
|
|
12
|
+
//#region src/webfinger/action.ts
|
|
13
|
+
async function runWebFinger({ command: _, resources,...options }) {
|
|
14
|
+
await Array.fromAsync(resources.map((resource) => ({
|
|
15
|
+
resource,
|
|
16
|
+
...options
|
|
17
|
+
})), spinnerWrapper(lookupSingleWebFinger));
|
|
18
|
+
}
|
|
19
|
+
async function lookupSingleWebFinger({ resource,...options }) {
|
|
20
|
+
const url = convertUrlIfHandle(resource);
|
|
21
|
+
const webFinger = await lookupWebFinger(url, options) ?? new NotFoundError(resource).throw();
|
|
22
|
+
return webFinger;
|
|
23
|
+
}
|
|
24
|
+
function spinnerWrapper(func) {
|
|
25
|
+
return async (...args) => {
|
|
26
|
+
const spinner = ora({
|
|
27
|
+
text: `Looking up WebFinger for ${args[0]}`,
|
|
28
|
+
discardStdin: false
|
|
29
|
+
}).start();
|
|
30
|
+
try {
|
|
31
|
+
const result = await func(...args);
|
|
32
|
+
spinner.succeed(formatMessage(message`WebFinger found for ${args[0].resource}:`));
|
|
33
|
+
print([{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: formatObject(result)
|
|
36
|
+
}]);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
spinner.fail(formatMessage(getErrorMessage(args[0].resource, error)));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { runWebFinger };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { debugOption } from "../globals.js";
|
|
5
|
+
import { argument, command, constant, flag, integer, merge, message, multiple, object, option, optional, string, withDefault } from "@optique/core";
|
|
6
|
+
|
|
7
|
+
//#region src/webfinger/command.ts
|
|
8
|
+
const userAgent = optional(option("-u", "--user-agent", string({ metavar: "USER_AGENT" }), { description: message`The custom User-Agent header value.` }));
|
|
9
|
+
const allowPrivateAddresses = optional(flag("-p", "--allow-private-address", { description: message`Allow private IP addresses in the URL.` }));
|
|
10
|
+
const maxRedirection = withDefault(option("--max-redirection", integer({ min: 0 }), { description: message`Maximum number of redirections to follow.` }), 5);
|
|
11
|
+
const webFingerCommand = command("webfinger", merge(object({
|
|
12
|
+
command: constant("webfinger"),
|
|
13
|
+
resources: multiple(argument(string({ metavar: "RESOURCE" }), { description: message`WebFinger resource(s) to look up.` })),
|
|
14
|
+
userAgent,
|
|
15
|
+
allowPrivateAddresses,
|
|
16
|
+
maxRedirection
|
|
17
|
+
}), debugOption), { description: message`Look up WebFinger resources. The argument can be multiple.` });
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { webFingerCommand };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { message } from "@optique/core";
|
|
5
|
+
|
|
6
|
+
//#region src/webfinger/error.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generates a user-friendly error message based on the type of error
|
|
9
|
+
* encountered during WebFinger lookup.
|
|
10
|
+
* @param {string} resource The resource being looked up.
|
|
11
|
+
* @param {unknown} error The error encountered.
|
|
12
|
+
* @returns {string} A descriptive error message.
|
|
13
|
+
*/
|
|
14
|
+
const getErrorMessage = (resource, error) => error instanceof InvalidHandleError ? message`Invalid handle format: ${error.handle}` : error instanceof NotFoundError ? message`Resource not found: ${error.resource}` : error instanceof Error ? message`Failed to look up WebFinger for ${resource}: ${error.message}` : message`Failed to look up WebFinger for ${resource}: ${String(error)}`;
|
|
15
|
+
/**
|
|
16
|
+
* Custom error class for invalid handle formats.
|
|
17
|
+
* @param {string} handle The invalid handle that caused the error.
|
|
18
|
+
* @extends {Error}
|
|
19
|
+
*/
|
|
20
|
+
var InvalidHandleError = class extends Error {
|
|
21
|
+
constructor(handle) {
|
|
22
|
+
super(`Invalid handle format: ${handle}`);
|
|
23
|
+
this.handle = handle;
|
|
24
|
+
this.name = "InvalidHandleError";
|
|
25
|
+
}
|
|
26
|
+
throw() {
|
|
27
|
+
throw this;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Custom error class for not found resources.
|
|
32
|
+
* @param {string} resource The resource that was not found.
|
|
33
|
+
* @extends {Error}
|
|
34
|
+
*/
|
|
35
|
+
var NotFoundError = class extends Error {
|
|
36
|
+
constructor(resource) {
|
|
37
|
+
super(`Resource not found: ${resource}`);
|
|
38
|
+
this.resource = resource;
|
|
39
|
+
this.name = "NotFoundError";
|
|
40
|
+
}
|
|
41
|
+
throw() {
|
|
42
|
+
throw this;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { InvalidHandleError, NotFoundError, getErrorMessage };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { InvalidHandleError } from "./error.js";
|
|
5
|
+
import { toAcctUrl } from "@fedify/fedify";
|
|
6
|
+
import { getLogger } from "@logtape/logtape";
|
|
7
|
+
|
|
8
|
+
//#region src/webfinger/lib.ts
|
|
9
|
+
const logger = getLogger([
|
|
10
|
+
"fedify",
|
|
11
|
+
"cli",
|
|
12
|
+
"webfinger"
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Converts a handle or URL to a URL object.
|
|
16
|
+
* If the input is a valid URL, it returns the URL object.
|
|
17
|
+
* If the input is a handle in the format `@username@domain`, it converts it to a URL.
|
|
18
|
+
* @param handleOrUrl The handle or URL to convert.
|
|
19
|
+
* @returns A URL object representing the handle or URL.
|
|
20
|
+
*/
|
|
21
|
+
function convertUrlIfHandle(handleOrUrl) {
|
|
22
|
+
try {
|
|
23
|
+
return new URL(handleOrUrl);
|
|
24
|
+
} catch {
|
|
25
|
+
return convertHandleToUrl(handleOrUrl);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts a handle in the format `@username@domain` to a URL.
|
|
30
|
+
* The resulting URL will be in the format `https://domain/@username`.
|
|
31
|
+
* @param handle The handle to convert, in the format `@username@domain`.
|
|
32
|
+
* @returns A URL object representing the handle.
|
|
33
|
+
* @throws {Error} If the handle format is invalid.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const url = convertHandleToUrl("@username@domain.com");
|
|
37
|
+
* console.log(url.toString()); // "https://domain.com/@username"
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function convertHandleToUrl(handle) {
|
|
41
|
+
return toAcctUrl(handle) ?? new InvalidHandleError(handle).throw();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { convertUrlIfHandle };
|
package/package.json
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"files": [
|
|
6
|
-
"README.md",
|
|
7
|
-
"package.json",
|
|
8
|
-
"src/install.mjs",
|
|
9
|
-
"src/run.mjs"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"fedify": "./src/run.mjs"
|
|
13
|
-
},
|
|
14
|
-
"engines": {
|
|
15
|
-
"node": ">=18.0.0"
|
|
16
|
-
},
|
|
17
|
-
"os": [
|
|
18
|
-
"darwin",
|
|
19
|
-
"linux",
|
|
20
|
-
"win32"
|
|
21
|
-
],
|
|
22
|
-
"cpu": [
|
|
23
|
-
"x64",
|
|
24
|
-
"arm64"
|
|
25
|
-
],
|
|
3
|
+
"version": "2.0.0-dev.1761+9e73442d",
|
|
26
4
|
"description": "CLI toolchain for Fedify and debugging ActivityPub",
|
|
27
5
|
"keywords": [
|
|
28
6
|
"fedify",
|
|
@@ -49,7 +27,69 @@
|
|
|
49
27
|
"url": "git+https://github.com/fedify-dev/fedify.git",
|
|
50
28
|
"directory": "packages/cli"
|
|
51
29
|
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20.0.0",
|
|
33
|
+
"bun": ">=1.2.0",
|
|
34
|
+
"denp": ">=2.0.0"
|
|
35
|
+
},
|
|
36
|
+
"bin": {
|
|
37
|
+
"fedify": "./dist/mod.js"
|
|
38
|
+
},
|
|
39
|
+
"exports": "./dist/mod.js",
|
|
40
|
+
"imports": {
|
|
41
|
+
"#kv": {
|
|
42
|
+
"bun": "./dist/kv.bun.js",
|
|
43
|
+
"default": "./dist/kv.node.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@fxts/core": "^1.15.0",
|
|
48
|
+
"@hongminhee/localtunnel": "^0.3.0",
|
|
49
|
+
"@inquirer/prompts": "^7.8.4",
|
|
50
|
+
"@jimp/core": "^1.6.0",
|
|
51
|
+
"@jimp/wasm-webp": "^1.6.0",
|
|
52
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
53
|
+
"@logtape/file": "^1.1.1",
|
|
54
|
+
"@logtape/logtape": "^1.1.1",
|
|
55
|
+
"@optique/core": "^0.6.1",
|
|
56
|
+
"@optique/run": "^0.6.1",
|
|
57
|
+
"@poppanator/http-constants": "^1.1.1",
|
|
58
|
+
"byte-encodings": "^1.0.11",
|
|
59
|
+
"chalk": "^5.6.2",
|
|
60
|
+
"cli-highlight": "^2.1.11",
|
|
61
|
+
"cli-table3": "^0.6.5",
|
|
62
|
+
"enquirer": "^2.4.1",
|
|
63
|
+
"env-paths": "^3.0.0",
|
|
64
|
+
"es-toolkit": "1.39.5",
|
|
65
|
+
"fetch-mock": "^12.5.4",
|
|
66
|
+
"hono": "^4.8.3",
|
|
67
|
+
"icojs": "^0.19.5",
|
|
68
|
+
"inquirer": "^12.9.4",
|
|
69
|
+
"inquirer-toggle": "^1.0.1",
|
|
70
|
+
"jimp": "^1.6.0",
|
|
71
|
+
"ora": "^8.2.0",
|
|
72
|
+
"shiki": "^1.6.4",
|
|
73
|
+
"srvx": "^0.8.7",
|
|
74
|
+
"@fedify/fedify": "2.0.0-dev.1761+9e73442d",
|
|
75
|
+
"@fedify/sqlite": "2.0.0-dev.1761+9e73442d",
|
|
76
|
+
"@fedify/vocab-runtime": "2.0.0-dev.1761+9e73442d"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@types/bun": "^1.2.23",
|
|
80
|
+
"@types/node": "^22.16.0",
|
|
81
|
+
"tsdown": "^0.12.9",
|
|
82
|
+
"typescript": "^5.9.2"
|
|
83
|
+
},
|
|
52
84
|
"scripts": {
|
|
53
|
-
"
|
|
85
|
+
"codegen": "deno task -f @fedify/fedify codegen",
|
|
86
|
+
"build": "pnpm run codegen && pnpm run --filter fedify build && pnpm run --filter sqlite build && tsdown",
|
|
87
|
+
"prepublish": "pnpm run build",
|
|
88
|
+
"test": "pnpm build && node --test --experimental-transform-types",
|
|
89
|
+
"test:bun": "pnpm build && bun test",
|
|
90
|
+
"run": "pnpm build && node dist/mod.js",
|
|
91
|
+
"runi": "tsdown && node dist/mod.js",
|
|
92
|
+
"run:bun": "pnpm build && bun dist/mod.js",
|
|
93
|
+
"runi:bun": "tsdown && bun dist/mod.js"
|
|
54
94
|
}
|
|
55
95
|
}
|
package/scripts/pack.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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 --target=${target} --output=${into} ${
|
|
28
|
+
join(dirname(import.meta.dirname!), "src", "mod.ts")
|
|
29
|
+
}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function pack(os: OS, arch: Arch): Promise<void> {
|
|
33
|
+
const dir = await Deno.makeTempDir();
|
|
34
|
+
await compile(os, arch, join(dir, "fedify"));
|
|
35
|
+
await Deno.copyFile(
|
|
36
|
+
join(dirname(import.meta.dirname!), "README.md"),
|
|
37
|
+
join(dir, "README.md"),
|
|
38
|
+
);
|
|
39
|
+
await Deno.copyFile(
|
|
40
|
+
join(dirname(dirname(dirname(import.meta.dirname!))), "LICENSE"),
|
|
41
|
+
join(dir, "LICENSE"),
|
|
42
|
+
);
|
|
43
|
+
if (os === "windows") {
|
|
44
|
+
const zipName = `fedify-cli-${metadata.version}-${os}-${arch}.zip`;
|
|
45
|
+
await $`7z a ${zipName} fedify.exe README.md LICENSE`.cwd(dir);
|
|
46
|
+
await Deno.copyFile(join(dir, zipName), zipName);
|
|
47
|
+
} else {
|
|
48
|
+
const tarName = `fedify-cli-${metadata.version}-${os}-${arch}.tar.xz`;
|
|
49
|
+
await $`tar cfvJ ${tarName} fedify README.md LICENSE`.cwd(dir);
|
|
50
|
+
await Deno.copyFile(join(dir, tarName), tarName);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const promises: Promise<void>[] = [];
|
|
55
|
+
for (const osKey in triplets) {
|
|
56
|
+
const os = osKey as OS;
|
|
57
|
+
for (const arch in triplets[os]) {
|
|
58
|
+
const promise = pack(os, arch as Arch);
|
|
59
|
+
promises.push(promise);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await Promise.all(promises);
|
|
63
|
+
|
|
64
|
+
// cSpell: ignore cfvz
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
package/src/globals.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { message, object, option } from "@optique/core";
|
|
2
|
+
import { configure, getConsoleSink } from "@logtape/logtape";
|
|
3
|
+
import { getFileSink } from "@logtape/file";
|
|
4
|
+
import { recordingSink } from "./log.ts";
|
|
5
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
|
+
import process from "node:process";
|
|
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
|
+
}
|