@storm-software/cloudflare-tools 0.58.2 → 0.59.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/dist/{chunk-QPABB45G.mjs → chunk-5TUHGXSI.mjs} +1 -1
  4. package/dist/{chunk-NJBI4AIW.js → chunk-7JMGYMUN.js} +2 -2
  5. package/dist/{chunk-QQ22YQSB.mjs → chunk-E4FJOPZF.mjs} +1 -1
  6. package/dist/{chunk-K2RS4LHV.mjs → chunk-GNQ5XIH7.mjs} +13 -16
  7. package/dist/{chunk-YVLYQXOO.mjs → chunk-GOVRQQWT.mjs} +3 -3
  8. package/dist/{chunk-UMK4B3XF.js → chunk-PSYJWYNN.js} +2 -2
  9. package/dist/{chunk-6GOJPDPL.js → chunk-WMNGJUHG.js} +1 -4
  10. package/dist/{chunk-3MZCAC7V.mjs → chunk-XWRKT3DB.mjs} +2 -2
  11. package/dist/executors.js +1 -1
  12. package/dist/executors.mjs +3 -3
  13. package/dist/generators.js +3 -3
  14. package/dist/generators.mjs +3 -3
  15. package/dist/index.js +4 -4
  16. package/dist/index.mjs +5 -5
  17. package/dist/src/executors/cloudflare-publish/executor.js +1 -1
  18. package/dist/src/executors/cloudflare-publish/executor.mjs +3 -3
  19. package/dist/src/executors/r2-upload-publish/executor.mjs +1 -1
  20. package/dist/src/executors/serve/executor.js +2 -2
  21. package/dist/src/executors/serve/executor.mjs +2 -2
  22. package/dist/src/generators/init/generator.js +2 -2
  23. package/dist/src/generators/init/generator.mjs +2 -2
  24. package/dist/src/generators/worker/generator.js +3 -3
  25. package/dist/src/generators/worker/generator.mjs +3 -3
  26. package/dist/src/utils/index.mjs +1 -1
  27. package/dist/src/utils/r2-bucket-helpers.mjs +1 -1
  28. package/dist/tsup.config.mjs +1 -1
  29. package/package.json +15 -44
  30. package/.eslintrc.json +0 -35
  31. package/executors.ts +0 -4
  32. package/generators.ts +0 -4
  33. package/index.ts +0 -4
  34. package/project.json +0 -56
  35. package/src/executors/cloudflare-publish/executor.ts +0 -100
  36. package/src/executors/r2-upload-publish/executor.ts +0 -264
  37. package/src/executors/serve/executor.ts +0 -84
  38. package/src/generators/init/generator.spec.ts +0 -20
  39. package/src/generators/init/generator.ts +0 -60
  40. package/src/generators/init/libs/versions.ts +0 -7
  41. package/src/generators/worker/generator.spec.ts +0 -20
  42. package/src/generators/worker/generator.ts +0 -289
  43. package/src/generators/worker/libs/get-account-id.ts +0 -3
  44. package/src/generators/worker/libs/vitest-imports.ts +0 -1
  45. package/src/generators/worker/libs/vitest-script.ts +0 -1
  46. package/src/plugins/index.ts +0 -137
  47. package/src/utils/index.ts +0 -1
  48. package/src/utils/r2-bucket-helpers.ts +0 -56
  49. package/tsconfig.json +0 -31
  50. package/tsup.config.ts +0 -27
  51. /package/{src → dist/src}/executors/cloudflare-publish/schema.d.ts +0 -0
  52. /package/{src → dist/src}/executors/cloudflare-publish/schema.json +0 -0
  53. /package/{src → dist/src}/executors/r2-upload-publish/schema.d.ts +0 -0
  54. /package/{src → dist/src}/executors/r2-upload-publish/schema.json +0 -0
  55. /package/{src → dist/src}/executors/serve/schema.d.ts +0 -0
  56. /package/{src → dist/src}/executors/serve/schema.json +0 -0
  57. /package/{src → dist/src}/generators/init/schema.d.ts +0 -0
  58. /package/{src → dist/src}/generators/init/schema.json +0 -0
  59. /package/{src → dist/src}/generators/worker/files/common/package.json__tmpl__ +0 -0
  60. /package/{src → dist/src}/generators/worker/files/common/wrangler.toml__tmpl__ +0 -0
  61. /package/{src → dist/src}/generators/worker/files/fetch-handler/index.test.ts__tmpl__ +0 -0
  62. /package/{src → dist/src}/generators/worker/files/fetch-handler/index.ts__tmpl__ +0 -0
  63. /package/{src → dist/src}/generators/worker/files/hono/index.test.ts__tmpl__ +0 -0
  64. /package/{src → dist/src}/generators/worker/files/hono/index.ts__tmpl__ +0 -0
  65. /package/{src → dist/src}/generators/worker/files/scheduled-handler/index.test.ts__tmpl__ +0 -0
  66. /package/{src → dist/src}/generators/worker/files/scheduled-handler/index.ts__tmpl__ +0 -0
  67. /package/{src → dist/src}/generators/worker/schema.d.ts +0 -0
  68. /package/{src → dist/src}/generators/worker/schema.json +0 -0
