@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.10

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.
Files changed (164) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +212 -2
  3. package/bin/sft.js +22 -0
  4. package/config/changeset-types.txt +350 -0
  5. package/config/install/gitmessage +6 -0
  6. package/config/install/release/README.md +26 -0
  7. package/config/install/release/deploy-target.txt +368 -0
  8. package/config/install/release/remove-target.txt +279 -0
  9. package/config/metadata-capability.txt +118 -0
  10. package/config/metadata-dirs.txt +79 -0
  11. package/config/metasync-detect.txt +52 -0
  12. package/config/metasync-extra.txt +30 -0
  13. package/config/metasync-fingerprint.txt +90 -0
  14. package/dist/cli.js +35 -0
  15. package/dist/commands/admin.js +46 -0
  16. package/dist/commands/check.js +20 -0
  17. package/dist/commands/ci.js +123 -0
  18. package/dist/commands/deploy.js +31 -0
  19. package/dist/commands/doctor.js +11 -0
  20. package/dist/commands/dryrun.js +17 -0
  21. package/dist/commands/hook.js +46 -0
  22. package/dist/commands/index.js +37 -0
  23. package/dist/commands/job.js +31 -0
  24. package/dist/commands/launcher.js +57 -0
  25. package/dist/commands/log.js +58 -0
  26. package/dist/commands/metasync.js +21 -0
  27. package/dist/commands/pr.js +32 -0
  28. package/dist/commands/project.js +102 -0
  29. package/dist/commands/push.js +16 -0
  30. package/dist/commands/release.js +19 -0
  31. package/dist/commands/start.js +67 -0
  32. package/dist/commands/switch-org.js +12 -0
  33. package/dist/commands/update-cli.js +11 -0
  34. package/dist/commands/version.js +18 -0
  35. package/dist/core/admin-clone.js +79 -0
  36. package/dist/core/ai-answers.js +40 -0
  37. package/dist/core/branches.js +88 -0
  38. package/dist/core/check-targets.js +170 -0
  39. package/dist/core/check.js +34 -0
  40. package/dist/core/ci-check-branch.js +150 -0
  41. package/dist/core/ci-login-steps.js +73 -0
  42. package/dist/core/ci-release-steps.js +193 -0
  43. package/dist/core/ci-sequence-steps.js +188 -0
  44. package/dist/core/ci-validate-steps.js +140 -0
  45. package/dist/core/cli-update-notice.js +47 -0
  46. package/dist/core/command.js +25 -0
  47. package/dist/core/create-connect.js +519 -0
  48. package/dist/core/create-setup.js +358 -0
  49. package/dist/core/create-state.js +82 -0
  50. package/dist/core/delegate.js +45 -0
  51. package/dist/core/deploy.js +66 -0
  52. package/dist/core/diag.js +200 -0
  53. package/dist/core/doctor.js +211 -0
  54. package/dist/core/eca.js +259 -0
  55. package/dist/core/exit-codes.js +12 -0
  56. package/dist/core/gh-identity.js +46 -0
  57. package/dist/core/hook-install.js +130 -0
  58. package/dist/core/hook.js +116 -0
  59. package/dist/core/identity.js +48 -0
  60. package/dist/core/job.js +243 -0
  61. package/dist/core/launcher-status.js +215 -0
  62. package/dist/core/lines.js +25 -0
  63. package/dist/core/log-auto.js +56 -0
  64. package/dist/core/log-box.js +109 -0
  65. package/dist/core/log-collector.js +370 -0
  66. package/dist/core/log-format.js +44 -0
  67. package/dist/core/log-pull.js +565 -0
  68. package/dist/core/log-select.js +126 -0
  69. package/dist/core/log-session.js +362 -0
  70. package/dist/core/log-start.js +421 -0
  71. package/dist/core/log-status.js +223 -0
  72. package/dist/core/log-summarize.js +127 -0
  73. package/dist/core/logger.js +71 -0
  74. package/dist/core/login-url.js +50 -0
  75. package/dist/core/manifest-build.js +118 -0
  76. package/dist/core/mask.js +70 -0
  77. package/dist/core/metadata-types.js +79 -0
  78. package/dist/core/metasync.js +684 -0
  79. package/dist/core/new-version.js +93 -0
  80. package/dist/core/org.js +115 -0
  81. package/dist/core/origin.js +62 -0
  82. package/dist/core/package-xml.js +157 -0
  83. package/dist/core/pr.js +217 -0
  84. package/dist/core/project-create.js +733 -0
  85. package/dist/core/project-reconnect.js +126 -0
  86. package/dist/core/project-status.js +246 -0
  87. package/dist/core/project-tier.js +374 -0
  88. package/dist/core/project-upgrade.js +138 -0
  89. package/dist/core/project-verify.js +517 -0
  90. package/dist/core/promote-check.js +401 -0
  91. package/dist/core/promote.js +141 -0
  92. package/dist/core/push.js +163 -0
  93. package/dist/core/release.js +256 -0
  94. package/dist/core/scoped-box.js +29 -0
  95. package/dist/core/start.js +155 -0
  96. package/dist/core/switch-org.js +49 -0
  97. package/dist/core/test-types.js +212 -0
  98. package/dist/core/toolbox.js +4 -0
  99. package/dist/core/update-cli.js +156 -0
  100. package/dist/core/update-secret.js +301 -0
  101. package/dist/core/update-workflows.js +132 -0
  102. package/dist/core/verify-gh.js +286 -0
  103. package/dist/core/verify-samples.js +152 -0
  104. package/dist/core/windows-shim.js +21 -0
  105. package/dist/io/capability-file.js +11 -0
  106. package/dist/io/create-deps.js +69 -0
  107. package/dist/io/doctor-deps.js +32 -0
  108. package/dist/io/hook-install-deps.js +11 -0
  109. package/dist/io/job-deps.js +39 -0
  110. package/dist/io/key-file.js +17 -0
  111. package/dist/io/keys.js +172 -0
  112. package/dist/io/log-deps.js +107 -0
  113. package/dist/io/metasync-deps.js +22 -0
  114. package/dist/io/open-browser.js +21 -0
  115. package/dist/io/package-version.js +10 -0
  116. package/dist/io/pinned-project.js +111 -0
  117. package/dist/io/promote-deps.js +28 -0
  118. package/dist/io/push-refs.js +20 -0
  119. package/dist/io/resolve.js +74 -0
  120. package/dist/io/run.js +201 -0
  121. package/dist/io/switch-org-deps.js +10 -0
  122. package/dist/io/temp-dir.js +24 -0
  123. package/dist/io/tool-versions.js +14 -0
  124. package/dist/io/toolbox.js +68 -0
  125. package/dist/io/update-cli-deps.js +75 -0
  126. package/dist/io/update-secret-deps.js +27 -0
  127. package/dist/launch.js +152 -0
  128. package/dist/ui/confirm.js +18 -0
  129. package/dist/ui/launcher.js +163 -0
  130. package/dist/ui/prompt.js +66 -0
  131. package/lib/apexlog.js +819 -0
  132. package/lib/metasync.js +1364 -0
  133. package/lib/package.json +4 -0
  134. package/lib/typecheck.js +547 -0
  135. package/package.json +44 -4
  136. package/templates/.forceignore +12 -0
  137. package/templates/.gitattributes +58 -0
  138. package/templates/.github/workflows/wf-metasync.yml +177 -0
  139. package/templates/.github/workflows/wf-release.yml +454 -0
  140. package/templates/.github/workflows/wf-sequence.yml +292 -0
  141. package/templates/.github/workflows/wf-validate.yml +389 -0
  142. package/templates/.prettierignore +11 -0
  143. package/templates/.prettierrc +17 -0
  144. package/templates/.vscode/extensions.json +9 -0
  145. package/templates/.vscode/launch.json +16 -0
  146. package/templates/.vscode/settings.json +39 -0
  147. package/templates/AGENTS.md +3 -0
  148. package/templates/CLAUDE.md +4 -0
  149. package/templates/README.md +11 -0
  150. package/templates/config/project-scratch-def.json +13 -0
  151. package/templates/eslint.config.js +55 -0
  152. package/templates/force-app/main/default/.gitkeep +0 -0
  153. package/templates/gitignore.template +62 -0
  154. package/templates/jest.config.js +6 -0
  155. package/templates/package.json +29 -0
  156. package/templates/scripts/apex/hello.apex +10 -0
  157. package/templates/scripts/soql/account.soql +6 -0
  158. package/templates/sf-tools/config/branches.txt +24 -0
  159. package/templates/sf-tools/config/metadata.txt +576 -0
  160. package/templates/sfdx-project.json +12 -0
  161. package/templates-ts/.github/workflows/wf-metasync.yml +109 -0
  162. package/templates-ts/.github/workflows/wf-release.yml +263 -0
  163. package/templates-ts/.github/workflows/wf-sequence.yml +153 -0
  164. package/templates-ts/.github/workflows/wf-validate.yml +185 -0
