@comet/upgrade 1.70.0 → 1.71.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.
- package/lib/v8/update-s3-config.js +41 -0
- package/package.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
4
|
+
async function updateS3Config() {
|
|
5
|
+
console.log(`🚀 Update s3 config to new structure.`);
|
|
6
|
+
const filePath = "api/src/config/config.ts";
|
|
7
|
+
const project = new ts_morph_1.Project();
|
|
8
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
9
|
+
// Find the createConfig function
|
|
10
|
+
const createConfigFn = sourceFile.getFunctionOrThrow("createConfig");
|
|
11
|
+
const returnStmt = createConfigFn.getBodyOrThrow().getDescendantsOfKind(ts_morph_1.SyntaxKind.ReturnStatement)[0];
|
|
12
|
+
const returnObj = returnStmt.getExpressionIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
13
|
+
// Navigate to blob.storage.s3
|
|
14
|
+
let s3Prop;
|
|
15
|
+
try {
|
|
16
|
+
const blobProp = returnObj.getPropertyOrThrow("blob").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
17
|
+
const storageProp = blobProp.getPropertyOrThrow("storage").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
18
|
+
s3Prop = storageProp.getPropertyOrThrow("s3").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.log("☑️ No S3 configuration found in the specified file. Skipping update.");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Get accessKeyId and secretAccessKey
|
|
25
|
+
const accessKeyIdProp = s3Prop.getProperty("accessKeyId");
|
|
26
|
+
const secretAccessKeyProp = s3Prop.getProperty("secretAccessKey");
|
|
27
|
+
if (accessKeyIdProp && secretAccessKeyProp) {
|
|
28
|
+
s3Prop.addPropertyAssignment({
|
|
29
|
+
name: "credentials",
|
|
30
|
+
initializer: `{
|
|
31
|
+
${accessKeyIdProp.getText()},
|
|
32
|
+
${secretAccessKeyProp.getText()}
|
|
33
|
+
}`,
|
|
34
|
+
});
|
|
35
|
+
accessKeyIdProp.remove();
|
|
36
|
+
secretAccessKeyProp.remove();
|
|
37
|
+
await sourceFile.save();
|
|
38
|
+
console.log(`✅ Structure changed.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.default = updateS3Config;
|