diff --git a/packages/doctor/src/sys-info.ts b/packages/doctor/src/sys-info.ts index 7c71d43491..4c8ebdc588 100644 --- a/packages/doctor/src/sys-info.ts +++ b/packages/doctor/src/sys-info.ts @@ -424,6 +424,38 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo { tempDirectory, ); const xcodeProjectDir = path.join(tempDirectory, "cocoapods"); + + // If asdf version manager is installed, get the current Ruby version for the project directory and write it to the temporary project directory + const asdfResult = await this.childProcess.spawnFromEvent( + "asdf", + ["current", "ruby"], + "exit", + { ignoreError: true }, + ); + + if (asdfResult.exitCode === 0) { + const asdfVersionMatch = (asdfResult.stdout as string).match( + SysInfo.VERSION_REGEXP, + ); + + if (asdfVersionMatch?.[0]) { + const asdfVersion = asdfVersionMatch[0]; + const asdfConfigPath = path.join( + xcodeProjectDir, + ".tool-versions", + ); + const wroteASDFConfig = this.fileSystem.appendFile( + asdfConfigPath, + `ruby ${asdfVersion}`, + ); + if (!wroteASDFConfig) { + console.warn( + `CocoaPods invocation may fail, check asdf config`, + ); + } + } + } + const spawnResult = await this.childProcess.spawnFromEvent( "pod", ["install"], @@ -432,6 +464,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo { ); return !spawnResult.exitCode; } catch (err) { + console.log(`Pod command failed - ${err}`); return false; } finally { this.fileSystem.deleteEntry(tempDirectory); diff --git a/packages/doctor/src/wrappers/file-system.ts b/packages/doctor/src/wrappers/file-system.ts index ac7a05ed95..759c826d0c 100644 --- a/packages/doctor/src/wrappers/file-system.ts +++ b/packages/doctor/src/wrappers/file-system.ts @@ -8,6 +8,17 @@ export class FileSystem { return fs.existsSync(path.resolve(filePath)); } + public appendFile(filePath: string, text: string): boolean { + let success = false; + try { + fs.appendFileSync(path.resolve(filePath), text); + success = true; + } catch (err) { + console.error(`appendFile failed with ${err}`); + } + return success; + } + public extractZip(pathToZip: string, outputDir: string): Promise { return new Promise((resolve, reject) => { yauzl.open( @@ -46,7 +57,7 @@ export class FileSystem { zipFile.once("end", () => resolve()); zipFile.readEntry(); - } + }, ); }); } @@ -57,7 +68,7 @@ export class FileSystem { public readJson( filePath: string, - options?: { encoding?: null; flag?: string } + options?: { encoding?: null; flag?: string }, ): T { const content = fs.readFileSync(filePath, options); return JSON.parse(content.toString());