Skip to content

Commit 35f6856

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

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Flags } from '@oclif/core';
2+
import chalk from 'chalk';
23
import dotenv from 'dotenv';
34
import * as fs from 'fs-extra';
45
import path from 'path';
@@ -43,6 +44,31 @@ 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+
if (
56+
newVariable.type === EnvironmentSecretType.FileBase64 &&
57+
newVariable.valueWithFileContent &&
58+
currentEnvValue
59+
) {
60+
if (!(await fs.exists(currentEnvValue))) {
61+
return false;
62+
}
63+
64+
const fileContent = await fs.readFile(currentEnvValue, 'base64');
65+
66+
return fileContent === newVariable.valueWithFileContent;
67+
}
68+
69+
return currentEnvValue === newVariable.value;
70+
}
71+
4672
async runAsync(): Promise<void> {
4773
let {
4874
args: { environment: argEnvironment },
@@ -105,6 +131,31 @@ export default class EnvPull extends EasCommand {
105131
await fs.mkdir(envDir, { recursive: true });
106132
}
107133

134+
const allVariableNames = new Set([
135+
...environmentVariables.map(v => v.name),
136+
...Object.keys(currentEnvLocal),
137+
]);
138+
139+
const diffLog = [];
140+
141+
for (const variableName of allVariableNames) {
142+
const newVariable = environmentVariables.find(v => v.name === variableName);
143+
if (newVariable) {
144+
if (Object.hasOwn(currentEnvLocal, variableName)) {
145+
if (await this.isVariableEqualAsync(currentEnvLocal[variableName], newVariable)) {
146+
diffLog.push(chalk.black(` ${variableName}`));
147+
} else {
148+
diffLog.push(chalk.yellow(`~ ${variableName}`));
149+
}
150+
} else {
151+
diffLog.push(chalk.green(`+ ${variableName}`));
152+
}
153+
} else if (currentEnvLocal[variableName]) {
154+
diffLog.push(chalk.red(`- ${variableName}`));
155+
}
156+
}
157+
Log.addNewLineIfNone();
158+
108159
const skippedSecretVariables: string[] = [];
109160
const overridenSecretVariables: string[] = [];
110161

@@ -146,5 +197,10 @@ export default class EnvPull extends EasCommand {
146197
)}.`
147198
);
148199
}
200+
201+
Log.addNewLineIfNone();
202+
diffLog.forEach(line => {
203+
Log.log(line);
204+
});
149205
}
150206
}

0 commit comments

Comments
 (0)