Skip to content

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.

Add typecript typechecking for the cli (#2227)

Jaya Krishna Namburufb60ff5d0499
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 14e16a0a5b..a03d5fcaca 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -9,6 +9,8 @@
"webstudio": "./bin.js"
},
"scripts": {
+ "typecheck": "tsc",
+ "checks": "pnpm typecheck",
"build:templates": "tsx ./templates/build.ts",
"build": "build-package"
},
@@ -31,6 +33,7 @@
"@types/node": "^18.13.0",
"@webstudio-is/scripts": "workspace:^",
"@webstudio-is/tsconfig": "workspace:^",
- "tsx": "^3.12.6"
+ "tsx": "^3.12.6",
+ "typescript": "5.1.6"
}
}
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index c6c3277fef..6b63279138 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -7,9 +7,8 @@ export const build: Command = async () => {
try {
await access(LOCAL_DATA_FILE);
await prebuild();
- } catch (error) {
- console.log(error);
- if (error.code === "ENOENT") {
+ } catch (error: unknown) {
+ if (error instanceof Error && "code" in error && error.code === "ENONET") {
throw new Error(
`You need to link a webstudio project before building it. Run \`webstudio link\` to link a project.`
);
diff --git a/packages/cli/src/commands/link.ts b/packages/cli/src/commands/link.ts
index ffde2a0acb..9de5be2dff 100644
--- a/packages/cli/src/commands/link.ts
+++ b/packages/cli/src/commands/link.ts
@@ -44,8 +44,8 @@ export const link: Command = async () => {
join(cwd(), LOCAL_CONFIG_FILE),
JSON.stringify({ projectId }, null, 2)
);
- } catch (error) {
- if (error.code === "ENONET") {
+ } catch (error: unknown) {
+ if (error instanceof Error && "code" in error && error.code === "ENONET") {
throw new Error(`Global config file is not found`);
}
diff --git a/packages/cli/templates/build.ts b/packages/cli/templates/build.ts
index c902fb56b2..0231be8886 100644
--- a/packages/cli/templates/build.ts
+++ b/packages/cli/templates/build.ts
@@ -20,7 +20,7 @@ const DEFUALT_ASSETS_PATH = new URL(
).pathname;
console.info("Building Templates...");
-await rm(new URL("../src/__generated__", import.meta.url).pathname, {
+await rm(new URL("../src/__generated__", import.meta.url), {
recursive: true,
force: true,
});
@@ -101,7 +101,7 @@ writeFileSync(TEMPLATES_JSON_PATH, content, "utf-8");
Building route template
*/
const routeTemplateFile = readFileSync(
- new URL("./route-template.ts", import.meta.url).pathname,
+ new URL("./route-template.tsx", import.meta.url),
"utf-8"
);
const routeTemplateContent = `/*
diff --git a/packages/cli/templates/route-template.ts b/packages/cli/templates/route-template.tsx
similarity index 100%
rename from packages/cli/templates/route-template.ts
rename to packages/cli/templates/route-template.tsx
diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json
index 2f3fdb5b2f..13237ee04f 100644
--- a/packages/cli/tsconfig.json
+++ b/packages/cli/tsconfig.json
@@ -1,5 +1,6 @@
{
"extends": "@webstudio-is/tsconfig/base.json",
+ "exclude": ["./templates/*"],
"compilerOptions": {
"module": "esnext"
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 87b60fad92..815ea4ea04 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -490,6 +490,9 @@ importers:
tsx:
specifier: ^3.12.6
version: 3.12.6
+ typescript:
+ specifier: 5.1.6
+ version: 5.1.6
packages/css-data:
dependencies: