MCPcopy
hub / github.com/callstack/haul / modifyGradleBuild

Function modifyGradleBuild

packages/haul-cli/src/commands/init.ts:212–258  ·  view source on GitHub ↗
(progress: Ora, cwd: string)

Source from the content-addressed store, hash-verified

210}
211
212async function modifyGradleBuild(progress: Ora, cwd: string) {
213 let gradleBuildFile;
214 // Does `android/app/build.gradle` exist?
215 const androidPath = path.join(cwd, 'android/app');
216 if (fs.existsSync(androidPath)) {
217 gradleBuildFile = fs
218 .readdirSync(androidPath)
219 .find(file => file.includes('build.gradle'));
220 gradleBuildFile = path.join(androidPath, gradleBuildFile || '');
221 }
222 // Otherwise, ask for path to a file
223 if (!gradleBuildFile) {
224 const result = (await inquirer.prompt([
225 {
226 type: 'input',
227 name: 'entry',
228 message: 'Enter path to the android/app/build.gradle file',
229 validate: (pathToFile: string) =>
230 fs.existsSync(pathToFile) && pathToFile.includes('build.gradle')
231 ? true
232 : `${pathToFile} is not a valid build.gradle`,
233 },
234 ])) as { entry: string };
235 gradleBuildFile = path.resolve(result.entry);
236 }
237 progress.start('Adding haul to your build.gradle');
238 await delay(1000);
239 let project = fs.readFileSync(gradleBuildFile).toString();
240 const cliString = '"node_modules/@haul-bundler/cli/bin/haul.js"';
241
242 // Are we already integrated?
243 if (project.includes(cliString)) {
244 progress.info('Haul is already part of your build.gradle');
245 return;
246 }
247 project = project.replace(
248 /project\.ext\.react = \[\n(.+)\n\]/,
249 dedent`
250 project.ext.react = [
251 $1,
252 cliPath: ${cliString}
253 ]
254 `
255 );
256 fs.writeFileSync(gradleBuildFile, project);
257 progress.succeed('Added haul to your build.gradle');
258}
259
260function getRunScript(scriptName: string) {
261 return `yarn run ${scriptName}`;

Callers 1

handlerFunction · 0.85

Calls 2

delayFunction · 0.85
startMethod · 0.65

Tested by

no test coverage detected