Skip to content

Commit 76cf786

Browse files
authored
Merge pull request #469 from dodok8/fix/465
fix: fedify init notice message deosn't show properly
2 parents 0e18041 + ebbd864 commit 76cf786

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

packages/cli/src/init/action/notice.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { message } from "@optique/core";
1+
import { message, text } from "@optique/core";
22
import { print, printError } from "@optique/run";
33
import { flow } from "es-toolkit";
44
import { colors, type RequiredNotNull } from "../../utils.ts";
@@ -80,15 +80,18 @@ export const noticeConfigEnv = () =>
8080
printMessage`Note that you probably want to edit the ${".env"} file.
8181
It currently contains the following values:\n`;
8282

83-
export const noticeEnvKeyValue = ([key, value]: [string, string]) =>
84-
printMessage` ${key}=${value}`;
83+
export const noticeEnvKeyValue = ([key, value]: [string, string]) => {
84+
printMessage`${text(` ${key}='${value}'`)}`;
85+
};
8586

8687
export function noticeHowToRun(
8788
{ initializer: { instruction, federationFile } }: InitCommandData,
8889
) {
89-
printMessage`${instruction}`;
90-
printMessage`Start by editing the ${federationFile} file to define your federation!
91-
`;
90+
print(message`
91+
${instruction}
92+
93+
Start by editing the ${federationFile} file to define your federation!
94+
`);
9295
}
9396

9497
export function noticeErrorWhileAddDeps(command: string[]) {

packages/cli/src/init/action/patch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const recommendPatchFiles = (data: InitCommandData) =>
5353
const getFiles = <
5454
T extends InitCommandData,
5555
>(data: T) => ({
56-
[data.initializer.federationFile]: loadFederation({
56+
[data.initializer.federationFile.toString()]: loadFederation({
5757
imports: getImports(data),
5858
...data,
5959
}),

packages/cli/src/init/lib.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import {
1010
when,
1111
} from "@fxts/core";
1212
import { getLogger } from "@logtape/logtape";
13-
import { dirname, join as joinPath } from "node:path";
13+
import type { Message } from "@optique/core";
14+
import { commandLine, message } from "@optique/core/message";
1415
import { toMerged } from "es-toolkit";
1516
import { readFileSync } from "node:fs";
1617
import { mkdir, readdir, writeFile } from "node:fs/promises";
18+
import { dirname, join as joinPath } from "node:path";
1719
import process from "node:process";
1820
import metadata from "../../deno.json" with { type: "json" };
19-
import { colors, isNotFoundError, runSubCommand } from "../utils.ts";
21+
import { isNotFoundError, runSubCommand } from "../utils.ts";
2022
import kv from "./json/kv.json" with { type: "json" };
2123
import mq from "./json/mq.json" with { type: "json" };
2224
import pm from "./json/pm.json" with { type: "json" };
@@ -108,31 +110,20 @@ export const readTemplate: (templatePath: string) => string = (
108110

109111
export const getInstruction: (
110112
packageManager: PackageManager,
111-
) => string = (pm) => `
113+
) => Message = (pm) =>
114+
message`
112115
To start the server, run the following command:
113116
114-
${getDevCommand(pm)}
117+
${commandLine(getDevCommand(pm))}
115118
116119
Then, try look up an actor from your server:
117120
118-
${
119-
colors.bold(colors.green(
120-
"fedify lookup http://localhost:8000/users/john",
121-
))
122-
}
121+
${commandLine("fedify lookup http://localhost:8000/users/john")}
123122
124123
`;
125124

126125
const getDevCommand = (pm: PackageManager) =>
127-
colors.bold(
128-
colors.green(
129-
pm === "deno"
130-
? "deno task dev"
131-
: pm === "bun"
132-
? "bun dev"
133-
: `${pm} run dev`,
134-
),
135-
);
126+
pm === "deno" ? "deno task dev" : pm === "bun" ? "bun dev" : `${pm} run dev`;
136127

137128
async function isCommandAvailable(
138129
{ checkCommand, outputPattern }: {

packages/cli/src/init/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Message } from "@optique/core";
12
import type { RequiredNotNull } from "../utils.ts";
23
import type { InitCommand } from "./command.ts";
34
import type {
@@ -35,12 +36,12 @@ export interface WebFrameworkInitializer {
3536
command?: string[];
3637
dependencies?: object;
3738
devDependencies?: object;
38-
federationFile: string;
39+
federationFile: Message;
3940
loggingFile: string;
4041
files?: Record<string, string>;
4142
compilerOptions?: Record<string, string | boolean | number | string[] | null>;
4243
tasks?: Record<string, string>;
43-
instruction: string;
44+
instruction: Message;
4445
}
4546

4647
export interface WebFrameworkDescription {

packages/cli/src/init/webframeworks.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { pipe } from "@fxts/core";
2+
import { message } from "@optique/core";
23
import { replace } from "../utils.ts";
34
import { PACKAGE_MANAGER } from "./const.ts";
45
import {
@@ -31,7 +32,7 @@ const webFrameworks: WebFrameworks = {
3132
"x-forwarded-fetch": "^0.2.0",
3233
},
3334
devDependencies: pm === "bun" ? { "@types/bun": "^1.1.6" } : {},
34-
federationFile: "src/federation.ts",
35+
federationFile: message`src/federation.ts`,
3536
loggingFile: "src/logging.ts",
3637
files: {
3738
"src/app.tsx": pipe(
@@ -87,7 +88,7 @@ const webFrameworks: WebFrameworks = {
8788
"@types/express": "^4.17.21",
8889
...(pm === "bun" ? { "@types/bun": "^1.1.6" } : {}),
8990
},
90-
federationFile: "src/federation.ts",
91+
federationFile: message`src/federation.ts`,
9192
loggingFile: "src/logging.ts",
9293
files: {
9394
"src/app.ts": readTemplate("express/app.ts")
@@ -121,7 +122,7 @@ const webFrameworks: WebFrameworks = {
121122
init: (_, pm) => ({
122123
command: getNitroInitCommand(pm),
123124
dependencies: { "@fedify/h3": PACKAGE_VERSION },
124-
federationFile: "server/federation.ts",
125+
federationFile: message`server/federation.ts`,
125126
loggingFile: "server/logging.ts",
126127
files: {
127128
"server/middleware/federation.ts": readTemplate(
@@ -141,7 +142,7 @@ const webFrameworks: WebFrameworks = {
141142
command: getNextInitCommand(pm),
142143
dependencies: { "@fedify/next": PACKAGE_VERSION },
143144
devDependencies: { "@types/node": "^20.11.2" },
144-
federationFile: "federation/index.ts",
145+
federationFile: message`federation/index.ts`,
145146
loggingFile: "logging.ts",
146147
files: { "middleware.ts": readTemplate("next/middleware.ts") },
147148
instruction: getInstruction(pm),

packages/cli/src/nodeinfo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
optional,
1717
or,
1818
string,
19+
text,
1920
} from "@optique/core";
2021
import { print, printError } from "@optique/run";
2122
import type { ChalkInstance } from "chalk";
@@ -111,7 +112,7 @@ export async function runNodeInfo(
111112
}
112113
spinner.succeed("NodeInfo document fetched.");
113114

114-
console.log(formatObject(nodeInfo, undefined, true));
115+
print(message`${text(formatObject(nodeInfo, undefined, true))}`);
115116
return;
116117
}
117118
const nodeInfo = await getNodeInfo(url, {

0 commit comments

Comments
 (0)