@storm-software/cloudflare-tools 0.48.0 → 0.49.1

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 (81) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/chunk-3J7KBHMJ.mjs +0 -0
  3. package/dist/chunk-7Z5PILRU.mjs +0 -0
  4. package/dist/chunk-A7FFSBE6.mjs +26 -0
  5. package/dist/chunk-CR22PACK.mjs +239 -0
  6. package/dist/chunk-CVGPWUNP.js +1 -0
  7. package/dist/chunk-DHBG5ASJ.js +1 -0
  8. package/dist/chunk-ITLKTOIK.mjs +4042 -0
  9. package/dist/chunk-J5SB6L2L.js +18 -0
  10. package/dist/chunk-JCB2DTP6.js +42 -0
  11. package/dist/chunk-NKCR3FSU.js +153 -0
  12. package/dist/chunk-NPJPHEFP.js +239 -0
  13. package/dist/chunk-NSLK6ZDO.mjs +603 -0
  14. package/dist/chunk-OARYMVO7.mjs +501 -0
  15. package/dist/chunk-QEWY5YJA.mjs +89 -0
  16. package/dist/chunk-R7AIVBS7.js +89 -0
  17. package/dist/chunk-RCE3CC76.js +603 -0
  18. package/dist/chunk-VPT6GF3S.mjs +153 -0
  19. package/dist/chunk-VTHBMY4B.js +133 -0
  20. package/dist/chunk-VYOULWAK.mjs +42 -0
  21. package/dist/chunk-W5J5EWQN.js +227 -0
  22. package/dist/chunk-WGOT27OY.js +4041 -0
  23. package/dist/chunk-XO66D74Z.js +1 -0
  24. package/dist/chunk-XU6MTFCV.mjs +133 -0
  25. package/dist/chunk-YE4FHRXJ.js +501 -0
  26. package/dist/chunk-YSCEY447.mjs +0 -0
  27. package/dist/chunk-ZY7TM2TA.mjs +228 -0
  28. package/dist/executors.d.mts +2 -0
  29. package/dist/executors.d.ts +2 -0
  30. package/dist/executors.js +9 -0
  31. package/dist/executors.mjs +9 -0
  32. package/dist/generator-DJ1RuHyR.d.mts +14 -0
  33. package/dist/generator-DJ1RuHyR.d.ts +14 -0
  34. package/dist/generator-DW-9W9Fk.d.mts +22 -0
  35. package/dist/generator-DW-9W9Fk.d.ts +22 -0
  36. package/dist/generators.d.mts +4 -0
  37. package/dist/generators.d.ts +4 -0
  38. package/dist/generators.js +18 -0
  39. package/dist/generators.mjs +18 -0
  40. package/dist/index.d.mts +45 -0
  41. package/dist/index.d.ts +45 -0
  42. package/dist/index.js +151 -0
  43. package/dist/index.mjs +151 -0
  44. package/dist/schema.d-DgA16PUG.d.mts +24 -0
  45. package/dist/schema.d-DgA16PUG.d.ts +24 -0
  46. package/dist/schema.d-oSirXiCO.d.mts +11 -0
  47. package/dist/schema.d-oSirXiCO.d.ts +11 -0
  48. package/dist/src/executors/cloudflare-publish/executor.d.mts +8 -0
  49. package/dist/src/executors/cloudflare-publish/executor.d.ts +8 -0
  50. package/dist/src/executors/cloudflare-publish/executor.js +11 -0
  51. package/dist/src/executors/cloudflare-publish/executor.mjs +11 -0
  52. package/dist/src/executors/r2-upload-publish/executor.d.mts +8 -0
  53. package/dist/src/executors/r2-upload-publish/executor.d.ts +8 -0
  54. package/dist/src/executors/r2-upload-publish/executor.js +11 -0
  55. package/dist/src/executors/r2-upload-publish/executor.mjs +11 -0
  56. package/dist/src/executors/serve/executor.d.mts +1240 -0
  57. package/dist/src/executors/serve/executor.d.ts +1240 -0
  58. package/dist/src/executors/serve/executor.js +75 -0
  59. package/dist/src/executors/serve/executor.mjs +75 -0
  60. package/dist/src/executors/serve/schema.d.ts +1 -1
  61. package/dist/src/generators/init/generator.d.mts +2 -0
  62. package/dist/src/generators/init/generator.d.ts +2 -0
  63. package/dist/src/generators/init/generator.js +11 -0
  64. package/dist/src/generators/init/generator.mjs +11 -0
  65. package/dist/src/generators/worker/generator.d.mts +3 -0
  66. package/dist/src/generators/worker/generator.d.ts +3 -0
  67. package/dist/src/generators/worker/generator.js +14 -0
  68. package/dist/src/generators/worker/generator.mjs +14 -0
  69. package/dist/src/utils/index.d.mts +3 -0
  70. package/dist/src/utils/index.d.ts +3 -0
  71. package/dist/src/utils/index.js +11 -0
  72. package/dist/src/utils/index.mjs +11 -0
  73. package/dist/src/utils/r2-bucket-helpers.d.mts +7 -0
  74. package/dist/src/utils/r2-bucket-helpers.d.ts +7 -0
  75. package/dist/src/utils/r2-bucket-helpers.js +10 -0
  76. package/dist/src/utils/r2-bucket-helpers.mjs +10 -0
  77. package/dist/tsup.config.d.mts +5 -0
  78. package/dist/tsup.config.d.ts +5 -0
  79. package/dist/tsup.config.js +35 -0
  80. package/dist/tsup.config.mjs +35 -0
  81. package/package.json +1 -1
