Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Install dependencies and run the dev server on `webstudio` command using cli (#2258)
Jaya Krishna Namburu288062167a70
diff --git a/packages/cli/src/commands/init-flow.ts b/packages/cli/src/commands/init-flow.tsindex e64c557e9e..89dc079181 100644--- a/packages/cli/src/commands/init-flow.ts+++ b/packages/cli/src/commands/init-flow.ts@@ -1,7 +1,9 @@import prompts, { type PromptObject } from "prompts";import { ensureFolderExists, isFileExists } from "../fs-utils";-import { chdir, cwd } from "node:process";+import { chdir, cwd, stdout as shellOutput } from "node:process";+import { spawn } from "node:child_process";import { join } from "node:path";+import ora from "ora";import { link } from "./link";import { sync } from "./sync";import { build, buildOptions } from "./build";@@ -12,6 +14,7 @@ export const initFlow = async () => {const isProjectConfigured = await isFileExists(".webstudio/config.json");const prompsList: PromptObject[] = [];+ const spinner = ora().start();if (isProjectConfigured === false) {prompsList.push(@@ -50,4 +53,44 @@ export const initFlow = async (*/await sync();await build(options);++ spinner.text = "Installing dependencies";+ const { stderr } = await exec("npm", ["install"]);+ if (stderr) {+ throw stderr;+ }++ spinner.text = "Starting dev server";+ spinner.stop();+ const { stderr: devServerError } = await exec("npm", ["run", "dev"]);+ if (devServerError) {+ throw devServerError;+ }+};++const exec = (+ command: string,+ args?: ReadonlyArray<string>+): Promise<{ stdout: string; stderr: string }> => {+ return new Promise((resolve, reject) => {+ const process = spawn(command, args);+ let stdout = "";+ let stderr = "";+ process.on("error", reject);+ process.on("exit", (code) => {+ if (code !== 0) {+ reject({ stdout, stderr });+ } else {+ resolve({ stdout, stderr });+ }+ });++ process.stderr.setEncoding("utf8");+ process.stdout.setEncoding("utf8");+ process.stdout.on("data", (data) => {+ stdout += data;+ shellOutput.write(data);+ });+ process.stderr.on("error", (error) => (stderr += error));+ });};