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
feat: improve CLI build command (#3456)
Bogdan Chadkin537cd3cca1a6
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex 653820da04..cf2d6a9abe 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -1,4 +1,6 @@import { access } from "node:fs/promises";+import { exit } from "node:process";+import { log } from "@clack/prompts";import { prebuild } from "../prebuild";import { LOCAL_DATA_FILE, PROJECT_TEMPALTES } from "../config";import type {@@ -21,6 +23,7 @@ export const buildOptions = (yargs: CommonYargsArgv) =>.option("template", {type: "array",string: true,+ default: [] as string[],describe: `Template to use for the build [choices: ${PROJECT_TEMPALTES.join(", ")}]`,@@ -34,9 +37,10 @@ export const build = async (await access(LOCAL_DATA_FILE);} catch (error: unknown) {if (error instanceof Error && "code" in error && error.code === "ENOENT") {- throw new Error(+ log.error(`You need to link a webstudio project before building it. Run \`webstudio link\` to link a project.`);+ exit(1);}throw error;diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.tsindex 95e73a5a76..ec4adf3fc9 100644--- a/packages/cli/src/prebuild.ts+++ b/packages/cli/src/prebuild.ts@@ -10,10 +10,10 @@ import {readdir,} from "node:fs/promises";import { pipeline } from "node:stream/promises";-import { cwd } from "node:process";+import { cwd, exit } from "node:process";import { fileURLToPath, pathToFileURL } from "node:url";import pLimit from "p-limit";-import ora from "ora";+import { log, spinner } from "@clack/prompts";import merge from "deepmerge";import {generateCss,@@ -210,12 +210,13 @@ export const prebuild = async (options: {/*** Template to use for the build in addition to defaults template**/- template?: string[];+ template: string[];}) => {- if (options.template === undefined) {- throw new Error(- `\n Template is not provided \n Please check webstudio --help for more details`+ if (options.template.length === 0) {+ log.error(+ `Template is not provided\nPlease check webstudio --help for more details`);+ exit(1);}for (const template of options.template) {@@ -230,16 +231,14 @@ export const prebuild = async (options: {}if ((await isCliTemplate(template)) === false) {- throw Error(- `\n Template ${options.template} is not available \n Please check webstudio --help for more details`+ log.error(+ `Template ${options.template} is not available\nPlease check webstudio --help for more details`);+ exit(1);}}- const spinner = ora("Scaffolding the project files");- spinner.start();-- spinner.text = "Generating files";+ log.step("Scaffolding the project files");const appRoot = "app";@@ -474,8 +473,6 @@ export const prebuild = async (options: {const assets = new Map(siteData.assets.map((asset) => [asset.id, asset]));- spinner.text = "Generating css file";-const { cssText, classesMap } = generateCss({instances: new Map(siteData.build.instances),props: new Map(siteData.build.props),@@ -491,8 +488,6 @@ export const prebuild = async (options: {await createFileIfNotExists(join(generatedDir, "index.css"), cssText);- spinner.text = "Generating routes and pages";-// MARK: - Route templates readconst routeTemplatesDir = join(cwd(), "app/route-templates");@@ -751,8 +746,6 @@ export const prebuild = async (options: {const redirects = siteData.build.pages?.redirects;if (redirects !== undefined && redirects.length > 0) {- spinner.text = "Generating redirects";-for (const redirect of redirects) {const redirectPagePath = generateRemixRoute(redirect.old);const redirectFileName = `${redirectPagePath}.ts`;@@ -768,8 +761,12 @@ export const prebuild = async (options: {}}- spinner.text = "Downloading fonts and images";- await Promise.all(assetsToDownload);+ if (assetsToDownload.length > 0) {+ const downloading = spinner();+ downloading.start("Downloading fonts and images");+ await Promise.all(assetsToDownload);+ downloading.stop("Downloaded fonts and images");+ }- spinner.succeed("Build finished");+ log.step("Build finished");};