1import path from 'path'; 2 3import { EXPO_DIR } from '../Constants'; 4import logger from '../Logger'; 5import { Package } from '../Packages'; 6import { spawnAsync } from '../Utils'; 7 8/** 9 * Checks whether the state of files is the same after running a script. 10 * @param pkg Package to check 11 * @param match Path or pattern of the files to match 12 */ 13export default async function checkUniformityAsync(pkg: Package, match: string): Promise<void> { 14 const child = await spawnAsync('git', ['status', '--porcelain', match], { 15 stdio: 'pipe', 16 cwd: pkg.path, 17 }); 18 const lines = child.stdout ? child.stdout.trim().split(/\r\n?|\n/g) : []; 19 20 if (lines.length > 0) { 21 logger.error(`The following files need to be rebuilt and committed:`); 22 lines.map((line) => { 23 const filePath = path.join(EXPO_DIR, line.replace(/^\s*\S+\s*/g, '')); 24 logger.warn(path.relative(pkg.path, filePath)); 25 }); 26 27 throw new Error(`${pkg.packageName} has uncommitted changes after building.`); 28 } 29} 30