This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-cli] Add a eas:build:init command
We want to add a separate command to configure the project for eas builds without having to actually start a build.
- Loading branch information
Showing
10 changed files
with
236 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/expo-cli/src/commands/eas-build/init/action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import chalk from 'chalk'; | ||
import figures from 'figures'; | ||
import fs from 'fs-extra'; | ||
import ora from 'ora'; | ||
import path from 'path'; | ||
|
||
import { EasConfig, EasJsonReader } from '../../../easJson'; | ||
import { gitAddAsync } from '../../../git'; | ||
import log from '../../../log'; | ||
import AndroidBuilder from '../build/builders/AndroidBuilder'; | ||
import iOSBuilder from '../build/builders/iOSBuilder'; | ||
import { BuildCommandPlatform } from '../types'; | ||
import createBuilderContextAsync from '../utils/createBuilderContextAsync'; | ||
import { | ||
DirtyGitTreeError, | ||
ensureGitStatusIsCleanAsync, | ||
reviewAndCommitChangesAsync, | ||
} from '../utils/git'; | ||
|
||
interface BuildOptions { | ||
platform: BuildCommandPlatform; | ||
skipCredentialsCheck?: boolean; // TODO: noop for now | ||
profile: string; | ||
parent?: { | ||
nonInteractive: boolean; | ||
}; | ||
} | ||
|
||
async function initAction(projectDir: string, options: BuildOptions): Promise<void> { | ||
const nonInteractive = options.parent?.nonInteractive === true; | ||
|
||
const spinner = ora('Checking for eas.json file'); | ||
|
||
await ensureGitStatusIsCleanAsync(); | ||
|
||
const easJsonPath = path.join(projectDir, 'eas.json'); | ||
const easJson = { | ||
builds: { | ||
android: { | ||
release: { | ||
workflow: 'generic', | ||
}, | ||
}, | ||
ios: { | ||
release: { | ||
workflow: 'generic', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
if (!(await fs.pathExists(easJsonPath))) { | ||
await fs.writeFile(easJsonPath, `${JSON.stringify(easJson, null, 2)}\n`); | ||
await gitAddAsync(easJsonPath, { intentToAdd: true }); | ||
} | ||
|
||
try { | ||
await ensureGitStatusIsCleanAsync(); | ||
spinner.succeed('Found existing eas.json file'); | ||
} catch (err) { | ||
if (err instanceof DirtyGitTreeError) { | ||
spinner.succeed('We created a minimal eas.json file'); | ||
log.newLine(); | ||
|
||
try { | ||
await reviewAndCommitChangesAsync('Create minimal eas.json', { nonInteractive }); | ||
|
||
log(`${chalk.green(figures.tick)} Successfully committed eas.json.`); | ||
} catch (e) { | ||
throw new Error( | ||
"Aborting, run the command again once you're ready. Make sure to commit any changes you've made." | ||
); | ||
} | ||
} else { | ||
spinner.fail(); | ||
throw err; | ||
} | ||
} | ||
|
||
const easConfig: EasConfig = await new EasJsonReader( | ||
projectDir, | ||
BuildCommandPlatform.ALL | ||
).readAsync('release'); | ||
|
||
const ctx = await createBuilderContextAsync(projectDir, easConfig, { | ||
platform: BuildCommandPlatform.ALL, | ||
nonInteractive, | ||
skipCredentialsCheck: options?.skipCredentialsCheck, | ||
skipProjectConfiguration: false, | ||
}); | ||
|
||
const androidBuilder = new AndroidBuilder(ctx); | ||
|
||
await androidBuilder.configureProjectAsync(); | ||
|
||
const iosBuilder = new iOSBuilder(ctx); | ||
|
||
await iosBuilder.ensureCredentialsAsync(); | ||
await iosBuilder.configureProjectAsync(); | ||
} | ||
|
||
export default initAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.