Skip to content

Commit

Permalink
Packaging @fedify/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Apr 27, 2024
1 parent 9240ffa commit 0d49eac
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 11 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: deno task check
- run: deno task hooks:pre-commit
- run: deno task check
working-directory: ${{ github.workspace }}/examples/blog/

Expand All @@ -71,6 +71,8 @@ jobs:
- run: deno task dnt
- run: npm publish --dry-run
working-directory: ${{ github.workspace }}/npm/
- run: deno task publish-dry-run
working-directory: ${{ github.workspace }}/cli/

publish:
needs: [test, lint, release-test]
Expand Down Expand Up @@ -129,6 +131,11 @@ jobs:
github.event_name == 'push' &&
github.ref_type == 'tag' || github.ref == 'refs/heads/main'
run: deno task publish --allow-dirty
- if: |
github.event_name == 'push' &&
github.ref_type == 'tag' || github.ref == 'refs/heads/main'
run: deno task publish --allow-dirty
working-directory: ${{ github.workspace }}/cli/
- if: |
github.event_name == 'push' &&
github.ref_type == 'tag' || github.ref == 'refs/heads/main'
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"deno.enable": true,
"deno.unstable": true,
"files.eol": "\n",
"files.exclude": {
"cli": true,
"examples/blog": true,
"examples/hono-sample": true
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"yaml.completion": true,
Expand Down
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Version 0.8.0

To be released.

- The CLI toolchain is now available on JSR: [@fedify/cli]. You can install
it with `deno install -A -n fedify jsr:@fedify/cli`.

- Implemented [followers collection synchronization mechanism][FEP-8fcf].

- Added `RequestContext.sendActivity()` overload that takes `"followers"`
Expand All @@ -21,7 +24,7 @@ To be released.
- Added the second type parameter to `CollectionCursor` type.
- Added the third parameter to `CollectionCursor` type.

- Relaxed the required type for activity recipients.
- Relaxed the required type for activity recipients.

- Added `Recipient` interface.
- The type of the second parameter of `Context.sendActivity()` method
Expand All @@ -46,6 +49,7 @@ To be released.
- `["fedify", "federation", "collection"]`
- `["fedify", "runtime", "docloader"]`

[@fedify/cli]: https://jsr.io/@fedify/cli
[FEP-8fcf]: https://codeberg.org/fediverse/fep/src/branch/main/fep/8fcf/fep-8fcf.md


Expand Down
6 changes: 6 additions & 0 deletions cli/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"denoland.vscode-deno",
"streetsidesoftware.code-spell-checker"
]
}
40 changes: 40 additions & 0 deletions cli/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"deno.enable": true,
"deno.unstable": true,
"files.eol": "\n",
"files.exclude": {
"cli": true,
"examples/blog": true,
"examples/hono-sample": true
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.sortImports": "always"
}
},
"cSpell.words": [
"codegen",
"denokv",
"docloader",
"fedify",
"hongminhee",
"hono",
"httpsig",
"logtape",
"nodeinfo",
"tempserver",
"webfinger"
]
}
19 changes: 19 additions & 0 deletions cli/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@fedify/cli",
"version": "0.8.0",
"exports": "./mod.ts",
"importMap": "import_map.g.json",
"exclude": [
".vscode",
"scripts"
],
"tasks": {
"fedify-codegen": "cat ../vocab/vocab.ts > /dev/null || (deno run --allow-read --allow-write --check ../codegen/main.ts ../vocab/ ../runtime/ > ../vocab/vocab.ts && deno fmt ../vocab/vocab.ts && deno cache ../vocab/vocab.ts && deno check ../vocab/vocab.ts)",
"generate-import-map": "deno run --allow-read --allow-write scripts/generate_import_map.ts",
"sync-version": "deno run --allow-read=deno.json --allow-write=deno.json scripts/sync_version.ts",
"codegen": "deno task fedify-codegen && deno task generate-import-map && deno task sync-version",
"run": "deno task codegen && deno run --allow-read --allow-write --allow-net --allow-env --allow-run mod.ts",
"publish": "deno task codegen && deno task generate-import-map --release && deno publish",
"publish-dry-run": "deno task codegen && deno publish --dry-run --allow-dirty"
}
}
48 changes: 48 additions & 0 deletions cli/import_map.g.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"imports": {
"@cfworker/json-schema": "npm:@cfworker/json-schema@^1.12.8",
"@david/which-runtime": "jsr:@david/which-runtime@^0.2.0",
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
"@fedify/fedify": ".././mod.ts",
"@fedify/fedify/federation": ".././federation/mod.ts",
"@fedify/fedify/httpsig": ".././httpsig/mod.ts",
"@fedify/fedify/nodeinfo": ".././nodeinfo/mod.ts",
"@fedify/fedify/runtime": ".././runtime/mod.ts",
"@fedify/fedify/vocab": ".././vocab/mod.ts",
"@fedify/fedify/webfinger": ".././webfinger/mod.ts",
"@fedify/fedify/x/denokv": ".././x/denokv.ts",
"@fedify/fedify/x/fresh": ".././x/fresh.ts",
"@fedify/fedify/x/hono": ".././x/hono.ts",
"@hongminhee/aitertools": "jsr:@hongminhee/aitertools@^0.6.0",
"@logtape/logtape": "jsr:@logtape/logtape@^0.2.2",
"@phensley/language-tag": "npm:@phensley/language-tag@^1.8.0",
"@std/assert": "jsr:@std/assert@^0.220.1",
"@std/async/delay": "jsr:@std/async@^0.220.1/delay",
"@std/bytes": "jsr:@std/bytes@^0.220.1",
"@std/collections": "jsr:@std/collections@^0.220.1",
"@std/encoding": "jsr:@std/encoding@^0.220.1",
"@std/encoding/base64": "jsr:@std/encoding@^0.220.1/base64",
"@std/encoding/hex": "jsr:@std/encoding@^0.220.1/hex",
"@std/fs": "jsr:@std/fs@^0.220.1",
"@std/http/negotiation": "jsr:@std/http@^0.220.1/negotiation",
"@std/json/common": "jsr:@std/json@^0.220.1/common",
"@std/path": "jsr:@std/path@^0.220.1",
"@std/semver": "jsr:@std/semver@^0.220.1",
"@std/testing": "jsr:@std/testing@^0.220.1",
"@std/text": "jsr:@std/text@^0.220.1",
"@std/url": "jsr:@std/url@^0.220.1",
"@std/yaml": "jsr:@std/yaml@^0.220.1",
"fast-check": "npm:fast-check@^3.17.0",
"jsonld": "npm:jsonld@^8.3.2",
"mock_fetch": "https://deno.land/x/[email protected]/mod.ts",
"uri-template-router": "npm:uri-template-router@^0.0.16",
"url-template": "npm:url-template@^3.1.1",
"@cliffy/command": "jsr:@cliffy/[email protected]",
"@cliffy/prompt": "jsr:@cliffy/[email protected]",
"@cross/dir": "jsr:@cross/dir@^1.1.0",
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.1.0",
"cli-highlight": "npm:cli-highlight@^2.1.11",
"json-preserve-indent": "npm:json-preserve-indent@^1.1.3",
"ora": "npm:ora@^8.0.1"
}
}
14 changes: 14 additions & 0 deletions cli/import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"imports": {
"@cliffy/command": "jsr:@cliffy/[email protected]",
"@cliffy/prompt": "jsr:@cliffy/[email protected]",
"@cross/dir": "jsr:@cross/dir@^1.1.0",
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.1.0",
"@logtape/logtape": "jsr:@logtape/logtape@^0.2.2",
"@std/fs": "jsr:@std/fs@^0.220.1",
"@std/path": "jsr:@std/path@^0.220.1",
"cli-highlight": "npm:cli-highlight@^2.1.11",
"json-preserve-indent": "npm:json-preserve-indent@^1.1.3",
"ora": "npm:ora@^8.0.1"
}
}
2 changes: 1 addition & 1 deletion cli/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, HelpCommand } from "@cliffy/command";
import { configure, getConsoleSink } from "@logtape/logtape";
import metadata from "../deno.json" with { type: "json" };
import { DEFAULT_CACHE_DIR, setCacheDir } from "./cache.ts";
import metadata from "./deno.json" with { type: "json" };
import { command as lookup } from "./lookup.ts";

