pipe-kan 0.13.2 → 0.13.3
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/pipe-kan.js +41 -13
- package/package.json +1 -1
package/dist/pipe-kan.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/server.ts
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
4
|
+
import { readFileSync, writeSync } from "node:fs";
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { join as join4 } from "node:path";
|
|
@@ -1037,6 +1037,36 @@ function resolveListen(env = process.env) {
|
|
|
1037
1037
|
port: Number(env.PORT ?? 5173)
|
|
1038
1038
|
};
|
|
1039
1039
|
}
|
|
1040
|
+
function bindListen(server, host, port) {
|
|
1041
|
+
return new Promise((resolve, reject) => {
|
|
1042
|
+
const onError = (err) => reject(err);
|
|
1043
|
+
server.once("error", onError);
|
|
1044
|
+
server.listen(port, host, () => {
|
|
1045
|
+
server.off("error", onError);
|
|
1046
|
+
resolve();
|
|
1047
|
+
});
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// src/stdin.ts
|
|
1052
|
+
import { fstatSync } from "node:fs";
|
|
1053
|
+
async function readOptionalStdin(stdin = process.stdin, stat = stdinStat()) {
|
|
1054
|
+
if (stdin.isTTY || !stat.isFile && !stat.isFIFO)
|
|
1055
|
+
return null;
|
|
1056
|
+
const chunks = [];
|
|
1057
|
+
for await (const chunk of stdin)
|
|
1058
|
+
chunks.push(Buffer.from(chunk));
|
|
1059
|
+
const text = Buffer.concat(chunks).toString("utf8").trim();
|
|
1060
|
+
return text ? JSON.parse(text) : null;
|
|
1061
|
+
}
|
|
1062
|
+
function stdinStat() {
|
|
1063
|
+
try {
|
|
1064
|
+
const info = fstatSync(0);
|
|
1065
|
+
return { isFile: info.isFile(), isFIFO: info.isFIFO() };
|
|
1066
|
+
} catch {
|
|
1067
|
+
return { isFile: false, isFIFO: false };
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1040
1070
|
|
|
1041
1071
|
// src/ui.ts
|
|
1042
1072
|
import { createReadStream, existsSync as existsSync2, statSync } from "node:fs";
|
|
@@ -1079,13 +1109,11 @@ function sendUi(root, req, res) {
|
|
|
1079
1109
|
|
|
1080
1110
|
// src/server.ts
|
|
1081
1111
|
async function readPipe() {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
const text = Buffer.concat(chunks).toString("utf8").trim();
|
|
1088
|
-
return text ? JSON.parse(text) : null;
|
|
1112
|
+
return readOptionalStdin();
|
|
1113
|
+
}
|
|
1114
|
+
function announce(line) {
|
|
1115
|
+
writeSync(1, `${line}
|
|
1116
|
+
`);
|
|
1089
1117
|
}
|
|
1090
1118
|
async function runServer(opts) {
|
|
1091
1119
|
const piped = await readPipe();
|
|
@@ -1107,13 +1135,13 @@ async function runServer(opts) {
|
|
|
1107
1135
|
}
|
|
1108
1136
|
});
|
|
1109
1137
|
const { host, port } = resolveListen();
|
|
1110
|
-
await
|
|
1138
|
+
await bindListen(server, host, port);
|
|
1111
1139
|
const origin = `http://127.0.0.1:${port}`;
|
|
1112
1140
|
const fakeConfig = writeJiraConfig(join4(tmpdir(), "pipe-kan"), origin);
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1141
|
+
announce(`pipe-kan http://${host}:${port}`);
|
|
1142
|
+
announce(`cli ${kind === "jira" ? resolveJiraBin() : "store"}`);
|
|
1143
|
+
announce(`Fake Jira ${origin}/rest/api/2/search`);
|
|
1144
|
+
announce(`Fake Jira config ${fakeConfig}`);
|
|
1117
1145
|
if (kind === "jira") {
|
|
1118
1146
|
try {
|
|
1119
1147
|
await refreshFromJira(app, kind, { piped: Boolean(piped) });
|