@evex-dev/linejs-cli 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +289 -2
- package/dist/cli-eG7C8gFC.mjs +6726 -0
- package/dist/cli-eG7C8gFC.mjs.map +1 -0
- package/dist/errors-pVbxr1wG.mjs +58 -0
- package/dist/errors-pVbxr1wG.mjs.map +1 -0
- package/dist/line.mjs +13 -0
- package/dist/line.mjs.map +1 -0
- package/dist/prompt-CbmvGD9d.mjs +67 -0
- package/dist/prompt-CbmvGD9d.mjs.map +1 -0
- package/dist/server-rpmfEN1F.mjs +1241 -0
- package/dist/server-rpmfEN1F.mjs.map +1 -0
- package/package.json +48 -3
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* An expected failure. `runCli` turns this into a stable message/exit code
|
|
4
|
+
* instead of dumping a stack trace.
|
|
5
|
+
*/
|
|
6
|
+
var CliError = class extends Error {
|
|
7
|
+
code;
|
|
8
|
+
exitCode;
|
|
9
|
+
details;
|
|
10
|
+
constructor(code, message, options = {}) {
|
|
11
|
+
super(message, { cause: options.cause });
|
|
12
|
+
this.name = "CliError";
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.exitCode = options.exitCode ?? 1;
|
|
15
|
+
this.details = options.details;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var UsageError = class extends CliError {
|
|
19
|
+
constructor(message, details) {
|
|
20
|
+
super("USAGE", message, {
|
|
21
|
+
exitCode: 2,
|
|
22
|
+
details
|
|
23
|
+
});
|
|
24
|
+
this.name = "UsageError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function errorMessage(error) {
|
|
28
|
+
if (error instanceof Error) return error.message;
|
|
29
|
+
if (typeof error === "string") return error;
|
|
30
|
+
try {
|
|
31
|
+
return JSON.stringify(error);
|
|
32
|
+
} catch {
|
|
33
|
+
return String(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function toErrorPayload(error) {
|
|
37
|
+
if (error instanceof CliError) return {
|
|
38
|
+
code: error.code,
|
|
39
|
+
message: error.message,
|
|
40
|
+
...error.details === void 0 ? {} : { details: error.details }
|
|
41
|
+
};
|
|
42
|
+
if (error instanceof Error) return {
|
|
43
|
+
code: "INTERNAL",
|
|
44
|
+
message: error.message,
|
|
45
|
+
details: {
|
|
46
|
+
name: error.name,
|
|
47
|
+
...error.stack ? { stack: error.stack } : {},
|
|
48
|
+
...error.cause === void 0 ? {} : { cause: errorMessage(error.cause) }
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
code: "INTERNAL",
|
|
53
|
+
message: errorMessage(error)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { toErrorPayload as i, UsageError as n, errorMessage as r, CliError as t };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=errors-pVbxr1wG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-pVbxr1wG.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type CliErrorCode =\n\t| \"USAGE\"\n\t| \"AUTH_REQUIRED\"\n\t| \"AUTH_FAILED\"\n\t| \"PROFILE_NOT_FOUND\"\n\t| \"PROFILE_EXISTS\"\n\t| \"PROFILE_INVALID\"\n\t| \"CONFIRMATION_REQUIRED\"\n\t| \"INTERACTIVE_REQUIRED\"\n\t| \"NOT_FOUND\"\n\t| \"TIMEOUT\"\n\t| \"CANCELED\"\n\t| \"LINEJS_ERROR\"\n\t| \"INTERNAL\";\n\n/**\n * An expected failure. `runCli` turns this into a stable message/exit code\n * instead of dumping a stack trace.\n */\nexport class CliError extends Error {\n\treadonly code: CliErrorCode;\n\treadonly exitCode: number;\n\treadonly details?: unknown;\n\n\tconstructor(\n\t\tcode: CliErrorCode,\n\t\tmessage: string,\n\t\toptions: { exitCode?: number; details?: unknown; cause?: unknown } = {},\n\t) {\n\t\tsuper(message, { cause: options.cause });\n\t\tthis.name = \"CliError\";\n\t\tthis.code = code;\n\t\tthis.exitCode = options.exitCode ?? 1;\n\t\tthis.details = options.details;\n\t}\n}\n\nexport class UsageError extends CliError {\n\tconstructor(message: string, details?: unknown) {\n\t\tsuper(\"USAGE\", message, { exitCode: 2, details });\n\t\tthis.name = \"UsageError\";\n\t}\n}\n\nexport function errorMessage(error: unknown): string {\n\tif (error instanceof Error) return error.message;\n\tif (typeof error === \"string\") return error;\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n\nexport function toErrorPayload(error: unknown): {\n\tcode: string;\n\tmessage: string;\n\tdetails?: unknown;\n} {\n\tif (error instanceof CliError) {\n\t\treturn {\n\t\t\tcode: error.code,\n\t\t\tmessage: error.message,\n\t\t\t...(error.details === undefined ? {} : { details: error.details }),\n\t\t};\n\t}\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\tcode: \"INTERNAL\",\n\t\t\tmessage: error.message,\n\t\t\tdetails: {\n\t\t\t\tname: error.name,\n\t\t\t\t...(error.stack ? { stack: error.stack } : {}),\n\t\t\t\t...(error.cause === undefined ? {} : { cause: errorMessage(error.cause) }),\n\t\t\t},\n\t\t};\n\t}\n\treturn { code: \"INTERNAL\", message: errorMessage(error) };\n}\n"],"mappings":";;;;;AAmBA,IAAa,WAAb,cAA8B,MAAM;CACnC;CACA;CACA;CAEA,YACC,MACA,SACA,UAAqE,CAAC,GACrE;EACD,MAAM,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;EACvC,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,WAAW,QAAQ,YAAY;EACpC,KAAK,UAAU,QAAQ;CACxB;AACD;AAEA,IAAa,aAAb,cAAgC,SAAS;CACxC,YAAY,SAAiB,SAAmB;EAC/C,MAAM,SAAS,SAAS;GAAE,UAAU;GAAG;EAAQ,CAAC;EAChD,KAAK,OAAO;CACb;AACD;AAEA,SAAgB,aAAa,OAAwB;CACpD,IAAI,iBAAiB,OAAO,OAAO,MAAM;CACzC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI;EACH,OAAO,KAAK,UAAU,KAAK;CAC5B,QAAQ;EACP,OAAO,OAAO,KAAK;CACpB;AACD;AAEA,SAAgB,eAAe,OAI7B;CACD,IAAI,iBAAiB,UACpB,OAAO;EACN,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;CACjE;CAED,IAAI,iBAAiB,OACpB,OAAO;EACN,MAAM;EACN,SAAS,MAAM;EACf,SAAS;GACR,MAAM,MAAM;GACZ,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAC5C,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,aAAa,MAAM,KAAK,EAAE;EACzE;CACD;CAED,OAAO;EAAE,MAAM;EAAY,SAAS,aAAa,KAAK;CAAE;AACzD"}
|
package/dist/line.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as runCli } from "./cli-eG7C8gFC.mjs";
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
const argv = process.argv.slice(2);
|
|
5
|
+
if (argv[0] === "--") argv.shift();
|
|
6
|
+
const result = await runCli(argv, {
|
|
7
|
+
color: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR && process.env.TERM !== "dumb",
|
|
8
|
+
handleSignals: true
|
|
9
|
+
});
|
|
10
|
+
process.exitCode = result.exitCode;
|
|
11
|
+
export {};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=line.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { runCli } from \"./cli.ts\";\n\nconst argv = process.argv.slice(2);\n// `pnpm line -- ...` / some runners forward the separator; it is not a CLI arg.\nif (argv[0] === \"--\") argv.shift();\n\nconst result = await runCli(argv, {\n\tcolor: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR && process.env.TERM !== \"dumb\",\n\thandleSignals: true,\n});\n\nprocess.exitCode = result.exitCode;\n"],"mappings":";;;AAGA,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,IAAI,KAAK,OAAO,MAAM,KAAK,MAAM;AAEjC,MAAM,SAAS,MAAM,OAAO,MAAM;CACjC,OAAO,QAAQ,QAAQ,OAAO,KAAK,KAAK,CAAC,QAAQ,IAAI,YAAY,QAAQ,IAAI,SAAS;CACtF,eAAe;AAChB,CAAC;AAED,QAAQ,WAAW,OAAO"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { t as CliError } from "./errors-pVbxr1wG.mjs";
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
// src/prompt.ts
|
|
4
|
+
/** Read a password without echoing it when stdin is a TTY. */
|
|
5
|
+
async function promptSecret(question, context) {
|
|
6
|
+
if (!context.interactive) throw new CliError("INTERACTIVE_REQUIRED", "Password prompt requires a terminal. Pass --password-stdin or --password.");
|
|
7
|
+
if (!process.stdin.isTTY) {
|
|
8
|
+
const readline = createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
return await readline.question(question);
|
|
14
|
+
} finally {
|
|
15
|
+
readline.close();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const stdin = process.stdin;
|
|
19
|
+
const stdout = process.stdout;
|
|
20
|
+
stdout.write(question);
|
|
21
|
+
stdin.setRawMode(true);
|
|
22
|
+
stdin.resume();
|
|
23
|
+
stdin.setEncoding("utf8");
|
|
24
|
+
return await new Promise((resolve, reject) => {
|
|
25
|
+
let value = "";
|
|
26
|
+
const cleanup = () => {
|
|
27
|
+
stdin.off("data", onData);
|
|
28
|
+
stdin.setRawMode(false);
|
|
29
|
+
stdin.pause();
|
|
30
|
+
stdout.write("\n");
|
|
31
|
+
};
|
|
32
|
+
const onData = (chunk) => {
|
|
33
|
+
for (const char of chunk) {
|
|
34
|
+
if (char === "\r" || char === "\n") {
|
|
35
|
+
cleanup();
|
|
36
|
+
resolve(value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (char === "") {
|
|
40
|
+
cleanup();
|
|
41
|
+
reject(new CliError("CANCELED", "Canceled"));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (char === "") {
|
|
45
|
+
cleanup();
|
|
46
|
+
resolve(value);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (char === "" || char === "\b") {
|
|
50
|
+
if (value.length) {
|
|
51
|
+
value = value.slice(0, -1);
|
|
52
|
+
stdout.write("\b \b");
|
|
53
|
+
}
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (char >= " ") {
|
|
57
|
+
value += char;
|
|
58
|
+
stdout.write("*");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
stdin.on("data", onData);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export { promptSecret };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=prompt-CbmvGD9d.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-CbmvGD9d.mjs","names":[],"sources":["../src/prompt.ts"],"sourcesContent":["import { createInterface } from \"node:readline/promises\";\nimport type { CommandContext } from \"./context.ts\";\nimport { CliError } from \"./errors.ts\";\n\nexport async function promptLine(question: string, context: CommandContext): Promise<string> {\n\tif (!context.interactive) {\n\t\tthrow new CliError(\n\t\t\t\"INTERACTIVE_REQUIRED\",\n\t\t\t`${question.trim()} requires an interactive terminal`,\n\t\t);\n\t}\n\tconst readline = createInterface({ input: process.stdin, output: process.stdout });\n\ttry {\n\t\treturn await readline.question(question);\n\t} finally {\n\t\treadline.close();\n\t}\n}\n\nexport async function confirm(question: string, context: CommandContext): Promise<boolean> {\n\tconst answer = await promptLine(`${question} [y/N] `, context);\n\treturn /^y(?:es)?$/i.test(answer.trim());\n}\n\n/** Read a password without echoing it when stdin is a TTY. */\nexport async function promptSecret(question: string, context: CommandContext): Promise<string> {\n\tif (!context.interactive) {\n\t\tthrow new CliError(\n\t\t\t\"INTERACTIVE_REQUIRED\",\n\t\t\t\"Password prompt requires a terminal. Pass --password-stdin or --password.\",\n\t\t);\n\t}\n\tif (!process.stdin.isTTY) {\n\t\tconst readline = createInterface({ input: process.stdin, output: process.stdout });\n\t\ttry {\n\t\t\treturn await readline.question(question);\n\t\t} finally {\n\t\t\treadline.close();\n\t\t}\n\t}\n\n\tconst stdin = process.stdin;\n\tconst stdout = process.stdout;\n\tstdout.write(question);\n\tstdin.setRawMode(true);\n\tstdin.resume();\n\tstdin.setEncoding(\"utf8\");\n\n\treturn await new Promise<string>((resolve, reject) => {\n\t\tlet value = \"\";\n\t\tconst cleanup = () => {\n\t\t\tstdin.off(\"data\", onData);\n\t\t\tstdin.setRawMode(false);\n\t\t\tstdin.pause();\n\t\t\tstdout.write(\"\\n\");\n\t\t};\n\t\tconst onData = (chunk: string) => {\n\t\t\tfor (const char of chunk) {\n\t\t\t\tif (char === \"\\r\" || char === \"\\n\") {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tresolve(value);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (char === \"\\u0003\") {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treject(new CliError(\"CANCELED\", \"Canceled\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (char === \"\\u0004\") {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tresolve(value);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (char === \"\\u007f\" || char === \"\\b\") {\n\t\t\t\t\tif (value.length) {\n\t\t\t\t\t\tvalue = value.slice(0, -1);\n\t\t\t\t\t\tstdout.write(\"\\b \\b\");\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (char >= \" \") {\n\t\t\t\t\tvalue += char;\n\t\t\t\t\tstdout.write(\"*\");\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tstdin.on(\"data\", onData);\n\t});\n}\n"],"mappings":";;;;AAyBA,eAAsB,aAAa,UAAkB,SAA0C;CAC9F,IAAI,CAAC,QAAQ,aACZ,MAAM,IAAI,SACT,wBACA,2EACD;CAED,IAAI,CAAC,QAAQ,MAAM,OAAO;EACzB,MAAM,WAAW,gBAAgB;GAAE,OAAO,QAAQ;GAAO,QAAQ,QAAQ;EAAO,CAAC;EACjF,IAAI;GACH,OAAO,MAAM,SAAS,SAAS,QAAQ;EACxC,UAAU;GACT,SAAS,MAAM;EAChB;CACD;CAEA,MAAM,QAAQ,QAAQ;CACtB,MAAM,SAAS,QAAQ;CACvB,OAAO,MAAM,QAAQ;CACrB,MAAM,WAAW,IAAI;CACrB,MAAM,OAAO;CACb,MAAM,YAAY,MAAM;CAExB,OAAO,MAAM,IAAI,SAAiB,SAAS,WAAW;EACrD,IAAI,QAAQ;EACZ,MAAM,gBAAgB;GACrB,MAAM,IAAI,QAAQ,MAAM;GACxB,MAAM,WAAW,KAAK;GACtB,MAAM,MAAM;GACZ,OAAO,MAAM,IAAI;EAClB;EACA,MAAM,UAAU,UAAkB;GACjC,KAAK,MAAM,QAAQ,OAAO;IACzB,IAAI,SAAS,QAAQ,SAAS,MAAM;KACnC,QAAQ;KACR,QAAQ,KAAK;KACb;IACD;IACA,IAAI,SAAS,KAAU;KACtB,QAAQ;KACR,OAAO,IAAI,SAAS,YAAY,UAAU,CAAC;KAC3C;IACD;IACA,IAAI,SAAS,KAAU;KACtB,QAAQ;KACR,QAAQ,KAAK;KACb;IACD;IACA,IAAI,SAAS,OAAY,SAAS,MAAM;KACvC,IAAI,MAAM,QAAQ;MACjB,QAAQ,MAAM,MAAM,GAAG,EAAE;MACzB,OAAO,MAAM,OAAO;KACrB;KACA;IACD;IACA,IAAI,QAAQ,KAAK;KAChB,SAAS;KACT,OAAO,MAAM,GAAG;IACjB;GACD;EACD;EACA,MAAM,GAAG,QAAQ,MAAM;CACxB,CAAC;AACF"}
|