@tama-create/sf-tools 1.4.0-dev.14 → 1.4.0-dev.16

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.
@@ -229,7 +229,7 @@ export function statusLines(input, paint) {
229
229
  if (st.next === "none" || i < nidx)
230
230
  return paint.green(`✓ ${t}`);
231
231
  if (i === nidx)
232
- return paint.boldCyan(st.pr !== "" ? `▸ ${t} (PR #${st.pr} 発行中)` : `▸ ${t} (次のPR)`);
232
+ return paint.boldCyan(st.pr !== "" ? `▸ ${t} (PR #${st.pr} 発行中)` : nidx === 0 ? `▸ ${t} (次のPR・このコミットは未リリース)` : `▸ ${t} (次のPR)`);
233
233
  return paint.dim(`× ${t}`);
234
234
  })
235
235
  .join(` ${paint.dim("⇒")} `);
@@ -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
- /** screenOnly: 標準出力の行も書き、外のコマンドの出力は書かない */
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;
package/dist/core/pr.js CHANGED
@@ -178,6 +178,11 @@ export async function runPr(args, box, deps, ask) {
178
178
  box.output.err(` ✗ ${t}`);
179
179
  }
180
180
  box.output.err("");
181
+ // 次の PR 先の理由: 印は「このコミット」に付くため、新しいコミットを積むと、前のコミットが出済みでも、最初の段階から出し直しになる
182
+ if (!plan.skipped && plan.next !== "none" && plan.prOpen === "" && plan.tiers[0] === plan.next) {
183
+ const short = head !== null && head.code === 0 ? ` ${head.stdout.trim().slice(0, 7)}` : "";
184
+ log("INFO", `この先端のコミット${short}は、まだ ${plan.next} に出ていません(新しいコミットを積むと、前のコミットが出済みでも、${plan.tiers.join(" → ")} の順に、最初の段階から出します)。`);
185
+ }
181
186
  if (plan.skipped) {
182
187
  log("INFO", "ターゲットファイル(deploy-target.txt・remove-target.txt)に対象がないため、出すものがありません。");
183
188
  return EXIT.ok;
@@ -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("'+B+'n") : [];
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}'+B+'n${result.branch}'+B+'n`);
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;
@@ -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
- const draw = async () => {
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
- err("");
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
- err(paint.dim(" ──────────"));
142
- err(` ${paint.cyan(`[${i + 1}]`)} ${paint.bold(item.label.padEnd(11))} ${paint.dim(item.description)}`);
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
- err(paint.dim(` ${LINE}`));
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
- err(prompt);
181
+ if (printed)
182
+ err(prompt);
168
183
  }
169
184
  continue;
170
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tama-create/sf-tools",
3
- "version": "1.4.0-dev.14",
3
+ "version": "1.4.0-dev.16",
4
4
  "description": "Salesforce 開発の環境構築と毎日の作業を自動化する(TypeScript 版・開発中)",
5
5
  "license": "Unlicense",
6
6
  "repository": {