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
fix: Display error messages when a template is not passed for building a project (#2660)
Jaya Krishna Namburu301e7d95ca6f
diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.jsonindex d35e08c984..051b0fa4d0 100644--- a/fixtures/webstudio-remix-vercel/package.json+++ b/fixtures/webstudio-remix-vercel/package.json@@ -6,7 +6,7 @@"typecheck": "tsc","fixtures:link": "webstudio link --link 'https://webstudio-builder-git-main-getwebstudio.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview'","fixtures:sync": "webstudio sync && pnpm prettier --write ./.webstudio/",- "fixtures:build": "webstudio build --preview && pnpm prettier --write ./app/ ./package.json"+ "fixtures:build": "webstudio build --template vercel --preview && pnpm prettier --write ./app/ ./package.json"},"private": true,"sideEffects": false,diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.tsindex 45c879423c..6bcc3ccf28 100644--- a/packages/cli/src/cli.ts+++ b/packages/cli/src/cli.ts@@ -45,7 +45,17 @@ export const main = async () => {cmd.version(packageJson.version).alias("v", "version");- cmd.command(["build"], "Build the project", buildOptions, build);+ cmd.command(+ ["build"],+ "Build the project",+ (yargs: CommonYargsArgv) => {+ return buildOptions(yargs).demandOption(+ "template",+ "Please specify a template to use for the build"+ );+ },+ build+ );cmd.command(["link"], "Link the project with the cloud", linkOptions, link);cmd.command(["sync"], "Sync your project", syncOptions, sync);cmd.command(["$0", "init"], "Setup the project", buildOptions, initFlow);diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex bb27ea8c4d..d586150613 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -20,8 +20,9 @@ export const buildOptions = (yargs: CommonYargsArgv) =>}).option("template", {type: "string",- default: "vercel",- describe: `[Experimental] Template to use for the build [choices: ${PROJECT_TEMPALTES.toString()}]`,+ describe: `Template to use for the build [choices: ${PROJECT_TEMPALTES.join(+ ", "+ )}]`,});// @todo: use options.assets to define if we need to download assetsdiff --git a/packages/cli/src/commands/init-flow.ts b/packages/cli/src/commands/init-flow.tsindex 3626fb96fe..f4dd14f55a 100644--- a/packages/cli/src/commands/init-flow.ts+++ b/packages/cli/src/commands/init-flow.ts@@ -58,27 +58,18 @@ export const initFlow = async (}await link({ link: projectLink });- const { shouldSetupDeployTarget } = await prompt({- type: "confirm",- name: "shouldSetupDeployTarget",- message: "Would you like to setup a deploy target?",- initial: false,+ const { deployTarget } = await prompt({+ type: "select",+ name: "deployTarget",+ message: "Where would you like to deploy your project?",+ choices: PROJECT_TEMPALTES.map((template) => {+ return {+ title: titleCase(template),+ value: template,+ };+ }),});-- if (shouldSetupDeployTarget === true) {- const { deployTarget } = await prompt({- type: "select",- name: "deployTarget",- message: "Where would you like to deploy your project?",- choices: PROJECT_TEMPALTES.map((template) => {- return {- title: titleCase(template),- value: template,- };- }),- });- projectTemplate = deployTarget;- }+ projectTemplate = deployTarget;const { installDeps } = await prompt({type: "confirm",@@ -91,6 +82,26 @@ export const initFlow = async (await sync({ buildId: undefined, origin: undefined, authToken: undefined });+ /*+ If a project is already linked, we sync direclty without asking for deploy target.+ We need to request for deploy target here as the current flow is running in a existing project.+ */++ if (projectTemplate === undefined) {+ const { deployTarget } = await prompt({+ type: "select",+ name: "deployTarget",+ message: "Where would you like to deploy your project?",+ choices: PROJECT_TEMPALTES.map((template) => {+ return {+ title: titleCase(template),+ value: template,+ };+ }),+ });+ projectTemplate = deployTarget;+ }+await build({...options,...(projectTemplate && { template: projectTemplate }),diff --git a/packages/cli/src/config.ts b/packages/cli/src/config.tsindex 29f3baa4ab..78184b004d 100644--- a/packages/cli/src/config.ts+++ b/packages/cli/src/config.ts@@ -53,6 +53,7 @@ export const jsonToGlobalConfig = (json: unknown) => {export type GlobalConfig = z.infer<typeof zGlobalConfig>;export const PROJECT_TEMPALTES = [+ "vanilla","vercel","netlify-functions","netlify-edge-functions",diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.tsindex baa326f3f7..6e3fb1adac 100644--- a/packages/cli/src/prebuild.ts+++ b/packages/cli/src/prebuild.ts@@ -199,8 +199,14 @@ export const prebuild = async (options: {**/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 !== undefined &&+ options.template !== "vanilla" &&(await isCliTemplate(options.template)) === false &&options.template.startsWith(".") === false) {@@ -224,7 +230,7 @@ export const prebuild = async (options: {await copyTemplates();- if (options.template !== undefined) {+ if (options.template !== "vanilla") {await copyTemplates(options.template);}