@@ -0,0 +1,153 @@
1
+ import {
2
+ getInternalDependencies,
3
+ r2UploadFile
4
+ } from "./chunk-VYOULWAK.mjs";
5
+ import {
6
+ createCliOptions,
7
+ getPackageInfo
8
+ } from "./chunk-XU6MTFCV.mjs";
9
+ import {
10
+ loadStormConfig
11
+ } from "./chunk-OARYMVO7.mjs";
12
+ import {
13
+ findWorkspaceRoot,
14
+ writeDebug,
15
+ writeInfo,
16
+ writeSuccess,
17
+ writeWarning
18
+ } from "./chunk-NSLK6ZDO.mjs";
19
+ import {
20
+ __name
21
+ } from "./chunk-A7FFSBE6.mjs";
22
+
23
+ // src/executors/r2-upload-publish/executor.ts
24
+ import { S3 } from "@aws-sdk/client-s3";
25
+ import { joinPathFragments, readCachedProjectGraph } from "@nx/devkit";
26
+ import { glob } from "glob";
27
+ import { execSync } from "node:child_process";
28
+ import { readFile } from "node:fs/promises";
29
+ async function runExecutor(options, context) {
30
+ const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
31
+ if (!context.projectName) {
32
+ throw new Error("The executor requires a projectName.");
33
+ }
34
+ console.info(`\u{1F680} Running Storm Cloudflare Publish executor on the ${context.projectName} worker`);
35
+ if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) {
36
+ throw new Error("The executor requires projectsConfigurations.");
37
+ }
38
+ try {
39
+ const workspaceRoot = findWorkspaceRoot();
40
+ const config = await loadStormConfig(workspaceRoot);
41
+ const sourceRoot = context.projectsConfigurations.projects[context.projectName]?.sourceRoot ?? workspaceRoot;
42
+ const projectName = context.projectsConfigurations.projects[context.projectName]?.name ?? context.projectName;
43
+ const projectDetails = getPackageInfo(context.projectsConfigurations.projects[context.projectName]);
44
+ if (!projectDetails?.content) {
45
+ throw new Error(`Could not find the project details for ${context.projectName}`);
46
+ }
47
+ const args = createCliOptions({
48
+ ...options
49
+ });
50
+ if (isDryRun) {
51
+ args.push("--dry-run");
52
+ }
53
+ const cloudflareAccountId = process.env.STORM_BOT_CLOUDFLARE_ACCOUNT;
54
+ if (!options?.registry && !cloudflareAccountId) {
55
+ throw new Error("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.");
56
+ }
57
+ if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
58
+ throw new Error("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.");
59
+ }
60
+ const endpoint = options?.registry ? options.registry : `https://${cloudflareAccountId}.r2.cloudflarestorage.com`;
61
+ const projectGraph = readCachedProjectGraph();
62
+ if (!projectGraph) {
63
+ throw new Error("No project graph found in cache");
64
+ }
65
+ writeInfo(`Publishing ${context.projectName} to the Storm Registry at ${endpoint}`);
66
+ const s3Client = new S3({
67
+ region: "auto",
68
+ endpoint,
69
+ credentials: {
70
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
71
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
72
+ }
73
+ });
74
+ const version = projectDetails.content?.version;
75
+ writeInfo(`Generated component version: ${version}`);
76
+ const files = await glob(joinPathFragments(sourceRoot, "**/*"), {
77
+ ignore: "**/{*.stories.tsx,*.stories.ts,*.spec.tsx,*.spec.ts}"
78
+ });
79
+ const projectPath = `registry/${context.projectName}`;
80
+ const internalDependencies = await getInternalDependencies(context.projectName, projectGraph);
81
+ const dependencies = internalDependencies.filter((projectNode) => !projectNode.data.tags || projectNode.data.tags.every((tag) => tag.toLowerCase() !== "component")).reduce((ret, dep) => {
82
+ if (!ret[dep.name]) {
83
+ ret[dep.name] = "latest";
84
+ }
85
+ return ret;
86
+ }, projectDetails.content.dependencies ?? {});
87
+ const release = options.tag ?? execSync("npm config get tag").toString().trim();
88
+ writeInfo(`Clearing out existing items in ${projectPath}`);
89
+ if (!isDryRun) {
90
+ const response = await s3Client.listObjects({
91
+ Bucket: options.bucketId,
92
+ Prefix: projectPath
93
+ });
94
+ if (response?.Contents && response.Contents.length > 0) {
95
+ writeDebug(`Deleting the following existing items from the component registry: ${response.Contents.map((item) => item.Key).join(", ")}`);
96
+ await Promise.all(response.Contents.map((item) => s3Client.deleteObjects({
97
+ Bucket: options.bucketId,
98
+ Delete: {
99
+ Objects: [
100
+ {
101
+ Key: item.Key
102
+ }
103
+ ],
104
+ Quiet: false
105
+ }
106
+ })));
107
+ } else {
108
+ writeDebug(`No existing items to delete in the component registry path ${projectPath}`);
109
+ }
110
+ } else {
111
+ writeWarning("[Dry run]: skipping upload to the Cyclone Registry.");
112
+ }
113
+ const meta = {
114
+ name: context.projectName,
115
+ version,
116
+ release,
117
+ description: projectDetails.content.description,
118
+ tags: projectDetails.content.keywords,
119
+ dependencies,
120
+ devDependencies: null,
121
+ internalDependencies: internalDependencies.filter((projectNode) => projectNode.data.tags && projectNode.data.tags.some((tag) => tag.toLowerCase() === "component")).map((dep) => dep.name)
122
+ };
123
+ if (projectDetails.type === "package.json") {
124
+ meta.devDependencies = projectDetails.content.devDependencies;
125
+ }
126
+ const metaJson = JSON.stringify(meta);
127
+ writeInfo(`Generating meta.json file:
128
+ ${metaJson}`);
129
+ await r2UploadFile(s3Client, options.bucketId, projectPath, "meta.json", version, metaJson, "application/json", isDryRun);
130
+ await Promise.all(files.map((file) => {
131
+ const fileName = file.replaceAll("\\", "/").replace(sourceRoot.replaceAll("\\", "/"), "");
132
+ return readFile(file, {
133
+ encoding: "utf8"
134
+ }).then((fileContent) => r2UploadFile(s3Client, options.bucketId, projectPath, fileName, version, fileContent, "text/plain", isDryRun));
135
+ }));
136
+ writeSuccess(`Successfully uploaded the ${projectName} component to the Cyclone Registry`, config);
137
+ return {
138
+ success: true
139
+ };
140
+ } catch (error) {
141
+ console.error("Failed to publish to Cloudflare Workers Registry");
142
+ console.error(error);
143
+ console.log("");
144
+ return {
145
+ success: false
146
+ };
147
+ }
148
+ }
149
+ __name(runExecutor, "runExecutor");
150
+
151
+ export {
152
+ runExecutor
153
+ };
@@ -0,0 +1,133 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkJ5SB6L2Ljs = require('./chunk-J5SB6L2L.js');
4
+
5
+ // ../workspace-tools/src/utils/create-cli-options.ts
6
+ var _devkit = require('@nx/devkit');
7
+ function createCliOptions(obj) {
8
+ const args = [];
9
+ for (const key in obj) {
10
+ const value = obj[key];
11
+ if (value) {
12
+ const arg = _devkit.names.call(void 0, key).fileName;
13
+ if (Array.isArray(value)) {
14
+ args.push(`--${arg.toLowerCase()}=${value.map((v) => v.trim()).join(",")}`);
15
+ } else {
16
+ args.push(`--${arg.toLowerCase()}=${value}`);
17
+ }
18
+ }
19
+ }
20
+ return args;
21
+ }
22
+ _chunkJ5SB6L2Ljs.__name.call(void 0, createCliOptions, "createCliOptions");
23
+
24
+ // ../workspace-tools/src/utils/package-helpers.ts
25
+
26
+ var _fs = require('fs');
27
+
28
+ // ../workspace-tools/src/utils/project-tags.ts
29
+ var ProjectTagConstants = {
30
+ Language: {
31
+ TAG_ID: "language",
32
+ TYPESCRIPT: "typescript",
33
+ RUST: "rust"
34
+ },
35
+ ProjectType: {
36
+ TAG_ID: "type",
37
+ LIBRARY: "library",
38
+ APPLICATION: "application"
39
+ },
40
+ DistStyle: {
41
+ TAG_ID: "dist-style",
42
+ NORMAL: "normal",
43
+ CLEAN: "clean"
44
+ },
45
+ Provider: {
46
+ TAG_ID: "provider"
47
+ },
48
+ Platform: {
49
+ TAG_ID: "platform",
50
+ NODE: "node",
51
+ BROWSER: "browser",
52
+ NEUTRAL: "neutral",
53
+ WORKER: "worker"
54
+ },
55
+ Registry: {
56
+ TAG_ID: "registry",
57
+ CARGO: "cargo",
58
+ NPM: "npm",
59
+ CONTAINER: "container",
60
+ CYCLONE: "cyclone"
61
+ },
62
+ Plugin: {
63
+ TAG_ID: "plugin"
64
+ }
65
+ };
66
+ var formatProjectTag = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (variant, value) => {
67
+ return `${variant}:${value}`;
68
+ }, "formatProjectTag");
69
+ var hasProjectTag = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (project, variant) => {
70
+ project.tags = _nullishCoalesce(project.tags, () => ( []));
71
+ const prefix = formatProjectTag(variant, "");
72
+ return project.tags.some((tag) => tag.startsWith(prefix) && tag.length > prefix.length);
73
+ }, "hasProjectTag");
74
+ var getProjectTag = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (project, variant) => {
75
+ if (!hasProjectTag(project, variant)) {
76
+ return void 0;
77
+ }
78
+ project.tags = _nullishCoalesce(project.tags, () => ( []));
79
+ const prefix = formatProjectTag(variant, "");
80
+ const tag = project.tags.find((tag2) => tag2.startsWith(prefix));
81
+ return _optionalChain([tag, 'optionalAccess', _ => _.replace, 'call', _2 => _2(prefix, "")]);
82
+ }, "getProjectTag");
83
+ var isEqualProjectTag = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (project, variant, value) => {
84
+ const tag = getProjectTag(project, variant);
85
+ return !!(tag && _optionalChain([tag, 'optionalAccess', _3 => _3.toUpperCase, 'call', _4 => _4()]) === value.toUpperCase());
86
+ }, "isEqualProjectTag");
87
+ var addProjectTag = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (project, variant, value, options = {
88
+ overwrite: false
89
+ }) => {
90
+ project.tags = _nullishCoalesce(project.tags, () => ( []));
91
+ if (options.overwrite || !hasProjectTag(project, variant)) {
92
+ project.tags = project.tags.filter((tag) => !tag.startsWith(formatProjectTag(variant, "")));
93
+ project.tags.push(formatProjectTag(variant, value));
94
+ }
95
+ }, "addProjectTag");
96
+
97
+ // ../workspace-tools/src/utils/toml.ts
98
+ var _jtoml = require('@ltd/j-toml'); var _jtoml2 = _interopRequireDefault(_jtoml);
99
+
100
+ function parseCargoToml(cargoString) {
101
+ if (!cargoString) {
102
+ throw new Error("Cargo.toml is empty");
103
+ }
104
+ return _jtoml2.default.parse(cargoString, {
105
+ x: {
106
+ comment: true
107
+ }
108
+ });
109
+ }
110
+ _chunkJ5SB6L2Ljs.__name.call(void 0, parseCargoToml, "parseCargoToml");
111
+
112
+ // ../workspace-tools/src/utils/package-helpers.ts
113
+ var getPackageInfo = /* @__PURE__ */ _chunkJ5SB6L2Ljs.__name.call(void 0, (project) => {
114
+ if (isEqualProjectTag(project, ProjectTagConstants.Language.TAG_ID, ProjectTagConstants.Language.RUST) && _fs.existsSync.call(void 0, _devkit.joinPathFragments.call(void 0, project.root, "Cargo.toml"))) {
115
+ return {
116
+ type: "Cargo.toml",
117
+ content: parseCargoToml(_devkit.joinPathFragments.call(void 0, project.root, "Cargo.toml"))
118
+ };
119
+ } else if (isEqualProjectTag(project, ProjectTagConstants.Language.TAG_ID, ProjectTagConstants.Language.TYPESCRIPT) && _fs.existsSync.call(void 0, _devkit.joinPathFragments.call(void 0, project.root, "package.json"))) {
120
+ return {
121
+ type: "package.json",
122
+ content: _devkit.readJsonFile.call(void 0, _devkit.joinPathFragments.call(void 0, project.root, "package.json"))
123
+ };
124
+ }
125
+ return null;
126
+ }, "getPackageInfo");
127
+
128
+
129
+
130
+
131
+
132
+
133
+ exports.ProjectTagConstants = ProjectTagConstants; exports.addProjectTag = addProjectTag; exports.createCliOptions = createCliOptions; exports.getPackageInfo = getPackageInfo;
@@ -0,0 +1,42 @@
1
+ import {
2
+ writeDebug,
3
+ writeWarning
4
+ } from "./chunk-NSLK6ZDO.mjs";
5
+ import {
6
+ __name
7
+ } from "./chunk-A7FFSBE6.mjs";
8
+
9
+ // src/utils/r2-bucket-helpers.ts
10
+ import { createHash } from "node:crypto";
11
+ var r2UploadFile = /* @__PURE__ */ __name(async (client, bucketName, projectPath, fileName, version, fileContent, contentType = "text/plain", isDryRun = false) => {
12
+ const checksum = createHash("sha256").update(fileContent).digest("base64");
13
+ const fileKey = `${projectPath}/${fileName.startsWith("/") ? fileName.substring(1) : fileName}`;
14
+ writeDebug(`Uploading file: ${fileKey}`);
15
+ if (!isDryRun) {
16
+ await client.putObject({
17
+ Bucket: bucketName,
18
+ Key: fileKey,
19
+ Body: fileContent.replaceAll(' from "@cyclone-ui/', ' from "../'),
20
+ ContentType: contentType,
21
+ Metadata: {
22
+ version,
23
+ checksum
24
+ }
25
+ });
26
+ } else {
27
+ writeWarning("[Dry run]: skipping upload to the Cyclone Registry.");
28
+ }
29
+ }, "r2UploadFile");
30
+ var getInternalDependencies = /* @__PURE__ */ __name((projectName, graph) => {
31
+ const allDeps = graph.dependencies[projectName] ?? [];
32
+ return Array.from(allDeps.reduce((acc, node) => {
33
+ const found = graph.nodes[node.target];
34
+ if (found) acc.push(found);
35
+ return acc;
36
+ }, []));
37
+ }, "getInternalDependencies");
38
+
39
+ export {
40
+ r2UploadFile,
41
+ getInternalDependencies
42
+ };
@@ -0,0 +1,227 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkNPJPHEFPjs = require('./chunk-NPJPHEFP.js');
4
+
5
+
6
+ var _chunkYE4FHRXJjs = require('./chunk-YE4FHRXJ.js');
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkRCE3CC76js = require('./chunk-RCE3CC76.js');
16
+
17
+
18
+ var _chunkJ5SB6L2Ljs = require('./chunk-J5SB6L2L.js');
19
+
20
+ // src/generators/worker/generator.ts
21
+ var _devkit = require('@nx/devkit');
22
+ var _projectnameandrootutils = require('@nx/devkit/src/generators/project-name-and-root-utils');
23
+ var _node = require('@nx/node');
24
+ var _versions = require('@nx/node/src/utils/versions');
25
+ var _path = require('path');
26
+
27
+ // src/generators/worker/libs/get-account-id.ts
28
+ function getAccountId(accountId) {
29
+ return `account_id = "${accountId}"`;
30
+ }
31
+ _chunkJ5SB6L2Ljs.__name.call(void 0, getAccountId, "getAccountId");
32
+
33
+ // src/generators/worker/libs/vitest-imports.ts
34
+ var vitestImports = `import { describe, expect, it, beforeAll, afterAll } from 'vitest';`;
35
+
36
+ // src/generators/worker/libs/vitest-script.ts
37
+ var vitestScript = `"test": "vitest run"`;
38
+
39
+ // src/generators/worker/generator.ts
40
+ async function applicationGenerator(tree, schema) {
41
+ const stopwatch = _chunkRCE3CC76js.getStopwatch.call(void 0, "Storm Worker generator");
42
+ let config;
43
+ try {
44
+ _chunkRCE3CC76js.writeInfo.call(void 0, `\u26A1 Running the Storm Worker generator...
45
+
46
+ `, config);
47
+ const workspaceRoot = _chunkRCE3CC76js.findWorkspaceRoot.call(void 0, );
48
+ _chunkRCE3CC76js.writeDebug.call(void 0, `Loading the Storm Config from environment variables and storm.json file...
49
+ - workspaceRoot: ${workspaceRoot}`, config);
50
+ config = await _chunkYE4FHRXJjs.loadStormConfig.call(void 0, workspaceRoot);
51
+ _chunkRCE3CC76js.writeTrace.call(void 0, `Loaded Storm config into env:
52
+ ${Object.keys(process.env).map((key) => ` - ${key}=${JSON.stringify(process.env[key])}`).join("\n")}`, config);
53
+ const options = await normalizeOptions(tree, schema, config);
54
+ const tasks = [];
55
+ tasks.push(await _chunkNPJPHEFPjs.generator_default.call(void 0, tree, {
56
+ ...options,
57
+ skipFormat: true
58
+ }));
59
+ tasks.push(await _node.applicationGenerator.call(void 0, tree, {
60
+ ...options,
61
+ framework: "none",
62
+ skipFormat: true,
63
+ unitTestRunner: options.unitTestRunner == "vitest" ? "none" : options.unitTestRunner,
64
+ e2eTestRunner: "none",
65
+ name: schema.name
66
+ }));
67
+ if (options.unitTestRunner === "vitest") {
68
+ const { vitestGenerator, createOrEditViteConfig } = _devkit.ensurePackage.call(void 0, "@nx/vite", _versions.nxVersion);
69
+ const vitestTask = await vitestGenerator(tree, {
70
+ project: options.name,
71
+ uiFramework: "none",
72
+ coverageProvider: "v8",
73
+ skipFormat: true,
74
+ testEnvironment: "node"
75
+ });
76
+ tasks.push(vitestTask);
77
+ createOrEditViteConfig(tree, {
78
+ project: options.name,
79
+ includeLib: false,
80
+ includeVitest: true,
81
+ testEnvironment: "node"
82
+ }, true);
83
+ }
84
+ addCloudflareFiles(tree, options);
85
+ updateTsAppConfig(tree, options);
86
+ addTargets(tree, options);
87
+ if (options.unitTestRunner === "none") {
88
+ removeTestFiles(tree, options);
89
+ }
90
+ if (!options.skipFormat) {
91
+ await _devkit.formatFiles.call(void 0, tree);
92
+ }
93
+ if (options.template === "hono") {
94
+ tasks.push(() => {
95
+ const packageJsonPath = _devkit.joinPathFragments.call(void 0, _nullishCoalesce(options.directory, () => ( "")), "package.json");
96
+ if (tree.exists(packageJsonPath)) {
97
+ _devkit.updateJson.call(void 0, tree, packageJsonPath, (json) => ({
98
+ ...json,
99
+ dependencies: {
100
+ hono: "4.4.0",
101
+ ..._optionalChain([json, 'optionalAccess', _ => _.dependencies])
102
+ }
103
+ }));
104
+ }
105
+ });
106
+ }
107
+ return _devkit.runTasksInSerial.call(void 0, ...tasks);
108
+ } catch (error) {
109
+ return () => {
110
+ _chunkRCE3CC76js.writeFatal.call(void 0, "A fatal error occurred while running the generator - the process was forced to terminate", config);
111
+ _chunkRCE3CC76js.writeError.call(void 0, `An exception was thrown in the generator's process
112
+ - Details: ${error.message}
113
+ - Stacktrace: ${error.stack}`, config);
114
+ };
115
+ } finally {
116
+ stopwatch();
117
+ }
118
+ }
119
+ _chunkJ5SB6L2Ljs.__name.call(void 0, applicationGenerator, "applicationGenerator");
120
+ function updateTsAppConfig(tree, options) {
121
+ _devkit.updateJson.call(void 0, tree, _path.join.call(void 0, options.appProjectRoot, "tsconfig.app.json"), (json) => {
122
+ json.compilerOptions = {
123
+ ...json.compilerOptions,
124
+ esModuleInterop: true,
125
+ target: "es2021",
126
+ lib: [
127
+ "es2021"
128
+ ],
129
+ module: "es2022",
130
+ moduleResolution: "node",
131
+ resolveJsonModule: true,
132
+ allowJs: true,
133
+ checkJs: false,
134
+ noEmit: true,
135
+ isolatedModules: true,
136
+ allowSyntheticDefaultImports: true,
137
+ forceConsistentCasingInFileNames: true,
138
+ strict: true,
139
+ skipLibCheck: true
140
+ };
141
+ json.compilerOptions.types = [
142
+ ...json.compilerOptions.types,
143
+ "@cloudflare/workers-types"
144
+ ];
145
+ return json;
146
+ });
147
+ }
148
+ _chunkJ5SB6L2Ljs.__name.call(void 0, updateTsAppConfig, "updateTsAppConfig");
149
+ function addCloudflareFiles(tree, options) {
150
+ tree.delete(_path.join.call(void 0, options.appProjectRoot, "src/main.ts"));
151
+ _devkit.generateFiles.call(void 0, tree, _path.join.call(void 0, __dirname, "./files/common"), options.appProjectRoot, {
152
+ ...options,
153
+ tmpl: "",
154
+ name: options.name,
155
+ accountId: options.accountId ? getAccountId(options.accountId) : "",
156
+ vitestScript: options.unitTestRunner === "vitest" ? vitestScript : ""
157
+ });
158
+ if (options.template && options.template !== "none") {
159
+ _devkit.generateFiles.call(void 0, tree, _path.join.call(void 0, __dirname, `./files/${options.template}`), _path.join.call(void 0, options.appProjectRoot, "src"), {
160
+ ...options,
161
+ tmpl: "",
162
+ name: options.name,
163
+ accountId: options.accountId ? getAccountId(options.accountId) : "",
164
+ vitestScript: options.unitTestRunner === "vitest" ? vitestScript : "",
165
+ vitestImports: options.unitTestRunner === "vitest" ? vitestImports : ""
166
+ });
167
+ }
168
+ }
169
+ _chunkJ5SB6L2Ljs.__name.call(void 0, addCloudflareFiles, "addCloudflareFiles");
170
+ function addTargets(tree, options) {
171
+ try {
172
+ const projectConfiguration = _devkit.readProjectConfiguration.call(void 0, tree, options.name);
173
+ projectConfiguration.targets = {
174
+ ..._nullishCoalesce(projectConfiguration.targets, () => ( {})),
175
+ serve: {
176
+ executor: "@storm-software/cloudflare-tools:serve",
177
+ options: {
178
+ port: options.port
179
+ }
180
+ },
181
+ "nx-release-publish": {
182
+ executor: "@storm-software/cloudflare-tools:cloudflare-publish"
183
+ }
184
+ };
185
+ if (projectConfiguration.targets.build) {
186
+ delete projectConfiguration.targets.build;
187
+ }
188
+ _devkit.updateProjectConfiguration.call(void 0, tree, options.name, projectConfiguration);
189
+ } catch (e) {
190
+ console.error(e);
191
+ }
192
+ }
193
+ _chunkJ5SB6L2Ljs.__name.call(void 0, addTargets, "addTargets");
194
+ function removeTestFiles(tree, options) {
195
+ tree.delete(_path.join.call(void 0, options.appProjectRoot, "src", "index.test.ts"));
196
+ }
197
+ _chunkJ5SB6L2Ljs.__name.call(void 0, removeTestFiles, "removeTestFiles");
198
+ async function normalizeOptions(host, options, config) {
199
+ const { projectName: appProjectName, projectRoot: appProjectRoot } = await _projectnameandrootutils.determineProjectNameAndRootOptions.call(void 0, host, {
200
+ name: options.name,
201
+ projectType: "application",
202
+ directory: options.directory,
203
+ rootProject: options.rootProject
204
+ });
205
+ options.rootProject = appProjectRoot === ".";
206
+ return {
207
+ addPlugin: process.env.NX_ADD_PLUGINS !== "false",
208
+ accountId: process.env.STORM_BOT_CLOUDFLARE_ACCOUNT,
209
+ ...options,
210
+ name: _devkit.names.call(void 0, appProjectName).fileName,
211
+ frontendProject: options.frontendProject ? _devkit.names.call(void 0, options.frontendProject).fileName : void 0,
212
+ appProjectRoot,
213
+ unitTestRunner: _nullishCoalesce(options.unitTestRunner, () => ( "vitest")),
214
+ rootProject: _nullishCoalesce(options.rootProject, () => ( false)),
215
+ template: _nullishCoalesce(options.template, () => ( "fetch-handler")),
216
+ port: _nullishCoalesce(options.port, () => ( 3e3))
217
+ };
218
+ }
219
+ _chunkJ5SB6L2Ljs.__name.call(void 0, normalizeOptions, "normalizeOptions");
220
+ var generator_default2 = applicationGenerator;
221
+ var applicationSchematic = _devkit.convertNxGenerator.call(void 0, applicationGenerator);
222
+
223
+
224
+
225
+
226
+
227
+ exports.applicationGenerator = applicationGenerator; exports.generator_default = generator_default2; exports.applicationSchematic = applicationSchematic;