@storm-software/cloudflare-tools 0.71.242 → 0.71.247
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.
- package/CHANGELOG.md +60 -0
- package/README.md +1 -1
- package/dist/{chunk-GLKR5BOA.js → chunk-2SPQ64QX.js} +2 -2
- package/dist/{chunk-BGMLQBUW.mjs → chunk-BTKJRCZQ.mjs} +1 -1
- package/dist/{chunk-KNN4W7QC.mjs → chunk-GYIUU2G4.mjs} +184 -142
- package/dist/{chunk-3GUCTXXT.mjs → chunk-KZQP6DGG.mjs} +2 -2
- package/dist/{chunk-MVEHOKMY.mjs → chunk-MCCHKUCS.mjs} +2 -2
- package/dist/{chunk-YCOA7IKG.mjs → chunk-NG5JLH7K.mjs} +7 -7
- package/dist/{chunk-4HEOMMTX.mjs → chunk-NZ4SP2BO.mjs} +2 -2
- package/dist/{chunk-AF4CHUYX.js → chunk-O6QQDVZ5.js} +2 -2
- package/dist/{chunk-GRVOVEJP.js → chunk-OTUOQHGH.js} +6 -6
- package/dist/{chunk-TMHLSIZ5.js → chunk-UGIZ5QUS.js} +1 -1
- package/dist/{chunk-EI77CIK7.mjs → chunk-WPIQWFHD.mjs} +1 -1
- package/dist/{chunk-7NFFNXFN.js → chunk-XKZTXB5T.js} +163 -121
- package/dist/executors.js +1 -1
- package/dist/executors.mjs +3 -3
- package/dist/generators.js +3 -3
- package/dist/generators.mjs +3 -3
- package/dist/index.js +4 -4
- package/dist/index.mjs +5 -5
- package/dist/src/executors/cloudflare-publish/executor.js +1 -1
- package/dist/src/executors/cloudflare-publish/executor.mjs +3 -3
- package/dist/src/executors/r2-upload-publish/executor.mjs +1 -1
- package/dist/src/executors/r2-upload-publish/untyped.mjs +1 -1
- package/dist/src/executors/serve/executor.js +2 -2
- package/dist/src/executors/serve/executor.mjs +2 -2
- package/dist/src/generators/init/generator.js +2 -2
- package/dist/src/generators/init/generator.mjs +2 -2
- package/dist/src/generators/worker/generator.js +3 -3
- package/dist/src/generators/worker/generator.mjs +3 -3
- package/dist/src/plugins/index.mjs +1 -1
- package/dist/src/utils/http-handler.mjs +1 -1
- package/dist/src/utils/index.mjs +1 -1
- package/dist/src/utils/r2-bucket-helpers.mjs +1 -1
- package/package.json +10 -10
- package/dist/chunk-BASIQFOW.js +0 -231
- package/dist/chunk-E2KDBKFZ.mjs +0 -231
package/dist/chunk-E2KDBKFZ.mjs
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCliOptions,
|
|
3
|
-
getPackageInfo
|
|
4
|
-
} from "./chunk-ZXLMDNFQ.mjs";
|
|
5
|
-
import {
|
|
6
|
-
findWorkspaceRoot,
|
|
7
|
-
getConfig
|
|
8
|
-
} from "./chunk-BJQFVPGK.mjs";
|
|
9
|
-
import {
|
|
10
|
-
createHttpHandler
|
|
11
|
-
} from "./chunk-SWYYMID7.mjs";
|
|
12
|
-
import {
|
|
13
|
-
getEncoding,
|
|
14
|
-
getInternalDependencies,
|
|
15
|
-
uploadFile
|
|
16
|
-
} from "./chunk-BY7MA3SM.mjs";
|
|
17
|
-
import {
|
|
18
|
-
correctPaths,
|
|
19
|
-
joinPaths,
|
|
20
|
-
writeDebug,
|
|
21
|
-
writeSuccess,
|
|
22
|
-
writeTrace,
|
|
23
|
-
writeWarning
|
|
24
|
-
} from "./chunk-K4H5ZMYA.mjs";
|
|
25
|
-
|
|
26
|
-
// src/executors/r2-upload-publish/executor.ts
|
|
27
|
-
import {
|
|
28
|
-
DeleteObjectsCommand,
|
|
29
|
-
ListObjectsCommand,
|
|
30
|
-
S3Client
|
|
31
|
-
} from "@aws-sdk/client-s3";
|
|
32
|
-
import {
|
|
33
|
-
createProjectGraphAsync,
|
|
34
|
-
readCachedProjectGraph
|
|
35
|
-
} from "@nx/devkit";
|
|
36
|
-
import { glob } from "glob";
|
|
37
|
-
import mime from "mime-types";
|
|
38
|
-
import { execSync } from "node:child_process";
|
|
39
|
-
import { statSync } from "node:fs";
|
|
40
|
-
import { readFile } from "node:fs/promises";
|
|
41
|
-
async function runExecutor(options, context) {
|
|
42
|
-
const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
|
|
43
|
-
if (!context.projectName) {
|
|
44
|
-
throw new Error("The executor requires a projectName.");
|
|
45
|
-
}
|
|
46
|
-
if (!options.path) {
|
|
47
|
-
throw new Error("The executor requires the `path` option to upload.");
|
|
48
|
-
}
|
|
49
|
-
console.info(
|
|
50
|
-
`\u{1F680} Running Storm Cloudflare Publish executor on the ${context.projectName} worker`
|
|
51
|
-
);
|
|
52
|
-
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) {
|
|
53
|
-
throw new Error("The executor requires projectsConfigurations.");
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
const workspaceRoot = findWorkspaceRoot();
|
|
57
|
-
const config = await getConfig(workspaceRoot);
|
|
58
|
-
const projectName = context.projectsConfigurations.projects[context.projectName]?.name ?? context.projectName;
|
|
59
|
-
const projectDetails = getPackageInfo(
|
|
60
|
-
context.projectsConfigurations.projects[context.projectName]
|
|
61
|
-
);
|
|
62
|
-
const bucketId = options.bucketId;
|
|
63
|
-
const bucketPath = options.bucketPath || "/";
|
|
64
|
-
if (!bucketId) {
|
|
65
|
-
throw new Error("The executor requires a bucketId.");
|
|
66
|
-
}
|
|
67
|
-
const args = createCliOptions({ ...options });
|
|
68
|
-
if (isDryRun) {
|
|
69
|
-
args.push("--dry-run");
|
|
70
|
-
}
|
|
71
|
-
const cloudflareAccountId = process.env.CLOUDFLARE_ACCOUNT_ID || process.env.STORM_BOT_CLOUDFLARE_ACCOUNT;
|
|
72
|
-
if (!options?.registry && !cloudflareAccountId) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
"The registry option and `CLOUDFLARE_ACCOUNT_ID` (or `STORM_BOT_CLOUDFLARE_ACCOUNT`) environment variable are not set. Please set one of these values to upload to the Cloudflare R2 bucket."
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
if (!process.env.STORM_BOT_ACCESS_KEY_ID && !process.env.ACCESS_KEY_ID && !process.env.CLOUDFLARE_ACCESS_KEY_ID && !process.env.AWS_ACCESS_KEY_ID || !process.env.STORM_BOT_SECRET_ACCESS_KEY && !process.env.CLOUDFLARE_SECRET_ACCESS_KEY && !process.env.SECRET_ACCESS_KEY && !process.env.AWS_SECRET_ACCESS_KEY) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
"The `ACCESS_KEY_ID` (or `STORM_BOT_ACCESS_KEY_ID`) and `SECRET_ACCESS_KEY` (or `STORM_BOT_SECRET_ACCESS_KEY`) environment variables are not set. Please set these environment variables to upload to the Cloudflare R2 bucket."
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const registry = options?.registry ? options.registry : `https://${cloudflareAccountId}.r2.cloudflarestorage.com`;
|
|
83
|
-
let projectGraph;
|
|
84
|
-
try {
|
|
85
|
-
projectGraph = readCachedProjectGraph();
|
|
86
|
-
} catch {
|
|
87
|
-
await createProjectGraphAsync();
|
|
88
|
-
projectGraph = readCachedProjectGraph();
|
|
89
|
-
}
|
|
90
|
-
if (!projectGraph) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
"The executor failed because the project graph is not available. Please run the build command again."
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
writeDebug(
|
|
96
|
-
`Publishing ${context.projectName} to the ${bucketId} R2 Bucket (at ${registry})`
|
|
97
|
-
);
|
|
98
|
-
const client = new S3Client({
|
|
99
|
-
region: "auto",
|
|
100
|
-
endpoint: registry,
|
|
101
|
-
credentials: {
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
103
|
-
accessKeyId: process.env.STORM_BOT_ACCESS_KEY_ID || process.env.CLOUDFLARE_ACCESS_KEY_ID || process.env.AWS_ACCESS_KEY_ID || process.env.ACCESS_KEY_ID,
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
|
-
secretAccessKey: process.env.STORM_BOT_SECRET_ACCESS_KEY || process.env.CLOUDFLARE_SECRET_ACCESS_KEY || process.env.AWS_SECRET_ACCESS_KEY || process.env.SECRET_ACCESS_KEY
|
|
106
|
-
},
|
|
107
|
-
requestHandler: createHttpHandler()
|
|
108
|
-
});
|
|
109
|
-
const version = projectDetails?.content?.version;
|
|
110
|
-
if (version) {
|
|
111
|
-
writeDebug(`Starting upload version ${version}`);
|
|
112
|
-
}
|
|
113
|
-
const basePath = options.path;
|
|
114
|
-
const files = await glob(joinPaths(basePath, "**/*"), {
|
|
115
|
-
ignore: "**/{*.stories.tsx,*.stories.ts,*.spec.tsx,*.spec.ts}"
|
|
116
|
-
});
|
|
117
|
-
const internalDependencies = await getInternalDependencies(
|
|
118
|
-
context.projectName,
|
|
119
|
-
projectGraph
|
|
120
|
-
);
|
|
121
|
-
const dependencies = internalDependencies.filter(
|
|
122
|
-
(projectNode) => !projectNode.data.tags || projectNode.data.tags.every((tag) => tag.toLowerCase() !== "component")
|
|
123
|
-
).reduce((ret, dep) => {
|
|
124
|
-
if (!ret[dep.name]) {
|
|
125
|
-
ret[dep.name] = "latest";
|
|
126
|
-
}
|
|
127
|
-
return ret;
|
|
128
|
-
}, projectDetails?.content.dependencies ?? {});
|
|
129
|
-
const release = options.tag ?? execSync("npm config get tag").toString().trim();
|
|
130
|
-
if (options.clean === true) {
|
|
131
|
-
writeDebug(`Clearing out existing items in ${bucketPath}`);
|
|
132
|
-
if (!isDryRun) {
|
|
133
|
-
const response = await client.send(
|
|
134
|
-
new ListObjectsCommand({
|
|
135
|
-
Bucket: bucketId,
|
|
136
|
-
Prefix: !bucketPath || bucketPath === "/" ? void 0 : bucketPath
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
if (response?.Contents && response.Contents.length > 0) {
|
|
140
|
-
writeTrace(
|
|
141
|
-
`Deleting the following existing items from the R2 bucket path ${bucketPath}: ${response.Contents.map((item) => item.Key).join(", ")}`
|
|
142
|
-
);
|
|
143
|
-
await client.send(
|
|
144
|
-
new DeleteObjectsCommand({
|
|
145
|
-
Bucket: bucketId,
|
|
146
|
-
Delete: {
|
|
147
|
-
Objects: response.Contents.map((item) => ({
|
|
148
|
-
Key: item.Key
|
|
149
|
-
})),
|
|
150
|
-
Quiet: false
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
} else {
|
|
155
|
-
writeDebug(
|
|
156
|
-
`No existing items to delete in the R2 bucket path ${bucketPath}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
writeWarning("[Dry run]: Skipping R2 bucket clean.");
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (options.writeMetaJson === true) {
|
|
164
|
-
const meta = {
|
|
165
|
-
name: context.projectName,
|
|
166
|
-
version,
|
|
167
|
-
release,
|
|
168
|
-
description: projectDetails?.content?.description,
|
|
169
|
-
tags: projectDetails?.content?.keywords,
|
|
170
|
-
dependencies,
|
|
171
|
-
devDependencies: null,
|
|
172
|
-
internalDependencies: internalDependencies.filter(
|
|
173
|
-
(projectNode) => projectNode.data.tags && projectNode.data.tags.some(
|
|
174
|
-
(tag) => tag.toLowerCase() === "component"
|
|
175
|
-
)
|
|
176
|
-
).map((dep) => dep.name)
|
|
177
|
-
};
|
|
178
|
-
if (projectDetails?.type === "package.json") {
|
|
179
|
-
meta.devDependencies = projectDetails?.content?.devDependencies;
|
|
180
|
-
}
|
|
181
|
-
await uploadFile(
|
|
182
|
-
client,
|
|
183
|
-
bucketId,
|
|
184
|
-
bucketPath,
|
|
185
|
-
"meta.json",
|
|
186
|
-
version,
|
|
187
|
-
JSON.stringify(meta),
|
|
188
|
-
"application/json",
|
|
189
|
-
isDryRun
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
await Promise.all(
|
|
193
|
-
files.map(async (file) => {
|
|
194
|
-
if (statSync(file, {
|
|
195
|
-
throwIfNoEntry: false
|
|
196
|
-
})?.isFile()) {
|
|
197
|
-
const name = correctPaths(file).replace(correctPaths(basePath), "");
|
|
198
|
-
const type = mime.lookup(name) || "application/octet-stream";
|
|
199
|
-
await uploadFile(
|
|
200
|
-
client,
|
|
201
|
-
bucketId,
|
|
202
|
-
bucketPath,
|
|
203
|
-
name,
|
|
204
|
-
version,
|
|
205
|
-
await readFile(file, getEncoding(type)),
|
|
206
|
-
type,
|
|
207
|
-
isDryRun
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
writeSuccess(
|
|
213
|
-
`Successfully uploaded the ${projectName} project to the Cloudflare R2 bucket.`,
|
|
214
|
-
config
|
|
215
|
-
);
|
|
216
|
-
return {
|
|
217
|
-
success: true
|
|
218
|
-
};
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.error("Failed to publish to Cloudflare R2 bucket");
|
|
221
|
-
console.error(error);
|
|
222
|
-
console.log("");
|
|
223
|
-
return {
|
|
224
|
-
success: false
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export {
|
|
230
|
-
runExecutor
|
|
231
|
-
};
|