@kinkai.cloud/vibecheck 0.1.0 → 0.1.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/dist/cli.js +45 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -14891,20 +14891,59 @@ function urlBase() {
|
|
|
14891
14891
|
""
|
|
14892
14892
|
);
|
|
14893
14893
|
}
|
|
14894
|
-
function
|
|
14895
|
-
|
|
14896
|
-
|
|
14894
|
+
function comandosAbrirBrowser(url2, platform = process.platform, env = process.env) {
|
|
14895
|
+
if (platform === "darwin") return [["open", [url2]]];
|
|
14896
|
+
if (platform === "win32") return [["cmd", ["/c", "start", "", url2]]];
|
|
14897
|
+
const wsl = env["WSL_DISTRO_NAME"] !== void 0 || env["WSL_INTEROP"] !== void 0;
|
|
14898
|
+
if (wsl) {
|
|
14899
|
+
return [
|
|
14900
|
+
["wslview", [url2]],
|
|
14901
|
+
["cmd.exe", ["/c", "start", "", url2]]
|
|
14902
|
+
];
|
|
14903
|
+
}
|
|
14904
|
+
return [["xdg-open", [url2]]];
|
|
14905
|
+
}
|
|
14906
|
+
function tentarSpawn(cmd, args) {
|
|
14907
|
+
return new Promise((resolve) => {
|
|
14908
|
+
const child = spawn2(cmd, args, { stdio: "ignore", detached: true });
|
|
14909
|
+
child.once("error", () => resolve(false));
|
|
14910
|
+
child.once("spawn", () => {
|
|
14911
|
+
child.unref();
|
|
14912
|
+
resolve(true);
|
|
14913
|
+
});
|
|
14914
|
+
});
|
|
14915
|
+
}
|
|
14916
|
+
async function abrirBrowser(url2) {
|
|
14917
|
+
for (const [cmd, args] of comandosAbrirBrowser(url2)) {
|
|
14918
|
+
if (await tentarSpawn(cmd, args)) return;
|
|
14919
|
+
}
|
|
14920
|
+
}
|
|
14921
|
+
async function detalheHttp(resposta) {
|
|
14922
|
+
const tipo = resposta.headers.get("content-type") ?? "";
|
|
14923
|
+
if (tipo.includes("application/json")) {
|
|
14924
|
+
const corpo = await resposta.json();
|
|
14925
|
+
if (typeof corpo.error === "string" && corpo.error.length > 0) {
|
|
14926
|
+
return ` \u2014 ${corpo.error}`;
|
|
14927
|
+
}
|
|
14928
|
+
}
|
|
14929
|
+
if (resposta.status === 404) {
|
|
14930
|
+
return " \u2014 a API do CLI ainda n\xE3o est\xE1 neste deploy";
|
|
14931
|
+
}
|
|
14932
|
+
return "";
|
|
14897
14933
|
}
|
|
14898
14934
|
async function loginDevice(ci) {
|
|
14899
14935
|
const base = urlBase();
|
|
14900
14936
|
const aberto = await fetch(`${base}/api/cli/device`, { method: "POST" });
|
|
14901
14937
|
if (!aberto.ok) {
|
|
14902
|
-
|
|
14938
|
+
const extra = await detalheHttp(aberto);
|
|
14939
|
+
throw new Error(
|
|
14940
|
+
`n\xE3o foi poss\xEDvel abrir o device-code em ${base} (HTTP ${aberto.status})${extra}`
|
|
14941
|
+
);
|
|
14903
14942
|
}
|
|
14904
14943
|
const corpo = await aberto.json();
|
|
14905
|
-
console.warn(`No navegador, autorize com o c\xF3digo ${corpo.user_code}`);
|
|
14944
|
+
console.warn(`No navegador, entre na conta e autorize com o c\xF3digo ${corpo.user_code}`);
|
|
14906
14945
|
console.warn(corpo.verification_url);
|
|
14907
|
-
if (!ci) abrirBrowser(corpo.verification_url);
|
|
14946
|
+
if (!ci) await abrirBrowser(corpo.verification_url);
|
|
14908
14947
|
const intervalo = Math.max(3, corpo.interval ?? 3) * 1e3;
|
|
14909
14948
|
const limite = Date.now() + 10 * 6e4;
|
|
14910
14949
|
while (Date.now() < limite) {
|