webstudio 0.120.0 → 0.122.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.js CHANGED
@@ -45,6 +45,7 @@ var jsonToGlobalConfig = (json) => {
45
45
  return zGlobalConfig.parse(json);
46
46
  };
47
47
  var PROJECT_TEMPALTES = [
48
+ "vanilla",
48
49
  "vercel",
49
50
  "netlify-functions",
50
51
  "netlify-edge-functions"
@@ -244,7 +245,6 @@ import { createWriteStream } from "node:fs";
244
245
  import {
245
246
  rm,
246
247
  access as access2,
247
- mkdtemp,
248
248
  rename,
249
249
  cp,
250
250
  readFile as readFile4,
@@ -252,7 +252,6 @@ import {
252
252
  readdir
253
253
  } from "node:fs/promises";
254
254
  import { pipeline } from "node:stream/promises";
255
- import { tmpdir } from "node:os";
256
255
  import { cwd as cwd3 } from "node:process";
257
256
  import { fileURLToPath, pathToFileURL } from "node:url";
258
257
  import pLimit from "p-limit";
@@ -276,12 +275,13 @@ import * as baseComponentMetas from "@webstudio-is/sdk-components-react/metas";
276
275
  import * as remixComponentMetas from "@webstudio-is/sdk-components-react-remix/metas";
277
276
  import * as radixComponentMetas from "@webstudio-is/sdk-components-react-radix/metas";
278
277
  var limit = pLimit(10);
279
- var downloadAsset = async (url, name, assetBaseUrl, temporaryDir) => {
278
+ var downloadAsset = async (url, name, assetBaseUrl) => {
280
279
  const assetPath = join4("public", assetBaseUrl, name);
281
- const tempAssetPath = join4(temporaryDir, name);
280
+ const tempAssetPath = `${assetPath}.tmp`;
282
281
  try {
283
282
  await access2(assetPath);
284
283
  } catch {
284
+ await ensureFolderExists(dirname2(assetPath));
285
285
  try {
286
286
  const response = await fetch(url);
287
287
  if (!response.ok) {
@@ -292,7 +292,6 @@ var downloadAsset = async (url, name, assetBaseUrl, temporaryDir) => {
292
292
  response.body,
293
293
  writableStream
294
294
  );
295
- await ensureFolderExists(dirname2(assetPath));
296
295
  await rename(tempAssetPath, assetPath);
297
296
  } catch (error) {
298
297
  console.error(`Error in downloading file ${name}
@@ -347,7 +346,14 @@ var copyTemplates = async (template = "defaults") => {
347
346
  }
348
347
  };
349
348
  var prebuild = async (options) => {
350
- if (options.template !== void 0 && await isCliTemplate(options.template) === false && options.template.startsWith(".") === false) {
349
+ if (options.template === void 0) {
350
+ throw new Error(
351
+ `
352
+ Template is not provided
353
+ Please check webstudio --help for more details`
354
+ );
355
+ }
356
+ if (options.template !== "vanilla" && await isCliTemplate(options.template) === false && options.template.startsWith(".") === false) {
351
357
  throw Error(
352
358
  `
353
359
  Template ${options.template} is not available
@@ -363,7 +369,7 @@ var prebuild = async (options) => {
363
369
  const routesDir = join4(appRoot, "routes");
364
370
  await rm(routesDir, { recursive: true, force: true });
365
371
  await copyTemplates();
366
- if (options.template !== void 0) {
372
+ if (options.template !== "vanilla") {
367
373
  await copyTemplates(options.template);
368
374
  }
369
375
  const constants2 = await import(pathToFileURL(join4(cwd3(), "app/constants.mjs")).href);
@@ -469,7 +475,6 @@ var prebuild = async (options) => {
469
475
  }
470
476
  const appDomain = options.preview ? "wstd.work" : "wstd.io";
471
477
  const assetBuildUrl = `https://${domain}.${appDomain}/cgi/asset/`;
472
- const temporaryDir = await mkdtemp(join4(tmpdir(), "webstudio-"));
473
478
  const imageLoader = createImageLoader({
474
479
  imageBaseUrl: assetBuildUrl
475
480
  });
@@ -481,9 +486,7 @@ var prebuild = async (options) => {
481
486
  format: "raw"
482
487
  });
483
488
  assetsToDownload.push(
484
- limit(
485
- () => downloadAsset(imageSrc, asset.name, assetBaseUrl, temporaryDir)
486
- )
489
+ limit(() => downloadAsset(imageSrc, asset.name, assetBaseUrl))
487
490
  );
488
491
  }
489
492
  if (asset.type === "font") {
@@ -492,8 +495,7 @@ var prebuild = async (options) => {
492
495
  () => downloadAsset(
493
496
  `${assetBuildUrl}${asset.name}`,
494
497
  asset.name,
495
- assetBaseUrl,
496
- temporaryDir
498
+ assetBaseUrl
497
499
  )
498
500
  )
499
501
  );
@@ -658,8 +660,9 @@ var buildOptions = (yargs) => yargs.option("assets", {
658
660
  describe: "[Experimental] Use preview version of the project"
659
661
  }).option("template", {
660
662
  type: "string",
661
- default: "vercel",
662
- describe: `[Experimental] Template to use for the build [choices: ${PROJECT_TEMPALTES.toString()}]`
663
+ describe: `Template to use for the build [choices: ${PROJECT_TEMPALTES.join(
664
+ ", "
665
+ )}]`
663
666
  });
664
667
  var build = async (options) => {
665
668
  try {
@@ -734,26 +737,18 @@ var initFlow = async (options) => {
734
737
  throw new Error(`Project Link is required`);
735
738
  }
736
739
  await link({ link: projectLink });
737
- const { shouldSetupDeployTarget } = await prompt({
738
- type: "confirm",
739
- name: "shouldSetupDeployTarget",
740
- message: "Would you like to setup a deploy target?",
741
- initial: false
740
+ const { deployTarget } = await prompt({
741
+ type: "select",
742
+ name: "deployTarget",
743
+ message: "Where would you like to deploy your project?",
744
+ choices: PROJECT_TEMPALTES.map((template) => {
745
+ return {
746
+ title: titleCase(template),
747
+ value: template
748
+ };
749
+ })
742
750
  });
743
- if (shouldSetupDeployTarget === true) {
744
- const { deployTarget } = await prompt({
745
- type: "select",
746
- name: "deployTarget",
747
- message: "Where would you like to deploy your project?",
748
- choices: PROJECT_TEMPALTES.map((template) => {
749
- return {
750
- title: titleCase(template),
751
- value: template
752
- };
753
- })
754
- });
755
- projectTemplate = deployTarget;
756
- }
751
+ projectTemplate = deployTarget;
757
752
  const { installDeps } = await prompt({
758
753
  type: "confirm",
759
754
  name: "installDeps",
@@ -763,6 +758,20 @@ var initFlow = async (options) => {
763
758
  shouldInstallDeps = installDeps;
764
759
  }
765
760
  await sync({ buildId: void 0, origin: void 0, authToken: void 0 });
761
+ if (projectTemplate === void 0) {
762
+ const { deployTarget } = await prompt({
763
+ type: "select",
764
+ name: "deployTarget",
765
+ message: "Where would you like to deploy your project?",
766
+ choices: PROJECT_TEMPALTES.map((template) => {
767
+ return {
768
+ title: titleCase(template),
769
+ value: template
770
+ };
771
+ })
772
+ });
773
+ projectTemplate = deployTarget;
774
+ }
766
775
  await build({
767
776
  ...options,
768
777
  ...projectTemplate && { template: projectTemplate }
@@ -806,7 +815,7 @@ import makeCLI from "yargs";
806
815
  // package.json
807
816
  var package_default = {
808
817
  name: "webstudio",
809
- version: "0.120.0",
818
+ version: "0.122.0",
810
819
  description: "Webstudio CLI",
811
820
  author: "Webstudio <github@webstudio.is>",
812
821
  homepage: "https://webstudio.is",
@@ -881,7 +890,17 @@ var main = async () => {
881
890
  `Webstudio CLI (${package_default.version}) allows you to setup, sync, build and preview your project.`
882
891
  );
883
892
  cmd.version(package_default.version).alias("v", "version");
884
- cmd.command(["build"], "Build the project", buildOptions, build);
893
+ cmd.command(
894
+ ["build"],
895
+ "Build the project",
896
+ (yargs) => {
897
+ return buildOptions(yargs).demandOption(
898
+ "template",
899
+ "Please specify a template to use for the build"
900
+ );
901
+ },
902
+ build
903
+ );
885
904
  cmd.command(["link"], "Link the project with the cloud", linkOptions, link);
886
905
  cmd.command(["sync"], "Sync your project", syncOptions, sync);
887
906
  cmd.command(["$0", "init"], "Setup the project", buildOptions, initFlow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webstudio",
3
- "version": "0.120.0",
3
+ "version": "0.122.0",
4
4
  "description": "Webstudio CLI",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -28,21 +28,21 @@
28
28
  "title-case": "^4.1.0",
29
29
  "yargs": "^17.7.2",
30
30
  "zod": "^3.21.4",
31
- "@webstudio-is/image": "0.120.0",
32
- "@webstudio-is/react-sdk": "0.120.0",
33
- "@webstudio-is/sdk": "0.120.0",
34
- "@webstudio-is/sdk-components-react": "0.120.0",
35
- "@webstudio-is/http-client": "0.120.0",
36
- "@webstudio-is/sdk-components-react-remix": "0.120.0",
37
- "@webstudio-is/sdk-components-react-radix": "0.120.0"
31
+ "@webstudio-is/image": "0.122.0",
32
+ "@webstudio-is/http-client": "0.122.0",
33
+ "@webstudio-is/react-sdk": "0.122.0",
34
+ "@webstudio-is/sdk": "0.122.0",
35
+ "@webstudio-is/sdk-components-react": "0.122.0",
36
+ "@webstudio-is/sdk-components-react-radix": "0.122.0",
37
+ "@webstudio-is/sdk-components-react-remix": "0.122.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^18.17.1",
41
41
  "@types/prompts": "^2.4.5",
42
42
  "tsx": "^3.12.8",
43
43
  "typescript": "5.2.2",
44
- "@webstudio-is/tsconfig": "1.0.7",
45
- "@webstudio-is/form-handlers": "0.120.0"
44
+ "@webstudio-is/form-handlers": "0.122.0",
45
+ "@webstudio-is/tsconfig": "1.0.7"
46
46
  },
47
47
  "scripts": {
48
48
  "typecheck": "tsc",
@@ -10,13 +10,13 @@
10
10
  "@remix-run/react": "^1.19.2",
11
11
  "@remix-run/server-runtime": "^1.19.2",
12
12
  "@remix-run/node": "^1.19.2",
13
- "@webstudio-is/react-sdk": "0.120.0",
14
- "@webstudio-is/sdk-components-react-radix": "0.120.0",
15
- "@webstudio-is/sdk-components-react-remix": "0.120.0",
16
- "@webstudio-is/sdk-components-react": "0.120.0",
17
- "@webstudio-is/form-handlers": "0.120.0",
18
- "@webstudio-is/image": "0.120.0",
19
- "@webstudio-is/sdk": "0.120.0",
13
+ "@webstudio-is/react-sdk": "0.122.0",
14
+ "@webstudio-is/sdk-components-react-radix": "0.122.0",
15
+ "@webstudio-is/sdk-components-react-remix": "0.122.0",
16
+ "@webstudio-is/sdk-components-react": "0.122.0",
17
+ "@webstudio-is/form-handlers": "0.122.0",
18
+ "@webstudio-is/image": "0.122.0",
19
+ "@webstudio-is/sdk": "0.122.0",
20
20
  "isbot": "^3.6.8",
21
21
  "react": "^18.2.0",
22
22
  "react-dom": "^18.2.0"
@@ -0,0 +1,29 @@
1
+ /**
2
+ * We use mjs extension as constants in this file is shared with the build script
3
+ * and we use `node --eval` to extract the constants.
4
+ */
5
+ export const assetBaseUrl = "/assets/";
6
+ export const imageBaseUrl = "/assets/";
7
+
8
+ /**
9
+ * @type {import("@webstudio-is/image").ImageLoader}
10
+ */
11
+ export const imageLoader = (props) => {
12
+ if (process.env.NODE_ENV !== "production") {
13
+ return imageBaseUrl + props.src;
14
+ }
15
+
16
+ if (props.format === "raw") {
17
+ return imageBaseUrl + props.src;
18
+ }
19
+
20
+ // https://docs.netlify.com/image-cdn/overview/
21
+ return (
22
+ "/.netlify/images?url=" +
23
+ encodeURIComponent(imageBaseUrl + props.src) +
24
+ "&w=" +
25
+ props.width +
26
+ "&q=" +
27
+ props.quality
28
+ );
29
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * We use mjs extension as constants in this file is shared with the build script
3
+ * and we use `node --eval` to extract the constants.
4
+ */
5
+ export const assetBaseUrl = "/assets/";
6
+ export const imageBaseUrl = "/assets/";
7
+
8
+ /**
9
+ * @type {import("@webstudio-is/image").ImageLoader}
10
+ */
11
+ export const imageLoader = (props) => {
12
+ if (process.env.NODE_ENV !== "production") {
13
+ return imageBaseUrl + props.src;
14
+ }
15
+
16
+ if (props.format === "raw") {
17
+ return imageBaseUrl + props.src;
18
+ }
19
+
20
+ // https://docs.netlify.com/image-cdn/overview/
21
+ return (
22
+ "/.netlify/images?url=" +
23
+ encodeURIComponent(imageBaseUrl + props.src) +
24
+ "&w=" +
25
+ props.width +
26
+ "&q=" +
27
+ props.quality
28
+ );
29
+ };