15f54863aSWill Schurmanimport process from 'process'; 25f54863aSWill Schurman 35f54863aSWill Schurmanimport * as EASCLI from './EASCLI'; 45f54863aSWill Schurmanimport * as ExpoCLI from './ExpoCLI'; 55f54863aSWill Schurmanimport * as Log from './Log'; 65f54863aSWill Schurman 75f54863aSWill Schurmantype Options = { 85f54863aSWill Schurman accessToken?: string; 95f54863aSWill Schurman userpass?: { 105f54863aSWill Schurman username: string; 115f54863aSWill Schurman password: string; 125f54863aSWill Schurman }; 13*dbe276f8SWill Schurman branch: string; 145f54863aSWill Schurman message: string; 155f54863aSWill Schurman}; 165f54863aSWill Schurman 175f54863aSWill Schurman/** 185f54863aSWill Schurman * Uses the installed version of `eas-cli` to publish a project. 195f54863aSWill Schurman */ 20*dbe276f8SWill Schurmanexport async function setAuthAndPublishProjectWithEasCliAsync( 215f54863aSWill Schurman projectRoot: string, 225f54863aSWill Schurman options: Options 235f54863aSWill Schurman): Promise<{ createdUpdateGroupId: string }> { 245f54863aSWill Schurman process.env.EXPO_NO_DOCTOR = '1'; 255f54863aSWill Schurman 265f54863aSWill Schurman if (options.accessToken) { 275f54863aSWill Schurman Log.collapsed('Using access token...'); 285f54863aSWill Schurman process.env.EXPO_TOKEN = options.accessToken; 295f54863aSWill Schurman } else { 305f54863aSWill Schurman const username = options.userpass?.username || process.env.EXPO_CI_ACCOUNT_USERNAME; 315f54863aSWill Schurman const password = options.userpass?.password || process.env.EXPO_CI_ACCOUNT_PASSWORD; 325f54863aSWill Schurman 335f54863aSWill Schurman if (username && password) { 345f54863aSWill Schurman Log.collapsed('Logging in...'); 355f54863aSWill Schurman await ExpoCLI.runExpoCliAsync('login', ['-u', username, '-p', password]); 365f54863aSWill Schurman } else { 375f54863aSWill Schurman Log.collapsed('Expo username and password not specified. Using currently logged-in account.'); 385f54863aSWill Schurman } 395f54863aSWill Schurman } 405f54863aSWill Schurman 41*dbe276f8SWill Schurman return await publishProjectWithEasCliAsync(projectRoot, options); 42*dbe276f8SWill Schurman} 43*dbe276f8SWill Schurman 44*dbe276f8SWill Schurmanexport async function publishProjectWithEasCliAsync( 45*dbe276f8SWill Schurman projectRoot: string, 46*dbe276f8SWill Schurman options: { 47*dbe276f8SWill Schurman branch: string; 48*dbe276f8SWill Schurman message: string; 49*dbe276f8SWill Schurman } 50*dbe276f8SWill Schurman): Promise<{ createdUpdateGroupId: string }> { 515f54863aSWill Schurman Log.collapsed('Publishing...'); 525f54863aSWill Schurman const publishedUpdatesJSONString = await EASCLI.runEASCliAsync( 535f54863aSWill Schurman 'update', 54*dbe276f8SWill Schurman ['--non-interactive', '--json', '--branch', options.branch, '--message', options.message], 555f54863aSWill Schurman { 565f54863aSWill Schurman cwd: projectRoot, 575f54863aSWill Schurman } 585f54863aSWill Schurman ); 595f54863aSWill Schurman 605f54863aSWill Schurman const publishedUpdates = JSON.parse(publishedUpdatesJSONString); 615f54863aSWill Schurman return { createdUpdateGroupId: publishedUpdates[0].group }; 625f54863aSWill Schurman} 63