pipe-kan 0.13.1 → 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 +59 -28
- 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";
|
|
@@ -623,30 +623,33 @@ function createApp(opts) {
|
|
|
623
623
|
async refresh(next) {
|
|
624
624
|
if (next !== undefined)
|
|
625
625
|
flags = next;
|
|
626
|
-
childrenError = undefined;
|
|
627
626
|
const [issues, epics] = await Promise.all([
|
|
628
627
|
cli.list(flags),
|
|
629
628
|
cli.listEpics()
|
|
630
629
|
]);
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const keys =
|
|
630
|
+
const nextPayload = JSON.parse(issues);
|
|
631
|
+
const nextEpics = JSON.parse(epics);
|
|
632
|
+
const keys = issuesToBoard(nextEpics).epics.map((epic) => epic.key);
|
|
633
|
+
let nextChildren = [];
|
|
634
|
+
let nextHasCache = false;
|
|
635
|
+
let nextError;
|
|
634
636
|
try {
|
|
635
|
-
|
|
636
|
-
const cards = cardsOf(
|
|
637
|
+
nextChildren = JSON.parse(await cli.listChildren(keys));
|
|
638
|
+
const cards = cardsOf(nextChildren);
|
|
637
639
|
if (cards.length > 0 && !cards.some((card) => card.epic)) {
|
|
638
|
-
|
|
639
|
-
for (const key of keys) {
|
|
640
|
-
stamped.push(...stampRawParent(JSON.parse(await cli.listEpic(key)), key));
|
|
641
|
-
}
|
|
642
|
-
childrenRaw = stamped;
|
|
640
|
+
nextChildren = (await Promise.all(keys.map(async (key) => stampRawParent(JSON.parse(await cli.listEpic(key)), key)))).flat();
|
|
643
641
|
}
|
|
644
|
-
|
|
642
|
+
nextHasCache = true;
|
|
645
643
|
} catch (err) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
644
|
+
nextHasCache = false;
|
|
645
|
+
nextChildren = [];
|
|
646
|
+
nextError = err instanceof Error ? err.message : "Epic children list failed";
|
|
649
647
|
}
|
|
648
|
+
payload = nextPayload;
|
|
649
|
+
epicsPayload = nextEpics;
|
|
650
|
+
childrenRaw = nextChildren;
|
|
651
|
+
hasChildrenCache = nextHasCache;
|
|
652
|
+
childrenError = nextError;
|
|
650
653
|
return app.board();
|
|
651
654
|
},
|
|
652
655
|
async children(epic) {
|
|
@@ -1034,6 +1037,36 @@ function resolveListen(env = process.env) {
|
|
|
1034
1037
|
port: Number(env.PORT ?? 5173)
|
|
1035
1038
|
};
|
|
1036
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
|
+
}
|
|
1037
1070
|
|
|
1038
1071
|
// src/ui.ts
|
|
1039
1072
|
import { createReadStream, existsSync as existsSync2, statSync } from "node:fs";
|
|
@@ -1076,13 +1109,11 @@ function sendUi(root, req, res) {
|
|
|
1076
1109
|
|
|
1077
1110
|
// src/server.ts
|
|
1078
1111
|
async function readPipe() {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
const text = Buffer.concat(chunks).toString("utf8").trim();
|
|
1085
|
-
return text ? JSON.parse(text) : null;
|
|
1112
|
+
return readOptionalStdin();
|
|
1113
|
+
}
|
|
1114
|
+
function announce(line) {
|
|
1115
|
+
writeSync(1, `${line}
|
|
1116
|
+
`);
|
|
1086
1117
|
}
|
|
1087
1118
|
async function runServer(opts) {
|
|
1088
1119
|
const piped = await readPipe();
|
|
@@ -1104,9 +1135,13 @@ async function runServer(opts) {
|
|
|
1104
1135
|
}
|
|
1105
1136
|
});
|
|
1106
1137
|
const { host, port } = resolveListen();
|
|
1107
|
-
await
|
|
1138
|
+
await bindListen(server, host, port);
|
|
1108
1139
|
const origin = `http://127.0.0.1:${port}`;
|
|
1109
1140
|
const fakeConfig = writeJiraConfig(join4(tmpdir(), "pipe-kan"), origin);
|
|
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}`);
|
|
1110
1145
|
if (kind === "jira") {
|
|
1111
1146
|
try {
|
|
1112
1147
|
await refreshFromJira(app, kind, { piped: Boolean(piped) });
|
|
@@ -1115,10 +1150,6 @@ async function runServer(opts) {
|
|
|
1115
1150
|
console.error(err);
|
|
1116
1151
|
}
|
|
1117
1152
|
}
|
|
1118
|
-
console.log(`pipe-kan http://${host}:${port}`);
|
|
1119
|
-
console.log(`cli ${kind === "jira" ? resolveJiraBin() : "store"}`);
|
|
1120
|
-
console.log(`Fake Jira ${origin}/rest/api/2/search`);
|
|
1121
|
-
console.log(`Fake Jira config ${fakeConfig}`);
|
|
1122
1153
|
}
|
|
1123
1154
|
|
|
1124
1155
|
// src/bin.ts
|