Skip to content

Commit

Permalink
use EasJsonAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsamp committed Dec 8, 2022
1 parent a4468fa commit cce63e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
4 changes: 1 addition & 3 deletions packages/eas-cli/src/commands/update/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export default class UpdateConfigure extends EasCommand {
Log.newLine();
Log.log('Preview an update:');
Log.log(
`1. Publish an update to a branch. Example: ${chalk.bold(
'eas update --branch new-feature'
)}.`
`1. Publish an update to a branch. Example: ${chalk.bold('eas update --branch new-feature')}.`
);
Log.log(
'2. In Expo Go or a development build, navigate to Projects > [project name] > Branch > Open.'
Expand Down
61 changes: 29 additions & 32 deletions packages/eas-cli/src/update/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,45 +271,42 @@ async function ensureEASUpdateIsConfiguredInEasJsonAsync(projectDir: string): Pr
}

try {
const easJsonData = await fs.readFile(easJsonPath, 'utf-8');
const easJson = JSON.parse(easJsonData);
const easBuildProfilesWithChannels = Object.keys(easJson.build).reduce(
(acc, profileNameKey) => {
const buildProfile = easJson.build[profileNameKey];
const isNotAlreadyConfigured = !buildProfile.channel && !buildProfile.releaseChannel;

if (isNotAlreadyConfigured) {
const easJsonAccessor = new EasJsonAccessor(projectDir);
await easJsonAccessor.readRawJsonAsync();

easJsonAccessor.patch(easJsonRawObject => {
const easBuildProfilesWithChannels = Object.keys(easJsonRawObject.build).reduce(
(acc, profileNameKey) => {
const buildProfile = easJsonRawObject.build[profileNameKey];
const isNotAlreadyConfigured = !buildProfile.channel && !buildProfile.releaseChannel;

if (isNotAlreadyConfigured) {
return {
...acc,
[profileNameKey]: {
...buildProfile,
channel: profileNameKey,
},
};
}

return {
...acc,
[profileNameKey]: {
...buildProfile,
channel: profileNameKey,
...easJsonRawObject.build[profileNameKey],
},
};
}

return {
...acc,
[profileNameKey]: {
...easJson.build[profileNameKey],
},
};
},
{}
);

await fs.writeFile(
easJsonPath,
`${JSON.stringify(
{
...easJson,
build: easBuildProfilesWithChannels,
},
null,
2
)}\n`
);
{}
);

return {
...easJsonRawObject,
build: easBuildProfilesWithChannels,
};
});

await easJsonAccessor.writeAsync();
Log.withTick(`Configured ${chalk.bold('eas.json')}.`);
} catch (error) {
Log.error(`We were not able to configure ${chalk.bold('eas.json')}. Error: ${error}.`);
Expand Down

0 comments on commit cce63e9

Please sign in to comment.