@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
3
3
import * as fs from 'fs-extra' ;
4
4
import path from 'path' ;
5
5
6
+ import chalk from 'chalk' ;
6
7
import EasCommand from '../../commandUtils/EasCommand' ;
7
8
import { EASEnvironmentFlag , EASNonInteractiveFlag } from '../../commandUtils/flags' ;
8
9
import { EnvironmentSecretType , EnvironmentVariableVisibility } from '../../graphql/generated' ;
@@ -43,6 +44,40 @@ export default class EnvPull extends EasCommand {
43
44
} ) ,
44
45
} ;
45
46
47
+ async isVariableEqualAsync (
48
+ currentEnvValue : string | undefined ,
49
+ newVariable : EnvironmentVariableWithFileContent
50
+ ) : Promise < boolean > {
51
+ if ( newVariable . visibility === EnvironmentVariableVisibility . Secret ) {
52
+ return true ;
53
+ }
54
+
55
+ // Log.log(
56
+ // newVariable.name,
57
+ // newVariable.type === EnvironmentSecretType.FileBase64,
58
+ // newVariable.valueWithFileContent,
59
+ // currentEnvValue
60
+ // );
61
+
62
+ if (
63
+ newVariable . type === EnvironmentSecretType . FileBase64 &&
64
+ newVariable . valueWithFileContent &&
65
+ currentEnvValue
66
+ ) {
67
+ if ( ! ( await fs . exists ( currentEnvValue ) ) ) {
68
+ // console.log('File does not exist');
69
+ return false ;
70
+ }
71
+
72
+ const fileContent = await fs . readFile ( currentEnvValue , 'base64' ) ;
73
+
74
+ // console.log('File content', fileContent, 'variable:', newVariable.valueWithFileContent);
75
+ return fileContent === newVariable . valueWithFileContent ;
76
+ }
77
+
78
+ return currentEnvValue === newVariable . value ;
79
+ }
80
+
46
81
async runAsync ( ) : Promise < void > {
47
82
let {
48
83
args : { environment : argEnvironment } ,
@@ -105,6 +140,31 @@ export default class EnvPull extends EasCommand {
105
140
await fs . mkdir ( envDir , { recursive : true } ) ;
106
141
}
107
142
143
+ const allVariableNames = new Set ( [
144
+ ...environmentVariables . map ( v => v . name ) ,
145
+ ...Object . keys ( currentEnvLocal ) ,
146
+ ] ) ;
147
+
148
+ const diffLog = [ ] ;
149
+
150
+ for ( const variableName of allVariableNames ) {
151
+ const newVariable = environmentVariables . find ( v => v . name === variableName ) ;
152
+ if ( newVariable ) {
153
+ if ( Object . hasOwn ( currentEnvLocal , variableName ) ) {
154
+ if ( await this . isVariableEqualAsync ( currentEnvLocal [ variableName ] , newVariable ) ) {
155
+ diffLog . push ( chalk . black ( ` ${ variableName } ` ) ) ;
156
+ } else {
157
+ diffLog . push ( chalk . yellow ( `~ ${ variableName } ` ) ) ;
158
+ }
159
+ } else {
160
+ diffLog . push ( chalk . green ( `+ ${ variableName } ` ) ) ;
161
+ }
162
+ } else if ( currentEnvLocal [ variableName ] ) {
163
+ diffLog . push ( chalk . red ( `- ${ variableName } ` ) ) ;
164
+ }
165
+ }
166
+ Log . addNewLineIfNone ( ) ;
167
+
108
168
const skippedSecretVariables : string [ ] = [ ] ;
109
169
const overridenSecretVariables : string [ ] = [ ] ;
110
170
@@ -146,5 +206,10 @@ export default class EnvPull extends EasCommand {
146
206
) } .`
147
207
) ;
148
208
}
209
+
210
+ Log . addNewLineIfNone ( ) ;
211
+ diffLog . forEach ( line => {
212
+ Log . log ( line ) ;
213
+ } ) ;
149
214
}
150
215
}
0 commit comments