@storm-software/cloudflare-tools 0.71.118 → 0.71.119

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.
@@ -1,269 +0,0 @@
1
- import {
2
- generator_default
3
- } from "./chunk-LACL4JSA.mjs";
4
- import {
5
- findWorkspaceRoot,
6
- getConfig
7
- } from "./chunk-5QM4JUN3.mjs";
8
- import {
9
- brandIcon,
10
- getStopwatch,
11
- writeDebug,
12
- writeError,
13
- writeFatal,
14
- writeInfo,
15
- writeTrace
16
- } from "./chunk-ZDABHOZ2.mjs";
17
- import {
18
- __dirname
19
- } from "./chunk-FU2GBN2O.mjs";
20
-
21
- // src/generators/worker/generator.ts
22
- import {
23
- convertNxGenerator,
24
- ensurePackage,
25
- formatFiles,
26
- generateFiles,
27
- joinPathFragments,
28
- names,
29
- readProjectConfiguration,
30
- runTasksInSerial,
31
- updateJson,
32
- updateProjectConfiguration
33
- } from "@nx/devkit";
34
- import { determineProjectNameAndRootOptions } from "@nx/devkit/src/generators/project-name-and-root-utils";
35
- import { applicationGenerator as nodeApplicationGenerator } from "@nx/node";
36
- import { nxVersion } from "@nx/node/src/utils/versions";
37
- import { join } from "path";
38
-
39
- // src/generators/worker/libs/get-account-id.ts
40
- function getAccountId(accountId) {
41
- return `account_id = "${accountId}"`;
42
- }
43
-
44
- // src/generators/worker/libs/vitest-imports.ts
45
- var vitestImports = `import { describe, expect, it, beforeAll, afterAll } from 'vitest';`;
46
-
47
- // src/generators/worker/libs/vitest-script.ts
48
- var vitestScript = `"test": "vitest run"`;
49
-
50
- // src/generators/worker/generator.ts
51
- async function applicationGenerator(tree, schema) {
52
- const stopwatch = getStopwatch("Storm Worker generator");
53
- let config;
54
- try {
55
- const workspaceRoot = findWorkspaceRoot();
56
- config = await getConfig(workspaceRoot);
57
- writeInfo(
58
- `${brandIcon(config)} Running the Storm Worker generator...
59
-
60
- `,
61
- config
62
- );
63
- writeDebug(
64
- `Loading the Storm Config from environment variables and storm.json file...
65
- - workspaceRoot: ${workspaceRoot}`,
66
- config
67
- );
68
- writeTrace(
69
- `Loaded Storm config into env:
70
- ${Object.keys(process.env).map((key) => ` - ${key}=${JSON.stringify(process.env[key])}`).join("\n")}`,
71
- config
72
- );
73
- const options = await normalizeOptions(tree, schema, config);
74
- const tasks = [];
75
- tasks.push(
76
- await generator_default(tree, {
77
- ...options,
78
- skipFormat: true
79
- })
80
- );
81
- tasks.push(
82
- await nodeApplicationGenerator(tree, {
83
- ...options,
84
- framework: "none",
85
- skipFormat: true,
86
- unitTestRunner: options.unitTestRunner == "vitest" ? "none" : options.unitTestRunner,
87
- e2eTestRunner: "none",
88
- name: schema.name
89
- })
90
- );
91
- if (options.unitTestRunner === "vitest") {
92
- const { vitestGenerator, createOrEditViteConfig } = ensurePackage(
93
- "@nx/vite",
94
- nxVersion
95
- );
96
- const vitestTask = await vitestGenerator(tree, {
97
- project: options.name,
98
- uiFramework: "none",
99
- coverageProvider: "v8",
100
- skipFormat: true,
101
- testEnvironment: "node"
102
- });
103
- tasks.push(vitestTask);
104
- createOrEditViteConfig(
105
- tree,
106
- {
107
- project: options.name,
108
- includeLib: false,
109
- includeVitest: true,
110
- testEnvironment: "node"
111
- },
112
- true
113
- );
114
- }
115
- addCloudflareFiles(tree, options);
116
- updateTsAppConfig(tree, options);
117
- addTargets(tree, options);
118
- if (options.unitTestRunner === "none") {
119
- removeTestFiles(tree, options);
120
- }
121
- if (!options.skipFormat) {
122
- await formatFiles(tree);
123
- }
124
- if (options.template === "hono") {
125
- tasks.push(() => {
126
- const packageJsonPath = joinPathFragments(
127
- options.directory ?? "",
128
- "package.json"
129
- );
130
- if (tree.exists(packageJsonPath)) {
131
- updateJson(tree, packageJsonPath, (json) => ({
132
- ...json,
133
- dependencies: {
134
- hono: "4.4.0",
135
- ...json?.dependencies
136
- }
137
- }));
138
- }
139
- });
140
- }
141
- return runTasksInSerial(...tasks);
142
- } catch (error) {
143
- return () => {
144
- writeFatal(
145
- "A fatal error occurred while running the generator - the process was forced to terminate",
146
- config
147
- );
148
- writeError(
149
- `An exception was thrown in the generator's process
150
- - Details: ${error.message}
151
- - Stacktrace: ${error.stack}`,
152
- config
153
- );
154
- };
155
- } finally {
156
- stopwatch();
157
- }
158
- }
159
- function updateTsAppConfig(tree, options) {
160
- updateJson(tree, join(options.appProjectRoot, "tsconfig.app.json"), (json) => {
161
- json.compilerOptions = {
162
- ...json.compilerOptions,
163
- esModuleInterop: true,
164
- target: "es2021",
165
- lib: ["es2021"],
166
- module: "es2022",
167
- moduleResolution: "node",
168
- resolveJsonModule: true,
169
- allowJs: true,
170
- checkJs: false,
171
- noEmit: true,
172
- isolatedModules: true,
173
- allowSyntheticDefaultImports: true,
174
- forceConsistentCasingInFileNames: true,
175
- strict: true,
176
- skipLibCheck: true
177
- };
178
- json.compilerOptions.types = [
179
- ...json.compilerOptions.types,
180
- "@cloudflare/workers-types"
181
- ];
182
- return json;
183
- });
184
- }
185
- function addCloudflareFiles(tree, options) {
186
- tree.delete(join(options.appProjectRoot, "src/main.ts"));
187
- generateFiles(
188
- tree,
189
- join(__dirname, "./files/common"),
190
- options.appProjectRoot,
191
- {
192
- ...options,
193
- tmpl: "",
194
- name: options.name,
195
- accountId: options.accountId ? getAccountId(options.accountId) : "",
196
- vitestScript: options.unitTestRunner === "vitest" ? vitestScript : ""
197
- }
198
- );
199
- if (options.template && options.template !== "none") {
200
- generateFiles(
201
- tree,
202
- join(__dirname, `./files/${options.template}`),
203
- join(options.appProjectRoot, "src"),
204
- {
205
- ...options,
206
- tmpl: "",
207
- name: options.name,
208
- accountId: options.accountId ? getAccountId(options.accountId) : "",
209
- vitestScript: options.unitTestRunner === "vitest" ? vitestScript : "",
210
- vitestImports: options.unitTestRunner === "vitest" ? vitestImports : ""
211
- }
212
- );
213
- }
214
- }
215
- function addTargets(tree, options) {
216
- try {
217
- const projectConfiguration = readProjectConfiguration(tree, options.name);
218
- projectConfiguration.targets = {
219
- ...projectConfiguration.targets ?? {},
220
- serve: {
221
- executor: "@storm-software/cloudflare-tools:serve",
222
- options: {
223
- port: options.port
224
- }
225
- },
226
- "nx-release-publish": {
227
- executor: "@storm-software/cloudflare-tools:cloudflare-publish"
228
- }
229
- };
230
- if (projectConfiguration.targets.build) {
231
- delete projectConfiguration.targets.build;
232
- }
233
- updateProjectConfiguration(tree, options.name, projectConfiguration);
234
- } catch (e) {
235
- console.error(e);
236
- }
237
- }
238
- function removeTestFiles(tree, options) {
239
- tree.delete(join(options.appProjectRoot, "src", "index.test.ts"));
240
- }
241
- async function normalizeOptions(host, options, config) {
242
- const { projectName: appProjectName, projectRoot: appProjectRoot } = await determineProjectNameAndRootOptions(host, {
243
- name: options.name,
244
- projectType: "application",
245
- directory: options.directory,
246
- rootProject: options.rootProject
247
- });
248
- options.rootProject = appProjectRoot === ".";
249
- return {
250
- addPlugin: process.env.NX_ADD_PLUGINS !== "false",
251
- accountId: process.env.STORM_BOT_CLOUDFLARE_ACCOUNT,
252
- ...options,
253
- name: names(appProjectName).fileName,
254
- frontendProject: options.frontendProject ? names(options.frontendProject).fileName : void 0,
255
- appProjectRoot,
256
- unitTestRunner: options.unitTestRunner ?? "vitest",
257
- rootProject: options.rootProject ?? false,
258
- template: options.template ?? "fetch-handler",
259
- port: options.port ?? 3e3
260
- };
261
- }
262
- var generator_default2 = applicationGenerator;
263
- var applicationSchematic = convertNxGenerator(applicationGenerator);
264
-
265
- export {
266
- applicationGenerator,
267
- generator_default2 as generator_default,
268
- applicationSchematic
269
- };