@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.1
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 +368 -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,286 @@
|
|
|
1
|
+
export const VERIFY_APEX_HELLO = "SfToolsE2eHello";
|
|
2
|
+
export const VERIFY_APEX_HELLO_TEST = "SfToolsE2eHelloTest";
|
|
3
|
+
/** UTF-8 の文字列を base64 に(改行なし) */
|
|
4
|
+
export function base64(text) {
|
|
5
|
+
let bin = "";
|
|
6
|
+
for (const b of new TextEncoder().encode(text))
|
|
7
|
+
bin += String.fromCharCode(b);
|
|
8
|
+
return btoa(bin);
|
|
9
|
+
}
|
|
10
|
+
const lines = (...l) => `${l.join("\n")}\n`;
|
|
11
|
+
const CLASSES = "force-app/main/default/classes";
|
|
12
|
+
export const APEX_META = lines('<?xml version="1.0" encoding="UTF-8"?>', '<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">', " <apiVersion>64.0</apiVersion>", " <status>Active</status>", "</ApexClass>");
|
|
13
|
+
export const EMPTY_TARGET = lines("[files]", "", "[members]");
|
|
14
|
+
/** Hello World(SfToolsE2eHello と、そのテストクラス) */
|
|
15
|
+
export const HELLO_SET = {
|
|
16
|
+
marker: VERIFY_APEX_HELLO,
|
|
17
|
+
paths: () => [
|
|
18
|
+
`${CLASSES}/${VERIFY_APEX_HELLO}.cls`,
|
|
19
|
+
`${CLASSES}/${VERIFY_APEX_HELLO}.cls-meta.xml`,
|
|
20
|
+
`${CLASSES}/${VERIFY_APEX_HELLO_TEST}.cls`,
|
|
21
|
+
`${CLASSES}/${VERIFY_APEX_HELLO_TEST}.cls-meta.xml`,
|
|
22
|
+
],
|
|
23
|
+
content: (path) => {
|
|
24
|
+
if (path.endsWith(`/${VERIFY_APEX_HELLO_TEST}.cls`))
|
|
25
|
+
return lines("@isTest", `private class ${VERIFY_APEX_HELLO_TEST} {`, " @isTest", " static void helloReturnsGreeting() {", ` System.assertEquals('Hello, World!', ${VERIFY_APEX_HELLO}.hello());`, " }", "}");
|
|
26
|
+
if (path.endsWith(`/${VERIFY_APEX_HELLO}.cls`))
|
|
27
|
+
return lines(`public with sharing class ${VERIFY_APEX_HELLO} {`, " public static String hello() {", " return 'Hello, World!';", " }", "}");
|
|
28
|
+
if (path.endsWith(".cls-meta.xml"))
|
|
29
|
+
return APEX_META;
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
deployTarget: () => lines("[files]", `${CLASSES}/${VERIFY_APEX_HELLO}.cls`, `${CLASSES}/${VERIFY_APEX_HELLO_TEST}.cls`, "", "[members]"),
|
|
33
|
+
removeTarget: () => lines("[files]", "", "[members]", `ApexClass:${VERIFY_APEX_HELLO_TEST}`, `ApexClass:${VERIFY_APEX_HELLO}`),
|
|
34
|
+
};
|
|
35
|
+
export function verifyTiming(box) {
|
|
36
|
+
const num = (names, def, min = 0) => {
|
|
37
|
+
for (const n of names) {
|
|
38
|
+
const v = box.env(n) ?? "";
|
|
39
|
+
if (/^[0-9]+$/.test(v) && Number(v) >= min)
|
|
40
|
+
return Number(v);
|
|
41
|
+
}
|
|
42
|
+
return def;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
ghTimeoutMs: num(["VERIFY_GH_TIMEOUT", "E2E_GH_TIMEOUT"], 120, 1) * 1000,
|
|
46
|
+
pollMs: num(["VERIFY_POLL_SEC", "E2E_POLL_SEC"], 5) * 1000,
|
|
47
|
+
wfTimeoutMs: num(["VERIFY_WF_TIMEOUT", "E2E_WF_TIMEOUT"], 1200) * 1000,
|
|
48
|
+
findTries: num(["VERIFY_RUN_FIND_TRIES", "E2E_RUN_FIND_TRIES"], 24, 1),
|
|
49
|
+
conclusionTries: num(["VERIFY_CONCLUSION_TRIES", "E2E_CONCLUSION_TRIES"], 6, 1),
|
|
50
|
+
logTries: num(["VERIFY_LOG_TRIES", "E2E_LOG_TRIES"], 12, 1),
|
|
51
|
+
dispatchTries: num(["VERIFY_DISPATCH_TRIES"], 12, 1),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export class VerifyGh {
|
|
55
|
+
box;
|
|
56
|
+
repo;
|
|
57
|
+
t;
|
|
58
|
+
constructor(box, repo, timing = verifyTiming(box)) {
|
|
59
|
+
this.box = box;
|
|
60
|
+
this.repo = repo;
|
|
61
|
+
this.t = timing;
|
|
62
|
+
}
|
|
63
|
+
/** gh を動かし、成功なら標準出力(末尾の改行・CR を除く)。失敗は null */
|
|
64
|
+
async gh(args, input) {
|
|
65
|
+
const r = await this.box
|
|
66
|
+
.run("gh", args, { timeoutMs: this.t.ghTimeoutMs, ...(input !== undefined ? { input } : {}) })
|
|
67
|
+
.catch(() => null);
|
|
68
|
+
if (r === null || r.code !== 0)
|
|
69
|
+
return null;
|
|
70
|
+
return r.stdout.replace(/\r/g, "").replace(/\n+$/, "");
|
|
71
|
+
}
|
|
72
|
+
sleep() {
|
|
73
|
+
return this.box.clock.sleep(this.t.pollMs);
|
|
74
|
+
}
|
|
75
|
+
// ---- PR ----
|
|
76
|
+
/** PR を作り、番号を返す(出力の URL の末尾の数字)。失敗・番号が取れなければ null */
|
|
77
|
+
async prCreate(head, title, body, base) {
|
|
78
|
+
const out = await this.gh(["pr", "create", "-R", this.repo, "--base", base, "--head", head, "--title", title, "--body", body]);
|
|
79
|
+
const m = out === null ? null : /([0-9]+)\s*$/.exec(out);
|
|
80
|
+
return m ? m[1] : null;
|
|
81
|
+
}
|
|
82
|
+
async prMerge(n) {
|
|
83
|
+
return (await this.gh(["pr", "merge", n, "-R", this.repo, "--merge"])) !== null;
|
|
84
|
+
}
|
|
85
|
+
async prClose(n) {
|
|
86
|
+
return (await this.gh(["pr", "close", n, "-R", this.repo])) !== null;
|
|
87
|
+
}
|
|
88
|
+
// ---- ワークフローの実行 ----
|
|
89
|
+
async latest(wf, branch, event) {
|
|
90
|
+
const args = ["run", "list", "-R", this.repo, "--workflow", wf];
|
|
91
|
+
if (branch !== null)
|
|
92
|
+
args.push("--branch", branch);
|
|
93
|
+
args.push("--event", event, "--limit", "1", "--json", "databaseId", "--jq", ".[0].databaseId // 0");
|
|
94
|
+
// gh の一時的な失敗を「実行がない(0)」と取り違えると、基準の ID が 0 になり、前の実行を今回の実行と誤る。数回やり直す
|
|
95
|
+
for (let i = 0; i < 3; i++) {
|
|
96
|
+
const out = await this.gh(args);
|
|
97
|
+
if (out !== null && /^[0-9]+$/.test(out))
|
|
98
|
+
return Number(out);
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
/** PR のイベントで起動した、最新の実行の ID(なければ 0)。同じブランチの前の実行と取り違えないための基準 */
|
|
103
|
+
latestPrRun(wf, branch) {
|
|
104
|
+
return this.latest(wf, branch, "pull_request");
|
|
105
|
+
}
|
|
106
|
+
async status(id, field) {
|
|
107
|
+
return (await this.gh(["run", "view", String(id), "-R", this.repo, "--json", field, "--jq", `.${field}`])) ?? "";
|
|
108
|
+
}
|
|
109
|
+
/** 実行の完了を待つ(上限 VERIFY_WF_TIMEOUT)。完了 = true */
|
|
110
|
+
async waitRun(id) {
|
|
111
|
+
const step = Math.max(this.t.pollMs, 1000);
|
|
112
|
+
for (let waited = 0; waited < this.t.wfTimeoutMs; waited += step) {
|
|
113
|
+
if ((await this.status(id, "status")) === "completed")
|
|
114
|
+
return true;
|
|
115
|
+
await this.sleep();
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/** PR のイベントで起動した実行(after より新しいもの)の完了を待ち、その ID。見つからない・完了しなければ null */
|
|
120
|
+
async waitPrRun(wf, branch, after) {
|
|
121
|
+
let id = 0;
|
|
122
|
+
for (let i = 1; i <= this.t.findTries; i++) {
|
|
123
|
+
const n = await this.latest(wf, branch, "pull_request");
|
|
124
|
+
if (n > after) {
|
|
125
|
+
id = n;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
await this.sleep();
|
|
129
|
+
}
|
|
130
|
+
if (id === 0)
|
|
131
|
+
return null;
|
|
132
|
+
return (await this.waitRun(id)) ? id : null;
|
|
133
|
+
}
|
|
134
|
+
/** 実行の結果(success / failure など)。空のときだけ読み直す */
|
|
135
|
+
async conclusion(id) {
|
|
136
|
+
let out = "";
|
|
137
|
+
for (let i = 1; i <= this.t.conclusionTries; i++) {
|
|
138
|
+
out = await this.status(id, "conclusion");
|
|
139
|
+
if (out !== "")
|
|
140
|
+
break;
|
|
141
|
+
if (i < this.t.conclusionTries)
|
|
142
|
+
await this.sleep();
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
/** 実行の中のステップの結果(同じ名前が複数あれば最初のもの)。見つからなければ空。tries を省くと VERIFY_CONCLUSION_TRIES 回 */
|
|
147
|
+
async stepConclusion(id, step, tries = this.t.conclusionTries) {
|
|
148
|
+
let out = "";
|
|
149
|
+
for (let i = 1; i <= tries; i++) {
|
|
150
|
+
const r = await this.gh([
|
|
151
|
+
"run",
|
|
152
|
+
"view",
|
|
153
|
+
String(id),
|
|
154
|
+
"-R",
|
|
155
|
+
this.repo,
|
|
156
|
+
"--json",
|
|
157
|
+
"jobs",
|
|
158
|
+
"--jq",
|
|
159
|
+
`.jobs[].steps[] | select(.name==${JSON.stringify(step)}) | .conclusion`,
|
|
160
|
+
]);
|
|
161
|
+
out = (r ?? "").split("\n")[0] ?? "";
|
|
162
|
+
if (out !== "")
|
|
163
|
+
break;
|
|
164
|
+
if (i < tries)
|
|
165
|
+
await this.sleep();
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
/** 失敗したジョブだけを 1 回再実行し、完了(試行番号が増えて完了)を待つ。待てたら true */
|
|
170
|
+
async rerunAndWait(id) {
|
|
171
|
+
const a0 = await this.status(id, "attempt");
|
|
172
|
+
if (!/^[0-9]+$/.test(a0))
|
|
173
|
+
return false;
|
|
174
|
+
if ((await this.gh(["run", "rerun", String(id), "-R", this.repo, "--failed"])) === null)
|
|
175
|
+
return false;
|
|
176
|
+
const step = Math.max(this.t.pollMs, 1000);
|
|
177
|
+
for (let waited = 0; waited < this.t.wfTimeoutMs; waited += step) {
|
|
178
|
+
const a = await this.status(id, "attempt");
|
|
179
|
+
if (/^[0-9]+$/.test(a) && Number(a) > Number(a0) && (await this.status(id, "status")) === "completed")
|
|
180
|
+
return true;
|
|
181
|
+
await this.sleep();
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
/** ワークフローを手動で起動し、起動した実行の ID(完了は待たない)。起動できない・見つからなければ null */
|
|
186
|
+
async dispatch(wf, ref) {
|
|
187
|
+
const before = await this.latest(wf, null, "workflow_dispatch");
|
|
188
|
+
let ok = false;
|
|
189
|
+
for (let i = 1; i <= this.t.dispatchTries; i++) {
|
|
190
|
+
if ((await this.gh(["workflow", "run", wf, "-R", this.repo, "--ref", ref])) !== null) {
|
|
191
|
+
ok = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
await this.sleep();
|
|
195
|
+
}
|
|
196
|
+
if (!ok)
|
|
197
|
+
return null;
|
|
198
|
+
for (let i = 1; i <= this.t.dispatchTries; i++) {
|
|
199
|
+
const id = await this.latest(wf, null, "workflow_dispatch");
|
|
200
|
+
if (id > before)
|
|
201
|
+
return id;
|
|
202
|
+
await this.sleep();
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
/** 実行のログに、文字列が含まれるか(完了の直後は、ログ全体がまだ返らないことがあるため、読み直す)。ログは画面に出さない */
|
|
207
|
+
async logHas(id, text) {
|
|
208
|
+
for (let i = 1; i <= this.t.logTries; i++) {
|
|
209
|
+
const out = await this.gh(["run", "view", String(id), "-R", this.repo, "--log"]);
|
|
210
|
+
if (out?.includes(text))
|
|
211
|
+
return true;
|
|
212
|
+
if (i < this.t.logTries)
|
|
213
|
+
await this.sleep();
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
/** 失敗したステップのログ(末尾 n 行) */
|
|
218
|
+
async failedLogTail(id, n) {
|
|
219
|
+
const out = await this.gh(["run", "view", String(id), "-R", this.repo, "--log-failed"]);
|
|
220
|
+
return (out ?? "").split("\n").slice(-n);
|
|
221
|
+
}
|
|
222
|
+
/** ログ全体(Slack の応答を読む) */
|
|
223
|
+
log(id) {
|
|
224
|
+
return this.gh(["run", "view", String(id), "-R", this.repo, "--log"]);
|
|
225
|
+
}
|
|
226
|
+
// ---- API(ブランチ・ファイル) ----
|
|
227
|
+
branchSha(branch) {
|
|
228
|
+
return this.gh(["api", `repos/${this.repo}/git/ref/heads/${branch}`, "--jq", ".object.sha"]);
|
|
229
|
+
}
|
|
230
|
+
async branchCreate(branch, sha) {
|
|
231
|
+
return ((await this.gh(["api", "-X", "POST", `repos/${this.repo}/git/refs`, "-f", `ref=refs/heads/${branch}`, "-f", `sha=${sha}`])) !== null);
|
|
232
|
+
}
|
|
233
|
+
async branchDelete(branch) {
|
|
234
|
+
return (await this.gh(["api", "-X", "DELETE", `repos/${this.repo}/git/refs/heads/${branch}`])) !== null;
|
|
235
|
+
}
|
|
236
|
+
/** そのブランチを head とする、開いている PR があるか。確かめられなければ、ある(安全側) */
|
|
237
|
+
async branchHasOpenPr(branch) {
|
|
238
|
+
const n = await this.gh(["pr", "list", "-R", this.repo, "--head", branch, "--state", "open", "--json", "number", "--jq", "length"]);
|
|
239
|
+
return n !== "0";
|
|
240
|
+
}
|
|
241
|
+
/** ブランチの名前の一覧。取れなければ null */
|
|
242
|
+
async branches() {
|
|
243
|
+
const out = await this.gh(["api", `repos/${this.repo}/branches`, "--paginate", "--jq", ".[].name"]);
|
|
244
|
+
return out === null ? null : out.split("\n").filter(Boolean);
|
|
245
|
+
}
|
|
246
|
+
/** Variable の値(なければ空) */
|
|
247
|
+
async variable(name) {
|
|
248
|
+
return (await this.gh(["variable", "get", name, "-R", this.repo])) ?? "";
|
|
249
|
+
}
|
|
250
|
+
/** contents API のパス(% と空白を符号にする) */
|
|
251
|
+
static urlPath(path) {
|
|
252
|
+
return path.replace(/%/g, "%25").replace(/ /g, "%20");
|
|
253
|
+
}
|
|
254
|
+
/** ファイルの SHA(ブランチ上)。なければ null */
|
|
255
|
+
async fileSha(branch, path) {
|
|
256
|
+
// gh の一時的な失敗を「ファイルなし」と取り違えないよう、失敗は数回やり直す(404 も失敗なので、なければ数回の後に null)
|
|
257
|
+
for (let i = 0; i < 3; i++) {
|
|
258
|
+
const s = await this.gh(["api", `repos/${this.repo}/contents/${VerifyGh.urlPath(path)}?ref=${branch}`, "--jq", ".sha"]);
|
|
259
|
+
if (s !== null)
|
|
260
|
+
return s === "" ? null : s;
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
/** ファイルの中身(ブランチ上)。なければ null */
|
|
265
|
+
fileText(branch, path) {
|
|
266
|
+
return this.gh(["api", `repos/${this.repo}/contents/${VerifyGh.urlPath(path)}?ref=${branch}`, "--jq", ".content | @base64d"]);
|
|
267
|
+
}
|
|
268
|
+
/** ファイルを追加・更新する(あれば SHA を付けて更新)。本文の base64 は、画面・ログに出さない */
|
|
269
|
+
async filePut(branch, path, text, message) {
|
|
270
|
+
const sha = await this.fileSha(branch, path);
|
|
271
|
+
const args = ["api", "-X", "PUT", `repos/${this.repo}/contents/${VerifyGh.urlPath(path)}`, "-f", `message=${message}`];
|
|
272
|
+
args.push("-f", `content=${base64(text)}`, "-f", `branch=${branch}`);
|
|
273
|
+
if (sha !== null)
|
|
274
|
+
args.push("-f", `sha=${sha}`);
|
|
275
|
+
return (await this.gh(args)) !== null;
|
|
276
|
+
}
|
|
277
|
+
/** ファイルを削除する(なければ、何もせず成功) */
|
|
278
|
+
async fileDelete(branch, path, message) {
|
|
279
|
+
const sha = await this.fileSha(branch, path);
|
|
280
|
+
if (sha === null)
|
|
281
|
+
return true;
|
|
282
|
+
const args = ["api", "-X", "DELETE", `repos/${this.repo}/contents/${VerifyGh.urlPath(path)}`, "-f", `message=${message}`];
|
|
283
|
+
args.push("-f", `sha=${sha}`, "-f", `branch=${branch}`);
|
|
284
|
+
return (await this.gh(args)) !== null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// リリースの仕組みの確認用サンプル(パターン別のコンポーネント)。lib/verify-samples.sh の移し先。
|
|
2
|
+
// sft project verify --components が、develop の組織に、リリースして、削除する。名前は、すべて SfToolsE2eHello 系(誰も使わない)。
|
|
3
|
+
// 目的は「種類ごとに書き方(ターゲットファイルの書式・パス・メンバー名)が違っても、リリースの仕組みが動く」ことの確認。
|
|
4
|
+
// 段階 1(先に削除する): ApexClass(SfToolsE2eHello・SfToolsE2eHelloTest・SfToolsE2eHelloTriggerTest)・ApexTrigger・LWC(バンドル。
|
|
5
|
+
// [files] に .js)・Aura([members]。LWC と名前空間が同じため別名)・Flow(Draft)・PermissionSet・Layout(名前に空白・ハイフン)・
|
|
6
|
+
// EmailTemplate(フォルダ付き・名前に $)・CustomLabels(1 ファイルに複数のメンバー)
|
|
7
|
+
// 段階 2(段階 1 のあとで削除する): CustomObject(SfToolsE2eHello__c)・CustomField(Note__c)
|
|
8
|
+
// 含めるもの(options):
|
|
9
|
+
// objects: オブジェクト系(トリガーとそのテスト・Layout・オブジェクト・項目)。削除したオブジェクトの名前は 15 日間予約されるため、
|
|
10
|
+
// 通しでは --with-objects のときだけ。検証のみは常に含める。Layout は削除対象にせず、オブジェクトの削除に任せる(最後の 1 つは消せない)
|
|
11
|
+
// flow: Flow。API で削除できない場合があるため、検証のみと --cleanup(リポジトリのファイルの削除)だけ。削除対象には含めない
|
|
12
|
+
// labels: CustomLabels。develop に、サンプル以外のラベルを含む labels のファイルがあれば含めない(上書きして消さないため)
|
|
13
|
+
import { APEX_META, HELLO_SET, VERIFY_APEX_HELLO, VERIFY_APEX_HELLO_TEST } from "./verify-gh.js";
|
|
14
|
+
export const SAMPLE_NAME = VERIFY_APEX_HELLO;
|
|
15
|
+
export const SAMPLE_OBJ = "SfToolsE2eHello__c";
|
|
16
|
+
const LWC = "sfToolsE2eHello";
|
|
17
|
+
const AURA = "SfToolsE2eHelloAura";
|
|
18
|
+
const B = "force-app/main/default";
|
|
19
|
+
const API = "64.0";
|
|
20
|
+
export const SAMPLE_LABELS_PATH = `${B}/labels/CustomLabels.labels-meta.xml`;
|
|
21
|
+
const TRIGGER = "SfToolsE2eHelloTrigger";
|
|
22
|
+
const TRIGGER_TEST = "SfToolsE2eHelloTriggerTest";
|
|
23
|
+
const LAYOUT = `${SAMPLE_OBJ}-${SAMPLE_NAME} Layout`;
|
|
24
|
+
const HEAD = '<?xml version="1.0" encoding="UTF-8"?>';
|
|
25
|
+
/** labels のファイルが、サンプル自身のもの(サンプルのラベルだけ。前回の検証の残り)か */
|
|
26
|
+
export function labelsFileIsOurs(body) {
|
|
27
|
+
const n = (body.match(/<fullName>/g) ?? []).length; // 行ではなく、出現の数(1 行の XML でも数え違えない)
|
|
28
|
+
return n === 1 && body.includes(`<fullName>${SAMPLE_NAME}</fullName>`);
|
|
29
|
+
}
|
|
30
|
+
const lines = (...l) => `${l.join("\n")}\n`;
|
|
31
|
+
const xml = (...l) => lines(HEAD, ...l);
|
|
32
|
+
/** パスに対応する本文(上から順に、最初に一致したもの) */
|
|
33
|
+
function content(p) {
|
|
34
|
+
const table = [
|
|
35
|
+
[
|
|
36
|
+
(x) => x.endsWith(`/classes/${SAMPLE_NAME}.cls`) || x.endsWith(`/classes/${VERIFY_APEX_HELLO_TEST}.cls`),
|
|
37
|
+
() => HELLO_SET.content(p) ?? "",
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
(x) => x.endsWith(`/classes/${TRIGGER_TEST}.cls`),
|
|
41
|
+
() => lines("@isTest", `private class ${TRIGGER_TEST} {`, " @isTest", " static void triggerSetsNote() {", ` ${SAMPLE_OBJ} r = new ${SAMPLE_OBJ}();`, " insert r;", ` r = [SELECT Note__c FROM ${SAMPLE_OBJ} WHERE Id = :r.Id];`, " System.assertEquals('hello', r.Note__c);", " }", "}"),
|
|
42
|
+
],
|
|
43
|
+
[(x) => x.endsWith(".cls-meta.xml"), () => APEX_META],
|
|
44
|
+
[
|
|
45
|
+
(x) => x.endsWith(`/triggers/${TRIGGER}.trigger`),
|
|
46
|
+
() => lines(`trigger ${TRIGGER} on ${SAMPLE_OBJ} (before insert) {`, ` for (${SAMPLE_OBJ} r : Trigger.new) {`, " if (r.Note__c == null) { r.Note__c = 'hello'; }", " }", "}"),
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
(x) => x.endsWith(".trigger-meta.xml"),
|
|
50
|
+
() => xml('<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">', ` <apiVersion>${API}</apiVersion>`, " <status>Active</status>", "</ApexTrigger>"),
|
|
51
|
+
],
|
|
52
|
+
[(x) => x.endsWith(`/lwc/${LWC}/${LWC}.html`), () => lines("<template>", " <p>Hello, World!</p>", "</template>")],
|
|
53
|
+
[
|
|
54
|
+
(x) => x.endsWith(`/lwc/${LWC}/${LWC}.js`),
|
|
55
|
+
// 「from」を式にするのは、読み込みの検査(tests/ts/boundary.test.ts)が、文字列の中の import を読み込みと取り違えないため
|
|
56
|
+
() => lines(`import { LightningElement } ${"from"} 'lwc';`, "export default class SfToolsE2eHello extends LightningElement {}"),
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
(x) => x.endsWith(`/lwc/${LWC}/${LWC}.js-meta.xml`),
|
|
60
|
+
() => xml('<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">', ` <apiVersion>${API}</apiVersion>`, " <isExposed>false</isExposed>", "</LightningComponentBundle>"),
|
|
61
|
+
],
|
|
62
|
+
[(x) => x.endsWith(`/aura/${AURA}/${AURA}.cmp`), () => lines("<aura:component>", " <p>Hello, World!</p>", "</aura:component>")],
|
|
63
|
+
[
|
|
64
|
+
(x) => x.endsWith(`/aura/${AURA}/${AURA}.cmp-meta.xml`),
|
|
65
|
+
() => xml('<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">', ` <apiVersion>${API}</apiVersion>`, " <description>SfToolsE2eHello</description>", "</AuraDefinitionBundle>"),
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
(x) => x.endsWith(`/flows/${SAMPLE_NAME}.flow-meta.xml`),
|
|
69
|
+
() => xml('<Flow xmlns="http://soap.sforce.com/2006/04/metadata">', ` <apiVersion>${API}</apiVersion>`, ` <label>${SAMPLE_NAME}</label>`, " <processType>AutoLaunchedFlow</processType>", " <start>", " <locationX>50</locationX>", " <locationY>0</locationY>", " </start>", " <status>Draft</status>", "</Flow>"),
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
(x) => x.endsWith(`/permissionsets/${SAMPLE_NAME}.permissionset-meta.xml`),
|
|
73
|
+
() => xml('<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">', " <hasActivationRequired>false</hasActivationRequired>", ` <label>${SAMPLE_NAME}</label>`, "</PermissionSet>"),
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
(x) => x.endsWith(`/layouts/${LAYOUT}.layout-meta.xml`),
|
|
77
|
+
() => xml('<Layout xmlns="http://soap.sforce.com/2006/04/metadata">', " <layoutSections>", " <customLabel>false</customLabel>", " <detailHeading>false</detailHeading>", " <editHeading>true</editHeading>", " <label>Information</label>", " <layoutColumns>", " <layoutItems>", " <behavior>Required</behavior>", " <field>Name</field>", " </layoutItems>", " </layoutColumns>", " <style>OneColumn</style>", " </layoutSections>", "</Layout>"),
|
|
78
|
+
],
|
|
79
|
+
[(x) => x.endsWith(`/email/unfiled$public/${SAMPLE_NAME}.email`), () => lines("Hello, World!")],
|
|
80
|
+
[
|
|
81
|
+
(x) => x.endsWith(`/email/unfiled$public/${SAMPLE_NAME}.email-meta.xml`),
|
|
82
|
+
() => xml('<EmailTemplate xmlns="http://soap.sforce.com/2006/04/metadata">', " <available>true</available>", ` <description>${SAMPLE_NAME}</description>`, " <encodingKey>UTF-8</encodingKey>", ` <name>${SAMPLE_NAME}</name>`, " <style>none</style>", ` <subject>${SAMPLE_NAME}</subject>`, " <type>text</type>", " <uiType>Aloha</uiType>", "</EmailTemplate>"),
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
(x) => x === SAMPLE_LABELS_PATH,
|
|
86
|
+
() => xml('<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">', " <labels>", ` <fullName>${SAMPLE_NAME}</fullName>`, " <language>en_US</language>", " <protected>false</protected>", " <shortDescription>SfToolsE2eHello</shortDescription>", " <value>Hello, World!</value>", " </labels>", "</CustomLabels>"),
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
(x) => x.endsWith(`/objects/${SAMPLE_OBJ}/${SAMPLE_OBJ}.object-meta.xml`),
|
|
90
|
+
() => xml('<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">', " <deploymentStatus>Deployed</deploymentStatus>", " <label>SfToolsE2eHello</label>", " <nameField>", " <label>Name</label>", " <type>Text</type>", " </nameField>", " <pluralLabel>SfToolsE2eHellos</pluralLabel>", " <sharingModel>ReadWrite</sharingModel>", "</CustomObject>"),
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
(x) => x.endsWith(`/objects/${SAMPLE_OBJ}/fields/Note__c.field-meta.xml`),
|
|
94
|
+
() => xml('<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">', " <fullName>Note__c</fullName>", " <label>Note</label>", " <length>80</length>", " <required>false</required>", " <type>Text</type>", " <unique>false</unique>", "</CustomField>"),
|
|
95
|
+
],
|
|
96
|
+
];
|
|
97
|
+
for (const [match, body] of table)
|
|
98
|
+
if (match(p))
|
|
99
|
+
return body();
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/** パターン別のサンプル */
|
|
103
|
+
export function sampleSet(o) {
|
|
104
|
+
return {
|
|
105
|
+
marker: SAMPLE_NAME,
|
|
106
|
+
paths: (stage) => {
|
|
107
|
+
const out = [];
|
|
108
|
+
if (stage === "stage1" || stage === "all") {
|
|
109
|
+
out.push(`${B}/classes/${SAMPLE_NAME}.cls`, `${B}/classes/${SAMPLE_NAME}.cls-meta.xml`, `${B}/classes/${VERIFY_APEX_HELLO_TEST}.cls`, `${B}/classes/${VERIFY_APEX_HELLO_TEST}.cls-meta.xml`, `${B}/lwc/${LWC}/${LWC}.html`, `${B}/lwc/${LWC}/${LWC}.js`, `${B}/lwc/${LWC}/${LWC}.js-meta.xml`, `${B}/aura/${AURA}/${AURA}.cmp`, `${B}/aura/${AURA}/${AURA}.cmp-meta.xml`, `${B}/permissionsets/${SAMPLE_NAME}.permissionset-meta.xml`, `${B}/email/unfiled$public/${SAMPLE_NAME}.email`, `${B}/email/unfiled$public/${SAMPLE_NAME}.email-meta.xml`);
|
|
110
|
+
if (o.flow)
|
|
111
|
+
out.push(`${B}/flows/${SAMPLE_NAME}.flow-meta.xml`);
|
|
112
|
+
if (o.objects)
|
|
113
|
+
out.push(`${B}/classes/${TRIGGER_TEST}.cls`, `${B}/classes/${TRIGGER_TEST}.cls-meta.xml`, `${B}/triggers/${TRIGGER}.trigger`, `${B}/triggers/${TRIGGER}.trigger-meta.xml`, `${B}/layouts/${LAYOUT}.layout-meta.xml`);
|
|
114
|
+
if (o.labels)
|
|
115
|
+
out.push(SAMPLE_LABELS_PATH);
|
|
116
|
+
}
|
|
117
|
+
if (o.objects && (stage === "stage2" || stage === "all"))
|
|
118
|
+
out.push(`${B}/objects/${SAMPLE_OBJ}/${SAMPLE_OBJ}.object-meta.xml`, `${B}/objects/${SAMPLE_OBJ}/fields/Note__c.field-meta.xml`);
|
|
119
|
+
return out;
|
|
120
|
+
},
|
|
121
|
+
content,
|
|
122
|
+
deployTarget: () => {
|
|
123
|
+
const f = [`${B}/classes/${SAMPLE_NAME}.cls`, `${B}/classes/${VERIFY_APEX_HELLO_TEST}.cls`];
|
|
124
|
+
if (o.objects)
|
|
125
|
+
f.push(`${B}/classes/${TRIGGER_TEST}.cls`, `${B}/triggers/${TRIGGER}.trigger`);
|
|
126
|
+
f.push(`${B}/lwc/${LWC}/${LWC}.js`);
|
|
127
|
+
if (o.flow)
|
|
128
|
+
f.push(`${B}/flows/${SAMPLE_NAME}.flow-meta.xml`);
|
|
129
|
+
f.push(`${B}/permissionsets/${SAMPLE_NAME}.permissionset-meta.xml`, `${B}/email/unfiled$public/${SAMPLE_NAME}.email`);
|
|
130
|
+
const m = [`AuraDefinitionBundle:${AURA}`];
|
|
131
|
+
if (o.objects)
|
|
132
|
+
m.push(`CustomObject:${SAMPLE_OBJ}`, `CustomField:${SAMPLE_OBJ}.Note__c`, `Layout:${LAYOUT}`);
|
|
133
|
+
if (o.labels)
|
|
134
|
+
m.push(`CustomLabel:${SAMPLE_NAME}`);
|
|
135
|
+
return lines("[files]", ...f, "", "[members]", ...m);
|
|
136
|
+
},
|
|
137
|
+
removeTarget: (stage) => {
|
|
138
|
+
const m = [];
|
|
139
|
+
if (stage === "stage1") {
|
|
140
|
+
if (o.objects)
|
|
141
|
+
m.push(`ApexTrigger:${TRIGGER}`, `ApexClass:${TRIGGER_TEST}`);
|
|
142
|
+
m.push(`ApexClass:${VERIFY_APEX_HELLO_TEST}`, `ApexClass:${SAMPLE_NAME}`, `LightningComponentBundle:${LWC}`, `AuraDefinitionBundle:${AURA}`, `PermissionSet:${SAMPLE_NAME}`, `EmailTemplate:unfiled$public/${SAMPLE_NAME}`);
|
|
143
|
+
if (o.labels)
|
|
144
|
+
m.push(`CustomLabel:${SAMPLE_NAME}`);
|
|
145
|
+
}
|
|
146
|
+
else if (o.objects) {
|
|
147
|
+
m.push(`CustomField:${SAMPLE_OBJ}.Note__c`, `CustomObject:${SAMPLE_OBJ}`);
|
|
148
|
+
}
|
|
149
|
+
return lines("[files]", "", "[members]", ...m);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Windows の .cmd の扱いの判定(doc/rebuild-design.md 7.1)。文字を読むだけで、起動は src/io/ がする
|
|
2
|
+
/**
|
|
3
|
+
* npm が作った、Node 用の起動ファイル(SET "_prog=node" と "%_prog%" 旗 "%dp0%\...\run.js" %*)なら、中身を返す。違う形なら null。
|
|
4
|
+
* npm は sh などの起動ファイルも同じ形で作るので、_prog が node であることを確かめる
|
|
5
|
+
*/
|
|
6
|
+
export function parseNodeShim(content) {
|
|
7
|
+
if (!/SET "_prog=node"/i.test(content))
|
|
8
|
+
return null;
|
|
9
|
+
const match = /"%_prog%"([^"\r\n]*)"%~?dp0%?\\([^"\r\n]+)"\s+%\*/.exec(content);
|
|
10
|
+
if (!match)
|
|
11
|
+
return null;
|
|
12
|
+
const [, flags = "", script = ""] = match;
|
|
13
|
+
return { nodeFlags: flags.split(/\s+/).filter(Boolean), script };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* cmd.exe を通すときに、渡してはいけない値か。cmd.exe では確実に打ち消せない文字と、末尾の \
|
|
17
|
+
* (引用符の前の \ は引用符を打ち消し、次の引数とつながる)
|
|
18
|
+
*/
|
|
19
|
+
export function isUnsafeForCmd(value) {
|
|
20
|
+
return /[&|<>^%!"\r\n]/.test(value) || value.endsWith("\\");
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// 可否の表(config/metadata-capability.txt)を読む。場所は、環境変数 SF_CHECK_CAPABILITY_FILE か、パッケージの config/。
|
|
2
|
+
// 表のファイルがなければ null(可否の確認をしない。シェル版の sf-check.sh と同じ)
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { parseCapabilityTable } from "../core/metadata-types.js";
|
|
6
|
+
export function loadCapabilityTable(env) {
|
|
7
|
+
const path = env("SF_CHECK_CAPABILITY_FILE") || fileURLToPath(new URL("../../config/metadata-capability.txt", import.meta.url));
|
|
8
|
+
if (!existsSync(path))
|
|
9
|
+
return null;
|
|
10
|
+
return parseCapabilityTable(readFileSync(path, "utf8"));
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// sft project create の外の部品の本物(入力の画面・作業フォルダ・雛形の場所・ブラウザ・PID・版・ファイルの権限)。
|
|
2
|
+
// テストは、偽物を渡す(src/core/project-create.ts)
|
|
3
|
+
import { chmodSync, statSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { readSecretValue } from "../ui/prompt.js";
|
|
6
|
+
import { realDoctorDeps } from "./doctor-deps.js";
|
|
7
|
+
import { pidAlive } from "./log-deps.js";
|
|
8
|
+
import { openBrowser } from "./open-browser.js";
|
|
9
|
+
import { readVersion } from "./package-version.js";
|
|
10
|
+
import { realUpdateSecretDeps } from "./update-secret-deps.js";
|
|
11
|
+
export function realCreateDeps(box, workflowTemplateDir) {
|
|
12
|
+
const base = realUpdateSecretDeps(box);
|
|
13
|
+
return {
|
|
14
|
+
...base,
|
|
15
|
+
prompts: {
|
|
16
|
+
...base.prompts,
|
|
17
|
+
// 合わないキーは聞き直す。q・Ctrl+C・入力の終わりは中断
|
|
18
|
+
key: async (prompt, valid) => {
|
|
19
|
+
for (;;) {
|
|
20
|
+
const k = await box.input.readKey(prompt);
|
|
21
|
+
if (k === null || k === "q" || k === "Q" || k === "\u0003")
|
|
22
|
+
return "quit"; // raw モードでは Ctrl+C が文字で届く
|
|
23
|
+
if (valid.test(k))
|
|
24
|
+
return k;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
secret: async (prompt) => {
|
|
28
|
+
for (;;) {
|
|
29
|
+
const r = await readSecretValue(box.input, prompt);
|
|
30
|
+
if (r.kind === "no-tty") {
|
|
31
|
+
box.output.err("[ERROR] 秘密の値は、端末(Windows Terminal・VS Code・Mac のターミナルなど)でないと、表示せずに受け取れません。端末で実行してください。");
|
|
32
|
+
return "quit";
|
|
33
|
+
}
|
|
34
|
+
if (r.kind !== "secret")
|
|
35
|
+
return "quit";
|
|
36
|
+
if (/^[qQ]$/.test(r.value))
|
|
37
|
+
return "quit"; // 「q で中断」(シェル版の read_secret と同じ)
|
|
38
|
+
return r.value;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
enter: async (prompt) => {
|
|
42
|
+
const v = await box.input.readLine(prompt);
|
|
43
|
+
return v !== null && !/^[qQ]$/.test(v);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
cwd: process.cwd(),
|
|
47
|
+
templatesDir: fileURLToPath(new URL("../../templates", import.meta.url)),
|
|
48
|
+
gitmessageFile: fileURLToPath(new URL("../../config/install/gitmessage", import.meta.url)),
|
|
49
|
+
workflowTemplateDir,
|
|
50
|
+
doctor: realDoctorDeps(box),
|
|
51
|
+
openBrowser,
|
|
52
|
+
pid: process.pid,
|
|
53
|
+
pidAlive,
|
|
54
|
+
interactive: process.stdin.isTTY === true,
|
|
55
|
+
version: readVersion(),
|
|
56
|
+
// フォルダは 0700(検索の権限が要る)、ファイルは 0600。効かない場所でも止めない(シェル版の chmod ... || true と同じ)
|
|
57
|
+
restrict: (path) => {
|
|
58
|
+
if (process.platform === "win32")
|
|
59
|
+
return;
|
|
60
|
+
try {
|
|
61
|
+
chmodSync(path, statSync(path).isDirectory() ? 0o700 : 0o600);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// 権限を絞れなくても、続ける
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// sft doctor の外の部品の本物(雛形の場所・更新時刻・node の場所・実行権限・OS・印のファイル)。テストは、偽物を渡す(src/core/doctor.ts)
|
|
2
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { realHookInstallDeps } from "./hook-install-deps.js";
|
|
7
|
+
export function realDoctorDeps(box) {
|
|
8
|
+
return {
|
|
9
|
+
...realHookInstallDeps(),
|
|
10
|
+
releaseTemplateDir: box.env("SF_TOOLS_RELEASE_TEMPLATE_DIR") || fileURLToPath(new URL("../../config/install/release", import.meta.url)),
|
|
11
|
+
mtime: (path) => {
|
|
12
|
+
try {
|
|
13
|
+
return statSync(path).mtimeMs;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
platform: process.platform,
|
|
20
|
+
sfBrokenMark: box.env("SF_TOOLS_SF_BROKEN_MARK") || join(homedir(), ".sf-tools-sf-broken"),
|
|
21
|
+
javaCheckStamp: box.env("SF_TOOLS_JAVA_CHECK_STAMP") || join(homedir(), ".sf-tools-java-check"),
|
|
22
|
+
isExecutable: (path) => {
|
|
23
|
+
try {
|
|
24
|
+
accessSync(path, constants.X_OK);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// sft hook install の外の部品の本物(今の node の場所・実行権限)。テストは、偽物を渡す(src/core/hook-install.ts)
|
|
2
|
+
import { chmodSync } from "node:fs";
|
|
3
|
+
export function realHookInstallDeps() {
|
|
4
|
+
return {
|
|
5
|
+
nodePath: process.execPath,
|
|
6
|
+
makeExecutable: (path) => {
|
|
7
|
+
if (process.platform !== "win32")
|
|
8
|
+
chmodSync(path, 0o755);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// sft job の外の部品の本物。クローンのあとは、そのフォルダへ移って、sft(引数なし)と同じ起動の準備とランチャーを動かす
|
|
2
|
+
// (src/commands/start.ts。サブコマンドの表は、循環を避けるため、動かすときに読み込む)
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { chooseNumber, readOrQuit } from "../ui/prompt.js";
|
|
5
|
+
export function realJobDeps(box) {
|
|
6
|
+
return {
|
|
7
|
+
prompts: {
|
|
8
|
+
text: async (prompt) => {
|
|
9
|
+
const r = await readOrQuit(box.input, prompt);
|
|
10
|
+
return r.kind === "text" ? r.value : "quit";
|
|
11
|
+
},
|
|
12
|
+
choose: async (title, items) => {
|
|
13
|
+
const r = await chooseNumber(box.input, box.output, title, items);
|
|
14
|
+
return r.kind === "chosen" ? r.index : "quit";
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
folderName: basename(process.cwd()),
|
|
18
|
+
cwd: process.cwd(),
|
|
19
|
+
startLauncher: async (repoDir) => {
|
|
20
|
+
try {
|
|
21
|
+
process.chdir(resolve(repoDir));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
box.output.err(`[ERROR] クローン先に移れません: ${repoDir}`);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const [{ commands }, { openStart }] = await Promise.all([import("../commands/index.js"), import("../commands/start.js")]);
|
|
28
|
+
return openStart(box, commands);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// 秘密鍵のファイル(JWT ログイン用)の本物。本人だけが読める場所と権限(フォルダ 0700・ファイル 0600)で作り、消すときはフォルダごと消す
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
export function realKeyFileDeps() {
|
|
6
|
+
return {
|
|
7
|
+
write: (text) => {
|
|
8
|
+
const dir = mkdtempSync(join(tmpdir(), "sf-key-"));
|
|
9
|
+
const path = join(dir, "server.key");
|
|
10
|
+
writeFileSync(path, text, { mode: 0o600 });
|
|
11
|
+
return path;
|
|
12
|
+
},
|
|
13
|
+
remove: (path) => {
|
|
14
|
+
rmSync(join(path, ".."), { recursive: true, force: true });
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|