@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.2
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/LICENSE +24 -0
- package/README.md +212 -2
- package/bin/sft.js +22 -0
- package/dist/cli.js +35 -0
- package/dist/commands/admin.js +46 -0
- package/dist/commands/check.js +20 -0
- package/dist/commands/ci.js +123 -0
- package/dist/commands/deploy.js +31 -0
- package/dist/commands/doctor.js +11 -0
- package/dist/commands/dryrun.js +17 -0
- package/dist/commands/hook.js +46 -0
- package/dist/commands/index.js +36 -0
- package/dist/commands/job.js +31 -0
- package/dist/commands/launcher.js +40 -0
- package/dist/commands/log.js +58 -0
- package/dist/commands/metasync.js +21 -0
- package/dist/commands/pr.js +32 -0
- package/dist/commands/project.js +93 -0
- package/dist/commands/push.js +16 -0
- package/dist/commands/release.js +19 -0
- package/dist/commands/start.js +19 -0
- package/dist/commands/switch-org.js +12 -0
- package/dist/commands/update-cli.js +11 -0
- package/dist/commands/version.js +18 -0
- package/dist/core/admin-clone.js +79 -0
- package/dist/core/ai-answers.js +40 -0
- package/dist/core/branches.js +88 -0
- package/dist/core/check-targets.js +170 -0
- package/dist/core/check.js +34 -0
- package/dist/core/ci-check-branch.js +150 -0
- package/dist/core/ci-login-steps.js +73 -0
- package/dist/core/ci-release-steps.js +193 -0
- package/dist/core/ci-sequence-steps.js +188 -0
- package/dist/core/ci-validate-steps.js +140 -0
- package/dist/core/command.js +25 -0
- package/dist/core/create-connect.js +519 -0
- package/dist/core/create-setup.js +314 -0
- package/dist/core/create-state.js +82 -0
- package/dist/core/delegate.js +45 -0
- package/dist/core/deploy.js +66 -0
- package/dist/core/diag.js +200 -0
- package/dist/core/doctor.js +211 -0
- package/dist/core/eca.js +259 -0
- package/dist/core/exit-codes.js +12 -0
- package/dist/core/gh-identity.js +46 -0
- package/dist/core/hook-install.js +130 -0
- package/dist/core/hook.js +116 -0
- package/dist/core/identity.js +48 -0
- package/dist/core/job.js +243 -0
- package/dist/core/launcher-status.js +184 -0
- package/dist/core/lines.js +25 -0
- package/dist/core/log-auto.js +56 -0
- package/dist/core/log-box.js +85 -0
- package/dist/core/log-collector.js +370 -0
- package/dist/core/log-format.js +44 -0
- package/dist/core/log-pull.js +565 -0
- package/dist/core/log-select.js +126 -0
- package/dist/core/log-session.js +362 -0
- package/dist/core/log-start.js +421 -0
- package/dist/core/log-status.js +223 -0
- package/dist/core/log-summarize.js +127 -0
- package/dist/core/logger.js +71 -0
- package/dist/core/login-url.js +50 -0
- package/dist/core/manifest-build.js +118 -0
- package/dist/core/mask.js +70 -0
- package/dist/core/metadata-types.js +79 -0
- package/dist/core/metasync.js +684 -0
- package/dist/core/org.js +115 -0
- package/dist/core/origin.js +62 -0
- package/dist/core/package-xml.js +157 -0
- package/dist/core/pr.js +199 -0
- package/dist/core/project-create.js +733 -0
- package/dist/core/project-reconnect.js +126 -0
- package/dist/core/project-status.js +235 -0
- package/dist/core/project-tier.js +374 -0
- package/dist/core/project-verify.js +517 -0
- package/dist/core/promote-check.js +380 -0
- package/dist/core/promote.js +141 -0
- package/dist/core/push.js +152 -0
- package/dist/core/release.js +256 -0
- package/dist/core/scoped-box.js +29 -0
- package/dist/core/start.js +155 -0
- package/dist/core/switch-org.js +49 -0
- package/dist/core/test-types.js +212 -0
- package/dist/core/toolbox.js +4 -0
- package/dist/core/update-cli.js +156 -0
- package/dist/core/update-secret.js +301 -0
- package/dist/core/update-workflows.js +132 -0
- package/dist/core/verify-gh.js +286 -0
- package/dist/core/verify-samples.js +152 -0
- package/dist/core/windows-shim.js +21 -0
- package/dist/io/capability-file.js +11 -0
- package/dist/io/create-deps.js +68 -0
- package/dist/io/doctor-deps.js +32 -0
- package/dist/io/hook-install-deps.js +11 -0
- package/dist/io/job-deps.js +31 -0
- package/dist/io/key-file.js +17 -0
- package/dist/io/keys.js +161 -0
- package/dist/io/log-deps.js +106 -0
- package/dist/io/metasync-deps.js +21 -0
- package/dist/io/open-browser.js +21 -0
- package/dist/io/package-version.js +10 -0
- package/dist/io/pinned-project.js +111 -0
- package/dist/io/promote-deps.js +27 -0
- package/dist/io/push-refs.js +20 -0
- package/dist/io/resolve.js +74 -0
- package/dist/io/run.js +201 -0
- package/dist/io/switch-org-deps.js +10 -0
- package/dist/io/temp-dir.js +10 -0
- package/dist/io/tool-versions.js +14 -0
- package/dist/io/toolbox.js +68 -0
- package/dist/io/update-cli-deps.js +75 -0
- package/dist/io/update-secret-deps.js +27 -0
- package/dist/launch.js +152 -0
- package/dist/ui/confirm.js +18 -0
- package/dist/ui/launcher.js +132 -0
- package/dist/ui/prompt.js +66 -0
- package/package.json +37 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { adminCommand } from "./admin.js";
|
|
2
|
+
import { checkCommand } from "./check.js";
|
|
3
|
+
import { ciCommand } from "./ci.js";
|
|
4
|
+
import { deployCommand } from "./deploy.js";
|
|
5
|
+
import { doctorCommand } from "./doctor.js";
|
|
6
|
+
import { dryrunCommand } from "./dryrun.js";
|
|
7
|
+
import { hookCommand } from "./hook.js";
|
|
8
|
+
import { jobCommand } from "./job.js";
|
|
9
|
+
import { logCommand } from "./log.js";
|
|
10
|
+
import { metasyncCommand } from "./metasync.js";
|
|
11
|
+
import { prCommand } from "./pr.js";
|
|
12
|
+
import { projectCommand } from "./project.js";
|
|
13
|
+
import { pushCommand } from "./push.js";
|
|
14
|
+
import { releaseCommand } from "./release.js";
|
|
15
|
+
import { switchOrgCommand } from "./switch-org.js";
|
|
16
|
+
import { updateCliCommand } from "./update-cli.js";
|
|
17
|
+
import { versionCommand } from "./version.js";
|
|
18
|
+
export const commands = [
|
|
19
|
+
adminCommand,
|
|
20
|
+
checkCommand,
|
|
21
|
+
ciCommand,
|
|
22
|
+
deployCommand,
|
|
23
|
+
doctorCommand,
|
|
24
|
+
dryrunCommand,
|
|
25
|
+
hookCommand,
|
|
26
|
+
jobCommand,
|
|
27
|
+
logCommand,
|
|
28
|
+
metasyncCommand,
|
|
29
|
+
prCommand,
|
|
30
|
+
projectCommand,
|
|
31
|
+
pushCommand,
|
|
32
|
+
releaseCommand,
|
|
33
|
+
switchOrgCommand,
|
|
34
|
+
updateCliCommand,
|
|
35
|
+
versionCommand,
|
|
36
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// sft job: 作業用のブランチとジョブフォルダの準備。本体は src/core/job.ts
|
|
2
|
+
import { createAsk } from "../core/ai-answers.js";
|
|
3
|
+
import { runJob } from "../core/job.js";
|
|
4
|
+
import { realJobDeps } from "../io/job-deps.js";
|
|
5
|
+
import { askYesNo } from "../ui/confirm.js";
|
|
6
|
+
export const jobCommand = {
|
|
7
|
+
name: "job",
|
|
8
|
+
summary: "作業用のブランチを main から作り、ジョブフォルダにクローンして、ランチャーを開く",
|
|
9
|
+
options: [
|
|
10
|
+
{
|
|
11
|
+
flag: "--name ジョブ名",
|
|
12
|
+
summary: "ジョブ名(英数字で始まり、英数字・-・_ の 1〜50 文字。main・staging・develop・admin は不可)。省くと入力する",
|
|
13
|
+
},
|
|
14
|
+
{ flag: "--project XXXX", summary: "プロジェクト名(force-XXXX の XXXX)。省くと、作業フォルダのクローンから選ぶか、入力する" },
|
|
15
|
+
{ flag: "--owner OWNER", summary: "GitHub のオーナー。省くと、作業フォルダのクローンか gh の候補から選ぶか、入力する" },
|
|
16
|
+
],
|
|
17
|
+
users: ["human", "ai"],
|
|
18
|
+
exitCodes: [{ code: 20, summary: "確認待ち(AI 操作で、job.existing・job.create の答えがない)" }],
|
|
19
|
+
questions: ["job.existing", "job.create"],
|
|
20
|
+
run: async (args, box) => {
|
|
21
|
+
let ask;
|
|
22
|
+
try {
|
|
23
|
+
ask = createAsk(box, "job", (q) => askYesNo(box.input, q));
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
box.output.err(`[ERROR] ${e instanceof Error ? e.message : String(e)}`);
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
return runJob(args, box, realJobDeps(box), ask);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// sft(引数なし・force-* の中): ランチャーを開く(本体は src/ui/launcher.ts)。サブコマンドの表の 1 行ではなく、表から項目を作る側。
|
|
2
|
+
// 項目: menu を持つコマンドを order の順に並べる。VS Code のターミナル(TERM_PROGRAM=vscode)では、切り替えの組(group 1)を出さない。
|
|
3
|
+
// 裏の判定(sft pr --status)は、同じプロセスの中で、画面に何も出さず・入力を受けずに動かす(別のプロセスを起こさない: 6.3)
|
|
4
|
+
import { basename } from "node:path";
|
|
5
|
+
import { runLauncher } from "../ui/launcher.js";
|
|
6
|
+
export function launcherItems(commands, box, orgSwitched) {
|
|
7
|
+
const vscode = box.env("TERM_PROGRAM") === "vscode";
|
|
8
|
+
return commands
|
|
9
|
+
.flatMap((c) => (c.menu && !(vscode && c.menu.group > 0) ? [{ c, m: c.menu }] : []))
|
|
10
|
+
.sort((a, b) => a.m.order - b.m.order)
|
|
11
|
+
.map(({ c, m }) => ({
|
|
12
|
+
name: c.name,
|
|
13
|
+
label: m.label,
|
|
14
|
+
description: m.description,
|
|
15
|
+
group: m.group,
|
|
16
|
+
// 組織の切り替えが成功したら、知らせる(デバッグログの取得を、新しい組織に移すため: src/core/start.ts)
|
|
17
|
+
run: async () => {
|
|
18
|
+
const code = await c.run([], box);
|
|
19
|
+
if (c.name === "switch-org" && code === 0)
|
|
20
|
+
await orgSwitched?.();
|
|
21
|
+
return code;
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
export async function openLauncher(commands, box, orgSwitched) {
|
|
26
|
+
const pr = commands.find((c) => c.name === "pr");
|
|
27
|
+
// 画面に出さず、入力も受けない箱(裏の判定用)
|
|
28
|
+
const quiet = {
|
|
29
|
+
...box,
|
|
30
|
+
output: { out: () => { }, err: () => { } },
|
|
31
|
+
input: { readKey: async () => null, readLine: async () => null, readSecret: async () => null },
|
|
32
|
+
};
|
|
33
|
+
return runLauncher([], box, {
|
|
34
|
+
items: launcherItems(commands, box, orgSwitched),
|
|
35
|
+
folderName: basename(process.cwd()),
|
|
36
|
+
color: process.stderr.isTTY === true && box.env("NO_COLOR") === undefined,
|
|
37
|
+
tick: () => new Promise((resolve) => setTimeout(resolve, 5000).unref()),
|
|
38
|
+
startPrStatus: pr ? () => pr.run(["--status"], quiet) : null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// sft log: AI の開発サイクル用のデバッグログ(doc/sf-log-design.md)。いまは pull(組織から取って要約)・summarize(手元の目録からの要約)・
|
|
2
|
+
// status(読み取りのみ)・auto on|off(このプロジェクトの答え)・start・stop(手動)。取得役(ランチャーの裏)と自動の取り始めは、
|
|
3
|
+
// sft の起動(src/core/log-session.ts)が動かす(doc/rebuild-coverage.md)
|
|
4
|
+
import { createAsk } from "../core/ai-answers.js";
|
|
5
|
+
import { runLogAuto } from "../core/log-auto.js";
|
|
6
|
+
import { runLogPull } from "../core/log-pull.js";
|
|
7
|
+
import { runLogStart, runLogStop } from "../core/log-start.js";
|
|
8
|
+
import { runLogStatus } from "../core/log-status.js";
|
|
9
|
+
import { runLogSummarize } from "../core/log-summarize.js";
|
|
10
|
+
import { folderLock, pidAlive, realLogPullDeps, realLogSummarizeDeps } from "../io/log-deps.js";
|
|
11
|
+
import { askYesNo } from "../ui/confirm.js";
|
|
12
|
+
export const logCommand = {
|
|
13
|
+
name: "log",
|
|
14
|
+
summary: "デバッグログを組織から取り、AI 向けの要約を作る(log pull。組織には書き込まない)",
|
|
15
|
+
options: [
|
|
16
|
+
{ flag: "pull", summary: "新しいログを組織から取り(自分のログだけ)、要約(logs/apex/latest.md)を作る(-o ALIAS で組織を指定)" },
|
|
17
|
+
{
|
|
18
|
+
flag: "start [-o ALIAS] [--level standard|detail] [--hours N] [-y]",
|
|
19
|
+
summary: "取り始める(TraceFlag を作る・延ばす。-y で確認を省く)",
|
|
20
|
+
},
|
|
21
|
+
{ flag: "stop [-o ALIAS]", summary: "止める(自分が作った TraceFlag を消す。手元のログは残す)" },
|
|
22
|
+
{ flag: "summarize", summary: "手元の目録(logs/apex/.index)から、要約(logs/apex/latest.md)を作る" },
|
|
23
|
+
{ flag: "status", summary: "手元の記録と、組織の TraceFlag・ログの本数を表示する(読み取りのみ。-o ALIAS で組織を指定)" },
|
|
24
|
+
{ flag: "auto on|off", summary: "sf-start のときに自動で取るか(logs/apex/.consent)を変える(-o ALIAS で組織を指定)" },
|
|
25
|
+
{ flag: "--max N", summary: "要約に入れるログの数の上限(既定 50。超えたら新しいほうから)" },
|
|
26
|
+
{ flag: "--since 分", summary: "しおりを使わず、直近 N 分に始まったログを要約する" },
|
|
27
|
+
],
|
|
28
|
+
users: ["ai", "human"],
|
|
29
|
+
exitCodes: [{ code: 20, summary: "確認待ち(AI 操作で、log.start・log.replace の答えがない)" }],
|
|
30
|
+
questions: ["log.start", "log.replace"],
|
|
31
|
+
run: async (args, box) => {
|
|
32
|
+
const [sub, ...rest] = args;
|
|
33
|
+
if (sub === "status")
|
|
34
|
+
return runLogStatus(rest, box, { pidAlive });
|
|
35
|
+
if (sub === "auto")
|
|
36
|
+
return runLogAuto(rest, box, { lock: folderLock() });
|
|
37
|
+
if (sub === "pull")
|
|
38
|
+
return runLogPull(rest, box, realLogPullDeps(box));
|
|
39
|
+
if (sub === "stop")
|
|
40
|
+
return runLogStop(rest, box, { lock: folderLock() });
|
|
41
|
+
if (sub === "start") {
|
|
42
|
+
let ask;
|
|
43
|
+
try {
|
|
44
|
+
ask = createAsk(box, "log", (q) => askYesNo(box.input, q));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
box.output.err(`[ERROR] ${e instanceof Error ? e.message : String(e)}`);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
return runLogStart(rest, box, { lock: folderLock() }, ask);
|
|
51
|
+
}
|
|
52
|
+
if (sub !== "summarize") {
|
|
53
|
+
box.output.err(`[ERROR] サブコマンドを指定してください(pull / start / stop / summarize / status / auto): ${sub ?? ""}`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
return runLogSummarize(rest, box, realLogSummarizeDeps(box));
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { runMetasync } from "../core/metasync.js";
|
|
2
|
+
import { realMetasyncDeps } from "../io/metasync-deps.js";
|
|
3
|
+
export const metasyncCommand = {
|
|
4
|
+
name: "metasync",
|
|
5
|
+
summary: "組織のメタデータを、main ブランチへ同期する(管理者向け)",
|
|
6
|
+
options: [
|
|
7
|
+
{ flag: "-n, --dry-run", summary: "計画の表示までで終了する(作業ツリー・コミット・push は行わない)" },
|
|
8
|
+
{ flag: "-y, --yes", summary: "--dry-run のときだけ、続行の確認を省く" },
|
|
9
|
+
{ flag: "--allow-mass-delete", summary: "削除の保留(S3・S4)を解く(手元で実行したときだけ)" },
|
|
10
|
+
{ flag: "--full", summary: "変更の検知が「変更なし」でも、全件取得する" },
|
|
11
|
+
{ flag: "-j, --json", summary: "取得の応答(JSON)の先頭を、ログにも記録する" },
|
|
12
|
+
],
|
|
13
|
+
users: ["actions", "human"],
|
|
14
|
+
exitCodes: [
|
|
15
|
+
{ code: 3, summary: "同期したが、削除の保留(S2・S3・S4)がある" },
|
|
16
|
+
{ code: 4, summary: "秘密の疑いで止めた(何もコミット・push していない)" },
|
|
17
|
+
{ code: 5, summary: "公開リポジトリ、または公開・非公開を確認できず、取得せずに止めた" },
|
|
18
|
+
],
|
|
19
|
+
questions: [],
|
|
20
|
+
run: (args, box) => runMetasync(args, box, realMetasyncDeps(box)),
|
|
21
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// sft pr: 次の段階へ PR を出す(出し先を確かめる)。本体は src/core/pr.ts
|
|
2
|
+
import { createAsk } from "../core/ai-answers.js";
|
|
3
|
+
import { runPr } from "../core/pr.js";
|
|
4
|
+
import { openBrowser } from "../io/open-browser.js";
|
|
5
|
+
import { realPromoteDeps } from "../io/promote-deps.js";
|
|
6
|
+
import { askYesNo } from "../ui/confirm.js";
|
|
7
|
+
export const prCommand = {
|
|
8
|
+
name: "pr",
|
|
9
|
+
summary: "次の段階へ PR を出す(出し先を確かめる)",
|
|
10
|
+
options: [
|
|
11
|
+
{ flag: "--create", summary: "ブラウザを開かずに、gh pr create で PR を作る(--title と --body-file が要る)" },
|
|
12
|
+
{ flag: "--title <題名>", summary: "PR の題名(--create のときだけ)" },
|
|
13
|
+
{ flag: "--body-file <ファイル>", summary: "PR の本文のファイル(--create のときだけ)" },
|
|
14
|
+
{ flag: "--status", summary: "判定して next-status.txt を書くだけ(ランチャーが裏で動かす)" },
|
|
15
|
+
{ flag: "-v, --verbose", summary: "コマンドの応答をコンソールにも表示する" },
|
|
16
|
+
],
|
|
17
|
+
users: ["human", "ai"],
|
|
18
|
+
exitCodes: [{ code: 20, summary: "確認待ち(AI 操作で、pr.create の答えがない)" }],
|
|
19
|
+
questions: ["pr.create"],
|
|
20
|
+
menu: { label: "PullRequest", order: 5, description: "次の段階へプルリクエストを出す(出し先を確かめる)", group: 0 },
|
|
21
|
+
run: async (args, box) => {
|
|
22
|
+
let ask;
|
|
23
|
+
try {
|
|
24
|
+
ask = createAsk(box, "pr", (q) => askYesNo(box.input, q));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
box.output.err(`[ERROR] ${e instanceof Error ? e.message : String(e)}`);
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
return runPr(args, box, { promote: realPromoteDeps(box), openBrowser }, ask);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// sft project: プロジェクトの作成と保守(管理者向け)。いまは update-workflows(src/core/update-workflows.ts)・
|
|
2
|
+
// update-secret(src/core/update-secret.ts)・status(src/core/project-status.ts)・verify(src/core/project-verify.ts)・
|
|
3
|
+
// reconnect(src/core/project-reconnect.ts)・add-tier・remove-tier(src/core/project-tier.ts)・create(src/core/project-create.ts)。
|
|
4
|
+
// upgrade は、シェル版(sf-project.sh)のまま
|
|
5
|
+
import { basename } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { createAsk } from "../core/ai-answers.js";
|
|
8
|
+
import { fileLoggedBox } from "../core/log-box.js";
|
|
9
|
+
import { runProjectCreate } from "../core/project-create.js";
|
|
10
|
+
import { runProjectReconnect } from "../core/project-reconnect.js";
|
|
11
|
+
import { runProjectStatus } from "../core/project-status.js";
|
|
12
|
+
import { runProjectAddTier, runProjectRemoveTier } from "../core/project-tier.js";
|
|
13
|
+
import { runProjectVerify } from "../core/project-verify.js";
|
|
14
|
+
import { runUpdateSecret } from "../core/update-secret.js";
|
|
15
|
+
import { runUpdateWorkflows } from "../core/update-workflows.js";
|
|
16
|
+
import { realCreateDeps } from "../io/create-deps.js";
|
|
17
|
+
import { realUpdateSecretDeps } from "../io/update-secret-deps.js";
|
|
18
|
+
import { askYesNo } from "../ui/confirm.js";
|
|
19
|
+
export const projectCommand = {
|
|
20
|
+
name: "project",
|
|
21
|
+
summary: "プロジェクトの作成と保守(管理者向け)。create(新しい force-* を作る)・update-workflows(ワークフローを雛形に合わせる)・update-secret(JWT の Secrets の更新)・status(診断と接続先の一覧)・verify(実際の組織でリリースと削除を検証)・reconnect(段階の接続先の付け替え)・add-tier・remove-tier(段階を増やす・外す)",
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
flag: "create [--owner OWNER] [--project XXXX] [--resume N | --only N]",
|
|
25
|
+
summary: "新しい force-XXXX を GitHub に作り、Token・Slack・保護のルール・Salesforce の接続までを進める(作業フォルダで実行。途中で止まったら、続きから再開できる)",
|
|
26
|
+
},
|
|
27
|
+
{ flag: "update-workflows", summary: "違いを表示し、確認のうえ、雛形で上書きする(コミット・プッシュはしない)" },
|
|
28
|
+
{ flag: "update-workflows --check", summary: "違いがあるかだけを調べる(警告・確認なし。違えば 1)" },
|
|
29
|
+
{ flag: "update-workflows --remove <ファイル名>", summary: "雛形から廃止されたワークフローを削除する" },
|
|
30
|
+
{ flag: "status", summary: "セットアップの診断と、段階ごとの Salesforce の接続先を表示する(読み取りのみ。不足・違反があれば 1)" },
|
|
31
|
+
{
|
|
32
|
+
flag: "verify [--plan] [--no-metasync] [--cleanup] [--components [--with-objects | --validate-only]]",
|
|
33
|
+
summary: "Hello World を各段階にリリースして削除し、動くことを確かめる(--plan は表示だけ・--cleanup は削除だけ・--components はパターン別のサンプルを develop だけで)",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
flag: "reconnect <main|staging|develop>",
|
|
37
|
+
summary: "1 つの段階の接続先の組織を付け替える(ブラウザでログインし、外部クライアントアプリを作って、Secrets・Variables を更新する)",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
flag: "add-tier <staging|develop>",
|
|
41
|
+
summary: "段階を増やす(組織につなぎ、ブランチを作り、branches.txt に足す PR を作る。外した段階は、つなぎ直さずに戻せる)",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
flag: "remove-tier <staging|develop> [--purge-secrets]",
|
|
45
|
+
summary: "段階を外す PR を作る(ブランチ・接続情報は残す)。--purge-secrets は、マージ後に接続情報を消す",
|
|
46
|
+
},
|
|
47
|
+
{ flag: "update-secret", summary: "GitHub Actions の JWT 認証の Secrets・Variables を、接続テストのうえで更新する" },
|
|
48
|
+
],
|
|
49
|
+
users: ["human"],
|
|
50
|
+
exitCodes: [
|
|
51
|
+
{ code: 1, summary: "中断、--check で違いあり、status で不足・違反あり、または verify で失敗した確認がある" },
|
|
52
|
+
{ code: 20, summary: "AI 操作で、人の確認が要る(SF_TOOLS_AI=1)" },
|
|
53
|
+
],
|
|
54
|
+
questions: [],
|
|
55
|
+
run: async (args, raw) => {
|
|
56
|
+
const [sub, ...rest] = args;
|
|
57
|
+
const subs = ["create", "update-workflows", "update-secret", "status", "verify", "reconnect", "add-tier", "remove-tier"];
|
|
58
|
+
if (sub === undefined || !subs.includes(sub)) {
|
|
59
|
+
raw.output.err(`[ERROR] サブコマンドを指定してください(${subs.join(" / ")}): ${sub ?? ""}`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
// force-* の中の保守(status 以外)は、sf-tools/logs/project-<サブコマンド>.log にも記録する。force-* でなければ、どこにも作らない。
|
|
63
|
+
// create は、admin/ を作ってから、admin/logs/project-create.log に記録する(src/core/project-create.ts)
|
|
64
|
+
const box = sub !== "create" && sub !== "status" && raw.files.exists("sf-tools/config")
|
|
65
|
+
? fileLoggedBox(raw, `sf-tools/logs/project-${sub}.log`, `sft project ${sub}`)
|
|
66
|
+
: raw;
|
|
67
|
+
const templateDir = box.env("SF_TOOLS_WORKFLOW_TEMPLATE_DIR") || fileURLToPath(new URL("../../templates/.github/workflows", import.meta.url));
|
|
68
|
+
// status は読み取りのみ(確認の質問をしない)
|
|
69
|
+
if (sub === "status")
|
|
70
|
+
return runProjectStatus(rest, box, { folderName: basename(process.cwd()), templateDir });
|
|
71
|
+
let ask;
|
|
72
|
+
try {
|
|
73
|
+
ask = createAsk(box, "project", (q) => askYesNo(box.input, q));
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
box.output.err(`[ERROR] ${e instanceof Error ? e.message : String(e)}`);
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
if (sub === "create")
|
|
80
|
+
return runProjectCreate(rest, box, realCreateDeps(box, templateDir), ask);
|
|
81
|
+
if (sub === "verify")
|
|
82
|
+
return runProjectVerify(rest, box, { folderName: basename(process.cwd()) }, ask);
|
|
83
|
+
if (sub === "update-secret")
|
|
84
|
+
return runUpdateSecret(rest, box, { ...realUpdateSecretDeps(box), folderName: basename(process.cwd()) }, ask);
|
|
85
|
+
if (sub === "reconnect")
|
|
86
|
+
return runProjectReconnect(rest, box, { ...realUpdateSecretDeps(box), folderName: basename(process.cwd()) }, ask);
|
|
87
|
+
if (sub === "add-tier" || sub === "remove-tier") {
|
|
88
|
+
const deps = { ...realUpdateSecretDeps(box), folderName: basename(process.cwd()), templateDir };
|
|
89
|
+
return (sub === "add-tier" ? runProjectAddTier : runProjectRemoveTier)(rest, box, deps, ask);
|
|
90
|
+
}
|
|
91
|
+
return runUpdateWorkflows(rest, box, { templateDir, folderName: basename(process.cwd()) }, ask);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { runPush } from "../core/push.js";
|
|
2
|
+
import { loadCapabilityTable } from "../io/capability-file.js";
|
|
3
|
+
import { realTempDeps } from "../io/temp-dir.js";
|
|
4
|
+
export const pushCommand = {
|
|
5
|
+
name: "push",
|
|
6
|
+
summary: "カレント配下をコミットしてプッシュする",
|
|
7
|
+
options: [
|
|
8
|
+
{ flag: "-m, --message FILE", summary: "VS Code を開かず、FILE の内容をコミットのメッセージにする(AI 操作で使う)" },
|
|
9
|
+
{ flag: "-v, --verbose", summary: "コマンドの応答をコンソールにも表示する" },
|
|
10
|
+
],
|
|
11
|
+
users: ["human", "ai"],
|
|
12
|
+
exitCodes: [{ code: 20, summary: "確認待ち(AI 操作で、-m がない)" }],
|
|
13
|
+
questions: ["push.message"],
|
|
14
|
+
menu: { label: "Push", order: 4, description: "変更をコミット & プッシュ", group: 0 },
|
|
15
|
+
run: (args, box) => runPush(args, box, { ...realTempDeps("sf-push-"), capability: () => loadCapabilityTable(box.env) }),
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { runRelease } from "../core/release.js";
|
|
2
|
+
import { loadCapabilityTable } from "../io/capability-file.js";
|
|
3
|
+
import { askYesNo } from "../ui/confirm.js";
|
|
4
|
+
export const releaseCommand = {
|
|
5
|
+
name: "release",
|
|
6
|
+
summary: "ターゲットファイルから、組織へ検証(既定)またはリリースする",
|
|
7
|
+
options: [
|
|
8
|
+
{ flag: "--validate, --dry-run", summary: "検証モード(既定)" },
|
|
9
|
+
{ flag: "-r, --release", summary: "実際に組織へリリースする" },
|
|
10
|
+
{ flag: "-n, --no-open", summary: "デプロイ状況の画面を、ブラウザで開かない" },
|
|
11
|
+
{ flag: "-f, --force", summary: "コンフリクト検知を無効にして上書きする(--ignore-conflicts)" },
|
|
12
|
+
{ flag: "-t, --target ALIAS", summary: "接続先組織のエイリアス" },
|
|
13
|
+
{ flag: "-j, --json", summary: "sf のコマンドに --json を付ける" },
|
|
14
|
+
],
|
|
15
|
+
users: ["actions", "human", "ai"],
|
|
16
|
+
exitCodes: [{ code: 20, summary: "確認待ち(AI 操作で、リリースの確認が要る)" }],
|
|
17
|
+
questions: [], // 確認に名前はまだない。AI 操作では、20(確認待ち)で止まる(doc/rebuild-coverage.md 3.5)
|
|
18
|
+
run: (args, box) => runRelease(args, box, { loadCapability: () => loadCapabilityTable(box.env), confirm: (q) => askYesNo(box.input, q) }),
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// sft(引数なし・force-* の中): 組織に接続し、手元の準備(doctor)をして、ランチャーを開く(本体は src/core/start.ts)。
|
|
2
|
+
// デバッグログを自動で取るなら、ランチャーの裏(同じプロセスの中)で取り続け、閉じたら後始末する(src/core/log-session.ts)。
|
|
3
|
+
// サブコマンドの表の 1 行ではなく、入口(src/cli.ts)と sft job(クローンのあと)から呼ぶ
|
|
4
|
+
import { basename } from "node:path";
|
|
5
|
+
import { beginLog } from "../core/log-session.js";
|
|
6
|
+
import { runStart } from "../core/start.js";
|
|
7
|
+
import { realSessionDeps } from "../io/log-deps.js";
|
|
8
|
+
import { loginPrompts } from "../ui/prompt.js";
|
|
9
|
+
import { openLauncher } from "./launcher.js";
|
|
10
|
+
export async function openStart(box, commands) {
|
|
11
|
+
const doctor = commands.find((c) => c.name === "doctor");
|
|
12
|
+
return runStart(box, {
|
|
13
|
+
folderName: basename(process.cwd()),
|
|
14
|
+
prompts: loginPrompts(box.input),
|
|
15
|
+
doctor: () => (doctor ? doctor.run([], box) : Promise.resolve(0)),
|
|
16
|
+
launcher: (orgSwitched) => openLauncher(commands, box, orgSwitched),
|
|
17
|
+
log: (org) => beginLog(box, realSessionDeps(box), org),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { runSwitchOrg } from "../core/switch-org.js";
|
|
2
|
+
import { realSwitchOrgDeps } from "../io/switch-org-deps.js";
|
|
3
|
+
export const switchOrgCommand = {
|
|
4
|
+
name: "switch-org",
|
|
5
|
+
summary: "接続する組織を切り替える(接続設定を消して、ログインからやり直す。失敗したら元に戻す)",
|
|
6
|
+
options: [{ flag: "-v, --verbose", summary: "コマンドの応答をコンソールにも表示する" }],
|
|
7
|
+
users: ["human"],
|
|
8
|
+
exitCodes: [],
|
|
9
|
+
questions: [],
|
|
10
|
+
menu: { label: "SwitchOrg", order: 7, description: "接続組織を切り替える", group: 1 },
|
|
11
|
+
run: (args, box) => runSwitchOrg(args, box, realSwitchOrgDeps(box)),
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { runUpdateCli } from "../core/update-cli.js";
|
|
2
|
+
import { realUpdateCliDeps } from "../io/update-cli-deps.js";
|
|
3
|
+
export const updateCliCommand = {
|
|
4
|
+
name: "update-cli",
|
|
5
|
+
summary: "npm・Salesforce CLI・Git(Windows のみ)を最新にする(失敗しても続け、最後に一覧する)",
|
|
6
|
+
options: [{ flag: "-v, --verbose", summary: "コマンドの応答をコンソールにも表示する" }],
|
|
7
|
+
users: ["human"],
|
|
8
|
+
exitCodes: [],
|
|
9
|
+
questions: [],
|
|
10
|
+
run: (args, box) => runUpdateCli(args, box, realUpdateCliDeps(box)),
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EXIT } from "../core/exit-codes.js";
|
|
2
|
+
import { readVersion } from "../io/package-version.js";
|
|
3
|
+
export const versionCommand = {
|
|
4
|
+
name: "version",
|
|
5
|
+
summary: "版を表示する",
|
|
6
|
+
options: [],
|
|
7
|
+
users: ["human", "ai", "actions"],
|
|
8
|
+
exitCodes: [],
|
|
9
|
+
questions: [],
|
|
10
|
+
run: async (args, { output }) => {
|
|
11
|
+
if (args.length > 0) {
|
|
12
|
+
output.err(`[ERROR] 知らない引数: ${args.join(" ")}`);
|
|
13
|
+
return EXIT.failure;
|
|
14
|
+
}
|
|
15
|
+
output.out(readVersion());
|
|
16
|
+
return EXIT.ok;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 管理者用のクローンの照合と、セットアップ完了の印。シェル版の lib/admin-clone.sh のうち、判定の部分
|
|
2
|
+
// (clone_matches_repo・state_matches_repo・mark_setup_complete・clear_setup_mark・clone_setup_completed)の移し先
|
|
3
|
+
// (doc/rebuild-design.md 11.2 の段階 1)。git は、渡された道具の箱だけで呼ぶ(7.2)。
|
|
4
|
+
// 目的: 別のリポジトリのクローンに、書き込み・push しないための番人(XXXX だけのフォルダ名で扱うため)
|
|
5
|
+
import { originRepo } from "./origin.js";
|
|
6
|
+
/** DIR が Git のクローンで、origin が GitHub の owner/repo か。大文字と小文字は区別しない(GitHub は区別しない) */
|
|
7
|
+
export async function cloneMatchesRepo(box, dir, owner, repo) {
|
|
8
|
+
if (dir === "" || owner === "" || repo === "" || !box.files.exists(dir))
|
|
9
|
+
return false;
|
|
10
|
+
const r = await originRepo(box, dir);
|
|
11
|
+
if (r.kind !== "ok")
|
|
12
|
+
return false;
|
|
13
|
+
return `${r.owner}/${r.repo}`.toLowerCase() === `${owner}/${repo}`.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
/** 状態ファイル(.sf-init-XXXX.env)の最後の REPO_FULL_NAME が、owner/repo か(大文字と小文字は区別しない)。ファイルがない・読めないときは false */
|
|
16
|
+
export function stateMatchesRepo(box, file, owner, repo) {
|
|
17
|
+
if (file === "" || owner === "" || repo === "" || !box.files.exists(file))
|
|
18
|
+
return false;
|
|
19
|
+
let text;
|
|
20
|
+
try {
|
|
21
|
+
text = box.files.readText(file);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const values = text.split("\n").filter((l) => l.startsWith("REPO_FULL_NAME="));
|
|
27
|
+
const last = values[values.length - 1];
|
|
28
|
+
if (last === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
const value = last
|
|
31
|
+
.slice(last.indexOf("=") + 1)
|
|
32
|
+
.replace(/\r$/, "")
|
|
33
|
+
.replace(/^"/, "")
|
|
34
|
+
.replace(/"$/, "")
|
|
35
|
+
.toLowerCase();
|
|
36
|
+
return value !== "" && value === `${owner}/${repo}`.toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
// セットアップ完了の印: クローンの git config(sf-tools.setup-complete。.git/config にあり、GitHub には送られない)。
|
|
39
|
+
// 1 = 完了した / 0 = やり直し中 / 未設定 = 印を導入する前の版で完了したプロジェクト、または、一度も完了していないクローン。
|
|
40
|
+
// やり直し中は、印を消さず 0 にして、未設定と区別する(印を導入する前に完了した運用中のリポジトリを、未完了と誤判定して、
|
|
41
|
+
// 新規セットアップとして上書きしないため)
|
|
42
|
+
const MARK_KEY = "sf-tools.setup-complete";
|
|
43
|
+
/** 印を 1(完了)にする。DIR がない・git config の失敗は false */
|
|
44
|
+
export async function markSetupComplete(box, dir) {
|
|
45
|
+
if (dir === "" || !box.files.exists(dir))
|
|
46
|
+
return false;
|
|
47
|
+
return (await box.run("git", ["-C", dir, "config", MARK_KEY, "1"])).code === 0;
|
|
48
|
+
}
|
|
49
|
+
/** やり直しの開始時に、印を 0(やり直し中)にする。失敗しても、やり直しは進める(意図的に無視)。クローンがなければ何もしない */
|
|
50
|
+
export async function clearSetupMark(box, dir) {
|
|
51
|
+
if (dir === "" || !box.files.exists(dir))
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
await box.run("git", ["-C", dir, "config", MARK_KEY, "0"]);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// 失敗しても、やり直しは進める
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* DIR が、owner/repo の、セットアップ済みのクローンか。origin が owner/repo(大文字と小文字は区別しない)で、かつ:
|
|
62
|
+
* 印が 1 → 完了済み / 0 → やり直し中(未完了) / 未設定 → ローカルに admin ブランチがあれば、印を導入する前の版で完了したものと
|
|
63
|
+
* みなして、印を 1 にする(その版は、完了時に admin ブランチを作り、状態ファイルを消すだけだった)。admin ブランチがなければ未完了
|
|
64
|
+
*/
|
|
65
|
+
export async function cloneSetupCompleted(box, dir, owner, repo) {
|
|
66
|
+
if (!(await cloneMatchesRepo(box, dir, owner, repo)))
|
|
67
|
+
return false;
|
|
68
|
+
const got = await box.run("git", ["-C", dir, "config", "--get", MARK_KEY]);
|
|
69
|
+
const value = got.stdout.trim();
|
|
70
|
+
if (value === "1")
|
|
71
|
+
return true;
|
|
72
|
+
if (value === "0")
|
|
73
|
+
return false;
|
|
74
|
+
const admin = await box.run("git", ["-C", dir, "rev-parse", "--verify", "--quiet", "refs/heads/admin"]);
|
|
75
|
+
if (admin.code !== 0)
|
|
76
|
+
return false;
|
|
77
|
+
await markSetupComplete(box, dir); // 印を付けられなくても、完了済みとして扱う(次回も、同じ判定になる)
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ITEM = /^([a-z][a-z0-9-]*(?:\.[a-z0-9-]+)+)=([yn])$/;
|
|
2
|
+
/** SF_TOOLS_ANSWERS を読む。形が違う・同じ名前が 2 つあれば、失敗 */
|
|
3
|
+
export function parseAnswers(text) {
|
|
4
|
+
const items = new Map();
|
|
5
|
+
for (const item of text.split(/\s+/).filter((s) => s !== "")) {
|
|
6
|
+
const m = ITEM.exec(item);
|
|
7
|
+
if (m === null)
|
|
8
|
+
return { ok: false, error: `SF_TOOLS_ANSWERS の形が正しくありません: ${item}(名前=y または 名前=n。名前は <コマンド>.<質問>)` };
|
|
9
|
+
const name = m[1];
|
|
10
|
+
if (items.has(name))
|
|
11
|
+
return { ok: false, error: `SF_TOOLS_ANSWERS に、同じ名前が 2 つあります: ${name}` };
|
|
12
|
+
items.set(name, m[2]);
|
|
13
|
+
}
|
|
14
|
+
return { ok: true, items };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* command は、自分のコマンドの短い名前(deploy など)。human は、人に聞く部品(画面)。
|
|
18
|
+
* AI 操作で、SF_TOOLS_ANSWERS の形が誤っていれば、問い合わせのたびに失敗を返さず、ここで例外にする(中断)
|
|
19
|
+
*/
|
|
20
|
+
export function createAsk(box, command, human) {
|
|
21
|
+
if (box.env("SF_TOOLS_AI") !== "1")
|
|
22
|
+
return (_name, question) => human(question);
|
|
23
|
+
const table = parseAnswers(box.env("SF_TOOLS_ANSWERS") ?? "");
|
|
24
|
+
if (!table.ok)
|
|
25
|
+
throw new Error(table.error);
|
|
26
|
+
const mine = new Map([...table.items].filter(([name]) => name.split(".")[0] === command || name.split(".")[0] === "update"));
|
|
27
|
+
if (mine.size > 0)
|
|
28
|
+
box.output.err(` (AI 経由の答えを受け取りました: ${[...mine].map(([k, v]) => `${k}=${v}`).join(" ")})`);
|
|
29
|
+
const used = new Set();
|
|
30
|
+
return async (name, question) => {
|
|
31
|
+
const answer = name === "" || used.has(name) ? undefined : mine.get(name);
|
|
32
|
+
if (answer === undefined) {
|
|
33
|
+
box.output.err(`[確認待ち] ${name === "" ? "(名前なし)" : name}: ${question.trim()}`);
|
|
34
|
+
return "need";
|
|
35
|
+
}
|
|
36
|
+
used.add(name);
|
|
37
|
+
box.output.err(` (AI 経由の回答: ${name}=${answer})`);
|
|
38
|
+
return answer === "y" ? "yes" : "no";
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// ブランチと段階(branches.txt)の判定。シェル版の lib/branches.sh の移し先(doc/rebuild-design.md 11.2 の段階 1)。
|
|
2
|
+
// core は Node 専用の機能を使わない(3.4)ので、ファイルは読まず、中身の文字列を受け取る。
|
|
3
|
+
// 画面に出す警告は、戻り値の warnings に入れて返す(出すかどうかは、呼ぶ側が決める)
|
|
4
|
+
/** 共有環境の組織エイリアス(予約名)。ローカルからのリリースを禁止する(lib/common.sh の SF_RESERVED_ORG_ALIASES と同じ) */
|
|
5
|
+
export const RESERVED_ORG_ALIASES = ["prod", "staging", "develop", "main"];
|
|
6
|
+
/** 行末の CR を除き、空の行と # で始まる行(前に空白があってもよい)を除いた行(行の中身は、トリムしない) */
|
|
7
|
+
export function contentLines(text) {
|
|
8
|
+
return text
|
|
9
|
+
.split("\n")
|
|
10
|
+
.map((line) => line.replace(/\r$/, ""))
|
|
11
|
+
.filter((line) => !/^\s*#/.test(line) && line.trim() !== "");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* branches.txt のブランチ一覧(名前を問わない全行)。保護するブランチの判定に使う。
|
|
15
|
+
* text が null(ファイルがない)・ブランチが 1 つもないときは、警告つきで main だけ
|
|
16
|
+
*/
|
|
17
|
+
export function branchList(text, fileName = "sf-tools/config/branches.txt") {
|
|
18
|
+
if (text === null) {
|
|
19
|
+
return { branches: ["main"], warnings: [`ブランチ構成ファイルが見つかりません: ${fileName}(デフォルト: main のみ)`] };
|
|
20
|
+
}
|
|
21
|
+
const branches = contentLines(text);
|
|
22
|
+
if (branches.length === 0) {
|
|
23
|
+
return { branches: ["main"], warnings: [`${fileName} にブランチが定義されていません。デフォルト: main のみ`] };
|
|
24
|
+
}
|
|
25
|
+
return { branches, warnings: [] };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 有効な段階(main / staging / develop)を、決まった順で返す。規則の正本は doc/tier-scaling-design.md の 3.1。
|
|
29
|
+
* - 前後の空白を除く。段階の名前でない行は無視(strict でない場合は警告)。同じ名前が 2 行あっても 1 つ。main の行がなくても main は有効
|
|
30
|
+
* - develop は、staging も有効なときだけ有効
|
|
31
|
+
* - strict(一方通行の確認): ファイルがない・main の行がない・develop があって staging がない、は失敗にする
|
|
32
|
+
*/
|
|
33
|
+
export function tierList(text, options = {}) {
|
|
34
|
+
const strict = options.strict ?? false;
|
|
35
|
+
const fileName = options.fileName ?? "sf-tools/config/branches.txt";
|
|
36
|
+
if (text === null) {
|
|
37
|
+
if (strict)
|
|
38
|
+
return { ok: false, error: `ブランチ構成ファイルが見つかりません(読めません): ${fileName}` };
|
|
39
|
+
return { ok: true, tiers: ["main"], warnings: [`ブランチ構成ファイルが見つかりません: ${fileName}(デフォルト: main のみ)`] };
|
|
40
|
+
}
|
|
41
|
+
const warnings = [];
|
|
42
|
+
let hasLine = false;
|
|
43
|
+
const has = { main: false, staging: false, develop: false };
|
|
44
|
+
for (const raw of text.split("\n")) {
|
|
45
|
+
const line = raw.replace(/\r$/, "").trim();
|
|
46
|
+
if (line === "" || line.startsWith("#"))
|
|
47
|
+
continue;
|
|
48
|
+
hasLine = true;
|
|
49
|
+
if (line === "main" || line === "staging" || line === "develop") {
|
|
50
|
+
has[line] = true;
|
|
51
|
+
}
|
|
52
|
+
else if (!strict) {
|
|
53
|
+
warnings.push(`${fileName} の「${line}」は、段階の名前(main / staging / develop)ではないため、段階としては無視します。`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (strict) {
|
|
57
|
+
if (!has.main)
|
|
58
|
+
return { ok: false, error: `${fileName} に main の行がありません(段階の構成を判断できません)。` };
|
|
59
|
+
if (has.develop && !has.staging) {
|
|
60
|
+
return { ok: false, error: `${fileName} に develop がありますが、staging がありません(段階の構成の誤り)。` };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (!hasLine) {
|
|
64
|
+
warnings.push(`${fileName} にブランチが定義されていません。デフォルト: main のみ`);
|
|
65
|
+
}
|
|
66
|
+
const tiers = ["main"];
|
|
67
|
+
if (has.staging)
|
|
68
|
+
tiers.push("staging");
|
|
69
|
+
if (has.develop) {
|
|
70
|
+
if (has.staging)
|
|
71
|
+
tiers.push("develop");
|
|
72
|
+
else
|
|
73
|
+
warnings.push(`${fileName} に develop がありますが、staging がないため、develop は段階として無効です。`);
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, tiers, warnings };
|
|
76
|
+
}
|
|
77
|
+
/** ブランチが保護対象か。branchList の一覧との完全一致(大文字と小文字は区別する。固定の文字列として比べる) */
|
|
78
|
+
export function isProtectedBranch(branch, list) {
|
|
79
|
+
return list.includes(branch);
|
|
80
|
+
}
|
|
81
|
+
/** 共有環境の組織エイリアス(予約名)か。完全一致(大文字と小文字は区別する) */
|
|
82
|
+
export function isReservedOrgAlias(alias) {
|
|
83
|
+
return RESERVED_ORG_ALIASES.includes(alias);
|
|
84
|
+
}
|
|
85
|
+
/** ブランチ保護(Ruleset)の必須ステータスチェックの名前。ワークフローのジョブ名(ワークフロー名は含めない) */
|
|
86
|
+
export function requiredStatusCheckNames() {
|
|
87
|
+
return ["対象ファイル確認", "デプロイ検証", "順序チェック"];
|
|
88
|
+
}
|