oche-cli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +62 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3371,7 +3371,7 @@ var program = new Command();
|
|
|
3371
3371
|
// package.json
|
|
3372
3372
|
var package_default = {
|
|
3373
3373
|
name: "oche-cli",
|
|
3374
|
-
version: "0.
|
|
3374
|
+
version: "0.3.0",
|
|
3375
3375
|
description: "Command-line client for Oche: promote dev \u2192 staging \u2192 main from your terminal.",
|
|
3376
3376
|
license: "MIT",
|
|
3377
3377
|
repository: {
|
|
@@ -4182,6 +4182,22 @@ async function npmOut(bin, args) {
|
|
|
4182
4182
|
return null;
|
|
4183
4183
|
}
|
|
4184
4184
|
}
|
|
4185
|
+
async function npmRead(bin, args) {
|
|
4186
|
+
const quiet = await npmOut(bin, args);
|
|
4187
|
+
if (quiet !== null) return quiet;
|
|
4188
|
+
closeReader();
|
|
4189
|
+
return new Promise((resolve) => {
|
|
4190
|
+
const child = spawn(bin[0], [...bin.slice(1), ...args], { stdio: ["inherit", "pipe", "inherit"] });
|
|
4191
|
+
let out = "";
|
|
4192
|
+
child.stdout.on("data", (d) => {
|
|
4193
|
+
out += d.toString();
|
|
4194
|
+
for (const line of d.toString().split("\n")) if (/https?:\/\/|ENTER/.test(line)) process.stderr.write(`${line}
|
|
4195
|
+
`);
|
|
4196
|
+
});
|
|
4197
|
+
child.on("error", () => resolve(null));
|
|
4198
|
+
child.on("exit", (code) => resolve(code === 0 ? out : null));
|
|
4199
|
+
});
|
|
4200
|
+
}
|
|
4185
4201
|
function npmLive(bin, args) {
|
|
4186
4202
|
closeReader();
|
|
4187
4203
|
return new Promise((resolve, reject) => {
|
|
@@ -4197,6 +4213,36 @@ async function localPackage() {
|
|
|
4197
4213
|
return null;
|
|
4198
4214
|
}
|
|
4199
4215
|
}
|
|
4216
|
+
function parseTrustList(out) {
|
|
4217
|
+
const entries = [];
|
|
4218
|
+
let depth = 0;
|
|
4219
|
+
let start = -1;
|
|
4220
|
+
let inString = false;
|
|
4221
|
+
for (let i = 0; i < out.length; i++) {
|
|
4222
|
+
const ch = out[i];
|
|
4223
|
+
if (inString) {
|
|
4224
|
+
if (ch === "\\") i++;
|
|
4225
|
+
else if (ch === '"') inString = false;
|
|
4226
|
+
} else if (ch === '"') inString = true;
|
|
4227
|
+
else if (ch === "{") {
|
|
4228
|
+
if (depth++ === 0) start = i;
|
|
4229
|
+
} else if (ch === "}" && --depth === 0) {
|
|
4230
|
+
try {
|
|
4231
|
+
const v = JSON.parse(out.slice(start, i + 1));
|
|
4232
|
+
if (typeof v.id === "string") entries.push(v);
|
|
4233
|
+
} catch {
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
if (!entries.length) {
|
|
4238
|
+
try {
|
|
4239
|
+
const v = JSON.parse(out);
|
|
4240
|
+
if (Array.isArray(v)) return v.filter((e) => typeof e?.id === "string");
|
|
4241
|
+
} catch {
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
return entries;
|
|
4245
|
+
}
|
|
4200
4246
|
function printSteps(st) {
|
|
4201
4247
|
for (const s of st.steps) {
|
|
4202
4248
|
print(` ${s.done ? c.green("\u2713") : c.dim("\u25CB")} ${s.label}${!s.done && s.hint ? c.dim(` ${s.hint}`) : ""}`);
|
|
@@ -4277,20 +4323,29 @@ async function npmSetupCommand(client2, repoArg, opts) {
|
|
|
4277
4323
|
throw e;
|
|
4278
4324
|
}
|
|
4279
4325
|
}
|
|
4280
|
-
const
|
|
4281
|
-
|
|
4282
|
-
|
|
4326
|
+
const listed = await npmRead(bin, ["trust", "list", name, "--json"]);
|
|
4327
|
+
if (listed === null) throw new CliError(`Couldn't read npm's trusted publishers for ${name}. Run \`npm trust list ${name}\` to see why.`);
|
|
4328
|
+
const trust = parseTrustList(listed);
|
|
4329
|
+
const sameRepo = (t) => t.type === "github" && t.repository?.toLowerCase() === slug(repo).toLowerCase();
|
|
4330
|
+
if (trust.some((t) => sameRepo(t) && t.file === WORKFLOW_FILE)) {
|
|
4283
4331
|
ok(`npm already trusts ${WORKFLOW_FILE} in ${slug(repo)}`);
|
|
4284
4332
|
} else {
|
|
4285
|
-
const old = others.find((f) => trusted && new RegExp(`(^|[^\\w.-])${f.replace(/\./g, "\\.")}`).test(trusted));
|
|
4286
|
-
if (old) print(`
|
|
4287
|
-
npm trusts ${old} to publish ${name} today. This points it at ${WORKFLOW_FILE} instead.`);
|
|
4288
4333
|
print(`
|
|
4289
4334
|
npm will trust ${c.bold(`${slug(repo)} \u2192 .github/workflows/${WORKFLOW_FILE}`)} to publish ${name}. npm may ask for 2FA.`);
|
|
4290
4335
|
if (!await ask2("Continue?")) throw new CliError("Stopped before changing npm's trust settings.");
|
|
4291
4336
|
await npmLive(bin, ["trust", "github", name, "--file", WORKFLOW_FILE, "--repository", slug(repo), "--allow-publish", ...opts.yes ? ["--yes"] : []]);
|
|
4292
4337
|
ok("npm trusts the workflow");
|
|
4293
4338
|
}
|
|
4339
|
+
for (const t of trust.filter((t2) => sameRepo(t2) && t2.file !== WORKFLOW_FILE)) {
|
|
4340
|
+
print(`
|
|
4341
|
+
npm still trusts ${c.bold(t.file ?? "another workflow")} in ${slug(repo)} to publish ${name}.${others.includes(t.file ?? "") ? " Oche's PR removes that file." : ""}`);
|
|
4342
|
+
if (await ask2(`Revoke it? Only ${WORKFLOW_FILE} will be able to publish.`)) {
|
|
4343
|
+
await npmLive(bin, ["trust", "revoke", name, `--id=${t.id}`]);
|
|
4344
|
+
ok(`Revoked ${t.file}`);
|
|
4345
|
+
} else {
|
|
4346
|
+
print(c.dim(`Kept. Revoke it later with: npm trust revoke ${name} --id=${t.id}`));
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4294
4349
|
st = await api.npmTrust(repo, { packageName: name, npmUser });
|
|
4295
4350
|
print();
|
|
4296
4351
|
printSteps(st);
|