Skip to content

Commit cf91e66

Browse files
committed
Add diff log to env:pull command
1 parent 20b4832 commit cf91e66

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages.
88

99
### 🎉 New features
1010

11+
- Add diff to `eas env:pull` command. ([#2984](https://github.com/expo/eas-cli/pull/2984) by [@khamilowicz](https://github.com/khamilowicz))
12+
1113
### 🐛 Bug fixes
1214

1315
### 🧹 Chores

packages/eas-cli/src/commands/env/pull.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
33
import * as fs from 'fs-extra';
44
import path from 'path';
55

6+
import chalk from 'chalk';
67
import EasCommand from '../../commandUtils/EasCommand';
78
import { EASEnvironmentFlag, EASNonInteractiveFlag } from '../../commandUtils/flags';
89
import { 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

Comments
 (0)