@tama-create/sf-tools 1.4.0-dev.14 → 1.4.0-dev.15
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/core/log-box.js +18 -4
- package/dist/core/promote-check.js +2 -2
- package/dist/core/push.js +1 -0
- package/dist/ui/launcher.js +26 -11
- package/package.json +1 -1
package/dist/core/log-box.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// コマンドの記録をログファイルに残す道具の箱(シェル版の sf-project.log・verify.log の移し先。doc/rebuild-design.md 5.3)。
|
|
2
|
-
// - 始めに空にする(実行ごとに新しく書く。シェル版の LOG_MODE=NEW
|
|
2
|
+
// - 始めに空にする(実行ごとに新しく書く。シェル版の LOG_MODE=NEW と同じ)。毎日のコマンド(commandLogged)だけは、前回までの記録を残して追記する
|
|
3
|
+
// (大きくなったら、新しい側の約半分だけ残す)
|
|
3
4
|
// - 画面(標準エラー)に出した行を、時刻と段階を付けて書く。[INFO] などの段階の印がない行は INFO として書く。
|
|
4
5
|
// 空の行と、罫線だけの行は書かない
|
|
5
6
|
// - 外のコマンドは、[CMD] の行(引数)と、[OUT] の行(出力)と、終了コードを書く(画面には出さない)
|
|
@@ -37,11 +38,24 @@ export function commandLogged(command) {
|
|
|
37
38
|
if (!box.files.isDir("sf-tools") || args.includes("--status"))
|
|
38
39
|
return command.run(args, box);
|
|
39
40
|
const file = `sf-tools/logs/${command.name}.log`;
|
|
40
|
-
return command.run(args, fileLoggedBox(box, file, `sft ${command.name}`, { screenOnly: true }));
|
|
41
|
+
return command.run(args, fileLoggedBox(box, file, `sft ${command.name}`, { screenOnly: true, keep: true }));
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
|
-
/**
|
|
45
|
+
/** ログが、これ(文字数)を超えたら、新しい側の半分だけ残す */
|
|
46
|
+
const KEEP_MAX = 200_000;
|
|
47
|
+
/** 前回までの記録(keep のとき)。大きければ、新しい側の半分を、行の区切りから残す */
|
|
48
|
+
function previousLog(box, file) {
|
|
49
|
+
if (!box.files.exists(file))
|
|
50
|
+
return "";
|
|
51
|
+
const text = box.files.readText(file);
|
|
52
|
+
if (text.length <= KEEP_MAX)
|
|
53
|
+
return text;
|
|
54
|
+
const tail = text.slice(text.length - KEEP_MAX / 2);
|
|
55
|
+
const cut = tail.indexOf("\n");
|
|
56
|
+
return cut < 0 ? "" : tail.slice(cut + 1);
|
|
57
|
+
}
|
|
58
|
+
/** screenOnly: 標準出力の行も書き、外のコマンドの出力は書かない。keep: 始めに空にせず、前回までの記録に追記する */
|
|
45
59
|
export function fileLoggedBox(box, file, name, options = {}) {
|
|
46
60
|
let ok = true;
|
|
47
61
|
const write = (text) => {
|
|
@@ -58,7 +72,7 @@ export function fileLoggedBox(box, file, name, options = {}) {
|
|
|
58
72
|
const folder = file.replace(/[^\\/]*$/, "");
|
|
59
73
|
if (folder !== "")
|
|
60
74
|
box.files.makeDir(folder);
|
|
61
|
-
box.files.writeText(file, "");
|
|
75
|
+
box.files.writeText(file, options.keep ? previousLog(box, file) : "");
|
|
62
76
|
}
|
|
63
77
|
catch {
|
|
64
78
|
ok = false;
|
|
@@ -152,7 +152,7 @@ export async function runPromoteCheck(args, box, deps) {
|
|
|
152
152
|
const symP = mode === "plan" ? git("symbolic-ref", "--quiet", "--short", "HEAD") : null;
|
|
153
153
|
// 表示用(--quick)は、直近 60 秒以内に取得していたら、取得を省く(Windows は 1 回 3 秒前後かかる)。取得した時刻と手元のブランチは FETCH_STAMP に残す
|
|
154
154
|
const nowMs = box.clock.now().getTime();
|
|
155
|
-
const stamp = quick && mode === "plan" && box.files.exists(FETCH_STAMP) ? box.files.readText(FETCH_STAMP).split("
|
|
155
|
+
const stamp = quick && mode === "plan" && box.files.exists(FETCH_STAMP) ? box.files.readText(FETCH_STAMP).split("\n") : [];
|
|
156
156
|
const mainFresh = stamp.length >= 2 && nowMs - Number(stamp[0]) >= 0 && nowMs - Number(stamp[0]) < FETCH_FRESH_MS;
|
|
157
157
|
const skipped = { code: 0, stdout: "" };
|
|
158
158
|
const fetchMainP = mainFresh ? Promise.resolve(skipped) : git("fetch", "--quiet", "origin", "main");
|
|
@@ -378,7 +378,7 @@ export async function runPromoteCheck(args, box, deps) {
|
|
|
378
378
|
if (quick && !mainFresh) {
|
|
379
379
|
try {
|
|
380
380
|
box.files.makeDir("./sf-tools/logs");
|
|
381
|
-
box.files.writeText(FETCH_STAMP, `${nowMs}
|
|
381
|
+
box.files.writeText(FETCH_STAMP, `${nowMs}\n${result.branch}\n`);
|
|
382
382
|
}
|
|
383
383
|
catch {
|
|
384
384
|
// 省くための印のため、書けなくても続ける
|
package/dist/core/push.js
CHANGED
|
@@ -133,6 +133,7 @@ export async function runPush(args, box, deps) {
|
|
|
133
133
|
return EXIT.ok;
|
|
134
134
|
}
|
|
135
135
|
log("WARNING", "現在のディレクトリ配下に、コミット対象の変更がありません。");
|
|
136
|
+
log("INFO", "コミットも push もするものがないため、次の段階への PR の確認だけ行います。");
|
|
136
137
|
// 変更がなくても、次の段階への PR が要ることがある(develop にマージしたあと、staging へ出すときなど)。出し先と PR の有無は、sft pr が確かめる
|
|
137
138
|
await offerPr();
|
|
138
139
|
return EXIT.ok;
|
package/dist/ui/launcher.js
CHANGED
|
@@ -12,6 +12,14 @@ import { apexlogState, makePaint, parseGitStatus, parseNextError, parsePrevStatu
|
|
|
12
12
|
import { countTargets } from "../core/promote-check.js";
|
|
13
13
|
/** 裏の判定を、この時間ごとにやり直す(60 秒) */
|
|
14
14
|
const RECHECK_MS = 60_000;
|
|
15
|
+
const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
16
|
+
/** 描いた内容の比べ用: 色を除き、「更新中」の点灯・消灯の違いを除く(結果が変わらないなら、描き直さない) */
|
|
17
|
+
export function comparable(text) {
|
|
18
|
+
return text
|
|
19
|
+
.replace(ANSI, "")
|
|
20
|
+
.replace(/(前回の結果。更新中…)/g, "(前回の結果)")
|
|
21
|
+
.replace(/ {2}(更新中…)/g, "");
|
|
22
|
+
}
|
|
15
23
|
const LINE = "──────────────────────────────────────────────────";
|
|
16
24
|
const readOrNull = (box, path) => {
|
|
17
25
|
try {
|
|
@@ -62,7 +70,10 @@ export async function runLauncher(args, box, deps) {
|
|
|
62
70
|
.map((l) => l.replace(/\r$/, "").trim())
|
|
63
71
|
.filter((l) => l !== "" && !l.startsWith("#"));
|
|
64
72
|
};
|
|
65
|
-
|
|
73
|
+
/** 最後に描いた内容(comparable)。変わらないときは、タイマーによる描き直しを省く */
|
|
74
|
+
let lastDrawn = "";
|
|
75
|
+
/** onlyIfChanged: 描く内容が前回と同じなら、何も出さない(判定は動かす)。描いたかどうかを返す */
|
|
76
|
+
const draw = async (onlyIfChanged = false) => {
|
|
66
77
|
const st = await box.run("git", ["status", "--porcelain=v2", "--branch"]).catch(() => null);
|
|
67
78
|
const statusText = st !== null && st.code === 0 ? st.stdout : "";
|
|
68
79
|
const git = parseGitStatus(statusText);
|
|
@@ -131,17 +142,20 @@ export async function runLauncher(args, box, deps) {
|
|
|
131
142
|
checkDone = true;
|
|
132
143
|
});
|
|
133
144
|
}
|
|
134
|
-
|
|
135
|
-
err(paint.dim(` ${LINE}`));
|
|
136
|
-
for (const l of lines)
|
|
137
|
-
err(l);
|
|
138
|
-
err(paint.dim(` ${LINE}`));
|
|
145
|
+
const block = ["", paint.dim(` ${LINE}`), ...lines, paint.dim(` ${LINE}`)];
|
|
139
146
|
items.forEach((item, i) => {
|
|
140
147
|
if (i > 0 && item.group !== items[i - 1]?.group)
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
block.push(paint.dim(" ──────────"));
|
|
149
|
+
block.push(` ${paint.cyan(`[${i + 1}]`)} ${paint.bold(item.label.padEnd(11))} ${paint.dim(item.description)}`);
|
|
143
150
|
});
|
|
144
|
-
|
|
151
|
+
block.push(paint.dim(` ${LINE}`));
|
|
152
|
+
const same = comparable(block.join("\n"));
|
|
153
|
+
if (onlyIfChanged && same === lastDrawn)
|
|
154
|
+
return false; // 画面が変わらないのに、メニューを流さない
|
|
155
|
+
lastDrawn = same;
|
|
156
|
+
for (const l of block)
|
|
157
|
+
err(l);
|
|
158
|
+
return true;
|
|
145
159
|
};
|
|
146
160
|
for (;;) {
|
|
147
161
|
await draw();
|
|
@@ -162,9 +176,10 @@ export async function runLauncher(args, box, deps) {
|
|
|
162
176
|
}
|
|
163
177
|
if (logChanged || checkDone || stale) {
|
|
164
178
|
checkDone = false;
|
|
165
|
-
await draw();
|
|
179
|
+
const printed = await draw(true); // 表示が変わらなければ、何も出さない(判定の更新中の点灯・消灯だけでは、描き直さない)
|
|
166
180
|
shown = now;
|
|
167
|
-
|
|
181
|
+
if (printed)
|
|
182
|
+
err(prompt);
|
|
168
183
|
}
|
|
169
184
|
continue;
|
|
170
185
|
}
|