@storm-software/cloudflare-tools
Version:
A Nx plugin package that contains various executors, generators, and utilities that assist in managing Cloudflare services.
45 lines (37 loc) • 1.54 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
var _chunkIATTWS2Ijs = require('./chunk-IATTWS2I.js');
// src/utils/r2-bucket-helpers.ts
var _crypto = require('crypto');
var r2UploadFile = async (client, bucketName, projectPath, fileName, version, fileContent, contentType = "text/plain", isDryRun = false) => {
const checksum = _crypto.createHash.call(void 0, "sha256").update(fileContent).digest("base64");
const fileKey = `${projectPath}/${fileName.startsWith("/") ? fileName.substring(1) : fileName}`;
_chunkIATTWS2Ijs.writeDebug.call(void 0, `Uploading file: ${fileKey}`);
if (!isDryRun) {
await client.putObject({
Bucket: bucketName,
Key: fileKey,
Body: fileContent.replaceAll(' from "@cyclone-ui/', ' from "../'),
ContentType: contentType,
Metadata: {
version,
checksum
}
});
} else {
_chunkIATTWS2Ijs.writeWarning.call(void 0, "[Dry run]: skipping upload to the Cyclone Registry.");
}
};
var getInternalDependencies = (projectName, graph) => {
const allDeps = _nullishCoalesce(graph.dependencies[projectName], () => ( []));
return Array.from(
allDeps.reduce(
(acc, node) => {
const found = graph.nodes[node.target];
if (found) acc.push(found);
return acc;
},
[]
)
);
};
exports.r2UploadFile = r2UploadFile; exports.getInternalDependencies = getInternalDependencies;