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
chore: Add checks for template names for build command in cli (#2358)
Jaya Krishna Namburuac793ca457cd
diff --git a/.github/workflows/cli-test.yml b/.github/workflows/cli-test.ymlindex 689a38b0ab..9e9e89483d 100644--- a/.github/workflows/cli-test.yml+++ b/.github/workflows/cli-test.yml@@ -43,56 +43,14 @@ jobs:working-directory: ./fixtures/webstudio-remix-vercelrun: pnpm webstudio-cli --help- - name: Test cli link command for vercel- working-directory: ./fixtures/webstudio-remix-vercel- run: pnpm webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'+ - name: Testing cli link command+ run: pnpm --filter='./fixtures/*' run fixtures:link- - name: Test cli sync command for vercel- working-directory: ./fixtures/webstudio-remix-vercel- run: pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/+ - name: Testing cli sync command+ run: pnpm --filter='./fixtures/*' run --parallel fixtures:sync- - name: Test cli build command for vercel- working-directory: ./fixtures/webstudio-remix-vercel- run: pnpm webstudio-cli build --preview && pnpm prettier --write ./app/ ./package.json-- # Testing fixtures for netlify-functions template- - name: Test cli link command for netlify-functions- working-directory: ./fixtures/webstudio-remix-netlify-functions- run: pnpm webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'-- - name: Test cli sync command for netlify-functions- working-directory: ./fixtures/webstudio-remix-netlify-functions- run: pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/-- - name: Test cli build command for netlify-functions- working-directory: ./fixtures/webstudio-remix-netlify-functions- run: pnpm webstudio-cli build --template netlify-functions --preview && pnpm prettier --write ./app/ ./package.json-- # Testing fixtures for netlify-edge-functions template- - name: Test cli link command for netlify-edge-functions- working-directory: ./fixtures/webstudio-remix-netlify-edge-functions- run: pnpm webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&'-- - name: Test cli sync command for netlify-edge-functions- working-directory: ./fixtures/webstudio-remix-netlify-edge-functions- run: pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/-- - name: Test cli build command for netlify-edge-functions- working-directory: ./fixtures/webstudio-remix-netlify-edge-functions- run: pnpm webstudio-cli build --template netlify-edge-functions --preview && pnpm prettier --write ./app/ ./package.json-- # Testing fixtures for custom template- - name: Test cli link command for custom template- working-directory: ./fixtures/webstudio-custom-template- run: pnpm webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'-- - name: Test cli sync command for custom template- working-directory: ./fixtures/webstudio-custom-template- run: pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/-- - name: Test cli build command for custom template- working-directory: ./fixtures/webstudio-custom-template- run: pnpm webstudio-cli build --template ./custom-template --preview && pnpm prettier --write ./app/ ./package.json+ - name: Testing cli build command+ run: pnpm --filter='./fixtures/*' run --parallel fixtures:build- name: Test git diff# This command will fail if there are uncommitted changes, i.e something has brokendiff --git a/fixtures/webstudio-custom-template/package.json b/fixtures/webstudio-custom-template/package.jsonindex 82df8c24a0..a707588a69 100644--- a/fixtures/webstudio-custom-template/package.json+++ b/fixtures/webstudio-custom-template/package.json@@ -6,7 +6,10 @@"typecheck": "tsc","start": "remix-serve build","checks": "pnpm typecheck",- "size-test": "rm -rf ./public && remix build && size-limit"+ "size-test": "rm -rf ./public && remix build && size-limit",+ "fixtures:link": "webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f'",+ "fixtures:sync": "webstudio-cli sync && pnpm prettier --write ./.webstudio/",+ "fixtures:build": "webstudio-cli build --template ./custom-template --preview && pnpm prettier --write ./app/ ./package.json"},"private": true,"sideEffects": false,diff --git a/fixtures/webstudio-remix-netlify-edge-functions/README.md b/fixtures/webstudio-remix-netlify-edge-functions/README.mdnew file mode 100644index 0000000000..aa841b8af2--- /dev/null+++ b/fixtures/webstudio-remix-netlify-edge-functions/README.md@@ -0,0 +1,21 @@+# Fixture to test/play with webstudio-cli++## How to develop++```bash+# Terminal 1+cd packages/webstudio-cli+pnpm dev+```++```bash+# Terminal 2+pnpm webstudio-cli link+# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93++pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/+# data.json generated++pnpm webstudio-cli build --preview && pnpm prettier --write ./app/ ./package.json+# exec `pnpm run dev` to see result+```diff --git a/fixtures/webstudio-remix-netlify-edge-functions/package.json b/fixtures/webstudio-remix-netlify-edge-functions/package.jsonindex 305c930317..fc613620bb 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/package.json+++ b/fixtures/webstudio-remix-netlify-edge-functions/package.json@@ -4,7 +4,10 @@"start": "netlify serve","build": "remix build","dev": "remix dev",- "typecheck": "tsc"+ "typecheck": "tsc",+ "fixtures:link": "webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&'",+ "fixtures:sync": "webstudio-cli sync && pnpm prettier --write ./.webstudio/",+ "fixtures:build": "webstudio-cli build --template netlify-edge-functions --preview && pnpm prettier --write ./app/ ./package.json"},"dependencies": {"@netlify/functions": "^1.3.0",diff --git a/fixtures/webstudio-remix-netlify-functions/README.md b/fixtures/webstudio-remix-netlify-functions/README.mdnew file mode 100644index 0000000000..aa841b8af2--- /dev/null+++ b/fixtures/webstudio-remix-netlify-functions/README.md@@ -0,0 +1,21 @@+# Fixture to test/play with webstudio-cli++## How to develop++```bash+# Terminal 1+cd packages/webstudio-cli+pnpm dev+```++```bash+# Terminal 2+pnpm webstudio-cli link+# add following link https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93++pnpm webstudio-cli sync && pnpm prettier --write ./.webstudio/+# data.json generated++pnpm webstudio-cli build --preview && pnpm prettier --write ./app/ ./package.json+# exec `pnpm run dev` to see result+```diff --git a/fixtures/webstudio-remix-netlify-functions/package.json b/fixtures/webstudio-remix-netlify-functions/package.jsonindex 2929dc3a7c..265c6f8534 100644--- a/fixtures/webstudio-remix-netlify-functions/package.json+++ b/fixtures/webstudio-remix-netlify-functions/package.json@@ -4,7 +4,10 @@"start": "netlify serve","build": "remix build","dev": "remix dev",- "typecheck": "tsc"+ "typecheck": "tsc",+ "fixtures:link": "webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",+ "fixtures:sync": "webstudio-cli sync && pnpm prettier --write ./.webstudio/",+ "fixtures:build": "webstudio-cli build --template netlify-functions --preview && pnpm prettier --write ./app/ ./package.json"},"dependencies": {"@netlify/functions": "^1.3.0",diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.jsonindex aec6bf9591..016a6be973 100644--- a/fixtures/webstudio-remix-vercel/package.json+++ b/fixtures/webstudio-remix-vercel/package.json@@ -3,7 +3,10 @@"start": "remix-serve build","build": "remix build","dev": "remix dev",- "typecheck": "tsc"+ "typecheck": "tsc",+ "fixtures:link": "webstudio-cli link --link 'https://webstudio-builder-git-main-webstudio-is.vercel.app/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview'",+ "fixtures:sync": "webstudio-cli sync && pnpm prettier --write ./.webstudio/",+ "fixtures:build": "webstudio-cli build --preview && pnpm prettier --write ./app/ ./package.json"},"private": true,"sideEffects": false,diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex fefeb645b4..45ed5a0775 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -38,6 +38,7 @@"picocolors": "^1.0.0","prompts": "^2.4.2","strip-indent": "^4.0.0",+ "title-case": "^3.0.3","yargs": "^17.7.2","zod": "^3.21.4"},diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex 4c3d2da2f6..bb27ea8c4d 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -1,6 +1,6 @@import { access } from "node:fs/promises";import { prebuild } from "../prebuild";-import { LOCAL_DATA_FILE } from "../config";+import { LOCAL_DATA_FILE, PROJECT_TEMPALTES } from "../config";import type {CommonYargsArgv,StrictYargsOptionsToInterface,@@ -21,7 +21,7 @@ export const buildOptions = (yargs: CommonYargsArgv) =>.option("template", {type: "string",default: "vercel",- describe: "[Experimental] Template to use for the build",+ describe: `[Experimental] Template to use for the build [choices: ${PROJECT_TEMPALTES.toString()}]`,});// @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 fcace29e06..2398e4e158 100644--- a/packages/cli/src/commands/init-flow.ts+++ b/packages/cli/src/commands/init-flow.ts@@ -9,6 +9,8 @@ import { prompt } from "../prompts";import type { StrictYargsOptionsToInterface } from "./yargs-types";import pc from "picocolors";import { $ } from "execa";+import { PROJECT_TEMPALTES } from "../config";+import { titleCase } from "title-case";export const initFlow = async (options: StrictYargsOptionsToInterface<typeof buildOptions>@@ -66,20 +68,12 @@ export const initFlow = async (type: "select",name: "deployTarget",message: "Where would you like to deploy your project?",- choices: [- {- title: "Vercel",- value: "vercel",- },- {- title: "Netlify Functions",- value: "netlify-functions",- },- {- title: "Netlify Edge Functions",- value: "netlify-edge-functions",- },- ],+ choices: PROJECT_TEMPALTES.map((template) => {+ return {+ title: titleCase(template),+ value: template,+ };+ }),});projectTemplate = deployTarget;}diff --git a/packages/cli/src/config.ts b/packages/cli/src/config.tsindex c3acc13455..b94842bccd 100644--- a/packages/cli/src/config.ts+++ b/packages/cli/src/config.ts@@ -51,3 +51,9 @@ export const jsonToGlobalConfig = (json: unknown) => {};export type GlobalConfig = z.infer<typeof zGlobalConfig>;++export const PROJECT_TEMPALTES = [+ "vercel",+ "netlify-functions",+ "netlify-edge-functions",+];diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.tsindex 291cddaf7b..3356a32d2a 100644--- a/packages/cli/src/prebuild.ts+++ b/packages/cli/src/prebuild.ts@@ -198,6 +198,16 @@ export const prebuild = async (options: {**/template?: string;}) => {+ if (+ options.template !== undefined &&+ (await isCliTemplate(options.template)) === false &&+ options.template.startsWith(".") === false+ ) {+ throw Error(+ `\n Template ${options.template} is not available \n Please check webstudio-cli --help for more details`+ );+ }+const spinner = ora("Scaffolding the project files");spinner.start();diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f6cf11d65d..4f666c6060 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -815,6 +815,9 @@ importers:strip-indent:specifier: ^4.0.0version: 4.0.0+ title-case:+ specifier: ^3.0.3+ version: 3.0.3yargs:specifier: ^17.7.2version: 17.7.2