const command = new Command()
Expand Down
10 changes: 10 additions & 0 deletions cli/scripts/check_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import parentMetadata from "../../deno.json" with { type: "json" };
import metadata from "../deno.json" with { type: "json" };

if (metadata.version !== parentMetadata.version) {
console.error(
`Version mismatch: parent version ${parentMetadata.version} ` +
`does not match child version ${metadata.version}`,
);
Deno.exit(1);
}
25 changes: 25 additions & 0 deletions cli/scripts/generate_import_map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fedifyMetadata from "../../deno.json" with { type: "json" };
import cliImportMap from "../import_map.json" with { type: "json" };

const release = Deno.args[0] == "--release";

const fedifyImports = Object.fromEntries(
Object.entries(fedifyMetadata.exports)
.map(([k, v]) => [
k.replace(/^\./, "@fedify/fedify"),
release
? `jsr:${k.replace(/^\./, "@fedify/fedify")}@^${fedifyMetadata.version}`
: "../" + v,
]),
);

const importMap = {
...fedifyMetadata.imports,
...fedifyImports,
...cliImportMap.imports,
};

await Deno.writeTextFile(
`${import.meta.dirname}/../import_map.g.json`,
JSON.stringify({ imports: importMap }, null, 2) + "\n",
);
8 changes: 8 additions & 0 deletions cli/scripts/sync_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import jsonPreserveIndent from "json-preserve-indent";
import metadata from "../../deno.json" with { type: "json" };

