refactor: share plugin setup helpers
parent
c98addeadd
commit
cca577a0cc
@ -0,0 +1,21 @@
|
||||
import { consumeRootOptionToken } from "../infra/cli-root-options.js";
|
||||
|
||||
export function forwardConsumedCliRootOption(
|
||||
args: readonly string[],
|
||||
index: number,
|
||||
out: string[],
|
||||
): number {
|
||||
const consumedRootOption = consumeRootOptionToken(args, index);
|
||||
if (consumedRootOption <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (let offset = 0; offset < consumedRootOption; offset += 1) {
|
||||
const token = args[index + offset];
|
||||
if (token !== undefined) {
|
||||
out.push(token);
|
||||
}
|
||||
}
|
||||
|
||||
return consumedRootOption;
|
||||
}
|
||||
@ -1,22 +1 @@
|
||||
import { isWSLEnv } from "../infra/wsl.js";
|
||||
|
||||
export function isRemoteEnvironment(): boolean {
|
||||
if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
process.platform === "linux" &&
|
||||
!process.env.DISPLAY &&
|
||||
!process.env.WAYLAND_DISPLAY &&
|
||||
!isWSLEnv()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export { isRemoteEnvironment } from "../infra/remote-env.js";
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
import { isWSLEnv } from "./wsl.js";
|
||||
|
||||
export function isRemoteEnvironment(): boolean {
|
||||
if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
process.platform === "linux" &&
|
||||
!process.env.DISPLAY &&
|
||||
!process.env.WAYLAND_DISPLAY &&
|
||||
!isWSLEnv()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
import type { messagingApi } from "@line/bot-sdk";
|
||||
|
||||
type QuickReply = messagingApi.QuickReply;
|
||||
type QuickReplyItem = messagingApi.QuickReplyItem;
|
||||
type TextMessage = messagingApi.TextMessage;
|
||||
|
||||
export function createQuickReplyItems(labels: string[]): QuickReply {
|
||||
const items: QuickReplyItem[] = labels.slice(0, 13).map((label) => ({
|
||||
type: "action",
|
||||
action: {
|
||||
type: "message",
|
||||
label: label.slice(0, 20),
|
||||
text: label,
|
||||
},
|
||||
}));
|
||||
return { items };
|
||||
}
|
||||
|
||||
export function createTextMessageWithQuickReplies(
|
||||
text: string,
|
||||
quickReplyLabels: string[],
|
||||
): TextMessage & { quickReply: QuickReply } {
|
||||
return {
|
||||
type: "text",
|
||||
text,
|
||||
quickReply: createQuickReplyItems(quickReplyLabels),
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue