cli create: fix installing deps spinner

This commit is contained in:
dswbx
2025-02-14 14:08:15 +01:00
parent 425465becd
commit b412da836c
3 changed files with 26 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
"type": "module", "type": "module",
"sideEffects": false, "sideEffects": false,
"bin": "./dist/cli/index.js", "bin": "./dist/cli/index.js",
"version": "0.8.0-rc.1", "version": "0.8.0-rc.3",
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, Remix, Astro, Cloudflare, Bun, Node, AWS Lambda & more.", "description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, Remix, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
"homepage": "https://bknd.io", "homepage": "https://bknd.io",
"repository": { "repository": {

View File

@@ -3,7 +3,7 @@ import { downloadTemplate } from "@bluwy/giget-core";
import * as $p from "@clack/prompts"; import * as $p from "@clack/prompts";
import type { CliCommand } from "cli/types"; import type { CliCommand } from "cli/types";
import { typewriter, wait } from "cli/utils/cli"; import { typewriter, wait } from "cli/utils/cli";
import { exec, getVersion } from "cli/utils/sys"; import { execAsync, getVersion } from "cli/utils/sys";
import { Option } from "commander"; import { Option } from "commander";
import color from "picocolors"; import color from "picocolors";
import { overridePackageJson, updateBkndPackages } from "./npm"; import { overridePackageJson, updateBkndPackages } from "./npm";
@@ -190,7 +190,7 @@ async function action(options: { template?: string; dir?: string; integration?:
//console.log("url", url); //console.log("url", url);
const s = $p.spinner(); const s = $p.spinner();
s.start("Downloading template..."); await s.start("Downloading template...");
try { try {
await downloadTemplate(url, { await downloadTemplate(url, {
dir: ctx.dir, dir: ctx.dir,
@@ -236,9 +236,9 @@ async function action(options: { template?: string; dir?: string; integration?:
const install_cmd = template.scripts?.install || "npm install"; const install_cmd = template.scripts?.install || "npm install";
const s = $p.spinner(); const s = $p.spinner();
s.start("Installing dependencies..."); await s.start("Installing dependencies...");
try { try {
exec(`cd ${ctx.dir} && ${install_cmd}`, { silent: true }); await execAsync(`cd ${ctx.dir} && ${install_cmd}`, { silent: true });
} catch (e) { } catch (e) {
if (e instanceof Error) { if (e instanceof Error) {
s.stop("Failed to install: " + color.red(e.message), 1); s.stop("Failed to install: " + color.red(e.message), 1);

View File

@@ -1,4 +1,4 @@
import { execSync } from "node:child_process"; import { execSync, exec as nodeExec } from "node:child_process";
import { readFile } from "node:fs/promises"; import { readFile } from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import url from "node:url"; import url from "node:url";
@@ -51,3 +51,23 @@ export function exec(command: string, opts?: { silent?: boolean; env?: Record<st
} }
return output.toString(); return output.toString();
} }
export function execAsync(
command: string,
opts?: { silent?: boolean; env?: Record<string, string> }
) {
return new Promise((resolve, reject) => {
nodeExec(
command,
{
env: { ...process.env, ...opts?.env }
},
(err, stdout, stderr) => {
if (err) {
return reject(err);
}
resolve(stdout);
}
);
});
}