@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
33import * as fs from 'fs-extra' ;
44import path from 'path' ;
55
6+ import chalk from 'chalk' ;
67import EasCommand from '../../commandUtils/EasCommand' ;
78import { EASEnvironmentFlag , EASNonInteractiveFlag } from '../../commandUtils/flags' ;
89import { EnvironmentSecretType , EnvironmentVariableVisibility } from '../../graphql/generated' ;
@@ -43,6 +44,40 @@ export default class EnvPull extends EasCommand {
4344 } ) ,
4445 } ;
4546
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+
4681 async runAsync ( ) : Promise < void > {
4782 let {
4883 args : { environment : argEnvironment } ,
@@ -105,6 +140,31 @@ export default class EnvPull extends EasCommand {
105140 await fs . mkdir ( envDir , { recursive : true } ) ;
106141 }
107142
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+
108168 const skippedSecretVariables : string [ ] = [ ] ;
109169 const overridenSecretVariables : string [ ] = [ ] ;
110170
@@ -146,5 +206,10 @@ export default class EnvPull extends EasCommand {
146206 ) } .`
147207 ) ;
148208 }
209+
210+ Log . addNewLineIfNone ( ) ;
211+ diffLog . forEach ( line => {
212+ Log . log ( line ) ;
213+ } ) ;
149214 }
150215}
0 commit comments