From 9e8407a2631affcf7089e6552aa3a0776a4f7755 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 4 Jan 2025 01:30:47 +0700 Subject: [PATCH] refactor: drop --preview flag from CLI We figured assets can be loaded from shared url without additional manipulation. Here got rid of asset origin detection and dropped excessive --preview flag. Now local, staging and prod will work automatically. --- .../.webstudio/data.json | 3 ++- .../ssg-netlify-by-project-id/package.json | 2 +- fixtures/ssg/.webstudio/data.json | 3 ++- fixtures/ssg/package.json | 2 +- .../.webstudio/data.json | 3 ++- .../webstudio-cloudflare-template/package.json | 2 +- .../.webstudio/data.json | 3 ++- .../webstudio-custom-template/package.json | 2 +- .../.webstudio/data.json | 3 ++- .../package.json | 2 +- .../.webstudio/data.json | 3 ++- .../package.json | 2 +- .../.webstudio/data.json | 3 ++- fixtures/webstudio-remix-vercel/package.json | 2 +- packages/cli/src/commands/build.ts | 5 ----- packages/cli/src/commands/sync.ts | 2 ++ packages/cli/src/prebuild.ts | 18 +----------------- packages/http-client/src/index.ts | 1 + 18 files changed, 25 insertions(+), 36 deletions(-) diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json index de8de364db59..142375b5a0df 100644 --- a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json +++ b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json @@ -136,5 +136,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "fixture-client-do-not-touch-wsmel", - "projectTitle": "FIXTURE-CLIENT-DO-NOT-TOUCH" + "projectTitle": "FIXTURE-CLIENT-DO-NOT-TOUCH", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/ssg-netlify-by-project-id/package.json b/fixtures/ssg-netlify-by-project-id/package.json index c4b77f2075e3..330536f81439 100644 --- a/fixtures/ssg-netlify-by-project-id/package.json +++ b/fixtures/ssg-netlify-by-project-id/package.json @@ -10,7 +10,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-8a7358b1-7de3-459d-b7b1-56dddfb6ce1e-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=f55154e6-36b9-4920-bc81-3095cc88f8ff'", "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/", - "fixtures:build": "rm -rf pages && pnpm cli build --template ssg-netlify --template internal --preview && prettier --write ." + "fixtures:build": "rm -rf pages && pnpm cli build --template ssg-netlify --template internal && prettier --write ." }, "engines": { "node": ">=20.0.0" diff --git a/fixtures/ssg/.webstudio/data.json b/fixtures/ssg/.webstudio/data.json index b7c01b0448aa..8f97956ab8a2 100644 --- a/fixtures/ssg/.webstudio/data.json +++ b/fixtures/ssg/.webstudio/data.json @@ -493,5 +493,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "cli-basic-test-d0osr", - "projectTitle": "cli-basic-test" + "projectTitle": "cli-basic-test", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/ssg/package.json b/fixtures/ssg/package.json index 27fe22987324..2927a72e028d 100644 --- a/fixtures/ssg/package.json +++ b/fixtures/ssg/package.json @@ -10,7 +10,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link ${BUILDER_URL_DEPRECATED:-https://main.development.webstudio.is}'/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'", "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/", - "fixtures:build": "rm -rf pages && pnpm cli build --template ssg --template internal --preview && prettier --write ." + "fixtures:build": "rm -rf pages && pnpm cli build --template ssg --template internal && prettier --write ." }, "engines": { "node": ">=20.0.0" diff --git a/fixtures/webstudio-cloudflare-template/.webstudio/data.json b/fixtures/webstudio-cloudflare-template/.webstudio/data.json index b7c01b0448aa..8f97956ab8a2 100644 --- a/fixtures/webstudio-cloudflare-template/.webstudio/data.json +++ b/fixtures/webstudio-cloudflare-template/.webstudio/data.json @@ -493,5 +493,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "cli-basic-test-d0osr", - "projectTitle": "cli-basic-test" + "projectTitle": "cli-basic-test", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/webstudio-cloudflare-template/package.json b/fixtures/webstudio-cloudflare-template/package.json index 27214c20a7d2..fbf3f49341f8 100644 --- a/fixtures/webstudio-cloudflare-template/package.json +++ b/fixtures/webstudio-cloudflare-template/package.json @@ -4,7 +4,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-d845c167-ea07-4875-b08d-83e97c09dcce-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'", "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/", - "fixtures:build": "pnpm cli build --template cloudflare --template saas-helpers --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json", + "fixtures:build": "pnpm cli build --template cloudflare --template saas-helpers --template internal && pnpm prettier --write ./app/ ./package.json ./tsconfig.json", "build": "remix vite:build", "dev": "remix vite:dev", "typecheck": "tsc", diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.json index dfd751959332..bb1df091feba 100644 --- a/fixtures/webstudio-custom-template/.webstudio/data.json +++ b/fixtures/webstudio-custom-template/.webstudio/data.json @@ -2331,5 +2331,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "webstudio-custom-template-cochj", - "projectTitle": "webstudio-custom-template" + "projectTitle": "webstudio-custom-template", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/webstudio-custom-template/package.json b/fixtures/webstudio-custom-template/package.json index 5a25d69a6724..a217991cb666 100644 --- a/fixtures/webstudio-custom-template/package.json +++ b/fixtures/webstudio-custom-template/package.json @@ -7,7 +7,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-0d856812-61d8-4014-a20a-82e01c0eb8ee-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f'", "fixtures:sync": "pnpm cli sync --buildId d48c7c5e-fdd3-4ef6-9173-ff2eaaf851d9 && pnpm prettier --write ./.webstudio/", - "fixtures:build": "pnpm cli build --template defaults --template ./custom-template --template ./custom-template-stage --template internal --preview --assets false && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" + "fixtures:build": "pnpm cli build --template defaults --template ./custom-template --template ./custom-template-stage --template internal --assets false && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" }, "private": true, "sideEffects": false, diff --git a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json index b7c01b0448aa..8f97956ab8a2 100644 --- a/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json +++ b/fixtures/webstudio-remix-netlify-edge-functions/.webstudio/data.json @@ -493,5 +493,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "cli-basic-test-d0osr", - "projectTitle": "cli-basic-test" + "projectTitle": "cli-basic-test", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/webstudio-remix-netlify-edge-functions/package.json b/fixtures/webstudio-remix-netlify-edge-functions/package.json index ecb10349e910..2fff770c419f 100644 --- a/fixtures/webstudio-remix-netlify-edge-functions/package.json +++ b/fixtures/webstudio-remix-netlify-edge-functions/package.json @@ -8,7 +8,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-d845c167-ea07-4875-b08d-83e97c09dcce-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'", "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/", - "fixtures:build": "pnpm cli build --template netlify-edge-functions --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" + "fixtures:build": "pnpm cli build --template netlify-edge-functions --template internal && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" }, "dependencies": { "@netlify/edge-functions": "^2.11.1", diff --git a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json index b7c01b0448aa..8f97956ab8a2 100644 --- a/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json +++ b/fixtures/webstudio-remix-netlify-functions/.webstudio/data.json @@ -493,5 +493,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "cli-basic-test-d0osr", - "projectTitle": "cli-basic-test" + "projectTitle": "cli-basic-test", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/webstudio-remix-netlify-functions/package.json b/fixtures/webstudio-remix-netlify-functions/package.json index 920f3e232508..8865e9782c16 100644 --- a/fixtures/webstudio-remix-netlify-functions/package.json +++ b/fixtures/webstudio-remix-netlify-functions/package.json @@ -7,7 +7,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-d845c167-ea07-4875-b08d-83e97c09dcce-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'", "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/", - "fixtures:build": "pnpm cli build --template netlify-functions --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" + "fixtures:build": "pnpm cli build --template netlify-functions --template internal && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" }, "dependencies": { "@netlify/functions": "^2.8.2", diff --git a/fixtures/webstudio-remix-vercel/.webstudio/data.json b/fixtures/webstudio-remix-vercel/.webstudio/data.json index 6a8f0c422e66..ee1980780f4e 100644 --- a/fixtures/webstudio-remix-vercel/.webstudio/data.json +++ b/fixtures/webstudio-remix-vercel/.webstudio/data.json @@ -5110,5 +5110,6 @@ "email": "hello@webstudio.is" }, "projectDomain": "webstudio-fixture-project-a-0su3o", - "projectTitle": "webstudio-fixture-project-a" + "projectTitle": "webstudio-fixture-project-a", + "origin": "https://main.development.webstudio.is" } diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.json index e7cf6dab6cca..4b0002b2b775 100644 --- a/fixtures/webstudio-remix-vercel/package.json +++ b/fixtures/webstudio-remix-vercel/package.json @@ -7,7 +7,7 @@ "cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio", "fixtures:link": "pnpm cli link --link https://p-cddc1d44-af37-4cb6-a430-d300cf6f932d-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'", "fixtures:sync": "pnpm cli sync --buildId 0ff71ecc-db91-41d0-ba52-26d2fc6c196d && pnpm prettier --write ./.webstudio/", - "fixtures:build": "pnpm cli build --template vercel --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" + "fixtures:build": "pnpm cli build --template vercel --template internal && pnpm prettier --write ./app/ ./package.json ./tsconfig.json" }, "private": true, "sideEffects": false, diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 3a1d0cdf01fa..943782090b9f 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -16,11 +16,6 @@ export const buildOptions = (yargs: CommonYargsArgv) => default: true, describe: "[Experimental] Download assets", }) - .option("preview", { - type: "boolean", - default: false, - describe: "[Experimental] Use preview version of the project", - }) .option("template", { type: "array", string: true, diff --git a/packages/cli/src/commands/sync.ts b/packages/cli/src/commands/sync.ts index 3e28da3aec86..15c3b0a946dd 100644 --- a/packages/cli/src/commands/sync.ts +++ b/packages/cli/src/commands/sync.ts @@ -55,6 +55,7 @@ export const sync = async ( seviceToken: options.authToken, origin: options.origin, }); + project.origin = options.origin; } else { const globalConfigText = await readFile(GLOBAL_CONFIG_FILE, "utf-8"); const globalConfig = jsonToGlobalConfig(JSON.parse(globalConfigText)); @@ -100,6 +101,7 @@ export const sync = async ( authToken: token, origin, }); + project.origin = origin; } catch (error) { // catch errors about unpublished project syncing.stop((error as Error).message, 2); diff --git a/packages/cli/src/prebuild.ts b/packages/cli/src/prebuild.ts index e4af2bfedcad..a85e44791e4a 100644 --- a/packages/cli/src/prebuild.ts +++ b/packages/cli/src/prebuild.ts @@ -211,10 +211,6 @@ const importFrom = (importee: string, importer: string) => { }; export const prebuild = async (options: { - /** - * Use preview (opensource) version of the project - **/ - preview: boolean; /** * Do we need download assets **/ @@ -434,19 +430,7 @@ export const prebuild = async (options: { const assetsToDownload: Promise[] = []; if (options.assets === true) { - const appDomain = options.preview ? "wstd.work" : "wstd.io"; - const domain = - siteData.build.deployment?.assetsDomain ?? - // fallback to project domain should not be used since 2025-01-01 (for now is used for backward compatibility) - (siteData.build.deployment?.destination !== "static" - ? siteData.build.deployment?.projectDomain - : undefined); - - if (domain === undefined) { - throw new Error(`Project domain is missing from the project data`); - } - - const assetOrigin = `https://${domain}.${appDomain}`; + const assetOrigin = siteData.origin; for (const asset of siteData.assets) { if (asset.type === "image") { diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts index 7c005bb965af..7e097cf124db 100644 --- a/packages/http-client/src/index.ts +++ b/packages/http-client/src/index.ts @@ -35,6 +35,7 @@ export type Data = { deployment?: Deployment | undefined; }; assets: Array; + origin?: string; }; // @todo: broken as expects non 200 code