@fedify/cli 0.11.3

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.
Files changed (4) hide show
  1. package/README.md +53 -0
  2. package/install.mjs +177 -0
  3. package/package.json +1 -0
  4. package/run.mjs +22 -0
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ <!-- deno-fmt-ignore-file -->
2
+
3
+ `fedify`: the CLI toolchain for Fedify and debugging ActivityPub
4
+ ================================================================
5
+
6
+ [![JSR][JSR badge]][JSR]
7
+ [![GitHub Releases][GitHub Releases badge]][GitHub Releases]
8
+
9
+ The `fedify` is a CLI toolchain for Fedify and debugging ActivityPub-enabled
10
+ federated server apps. Although it is primarily designed for developers who use
11
+ [Fedify], it can be used with any ActivityPub-enabled server.
12
+
13
+ [JSR]: https://jsr.io/@fedify/cli
14
+ [JSR badge]: https://jsr.io/badges/@fedify/cli
15
+ [GitHub Releases]: https://github.com/dahlia/fedify/releases
16
+ [GitHub Releases badge]: https://img.shields.io/github/v/release/dahlia/fedify?sort=semver&logo=github
17
+ [Fedify]: https://fedify.dev/
18
+
19
+
20
+ Installation
21
+ ------------
22
+
23
+ ### Using Deno
24
+
25
+ If you have [Deno] installed, you can install `fedify` by running the following
26
+ command:
27
+
28
+ ~~~~ sh
29
+ # Linux/macOS
30
+ deno install \
31
+ -A \
32
+ --unstable-fs --unstable-kv --unstable-temporal \
33
+ -n fedify \
34
+ jsr:@fedify/cli
35
+ ~~~~
36
+
37
+ ~~~~ powershell
38
+ # Windows
39
+ deno install `
40
+ -A `
41
+ --unstable-fs --unstable-kv --unstable-temporal `
42
+ -n fedify `
43
+ jsr:@fedify/cli
44
+ ~~~~
45
+
46
+ [Deno]: https://deno.com/
47
+
48
+ ### Downloading the executable
49
+
50
+ You can download the pre-built executables from the [releases] page. Download
51
+ the appropriate executable for your platform and put it in your `PATH`.
52
+
53
+ [releases]: https://github.com/dahlia/fedify/releases
package/install.mjs ADDED
@@ -0,0 +1,177 @@
1
+ import { execFile } from "node:child_process";
2
+ import { createWriteStream } from "node:fs";
3
+ import {
4
+ access,
5
+ chmod,
6
+ constants,
7
+ copyFile,
8
+ mkdir,
9
+ mkdtemp,
10
+ readFile,
11
+ realpath,
12
+ } from "node:fs/promises";
13
+ import { tmpdir } from "node:os";
14
+ import { dirname, join } from "node:path";
15
+ import { Readable } from "node:stream";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ const platforms = {
19
+ darwin: {
20
+ arm64: "macos-aarch64.tar.xz",
21
+ x64: "macos-x86_64.tar.xz",
22
+ },
23
+ linux: {
24
+ arm64: "linux-aarch64.tar.xz",
25
+ x64: "linux-x86_64.tar.xz",
26
+ },
27
+ win32: {
28
+ x64: "windows-x86_64.zip",
29
+ },
30
+ };
31
+
32
+ export async function main(version) {
33
+ const filename = fileURLToPath(import.meta.url);
34
+ const dirName = dirname(filename);
35
+ const packageJson = await readFile(join(dirName, "package.json"), {
36
+ encoding: "utf8",
37
+ });
38
+ const pkg = JSON.parse(packageJson);
39
+ const binDir = join(dirName, "bin");
40
+ await mkdir(binDir, { recursive: true });
41
+ await install(version ?? pkg.version, binDir);
42
+ }
43
+
44
+ async function install(version, targetDir) {
45
+ const downloadUrl = getDownloadUrl(version);
46
+ const downloadPath = await download(downloadUrl);
47
+ let extractPath;
48
+ if (downloadPath.endsWith(".zip")) {
49
+ extractPath = await extractZip(downloadPath);
50
+ } else {
51
+ extractPath = await extractTar(downloadPath);
52
+ }
53
+ const exePath = join(extractPath, "fedify.exe");
54
+ if (await isFile(exePath)) {
55
+ const targetPath = join(targetDir, "fedify.exe");
56
+ await copyFile(exePath, targetPath);
57
+ return targetPath;
58
+ }
59
+ const binPath = join(extractPath, "fedify");
60
+ if (await isFile(binPath)) {
61
+ const targetPath = join(targetDir, "fedify");
62
+ await copyFile(binPath, targetPath);
63
+ await chmod(targetPath, 0o755);
64
+ return targetPath;
65
+ }
66
+ throw new Error("Executable not found in the archive");
67
+ }
68
+
69
+ function getDownloadUrl(version) {
70
+ const platform = platforms[process.platform];
71
+ if (!platform) {
72
+ console.error("Unsupported platform:", process.platform);
73
+ return;
74
+ }
75
+ const suffix = platform[process.arch];
76
+ if (!suffix) {
77
+ console.error("Unsupported architecture:", process.arch);
78
+ return;
79
+ }
80
+ const filename = `fedify-cli-${version}-${suffix}`;
81
+ const url =
82
+ `https://github.com/dahlia/fedify/releases/download/${version}/${filename}`;
83
+ return url;
84
+ }
85
+
86
+ async function download(url) {
87
+ const response = await fetch(url, { redirect: "follow" });
88
+ if (!response.ok) {
89
+ console.error("Download failed:", response.statusText);
90
+ return;
91
+ }
92
+ const tmpDir = await mkdtemp(join(tmpdir(), `fedify-`));
93
+ const filename = url.substring(url.lastIndexOf("/") + 1);
94
+ const downloadPath = join(tmpDir, filename);
95
+ const fileStream = createWriteStream(downloadPath);
96
+ const readable = Readable.fromWeb(response.body);
97
+ await new Promise((resolve, reject) => {
98
+ readable.pipe(fileStream);
99
+ readable.on("error", reject);
100
+ fileStream.on("finish", resolve);
101
+ });
102
+ return downloadPath;
103
+ }
104
+
105
+ async function extractZip(path) {
106
+ const dir = await mkdtemp(join(tmpdir(), "fedify-"));
107
+ await new Promise((resolve, reject) => {
108
+ execFile("powershell", [
109
+ "-NoProfile",
110
+ "-ExecutionPolicy",
111
+ "Bypass",
112
+ "-Command",
113
+ `Import-Module Microsoft.PowerShell.Archive;\
114
+ Expand-Archive -LiteralPath '${path}' -DestinationPath '${dir}'`,
115
+ ], (error, _, stderr) => {
116
+ if (error) {
117
+ console.error("Extraction failed:", error);
118
+ reject(error);
119
+ return;
120
+ }
121
+ if (stderr) console.warn(stderr);
122
+ resolve();
123
+ });
124
+ });
125
+ return dir;
126
+ }
127
+
128
+ async function extractTar(path) {
129
+ const switches = {
130
+ ".tar": "",
131
+ ".tar.gz": "z",
132
+ ".tgz": "z",
133
+ ".tar.bz2": "j",
134
+ ".tbz2": "j",
135
+ ".tar.xz": "J",
136
+ ".txz": "J",
137
+ };
138
+ let switch_ = "";
139
+ for (const ext in switches) {
140
+ if (path.endsWith(ext)) {
141
+ switch_ = switches[ext];
142
+ break;
143
+ }
144
+ }
145
+ path = await realpath(path);
146
+ const dir = await mkdtemp(join(tmpdir(), "fedify-"));
147
+ await execTar(`xvf${switch_}`, dir, path);
148
+ return dir;
149
+ }
150
+
151
+ function execTar(switch_, dir, path) {
152
+ return new Promise((resolve, reject) => {
153
+ execFile("tar", [switch_, path], { cwd: dir }, (error, _, stderr) => {
154
+ if (error) {
155
+ console.error("Extraction failed:", error);
156
+ reject(error);
157
+ return;
158
+ }
159
+ if (stderr) console.warn(stderr);
160
+ resolve();
161
+ });
162
+ });
163
+ }
164
+
165
+ export async function isFile(path) {
166
+ try {
167
+ await access(path, constants.R_OK);
168
+ return true;
169
+ } catch (error) {
170
+ if (error.code === "ENOENT") return false;
171
+ throw error;
172
+ }
173
+ }
174
+
175
+ if (fileURLToPath(import.meta.url) === process.argv[1]) {
176
+ await main(process.argv[2]);
177
+ }
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"@fedify/cli","version":"0.11.3","private":false,"type":"module","files":["README.md","install.mjs","run.mjs"],"bin":{"fedify":"./run.mjs"},"scripts":{"postinstall":"node install.mjs"},"engines":{"node":">=18.0.0"},"os":["darwin","linux","win32"],"cpu":["x64","arm64"],"description":"CLI toolchain for Fedify and debugging ActivityPub","keywords":["fedify","activitypub","cli","fediverse"],"homepage":"https://fedify.dev/cli","bugs":{"url":"https://github.com/dahlia/fedify/issues"},"license":"MIT","author":{"name":"Hong Minhee","email":"hong@minhee.org","url":"https://hongminhee.org/"},"funding":["https://github.com/sponsors/dahlia","https://toss.me/hongminhee"],"repository":{"type":"git","url":"git+https://github.com/dahlia/fedify.git"}}
package/run.mjs ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { isFile, main as install } from "./install.mjs";
6
+
7
+ async function main() {
8
+ const filename = fileURLToPath(import.meta.url);
9
+ const dirName = dirname(filename);
10
+ const binPath = join(
11
+ dirName,
12
+ "bin",
13
+ process.platform === "win32" ? "fedify.exe" : "fedify",
14
+ );
15
+ if (!await isFile(binPath)) await install();
16
+ const result = spawnSync(binPath, process.argv.slice(2), {
17
+ stdio: "inherit",
18
+ });
19
+ process.exit(result.status);
20
+ }
21
+
22
+ await main();