package/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./executors";
2
- export * from "./generators";
3
- export * from "./src/plugins";
4
- export * from "./src/utils";
package/project.json DELETED
@@ -1,56 +0,0 @@
1
- {
2
- "name": "cloudflare-tools",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/cloudflare-tools/src",
5
- "projectType": "library",
6
- "targets": {
7
- "build-untyped": {
8
- "executor": "nx:run-commands",
9
- "dependsOn": ["clean", "^build"],
10
- "inputs": [
11
- "{projectRoot}/src/**/untyped.ts",
12
- "{projectRoot}/src/**/*.untyped.ts"
13
- ],
14
- "outputs": [
15
- "{projectRoot}/src/**/schema.d.ts",
16
- "{projectRoot}/src/**/*.schema.d.ts",
17
- "{projectRoot}/src/**/schema.md",
18
- "{projectRoot}/src/**/*.schema.md",
19
- "{projectRoot}/src/**/schema.json",
20
- "{projectRoot}/src/**/*.schema.json"
21
- ],
22
- "options": {
23
- "commands": [
24
- "node dist/packages/untyped/bin/untyped.cjs generate --entry=\"packages/cloudflare-tools/**/{untyped.ts,*.untyped.ts}\" "
25
- ]
26
- }
27
- },
28
- "build-base": {
29
- "executor": "nx:run-commands",
30
- "dependsOn": ["build-untyped", "clean", "^build"],
31
- "options": {
32
- "command": "tsup-node --config=tsup.config.ts",
33
- "cwd": "{projectRoot}"
34
- }
35
- },
36
- "build": {
37
- "executor": "nx:run-commands",
38
- "dependsOn": ["build-base", "build-untyped"],
39
- "options": {
40
- "commands": [
41
- "pnpm copyfiles LICENSE dist/packages/cloudflare-tools",
42
- "pnpm copyfiles --up=2 ./packages/cloudflare-tools/*.md ./packages/cloudflare-tools/executors.json ./packages/cloudflare-tools/generators.json ./packages/cloudflare-tools/package.json dist/packages/cloudflare-tools",
43
- "pnpm copyfiles --up=3 \"./packages/cloudflare-tools/dist/**/*\" dist/packages/cloudflare-tools/dist",
44
- "pnpm copyfiles --up=3 \"./packages/cloudflare-tools/src/**/*schema.d.ts\" dist/packages/cloudflare-tools/dist/src",
45
- "pnpm copyfiles --up=3 \"./packages/cloudflare-tools/src/**/*schema.json\" dist/packages/cloudflare-tools/dist/src",
46
- "pnpm copyfiles --up=3 \"./packages/cloudflare-tools/src/**/*.md\" dist/packages/cloudflare-tools/docs/api",
47
- "pnpm copyfiles --up=4 \"./packages/cloudflare-tools/src/generators/*/files/**/*\" dist/packages/cloudflare-tools/dist/src/generators"
48
- ]
49
- }
50
- },
51
- "nx-release-publish": {
52
- "executor": "@storm-software/workspace-tools:npm-publish"
53
- }
54
- },
55
- "implicitDependencies": ["workspace-tools", "config-tools", "config"]
56
- }
@@ -1,100 +0,0 @@
1
- import { joinPathFragments, type ExecutorContext } from "@nx/devkit";
2
- import { createCliOptions } from "@storm-software/workspace-tools";
3
- import { fork } from "node:child_process";
4
- import type { CloudflarePublishExecutorSchema } from "./schema";
5
-
6
- export default async function runExecutor(
7
- options: CloudflarePublishExecutorSchema,
8
- context: ExecutorContext,
9
- ) {
10
- /**
11
- * We need to check both the env var and the option because the executor may have been triggered
12
- * indirectly via dependsOn, in which case the env var will be set, but the option will not.
13
- */
14
- const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
15
-
16
- if (!context.projectName) {
17
- throw new Error("The executor requires a projectName.");
18
- }
19
-
20
- console.info(
21
- `🚀 Running Storm Cloudflare Publish executor on the ${context.projectName} worker`,
22
- );
23
-
24
- if (
25
- !context.projectName ||
26
- !context.projectsConfigurations?.projects ||
27
- !context.projectsConfigurations.projects[context.projectName] ||
28
- !context.projectsConfigurations.projects[context.projectName]?.root
29
- ) {
30
- throw new Error("The executor requires projectsConfigurations.");
31
- }
32
-
33
- const packageRoot = joinPathFragments(
34
- context.root,
35
- context.projectsConfigurations.projects[context.projectName]
36
- ?.root as string,
37
- );
38
-
39
- try {
40
- const args = createCliOptions({ ...options });
41
- if (isDryRun) {
42
- args.push("--dry-run");
43
- }
44
-
45
- console.log("");
46
- console.log(`Running "wrangler deploy ${args.join(" ")}"...`);
47
- console.log("");
48
-
49
- let proc;
50
- try {
51
- fork(require.resolve("wrangler/bin/wrangler"), ["deploy", ...args], {
52
- env: {
53
- CLOUDFLARE_ACCOUNT_ID: process.env.STORM_BOT_CLOUDFLARE_ACCOUNT,
54
- CLOUDFLARE_API_TOKEN: process.env.STORM_BOT_CLOUDFLARE_TOKEN,
55
- WRANGLER_LOG: "debug",
56
- ...process.env,
57
- FORCE_COLOR: "true",
58
- },
59
- cwd: packageRoot,
60
- stdio: ["pipe", "pipe", "pipe", "ipc"],
61
- });
62
- } catch (e) {
63
- console.error(e);
64
- throw new Error(
65
- "Unable to run Wrangler. Please ensure Wrangler is installed.",
66
- );
67
- }
68
-
69
- proc?.stdout?.on("data", (message) => {
70
- process.stdout.write(message);
71
- });
72
- proc?.stderr?.on("data", (message) => {
73
- process.stderr.write(message);
74
- });
75
-
76
- return new Promise<{ success: boolean }>((resolve) => {
77
- proc?.on("close", (code) => {
78
- console.log("");
79
-
80
- if (isDryRun) {
81
- console.log(
82
- "Would publish to Cloudflare Workers Registry, but [dry-run] was set",
83
- );
84
- } else {
85
- console.log("Published to Cloudflare Workers Registry");
86
- }
87
-
88
- return resolve({ success: code === 0 });
89
- });
90
- });
91
- } catch (error: any) {
92
- console.error("Failed to publish to Cloudflare Workers Registry");
93
- console.error(error);
94
- console.log("");
95
-
96
- return {
97
- success: false,
98
- };
99
- }
100
- }
@@ -1,264 +0,0 @@
1
- import { S3 } from "@aws-sdk/client-s3";
2
- import {
3
- createProjectGraphAsync,
4
- joinPathFragments,
5
- ProjectGraph,
6
- readCachedProjectGraph,
7
- type ExecutorContext
8
- } from "@nx/devkit";
9
- import {
10
- getConfig,
11
- writeDebug,
12
- writeInfo,
13
- writeSuccess,
14
- writeWarning
15
- } from "@storm-software/config-tools";
16
- import { findWorkspaceRoot } from "@storm-software/config-tools/utilities/find-workspace-root";
17
- import { createCliOptions } from "@storm-software/workspace-tools/utils/create-cli-options";
18
- import { getPackageInfo } from "@storm-software/workspace-tools/utils/package-helpers";
19
- import { glob } from "glob";
20
- import { execSync } from "node:child_process";
21
- import { readFile } from "node:fs/promises";
22
- import {
23
- getInternalDependencies,
24
- r2UploadFile
25
- } from "../../utils/r2-bucket-helpers";
26
- import type { R2UploadPublishExecutorSchema } from "./schema";
27
-
28
- export default async function runExecutor(
29
- options: R2UploadPublishExecutorSchema,
30
- context: ExecutorContext
31
- ) {
32
- /**
33
- * We need to check both the env var and the option because the executor may have been triggered
34
- * indirectly via dependsOn, in which case the env var will be set, but the option will not.
35
- */
36
- const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
37
-
38
- if (!context.projectName) {
39
- throw new Error("The executor requires a projectName.");
40
- }
41
-
42
- console.info(
43
- `🚀 Running Storm Cloudflare Publish executor on the ${context.projectName} worker`
44
- );
45
-
46
- if (
47
- !context.projectName ||
48
- !context.projectsConfigurations?.projects ||
49
- !context.projectsConfigurations.projects[context.projectName] ||
50
- !context.projectsConfigurations.projects[context.projectName]?.root
51
- ) {
52
- throw new Error("The executor requires projectsConfigurations.");
53
- }
54
-
55
- try {
56
- const workspaceRoot = findWorkspaceRoot();
57
- const config = await getConfig(workspaceRoot);
58
-
59
- const sourceRoot =
60
- context.projectsConfigurations.projects[context.projectName]
61
- ?.sourceRoot ?? workspaceRoot;
62
- const projectName =
63
- context.projectsConfigurations.projects[context.projectName]?.name ??
64
- context.projectName;
65
-
66
- const projectDetails = getPackageInfo(
67
- context.projectsConfigurations.projects[context.projectName]!
68
- );
69
- if (!projectDetails?.content) {
70
- throw new Error(
71
- `Could not find the project details for ${context.projectName}`
72
- );
73
- }
74
-
75
- const args = createCliOptions({ ...options });
76
- if (isDryRun) {
77
- args.push("--dry-run");
78
- }
79
-
80
- const cloudflareAccountId = process.env.STORM_BOT_CLOUDFLARE_ACCOUNT;
81
- if (!options?.registry && !cloudflareAccountId) {
82
- throw new Error(
83
- "The Storm Registry URL is not set in the Storm config. Please set either the `extensions.cyclone.registry` or `config.extensions.cyclone.accountId` property in the Storm config."
84
- );
85
- }
86
-
87
- if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
88
- throw new Error(
89
- "The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are not set. Please set these environment variables to upload to the Cyclone Registry."
90
- );
91
- }
92
-
93
- const endpoint = options?.registry
94
- ? options.registry
95
- : `https://${cloudflareAccountId}.r2.cloudflarestorage.com`;
96
-
97
- let projectGraph!: ProjectGraph;
98
- try {
99
- projectGraph = readCachedProjectGraph();
100
- } catch {
101
- await createProjectGraphAsync();
102
- projectGraph = readCachedProjectGraph();
103
- }
104
-
105
- if (!projectGraph) {
106
- throw new Error(
107
- "The executor failed because the project graph is not available. Please run the build command again."
108
- );
109
- }
110
-
111
- writeInfo(
112
- `Publishing ${context.projectName} to the Storm Registry at ${endpoint}`
113
- );
114
-
115
- const s3Client = new S3({
116
- region: "auto",
117
- endpoint,
118
- credentials: {
119
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
120
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
121
- }
122
- });
123
-
124
- const version = projectDetails.content?.version;
125
- writeInfo(`Generated component version: ${version}`);
126
-
127
- const files = await glob(joinPathFragments(sourceRoot, "**/*"), {
128
- ignore: "**/{*.stories.tsx,*.stories.ts,*.spec.tsx,*.spec.ts}"
129
- });
130
- const projectPath = `registry/${context.projectName}`;
131
-
132
- const internalDependencies = await getInternalDependencies(
133
- context.projectName,
134
- projectGraph as ProjectGraph
135
- );
136
-
137
- const dependencies = internalDependencies
138
- .filter(
139
- projectNode =>
140
- !projectNode.data.tags ||
141
- projectNode.data.tags.every(tag => tag.toLowerCase() !== "component")
142
- )
143
- .reduce((ret, dep) => {
144
- if (!ret[dep.name]) {
145
- ret[dep.name] = "latest";
146
- }
147
-
148
- return ret;
149
- }, projectDetails.content.dependencies ?? {});
150
-
151
- const release =
152
- options.tag ?? execSync("npm config get tag").toString().trim();
153
-
154
- writeInfo(`Clearing out existing items in ${projectPath}`);
155
-
156
- if (!isDryRun) {
157
- const response = await s3Client.listObjects({
158
- Bucket: options.bucketId,
159
- Prefix: projectPath
160
- });
161
-
162
- if (response?.Contents && response.Contents.length > 0) {
163
- writeDebug(
164
- `Deleting the following existing items from the component registry: ${response.Contents.map(item => item.Key).join(", ")}`
165
- );
166
-
167
- await Promise.all(
168
- response.Contents.map(item =>
169
- s3Client.deleteObjects({
170
- Bucket: options.bucketId,
171
- Delete: {
172
- Objects: [
173
- {
174
- Key: item.Key
175
- }
176
- ],
177
- Quiet: false
178
- }
179
- })
180
- )
181
- );
182
- } else {
183
- writeDebug(
184
- `No existing items to delete in the component registry path ${projectPath}`
185
- );
186
- }
187
- } else {
188
- writeWarning("[Dry run]: skipping upload to the Cyclone Registry.");
189
- }
190
-
191
- const meta = {
192
- name: context.projectName,
193
- version,
194
- release,
195
- description: projectDetails.content.description,
196
- tags: projectDetails.content.keywords,
197
- dependencies,
198
- devDependencies: null,
199
- internalDependencies: internalDependencies
200
- .filter(
201
- projectNode =>
202
- projectNode.data.tags &&
203
- projectNode.data.tags.some(tag => tag.toLowerCase() === "component")
204
- )
205
- .map(dep => dep.name)
206
- };
207
- if (projectDetails.type === "package.json") {
208
- meta.devDependencies = projectDetails.content.devDependencies;
209
- }
210
-
211
- const metaJson = JSON.stringify(meta);
212
-
213
- writeInfo(`Generating meta.json file: \n${metaJson}`);
214
-
215
- await r2UploadFile(
216
- s3Client,
217
- options.bucketId,
218
- projectPath,
219
- "meta.json",
220
- version,
221
- metaJson,
222
- "application/json",
223
- isDryRun
224
- );
225
-
226
- await Promise.all(
227
- files.map(file => {
228
- const fileName = file
229
- .replaceAll("\\", "/")
230
- .replace(sourceRoot.replaceAll("\\", "/"), "");
231
-
232
- return readFile(file, { encoding: "utf8" }).then(fileContent =>
233
- r2UploadFile(
234
- s3Client,
235
- options.bucketId,
236
- projectPath,
237
- fileName,
238
- version,
239
- fileContent,
240
- "text/plain",
241
- isDryRun
242
- )
243
- );
244
- })
245
- );
246
-
247
- writeSuccess(
248
- `Successfully uploaded the ${projectName} component to the Cyclone Registry`,
249
- config
250
- );
251
-
252
- return {
253
- success: true
254
- };
255
- } catch (error: any) {
256
- console.error("Failed to publish to Cloudflare Workers Registry");
257
- console.error(error);
258
- console.log("");
259
-
260
- return {
261
- success: false
262
- };
263
- }
264
- }
@@ -1,84 +0,0 @@
1
- import type { ExecutorContext, PromiseExecutor } from "@nx/devkit";
2
- import { createAsyncIterable } from "@nx/devkit/src/utils/async-iterable";
3
- import { waitForPortOpen } from "@nx/web/src/utils/wait-for-port-open";
4
- import type { StormWorkspaceConfig } from "@storm-software/config";
5
- import {
6
- createCliOptions,
7
- withRunExecutor
8
- } from "@storm-software/workspace-tools";
9
- import { fork } from "child_process";
10
- import { ServeExecutorSchema } from "./schema";
11
-
12
- export async function* serveExecutor(
13
- options: ServeExecutorSchema,
14
- context: ExecutorContext,
15
- config?: StormWorkspaceConfig
16
- ) {
17
- if (
18
- !context?.projectName ||
19
- !context?.projectsConfigurations?.projects?.[context.projectName]?.root
20
- ) {
21
- throw new Error("Nx executor context was invalid");
22
- }
23
-
24
- const projectRoot =
25
- context!.projectsConfigurations!.projects[context.projectName!]!.root;
26
-
27
- const wranglerOptions = createCliOptions({ ...options });
28
- const wranglerBin = require.resolve("wrangler/bin/wrangler");
29
-
30
- yield* createAsyncIterable<{ success: boolean; baseUrl: string }>(
31
- async ({ done, next, error }) => {
32
- process.env.PWD = projectRoot;
33
- const server = fork(wranglerBin, ["dev", ...wranglerOptions], {
34
- cwd: projectRoot,
35
- stdio: "inherit"
36
- });
37
-
38
- server.once("exit", code => {
39
- if (code === 0) {
40
- done();
41
- } else {
42
- error(new Error(`Cloudflare worker exited with code ${code}`));
43
- }
44
- });
45
-
46
- const killServer = () => {
47
- if (server.connected) {
48
- server.kill("SIGTERM");
49
- }
50
- };
51
-
52
- process.on("exit", () => killServer());
53
- process.on("SIGINT", () => killServer());
54
- process.on("SIGTERM", () => killServer());
55
- process.on("SIGHUP", () => killServer());
56
-
57
- await waitForPortOpen(options.port ?? 4500);
58
-
59
- next({
60
- success: true,
61
- baseUrl: `http://localhost:${options.port}`
62
- });
63
- }
64
- );
65
-
66
- return {
67
- success: true
68
- };
69
- }
70
-
71
- export default withRunExecutor<ServeExecutorSchema>(
72
- "Cloudflare Serve executor",
73
- serveExecutor,
74
- {
75
- skipReadingConfig: false,
76
- hooks: {
77
- applyDefaultOptions: (options: ServeExecutorSchema) => {
78
- options.port ??= 4500;
79
-
80
- return options as ServeExecutorSchema;
81
- }
82
- }
83
- }
84
- ) as PromiseExecutor<ServeExecutorSchema>;
@@ -1,20 +0,0 @@
1
- import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
2
- import { Tree, readProjectConfiguration } from "@nx/devkit";
3
-
4
- import { initGenerator } from "./generator";
5
- import { InitGeneratorSchema } from "./schema";
6
-
7
- describe("init generator", () => {
8
- let tree: Tree;
9
- const options: InitGeneratorSchema = { name: "test" };
10
-
11
- beforeEach(() => {
12
- tree = createTreeWithEmptyWorkspace();
13
- });
14
-
15
- it("should run successfully", async () => {
16
- await initGenerator(tree, options);
17
- const config = readProjectConfiguration(tree, "test");
18
- expect(config).toBeDefined();
19
- });
20
- });
@@ -1,60 +0,0 @@
1
- import {
2
- addDependenciesToPackageJson,
3
- convertNxGenerator,
4
- formatFiles,
5
- removeDependenciesFromPackageJson,
6
- Tree,
7
- } from "@nx/devkit";
8
- import { initGenerator as nodeInitGenerator } from "@nx/js";
9
- import { tslibVersion } from "@nx/node/src/utils/versions";
10
- import {
11
- cloudflareToolsVersion,
12
- cloudflareWorkersTypeVersions,
13
- honoVersion,
14
- wranglerVersion,
15
- } from "./libs/versions";
16
- import type { InitGeneratorSchema } from "./schema";
17
-
18
- export async function initGenerator(tree: Tree, schema: InitGeneratorSchema) {
19
- const initTask = await nodeInitGenerator(tree, {
20
- ...schema,
21
- skipFormat: true,
22
- });
23
-
24
- const installTask = updateDependencies(tree, schema);
25
- if (!schema.skipFormat) {
26
- await formatFiles(tree);
27
- }
28
-
29
- return async () => {
30
- await initTask();
31
- await installTask();
32
- };
33
- }
34
-
35
- function updateDependencies(tree: Tree, schema: InitGeneratorSchema) {
36
- removeDependenciesFromPackageJson(
37
- tree,
38
- ["@storm-software/cloudflare-tools"],
39
- [],
40
- );
41
-
42
- const honoPackage = (
43
- schema.template === "hono" ? { hono: honoVersion } : {}
44
- ) as Record<string, string>;
45
- return addDependenciesToPackageJson(
46
- tree,
47
- {
48
- tslib: tslibVersion,
49
- ...honoPackage,
50
- },
51
- {
52
- wrangler: wranglerVersion,
53
- "@cloudflare/workers-types": cloudflareWorkersTypeVersions,
54
- "@storm-software/cloudflare-tools": cloudflareToolsVersion,
55
- },
56
- );
57
- }
58
-
59
- export default initGenerator;
60
- export const initSchematic = convertNxGenerator(initGenerator);
@@ -1,7 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- export const cloudflareToolsVersion =
3
- require("../../../../package.json").version;
4
-
5
- export const wranglerVersion = "^3.51.2";
6
- export const cloudflareWorkersTypeVersions = "^4.20240419.0";
7
- export const honoVersion = "^4.2.6";
@@ -1,20 +0,0 @@
1
- import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
2
- import { Tree, readProjectConfiguration } from "@nx/devkit";
3
-
4
- import { workerGenerator } from "./generator";
5
- import { WorkerGeneratorSchema } from "./schema";
6
-
7
- describe("worker generator", () => {
8
- let tree: Tree;
9
- const options: WorkerGeneratorSchema = { name: "test" };
10
-
11
- beforeEach(() => {
12
- tree = createTreeWithEmptyWorkspace();
13
- });
14
-
15
- it("should run successfully", async () => {
16
- await workerGenerator(tree, options);
17
- const config = readProjectConfiguration(tree, "test");
18
- expect(config).toBeDefined();
19
- });
20
- });