const denoJsonPath = `${import.meta.dirname}/../deno.json`;
const denoJson = await Deno.readTextFile(denoJsonPath);
const data = jsonPreserveIndent(denoJson);
data.set("version", metadata.version);
await Deno.writeTextFile(denoJsonPath, data.format());
11 changes: 3 additions & 8 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
},
"imports": {
"@cfworker/json-schema": "npm:@cfworker/json-schema@^1.12.8",
"@cliffy/command": "https://deno.land/x/[email protected]/command/mod.ts",
"@cliffy/prompt": "https://deno.land/x/[email protected]/prompt/mod.ts",
"@cross/dir": "jsr:@cross/dir@^1.1.0",
"@david/which-runtime": "jsr:@david/which-runtime@^0.2.0",
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
"@fedify/fedify": "./mod.ts",
Expand All @@ -31,7 +28,6 @@
"@fedify/fedify/x/fresh": "./x/fresh.ts",
"@fedify/fedify/x/hono": "./x/hono.ts",
"@hongminhee/aitertools": "jsr:@hongminhee/aitertools@^0.6.0",
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.1.0",
"@logtape/logtape": "jsr:@logtape/logtape@^0.2.2",
"@phensley/language-tag": "npm:@phensley/language-tag@^1.8.0",
"@std/assert": "jsr:@std/assert@^0.220.1",
Expand All @@ -50,11 +46,9 @@
"@std/text": "jsr:@std/text@^0.220.1",
"@std/url": "jsr:@std/url@^0.220.1",
"@std/yaml": "jsr:@std/yaml@^0.220.1",
"cli-highlight": "npm:cli-highlight@^2.1.11",
"fast-check": "npm:fast-check@^3.17.0",
"jsonld": "npm:jsonld@^8.3.2",
"mock_fetch": "https://deno.land/x/[email protected]/mod.ts",
"ora": "npm:ora@^8.0.1",
"uri-template-router": "npm:uri-template-router@^0.0.16",
"url-template": "npm:url-template@^3.1.1"
},
Expand All @@ -64,6 +58,7 @@
"exclude": [
".git/",
"apidoc/",
"cli/",
"docs/",
"examples/",
"npm/"
Expand All @@ -72,15 +67,15 @@
"cache": "deno task codegen && deno cache mod.ts",
"check": "deno task codegen && deno fmt --check && deno lint && deno check */*.ts",
"codegen": "deno run --allow-read --allow-write --check codegen/main.ts vocab/ ../runtime/ > vocab/vocab.ts && deno fmt vocab/vocab.ts && deno cache vocab/vocab.ts && deno check vocab/vocab.ts",
"cli": "deno task codegen && deno run --allow-read --allow-write --allow-net --allow-env --allow-run cli/mod.ts",
"test-without-codegen": "deno test --check --doc --allow-read --allow-write --unstable-kv --trace-leaks",
"test": "deno task codegen && deno task test-without-codegen",
"coverage": "rm -rf coverage/ && deno task test --coverage && deno coverage --html coverage",
"apidoc": "deno task codegen && deno doc --html --name=Fedify --output=apidoc/ mod.ts",
"check-version": "deno run cli/scripts/check_version.ts",
"publish": "deno task codegen && deno publish",
"dnt": "deno task codegen && deno run -A dnt.ts",
"hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks",
"hooks:pre-commit": "deno task check"
"hooks:pre-commit": "deno task check && deno task check-version"
},
"unstable": [
"kv",
Expand Down
16 changes: 16 additions & 0 deletions fedify.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"folders": [
{
"path": "."
},
{
"path": "cli"
},
{
"path": "examples/blog"
},
{
"path": "examples/hono-example"
}
]
}

0 comments on commit 0d49eac

Please sign in to comment.