Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[workers] Start migrating workers to the monorepo

Manav Rathicfd298a05252
diff --git a/infra/workers/.gitignore b/infra/workers/.gitignore
new file mode 100644
index 0000000000..7f811e1280
--- /dev/null
+++ b/infra/workers/.gitignore
@@ -0,0 +1,10 @@
+node_modules/
+.DS_Store
+.wrangler/
+
+# Workers mostly have dev dependencies, and usually only wrangler, so exact
+# version details and the resulting `yarn.lock` is unnecessary noise.
+#
+# If we need to pin some runtime dependency, we can pin it to an exact version
+# in the package.json itself.
+yarn.lock
diff --git a/infra/workers/.prettierrc.json b/infra/workers/.prettierrc.json
new file mode 100644
index 0000000000..0a02bcefda
--- /dev/null
+++ b/infra/workers/.prettierrc.json
@@ -0,0 +1,3 @@
+{
+ "tabWidth": 4
+}
diff --git a/infra/workers/README.md b/infra/workers/README.md
new file mode 100644
index 0000000000..887dd4357a
--- /dev/null
+++ b/infra/workers/README.md
@@ -0,0 +1,32 @@
+# Cloudflare Workers
+
+Source code for our [Cloudflare
+Workers](https://developers.cloudflare.com/workers/).
+
+Each worker is a self contained directory with its each `package.json`.
+
+## Deploying
+
+* Switch to a worker directory, e.g. `cd health-check`.
+
+* Install dependencies (if needed) with `yarn`
+
+* Login into wrangler (if needed) using `yarn wrangler login`
+
+* Deploy! `yarn wrangler publish`
+
+Wrangler is the CLI provided by Cloudflare to manage workers. Apart from
+deploying, it also allows us to stream logs from running workers by using `yarn
+wrangler tail`.
+
+## Creating a new worker
+
+Copy paste an existing one. Unironically this is a good option because the
+Cloudflare template has a lot of unnecessary noise, but if really do want to
+create one from scratch, use `npm create cloudflare@latest`.
+
+To import an existing worker from the Cloudflare dashboard, use
+
+```sh
+npm create cloudflare@2 existing-worker-name -- --type pre-existing --existing-script existing-worker-name
+```
diff --git a/infra/workers/tsconfig.base.json b/infra/workers/tsconfig.base.json
new file mode 100644
index 0000000000..f330c4ca50
--- /dev/null
+++ b/infra/workers/tsconfig.base.json
@@ -0,0 +1,38 @@
+{
+ /* A shared TSConfig for use by TypeScript Cloudflare Workers */
+ /* TSConfig docs: https://aka.ms/tsconfig.json */
+ "compilerOptions": {
+ /* tsc is used for by us for type checking, not compilation (the
+ Cloudflare workers runtime natively supports TypeScript) */
+ "noEmit": true,
+
+ /* The Workers runtime supports the latest and greatest */
+ /* https://developers.cloudflare.com/workers/reference/languages/#javascript--typescript */
+ "lib": ["esnext"],
+ "target": "esnext",
+ "module": "esnext",
+
+ /* Types that are implicitly available */
+ /* https://www.npmjs.com/package/@cloudflare/workers-types */
+ "types": ["@cloudflare/workers-types"],
+
+ /* Tell TypeScript how to lookup the file for a given import */
+ "moduleResolution": "node",
+
+ /* Speed things up by not type checking `node_modules` */
+ "skipLibCheck": true,
+ /* Require the `type` modifier when importing types */
+ "verbatimModuleSyntax": true,
+ /* Enable importing .json files */
+ "resolveJsonModule": true,
+
+ /* strict and then some */
+ "strict": true,
+ "noImplicitReturns": true,
+ "noUnusedParameters": true,
+ "noUnusedLocals": true,
+ "noFallthroughCasesInSwitch": true,
+ "noUncheckedIndexedAccess": true,
+ "exactOptionalPropertyTypes": true
+ }
+}