@@ -0,0 +1,163 @@
1
+ // ランチャー(sft を引数なしで、force-* の中で打ったときのメニュー)。phases/start/launcher.sh の移し先(doc/rebuild-design.md 6.1)。
2
+ // 項目は、サブコマンドの表(menu を持つもの)から作る。番号のキーを押すとすぐ動き(Enter は要らない)、終わるとメニューに戻る。
3
+ // q と入力の終わりで終了(0)。範囲外の数字・ほかのキーは聞き直す。Ctrl+C は、メニューの中では無効(誤って閉じない: 6.3)。
4
+ // 何も打たずに Enter: メニューを描き直し、裏の判定をやり直す(PR のマージは先端のコミットを変えないため、保存した結果では次の段階に変わらない)。
5
+ // 判定が動いているあいだの Enter は、描き直すだけ(2 つ同時には動かさない)。
6
+ // 見出し(core/launcher-status.ts)は、メニューを描くたびに作る。入力を 5 秒ずつ待ち、デバッグログの状態(準備中・取得中)が
7
+ // 変わった・裏の判定(sft pr --status)が終わったら、コマンドを動かさずに描き直す(待っている入力は、そのまま続ける)。
8
+ // 結果は 1 行: 0 →「✓ <名前>: 終わりました(成功)」/ それ以外 →「✗ <名前>: 失敗、または中断しました(終了コード N)」。
9
+ // なくしたもの: 自分のファイルの書き換わりを見て読み込み直す動き(版を固定するため: 設計 2.4.2)。
10
+ // 組織への接続・doctor・デバッグログの取得は、開く前に src/core/start.ts が行う。項目 Start は、組織の接続・VS Code・doctor をやり直す(src/commands/start.ts。ランチャーは開き直さない)
11
+ import { apexlogState, makePaint, parseGitStatus, statusLines, targetOrg, uncommittedTargets } from "../core/launcher-status.js";
12
+ import { countTargets } from "../core/promote-check.js";
13
+ const LINE = "──────────────────────────────────────────────────";
14
+ const readOrNull = (box, path) => {
15
+ try {
16
+ return box.files.exists(path) ? box.files.readText(path) : null;
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ };
22
+ export async function runLauncher(args, box, deps) {
23
+ const paint = makePaint(deps.color);
24
+ const err = (l) => box.output.err(l);
25
+ if (args.length > 0) {
26
+ err(paint.yellow(" ⚠ 引数は付けません"));
27
+ return 1;
28
+ }
29
+ if (!deps.folderName.startsWith("force-")) {
30
+ err(paint.yellow(" ⚠ force-* ディレクトリ内で実行してください。"));
31
+ return 1;
32
+ }
33
+ const { items } = deps;
34
+ const prNumber = items.findIndex((i) => i.name === "pr") + 1;
35
+ const prompt = ` 番号を入力 (1-${items.length} / Enter で再表示 / q で終了): `;
36
+ /** 裏の判定を最後に頼んだときの、先端のコミットと対象のファイルの空・空でない */
37
+ let checkedKey = "";
38
+ let checking = false;
39
+ let checkDone = false;
40
+ /** Enter で頼まれた判定のやり直し(次に描くとき、保存した結果を使わずに判定する) */
41
+ let recheck = false;
42
+ const wantCheckFor = (head, key) => head !== "" && key !== checkedKey;
43
+ const targetsEmpty = (branch) => {
44
+ try {
45
+ const counts = ["deploy-target.txt", "remove-target.txt"].map((f) => countTargets(box, `sf-tools/release/${branch}/${f}`));
46
+ return counts.every((n) => n === null) ? null : counts.every((n) => !n);
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ };
52
+ const envBranches = () => {
53
+ const text = readOrNull(box, "sf-tools/config/branches.txt") ?? "";
54
+ return text
55
+ .split("\n")
56
+ .map((l) => l.replace(/\r$/, "").trim())
57
+ .filter((l) => l !== "" && !l.startsWith("#"));
58
+ };
59
+ const draw = async () => {
60
+ const st = await box.run("git", ["status", "--porcelain=v2", "--branch"]).catch(() => null);
61
+ const statusText = st !== null && st.code === 0 ? st.stdout : "";
62
+ const git = parseGitStatus(statusText);
63
+ const empty = targetsEmpty(git.branch);
64
+ const key = `${git.head} ${empty}`;
65
+ const fresh = recheck && !checking && deps.startPrStatus !== null;
66
+ if (fresh)
67
+ checkedKey = "";
68
+ recheck = false;
69
+ const { lines, wantCheck } = statusLines({
70
+ git,
71
+ org: targetOrg(readOrNull(box, ".sf/config.json")),
72
+ apexlog: readOrNull(box, "logs/apex/.status"),
73
+ nextStatus: readOrNull(box, "sf-tools/logs/next-status.txt"), // 判定し直すあいだも、前回の結果を出す(「更新中」を添える)
74
+ targetsEmpty: empty,
75
+ uncommitted: uncommittedTargets(statusText, git.branch),
76
+ envBranches: envBranches(),
77
+ checking: checking || (wantCheckFor(git.head, key) && deps.startPrStatus !== null), // これから始める分も「確かめています」
78
+ refresh: fresh,
79
+ prNumber,
80
+ }, paint);
81
+ // 使える結果がない → 裏で判定する(先端のコミットと対象の空・空でないの組ごとに 1 回。失敗しても繰り返さない)
82
+ if (wantCheck && wantCheckFor(git.head, key) && deps.startPrStatus !== null) {
83
+ checkedKey = key;
84
+ checking = true;
85
+ deps
86
+ .startPrStatus()
87
+ .catch(() => undefined)
88
+ .finally(() => {
89
+ checking = false;
90
+ checkDone = true;
91
+ });
92
+ }
93
+ err("");
94
+ err(paint.dim(` ${LINE}`));
95
+ for (const l of lines)
96
+ err(l);
97
+ err(paint.dim(` ${LINE}`));
98
+ items.forEach((item, i) => {
99
+ if (i > 0 && item.group !== items[i - 1]?.group)
100
+ err(paint.dim(" ──────────"));
101
+ err(` ${paint.cyan(`[${i + 1}]`)} ${paint.bold(item.label.padEnd(11))} ${paint.dim(item.description)}`);
102
+ });
103
+ err(paint.dim(` ${LINE}`));
104
+ };
105
+ for (;;) {
106
+ await draw();
107
+ let shown = apexlogState(readOrNull(box, "logs/apex/.status"));
108
+ let pending = box.input.readKey(prompt);
109
+ let chosen = null;
110
+ while (chosen === null && !recheck) {
111
+ const got = await Promise.race([pending.then((key) => ({ key })), deps.tick().then(() => null)]);
112
+ if (got === null) {
113
+ // 待ち切れ: 準備中・取得中の状態が変わった・裏の判定が終わったら、描き直す(本数・期限の更新では描き直さない)
114
+ const now = apexlogState(readOrNull(box, "logs/apex/.status"));
115
+ const logChanged = (shown === "starting" || shown === "collecting") && now !== shown;
116
+ if (logChanged || checkDone) {
117
+ checkDone = false;
118
+ await draw();
119
+ shown = now;
120
+ err(prompt);
121
+ }
122
+ continue;
123
+ }
124
+ const { key } = got;
125
+ if (key === null) {
126
+ err("");
127
+ return 0;
128
+ }
129
+ if (key === "q" || key === "Q") {
130
+ err(paint.dim(" 終了しました"));
131
+ err("");
132
+ return 0;
133
+ }
134
+ if (key === "" || key === "\r" || key === "\n") {
135
+ recheck = true;
136
+ continue;
137
+ }
138
+ const n = /^[1-9]$/.test(key) ? Number(key) : 0;
139
+ const item = n >= 1 && n <= items.length ? items[n - 1] : undefined;
140
+ if (item)
141
+ chosen = item;
142
+ else
143
+ pending = box.input.readKey(prompt); // 範囲外・ほかのキー・Ctrl+C は聞き直す
144
+ }
145
+ if (chosen === null)
146
+ continue; // Enter: 描き直す
147
+ err("");
148
+ err(paint.green(` ▶ sft ${chosen.name}`));
149
+ err("");
150
+ let rc;
151
+ try {
152
+ rc = await chosen.run();
153
+ }
154
+ catch (e) {
155
+ err(`[ERROR] ${e instanceof Error ? e.message : String(e)}`);
156
+ rc = 1;
157
+ }
158
+ err("");
159
+ err(rc === 0
160
+ ? paint.boldGreen(` ✓ ${chosen.label}: 終わりました(成功)`)
161
+ : paint.boldRed(` ✗ ${chosen.label}: 失敗、または中断しました(終了コード ${rc})`));
162
+ }
163
+ }
@@ -0,0 +1,66 @@
1
+ const ctrlC = String.fromCharCode(3);
2
+ /** 空でない 1 行を読む(空の Enter は聞き直す)。q だけの行は中断 */
3
+ export async function readOrQuit(input, prompt) {
4
+ for (;;) {
5
+ const line = await input.readLine(prompt);
6
+ if (line === null)
7
+ return { kind: "quit" };
8
+ if (line === ctrlC)
9
+ return { kind: "interrupted" };
10
+ if (line === "")
11
+ continue;
12
+ if (line === "q" || line === "Q")
13
+ return { kind: "quit" };
14
+ return { kind: "text", value: line };
15
+ }
16
+ }
17
+ /** 表示しない入力(空の Enter は聞き直す)。端末でなければ受け付けない(設計 5.5)。値は、画面にもログにも出さない */
18
+ export async function readSecretValue(input, prompt) {
19
+ for (;;) {
20
+ const value = await input.readSecret(prompt);
21
+ if (value === "no-tty")
22
+ return { kind: "no-tty" };
23
+ if (value === null)
24
+ return { kind: "quit" };
25
+ if (value === ctrlC)
26
+ return { kind: "interrupted" };
27
+ if (value === "")
28
+ continue;
29
+ return { kind: "secret", value };
30
+ }
31
+ }
32
+ /**
33
+ * 番号で選ぶ(1 から)。9 個までは、キー 1 つ(端末では Enter が要らない)。10 個からは、番号を打って Enter。
34
+ * 範囲の外・数字でない入力は、聞き直す
35
+ */
36
+ export async function chooseNumber(input, output, title, items) {
37
+ output.err(title);
38
+ for (const [i, item] of items.entries())
39
+ output.err(` ${i + 1}) ${item}`);
40
+ const prompt = ` 番号を選んでください(1〜${items.length} / q で中断): `;
41
+ for (;;) {
42
+ const got = items.length <= 9 ? await input.readKey(prompt) : await input.readLine(prompt);
43
+ if (got === null)
44
+ return { kind: "quit" };
45
+ if (got === ctrlC)
46
+ return { kind: "interrupted" };
47
+ const v = got.trim();
48
+ if (v === "q" || v === "Q")
49
+ return { kind: "quit" };
50
+ if (/^[0-9]+$/.test(v)) {
51
+ const n = Number(v);
52
+ if (n >= 1 && n <= items.length)
53
+ return { kind: "chosen", index: n - 1 };
54
+ }
55
+ }
56
+ }
57
+ /** ログイン先の選択(core/login-url.ts)などに渡す、1 行の入力の組(text: 空は聞き直し・q で "quit" / line: 空も返す) */
58
+ export function loginPrompts(input) {
59
+ return {
60
+ text: async (prompt) => {
61
+ const r = await readOrQuit(input, prompt);
62
+ return r.kind === "text" ? r.value : "quit";
63
+ },
64
+ line: (prompt) => input.readLine(prompt),
65
+ };
66
+ }