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