1
+ import { existsSync } from "fs" ;
2
+ import { logWarning } from "shared" ;
3
+ import { readJSONSync } from "fs-extra" ;
4
+ import path from "path" ;
5
+
1
6
import { DEPLOYMENT_CONFIG_EXAMPLE_DEFAULTS , getDefaultAppConfig } from "data-models" ;
2
7
import type { IDeploymentConfig , IDeploymentConfigJson } from "data-models" ;
3
- import path from "path" ;
4
8
5
9
import { DEPLOYMENTS_PATH } from "../../paths" ;
6
- import { loadDeploymentJson } from "./utils" ;
10
+ import { getStackFileNames , loadDeploymentJson } from "./utils" ;
7
11
8
12
// re-export of type for convenience
9
13
export type { IDeploymentConfigJson } ;
@@ -16,6 +20,28 @@ export function generateDeploymentConfig(name: string): IDeploymentConfig {
16
20
return config ;
17
21
}
18
22
23
+ /**
24
+ * Read a json file from deployment encrypted folder
25
+ * @param deploymentName name of deployment folder to read config from
26
+ * @param filename name of json to read config from (should already be decrypted)
27
+ * @returns parsed json if exists, null if does not exist
28
+ **/
29
+ export function loadEncryptedConfig ( filename : string ) {
30
+ // Determine path to deployment config ts that called function for source of encrypted config
31
+ const configTsPath = getStackFileNames ( ) . find ( ( filePath ) => filePath . includes ( ".idems_app" ) ) ;
32
+ const encryptedConfigPath = path . resolve ( configTsPath , "../" , "encrypted" ) ;
33
+ const target = path . resolve ( encryptedConfigPath , filename ) ;
34
+ if ( ! existsSync ( target ) ) {
35
+ logWarning ( {
36
+ msg1 : `Encrypted config does not exist,\nsome features may be unavailable` ,
37
+ msg2 : filename ,
38
+ } ) ;
39
+ console . log ( target ) ;
40
+ return null ;
41
+ }
42
+ return readJSONSync ( target ) ;
43
+ }
44
+
19
45
/** Load and extend an existing deployment config **/
20
46
export function extendDeploymentConfig ( options : {
21
47
parent : string ;
0 commit comments