1import process from 'process'; 2 3import * as EASCLI from './EASCLI'; 4import * as ExpoCLI from './ExpoCLI'; 5import * as Log from './Log'; 6 7type Options = { 8 accessToken?: string; 9 userpass?: { 10 username: string; 11 password: string; 12 }; 13 branch: string; 14 message: string; 15}; 16 17/** 18 * Uses the installed version of `eas-cli` to publish a project. 19 */ 20export async function setAuthAndPublishProjectWithEasCliAsync( 21 projectRoot: string, 22 options: Options 23): Promise<{ createdUpdateGroupId: string }> { 24 process.env.EXPO_NO_DOCTOR = '1'; 25 26 if (options.accessToken) { 27 Log.collapsed('Using access token...'); 28 process.env.EXPO_TOKEN = options.accessToken; 29 } else { 30 const username = options.userpass?.username || process.env.EXPO_CI_ACCOUNT_USERNAME; 31 const password = options.userpass?.password || process.env.EXPO_CI_ACCOUNT_PASSWORD; 32 33 if (username && password) { 34 Log.collapsed('Logging in...'); 35 await ExpoCLI.runExpoCliAsync('login', ['-u', username, '-p', password]); 36 } else { 37 Log.collapsed('Expo username and password not specified. Using currently logged-in account.'); 38 } 39 } 40 41 return await publishProjectWithEasCliAsync(projectRoot, options); 42} 43 44export async function publishProjectWithEasCliAsync( 45 projectRoot: string, 46 options: { 47 branch: string; 48 message: string; 49 } 50): Promise<{ createdUpdateGroupId: string }> { 51 Log.collapsed('Publishing...'); 52 const publishedUpdatesJSONString = await EASCLI.runEASCliAsync( 53 'update', 54 ['--non-interactive', '--json', '--branch', options.branch, '--message', options.message], 55 { 56 cwd: projectRoot, 57 } 58 ); 59 60 const publishedUpdates = JSON.parse(publishedUpdatesJSONString); 61 return { createdUpdateGroupId: publishedUpdates[0].group }; 62} 63