@cloudflare/cli-shared-helpers 0.0.1

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/dist/index.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import { bgBlue, bgGreen, bgRed, bgYellow, brandColor, dim, gray, hidden, white } from "./colors.mjs";
2
+ import { stderr, stdout } from "./streams.mjs";
3
+ import { checkMacOSVersion } from "./check-macos-version.mjs";
4
+ import { showCursor } from "./cursor.mjs";
5
+ import { exit } from "node:process";
6
+
7
+ //#region index.ts
8
+ const shapes = {
9
+ diamond: "◇",
10
+ dash: "─",
11
+ radioInactive: "○",
12
+ radioActive: "●",
13
+ backActive: "◀",
14
+ backInactive: "◁",
15
+ bar: "│",
16
+ leftT: "├",
17
+ rigthT: "┤",
18
+ arrows: {
19
+ left: "‹",
20
+ right: "›"
21
+ },
22
+ corners: {
23
+ tl: "╭",
24
+ bl: "╰",
25
+ tr: "╮",
26
+ br: "╯"
27
+ }
28
+ };
29
+ const status = {
30
+ error: bgRed(` ERROR `),
31
+ warning: bgYellow(` WARNING `),
32
+ info: bgBlue(` INFO `),
33
+ success: bgGreen(` SUCCESS `),
34
+ cancel: white.bgRed(` X `)
35
+ };
36
+ const space = (n = 1) => {
37
+ return hidden(" ".repeat(n));
38
+ };
39
+ const LOGGER_LEVELS = {
40
+ none: -1,
41
+ error: 0,
42
+ warn: 1,
43
+ info: 2,
44
+ log: 3,
45
+ debug: 4
46
+ };
47
+ let currentLogLevel = "log";
48
+ function setLogLevel(level) {
49
+ currentLogLevel = level;
50
+ }
51
+ function getLogLevel() {
52
+ return currentLogLevel;
53
+ }
54
+ const logRaw = (msg) => {
55
+ if (LOGGER_LEVELS[getLogLevel()] >= LOGGER_LEVELS.log) stdout.write(`${msg}\n`);
56
+ };
57
+ const log = (msg) => {
58
+ logRaw(msg.split("\n").map((ln) => `${gray(shapes.bar)}${ln.length > 0 ? " " + white(ln) : ""}`).join("\n"));
59
+ };
60
+ const newline = () => {
61
+ log("");
62
+ };
63
+ const format = (msg, { linePrefix = gray(shapes.bar), firstLinePrefix = linePrefix, newlineBefore = false, newlineAfter = false, formatLine = (line) => white(line), multiline = true } = {}) => {
64
+ const formattedLines = (multiline ? msg.split("\n") : [msg]).map((line, i) => (i === 0 ? firstLinePrefix : linePrefix) + space() + formatLine(line));
65
+ if (newlineBefore) formattedLines.unshift(linePrefix);
66
+ if (newlineAfter) formattedLines.push(linePrefix);
67
+ return formattedLines.join("\n");
68
+ };
69
+ const updateStatus = (msg, printNewLine = true) => {
70
+ logRaw(format(msg, {
71
+ firstLinePrefix: gray(shapes.leftT),
72
+ linePrefix: gray(shapes.bar),
73
+ newlineAfter: printNewLine
74
+ }));
75
+ };
76
+ const startSection = (heading, subheading, printNewLine = true) => {
77
+ logRaw(`${gray(shapes.corners.tl)} ${brandColor(heading)} ${subheading ? dim(subheading) : ""}`);
78
+ if (printNewLine) newline();
79
+ };
80
+ const endSection = (heading, subheading) => {
81
+ logRaw(`${gray(shapes.corners.bl)} ${brandColor(heading)} ${subheading ? dim(subheading) : ""}\n`);
82
+ };
83
+ const cancel = (msg, { shape = shapes.corners.bl, multiline = false } = {}) => {
84
+ logRaw(format(msg, {
85
+ firstLinePrefix: `${gray(shape)} ${status.cancel}`,
86
+ linePrefix: gray(shapes.bar),
87
+ newlineBefore: true,
88
+ formatLine: (line) => dim(line),
89
+ multiline
90
+ }));
91
+ };
92
+ const warn = (msg, { shape = shapes.corners.bl, multiline = false, newlineBefore = true } = {}) => {
93
+ logRaw(format(msg, {
94
+ firstLinePrefix: gray(shape) + space() + status.warning,
95
+ linePrefix: gray(shapes.bar),
96
+ formatLine: (line) => dim(line),
97
+ multiline,
98
+ newlineBefore
99
+ }));
100
+ };
101
+ const success = (msg, { shape = shapes.corners.bl, multiline = false } = {}) => {
102
+ logRaw(format(msg, {
103
+ firstLinePrefix: gray(shape) + space() + status.success,
104
+ linePrefix: gray(shapes.bar),
105
+ newlineBefore: true,
106
+ formatLine: (line) => dim(line),
107
+ multiline
108
+ }));
109
+ };
110
+ const stripAnsi = (str) => {
111
+ const pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
112
+ const regex = RegExp(pattern, "g");
113
+ return str.replace(linkRegex, "$2").replace(regex, "");
114
+ };
115
+ const linkRegex = /\u001B\]8;;(?<url>.+)\u001B\\(?<label>.+)\u001B\]8;;\u001B\\/g;
116
+ const hyperlink = (url, label = url) => {
117
+ return `\u001B]8;;${url}\u001B\\${label}\u001B]8;;\u001B\\`;
118
+ };
119
+ const crash = (msg, extra) => {
120
+ error(msg, extra);
121
+ exit(1);
122
+ };
123
+ const error = (msg, extra, corner = shapes.corners.bl) => {
124
+ const currentLevel = getLogLevel();
125
+ if (msg && LOGGER_LEVELS[currentLevel] >= LOGGER_LEVELS.error) stderr.write(`${gray(corner)} ${status.error} ${dim(msg)}\n${extra ? space() + extra + "\n" : ""}`);
126
+ };
127
+
128
+ //#endregion
129
+ export { cancel, checkMacOSVersion, crash, endSection, error, format, getLogLevel, hyperlink, linkRegex, log, logRaw, newline, setLogLevel, shapes, showCursor, space, startSection, status, stripAnsi, success, updateStatus, warn };
130
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["currentLogLevel: LoggerLevel","crash: (msg?: string, extra?: string) => never"],"sources":["../index.ts"],"sourcesContent":["import { exit } from \"node:process\";\nimport {\n\tbgBlue,\n\tbgGreen,\n\tbgRed,\n\tbgYellow,\n\tbrandColor,\n\tdim,\n\tgray,\n\thidden,\n\twhite,\n} from \"./colors\";\nimport { stderr, stdout } from \"./streams\";\n\nexport const shapes = {\n\tdiamond: \"◇\",\n\tdash: \"─\",\n\tradioInactive: \"○\",\n\tradioActive: \"●\",\n\n\tbackActive: \"◀\",\n\tbackInactive: \"◁\",\n\n\tbar: \"│\",\n\tleftT: \"├\",\n\trigthT: \"┤\",\n\n\tarrows: {\n\t\tleft: \"‹\",\n\t\tright: \"›\",\n\t},\n\n\tcorners: {\n\t\ttl: \"╭\",\n\t\tbl: \"╰\",\n\t\ttr: \"╮\",\n\t\tbr: \"╯\",\n\t},\n};\n\nexport const status = {\n\terror: bgRed(` ERROR `),\n\twarning: bgYellow(` WARNING `),\n\tinfo: bgBlue(` INFO `),\n\tsuccess: bgGreen(` SUCCESS `),\n\tcancel: white.bgRed(` X `),\n};\n\n// Returns a string containing n non-trimmable spaces\n// This is useful for places where clack trims lines of output\n// but we need leading spaces\nexport const space = (n = 1) => {\n\treturn hidden(\"\\u200A\".repeat(n));\n};\n\nconst LOGGER_LEVELS = {\n\tnone: -1,\n\terror: 0,\n\twarn: 1,\n\tinfo: 2,\n\tlog: 3,\n\tdebug: 4,\n} as const;\n\nexport type LoggerLevel = keyof typeof LOGGER_LEVELS;\n\n// Global log level that can be set by consuming packages\nlet currentLogLevel: LoggerLevel = \"log\";\n\nexport function setLogLevel(level: LoggerLevel) {\n\tcurrentLogLevel = level;\n}\n\nexport function getLogLevel(): LoggerLevel {\n\treturn currentLogLevel;\n}\n\n// Primitive for printing to stdout. Use this instead of\n// console.log or printing to stdout directly\nexport const logRaw = (msg: string) => {\n\t// treat all log calls as 'log' level logs\n\tconst currentLevel = getLogLevel();\n\n\t// Only output if current log level allows 'log' level messages\n\tif (LOGGER_LEVELS[currentLevel] >= LOGGER_LEVELS.log) {\n\t\tstdout.write(`${msg}\\n`);\n\t}\n};\n\n// A simple stylized log for use within a prompt\nexport const log = (msg: string) => {\n\tconst lines = msg\n\t\t.split(\"\\n\")\n\t\t.map((ln) => `${gray(shapes.bar)}${ln.length > 0 ? \" \" + white(ln) : \"\"}`);\n\n\tlogRaw(lines.join(\"\\n\"));\n};\n\nexport const newline = () => {\n\tlog(\"\");\n};\n\ntype FormatOptions = {\n\tlinePrefix?: string;\n\tfirstLinePrefix?: string;\n\tnewlineBefore?: boolean;\n\tnewlineAfter?: boolean;\n\tformatLine?: (line: string) => string;\n\tmultiline?: boolean;\n};\nexport const format = (\n\tmsg: string,\n\t{\n\t\tlinePrefix = gray(shapes.bar),\n\t\tfirstLinePrefix = linePrefix,\n\t\tnewlineBefore = false,\n\t\tnewlineAfter = false,\n\t\tformatLine = (line: string) => white(line),\n\t\tmultiline = true,\n\t}: FormatOptions = {}\n) => {\n\tconst lines = multiline ? msg.split(\"\\n\") : [msg];\n\tconst formattedLines = lines.map(\n\t\t(line, i) =>\n\t\t\t(i === 0 ? firstLinePrefix : linePrefix) + space() + formatLine(line)\n\t);\n\n\tif (newlineBefore) {\n\t\tformattedLines.unshift(linePrefix);\n\t}\n\tif (newlineAfter) {\n\t\tformattedLines.push(linePrefix);\n\t}\n\n\treturn formattedLines.join(\"\\n\");\n};\n\n// Log a simple status update with a style similar to the clack spinner\nexport const updateStatus = (msg: string, printNewLine = true) => {\n\tlogRaw(\n\t\tformat(msg, {\n\t\t\tfirstLinePrefix: gray(shapes.leftT),\n\t\t\tlinePrefix: gray(shapes.bar),\n\t\t\tnewlineAfter: printNewLine,\n\t\t})\n\t);\n};\n\nexport const startSection = (\n\theading: string,\n\tsubheading?: string,\n\tprintNewLine = true\n) => {\n\tlogRaw(\n\t\t`${gray(shapes.corners.tl)} ${brandColor(heading)} ${\n\t\t\tsubheading ? dim(subheading) : \"\"\n\t\t}`\n\t);\n\tif (printNewLine) {\n\t\tnewline();\n\t}\n};\n\nexport const endSection = (heading: string, subheading?: string) => {\n\tlogRaw(\n\t\t`${gray(shapes.corners.bl)} ${brandColor(heading)} ${\n\t\t\tsubheading ? dim(subheading) : \"\"\n\t\t}\\n`\n\t);\n};\n\nexport const cancel = (\n\tmsg: string,\n\t{\n\t\t// current default is backcompat and makes sense going forward too\n\t\tshape = shapes.corners.bl,\n\t\t// current default for backcompat -- TODO: change default to true once all callees have been updated\n\t\tmultiline = false,\n\t} = {}\n) => {\n\tlogRaw(\n\t\tformat(msg, {\n\t\t\tfirstLinePrefix: `${gray(shape)} ${status.cancel}`,\n\t\t\tlinePrefix: gray(shapes.bar),\n\t\t\tnewlineBefore: true,\n\t\t\tformatLine: (line) => dim(line), // for backcompat but it's not ideal for this to be \"dim\"\n\t\t\tmultiline,\n\t\t})\n\t);\n};\n\nexport const warn = (\n\tmsg: string,\n\t{\n\t\t// current default for backcompat -- TODO: change default to shapes.bar once all callees have been updated\n\t\tshape = shapes.corners.bl,\n\t\t// current default for backcompat -- TODO: change default to true once all callees have been updated\n\t\tmultiline = false,\n\t\tnewlineBefore = true,\n\t} = {}\n) => {\n\tlogRaw(\n\t\tformat(msg, {\n\t\t\tfirstLinePrefix: gray(shape) + space() + status.warning,\n\t\t\tlinePrefix: gray(shapes.bar),\n\t\t\tformatLine: (line) => dim(line), // for backcompat but it's not ideal for this to be \"dim\"\n\t\t\tmultiline,\n\t\t\tnewlineBefore,\n\t\t})\n\t);\n};\n\nexport const success = (\n\tmsg: string,\n\t{\n\t\t// current default for backcompat -- TODO: change default to shapes.bar once all callees have been updated\n\t\tshape = shapes.corners.bl,\n\t\t// current default for backcompat -- TODO: change default to true once all callees have been updated\n\t\tmultiline = false,\n\t} = {}\n) => {\n\tlogRaw(\n\t\tformat(msg, {\n\t\t\tfirstLinePrefix: gray(shape) + space() + status.success,\n\t\t\tlinePrefix: gray(shapes.bar),\n\t\t\tnewlineBefore: true,\n\t\t\tformatLine: (line) => dim(line), // for backcompat but it's not ideal for this to be \"dim\"\n\t\t\tmultiline,\n\t\t})\n\t);\n};\n\n// Strip the ansi color characters out of the line when calculating\n// line length, otherwise the padding will be thrown off\n// Used from https://github.com/natemoo-re/clack/blob/main/packages/prompts/src/index.ts\nexport const stripAnsi = (str: string) => {\n\tconst pattern = [\n\t\t\"[\\\\u001B\\\\u009B][[\\\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]+)*|[a-zA-Z\\\\d]+(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*)?\\\\u0007)\",\n\t\t\"(?:(?:\\\\d{1,4}(?:;\\\\d{0,4})*)?[\\\\dA-PR-TZcf-nq-uy=><~]))\",\n\t].join(\"|\");\n\tconst regex = RegExp(pattern, \"g\");\n\n\treturn str.replace(linkRegex, \"$2\").replace(regex, \"\");\n};\n\n// Regular Expression that matches a hyperlink\n// e.g. `\\u001B]8;;http://example.com/\\u001B\\\\This is a link\\u001B]8;;\\u001B\\`\nexport const linkRegex =\n\t// eslint-disable-next-line no-control-regex\n\t/\\u001B\\]8;;(?<url>.+)\\u001B\\\\(?<label>.+)\\u001B\\]8;;\\u001B\\\\/g;\n\n// Create a hyperlink in terminal\n// It works in iTerm2 and VSCode's terminal, but not macOS built-in terminal app\nexport const hyperlink = (url: string, label = url) => {\n\treturn `\\u001B]8;;${url}\\u001B\\\\${label}\\u001B]8;;\\u001B\\\\`;\n};\n\nexport const crash: (msg?: string, extra?: string) => never = (msg, extra) => {\n\terror(msg, extra);\n\texit(1);\n};\n\nexport const error = (\n\tmsg?: string,\n\textra?: string,\n\tcorner = shapes.corners.bl\n) => {\n\t// Only output if current log level allows 'error' level messages\n\tconst currentLevel = getLogLevel();\n\tif (msg && LOGGER_LEVELS[currentLevel] >= LOGGER_LEVELS.error) {\n\t\tstderr.write(\n\t\t\t`${gray(corner)} ${status.error} ${dim(msg)}\\n${\n\t\t\t\textra ? space() + extra + \"\\n\" : \"\"\n\t\t\t}`\n\t\t);\n\t}\n};\n\nexport { checkMacOSVersion } from \"./check-macos-version\";\nexport { showCursor } from \"./cursor\";\n"],"mappings":";;;;;;;AAcA,MAAa,SAAS;CACrB,SAAS;CACT,MAAM;CACN,eAAe;CACf,aAAa;CAEb,YAAY;CACZ,cAAc;CAEd,KAAK;CACL,OAAO;CACP,QAAQ;CAER,QAAQ;EACP,MAA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AMF,MAAa,aAAa,QAAgB;CACzC,MAAM,UAAU,CACf,gIACA,2DACA,CAAC,KAAK,IAAI;CACX,MAAM,QAAQ,OAAO,SAAS,IAAI;AAElC,QAAO,IAAI,QAAQ,WAAW,KAAK,CAAC,QAAQ,OAAO,GAAG;;AAKvD,MAAa,YAEZ;AAID,MAAa,aAAa,KAAa,QAAQ,QAAQ;AACtD,QAAO,aAAa,IAAI,UAAU,MAAM;;AAGzC,MAAaC,SAAkD,KAAK,UAAU;AAC7E,OAAM,KAAK,MAAM;AACjB,MAAK,EAAE;;AAGR,MAAa,SACZ,KACA,OACA,SAAS,OAAO,QAAQ,OACpB;CAEJ,MAAM,eAAe,aAAa;AAClC,KAAI,OAAO,cAAc,iBAAiB,cAAc,MACvD,QAAO,MACN,GAAG,KAAK,OAAO,CAAC,GAAG,OAAO,MAAM,GAAG,IAAI,IAAI,CAAC,IAC3C,QAAQ,OAAO,GAAG,QAAQ,OAAO,KAElC"}
@@ -0,0 +1,129 @@
1
+ import { brandColor } from "./colors.mjs";
2
+ import { OptionWithDetails, SelectRefreshablePrompt } from "./select-list.mjs";
3
+ import { ConfirmPrompt, MultiSelectPrompt, Prompt, SelectPrompt, TextPrompt } from "@clack/core";
4
+
5
+ //#region interactive.d.ts
6
+ type Arg = string | boolean | string[] | undefined | number;
7
+ declare const grayBar: string;
8
+ declare const blCorner: string;
9
+ declare const leftT: string;
10
+ type Option = {
11
+ label: string;
12
+ sublabel?: string;
13
+ description?: string;
14
+ value: string;
15
+ hidden?: boolean;
16
+ activeIcon?: string;
17
+ inactiveIcon?: string;
18
+ };
19
+ type BasePromptConfig = {
20
+ question: string;
21
+ helpText?: string;
22
+ defaultValue?: Arg;
23
+ initialErrorMessage?: string | null;
24
+ acceptDefault?: boolean;
25
+ label: string;
26
+ format?: (value: Arg) => string;
27
+ validate?: (value: Arg) => string | void;
28
+ renderers?: Partial<ReturnType<typeof getRenderers>>;
29
+ throwOnError?: boolean;
30
+ };
31
+ type TextPromptConfig = BasePromptConfig & {
32
+ type: "text";
33
+ initialValue?: string;
34
+ };
35
+ type BaseSelectPromptConfig = BasePromptConfig & {
36
+ options: Option[];
37
+ maxItemsPerPage?: number;
38
+ };
39
+ type SelectPromptConfig = BaseSelectPromptConfig & {
40
+ type: "select";
41
+ };
42
+ type MultiSelectPromptConfig = BaseSelectPromptConfig & {
43
+ type: "multiselect";
44
+ };
45
+ type ConfirmPromptConfig = BasePromptConfig & {
46
+ type: "confirm";
47
+ activeText?: string;
48
+ inactiveText?: string;
49
+ };
50
+ type ListPromptConfig = BasePromptConfig & {
51
+ type: "list";
52
+ options: OptionWithDetails[];
53
+ onRefresh?: () => Promise<OptionWithDetails[]>;
54
+ };
55
+ type PromptConfig = TextPromptConfig | ConfirmPromptConfig | SelectPromptConfig | MultiSelectPromptConfig | ListPromptConfig;
56
+ type RenderProps = Omit<SelectPrompt<Option>, "prompt"> | Omit<MultiSelectPrompt<Option>, "prompt"> | Omit<TextPrompt, "prompt"> | Omit<ConfirmPrompt, "prompt"> | Omit<SelectRefreshablePrompt, "prompt">;
57
+ declare const inputPrompt: <T = string>(promptConfig: PromptConfig) => Promise<T>;
58
+ type Renderer = (props: {
59
+ state?: string;
60
+ error?: string;
61
+ cursor?: number;
62
+ value: Arg;
63
+ }, prompt: Prompt) => string[];
64
+ declare const getRenderers: (config: PromptConfig) => {
65
+ initial: Renderer;
66
+ active: Renderer;
67
+ confirm: Renderer;
68
+ error: (opts: {
69
+ value: Arg;
70
+ error: string;
71
+ }, prompt: Prompt) => string[];
72
+ submit: ({
73
+ value
74
+ }: {
75
+ value: Arg;
76
+ }) => string[];
77
+ cancel: Renderer;
78
+ } | {
79
+ initial: Renderer;
80
+ active: Renderer;
81
+ confirm: Renderer;
82
+ error: Renderer;
83
+ submit: ({
84
+ value
85
+ }: {
86
+ value: Arg;
87
+ }) => string[];
88
+ cancel: Renderer;
89
+ } | {
90
+ initial: () => string[];
91
+ active: (props: RenderProps) => string[];
92
+ error: ({
93
+ value,
94
+ error
95
+ }: {
96
+ value: Arg;
97
+ error: string;
98
+ }) => string[];
99
+ submit: ({
100
+ value
101
+ }: {
102
+ value: Arg;
103
+ }) => string[];
104
+ cancel: (props: RenderProps) => string[];
105
+ };
106
+ type SpinnerStyle = keyof typeof spinnerFrames;
107
+ declare const spinnerFrames: {
108
+ clockwise: string[];
109
+ vertical: string[];
110
+ };
111
+ declare const spinner: (frames?: string[], color?: typeof brandColor) => {
112
+ start(msg: string, helpText?: string): void;
113
+ update(msg: string): void;
114
+ stop(msg?: string): void;
115
+ };
116
+ type FactoryOrValue<T$1> = T$1 | (() => T$1);
117
+ declare const spinnerWhile: <T>(opts: {
118
+ promise: FactoryOrValue<Promise<T>>;
119
+ startMessage: FactoryOrValue<string>;
120
+ endMessage?: FactoryOrValue<string>;
121
+ spinner?: ReturnType<typeof spinner>;
122
+ }) => Promise<T>;
123
+ /**
124
+ * Test whether the process is "interactive".
125
+ */
126
+ declare function isInteractive(): boolean;
127
+ //#endregion
128
+ export { Arg, BasePromptConfig, BaseSelectPromptConfig, ConfirmPromptConfig, ListPromptConfig, MultiSelectPromptConfig, Option, PromptConfig, SelectPromptConfig, SpinnerStyle, TextPromptConfig, blCorner, getRenderers, grayBar, inputPrompt, isInteractive, leftT, spinner, spinnerFrames, spinnerWhile };
129
+ //# sourceMappingURL=interactive.d.mts.map