Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/doctor/src/sys-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,29 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
tempDirectory,
);
const xcodeProjectDir = path.join(tempDirectory, "cocoapods");

// If ADSF version manager is installed, get the config for the project directory and write it to the temporary project directory
const asdfResult = await this.childProcess.spawnFromEvent(
"asdf",
["list", "ruby"],
"exit",
);
const asdfVersionMatch = (asdfResult.stdout as string).match(
SysInfo.VERSION_REGEXP,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should set cwd since ns doctor can be run outside of project directories.


if (asdfVersionMatch?.[0]) {
const asdfVersion = asdfVersionMatch[0];
const asdfConfigPath = path.join(xcodeProjectDir, ".tool-versions");
const wroteASDFConfig = this.fileSystem.appendFile(
asdfConfigPath,
`ruby ${asdfVersion}`,
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (!wroteASDFConfig) {
console.warn(`Cocoapods invocation may fail, check asdf config`);
}
}

const spawnResult = await this.childProcess.spawnFromEvent(
"pod",
["install"],
Expand All @@ -432,6 +455,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);
Expand Down
15 changes: 13 additions & 2 deletions packages/doctor/src/wrappers/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
return new Promise((resolve, reject) => {
yauzl.open(
Expand Down Expand Up @@ -46,7 +57,7 @@ export class FileSystem {
zipFile.once("end", () => resolve());

zipFile.readEntry();
}
},
);
});
}
Expand All @@ -57,7 +68,7 @@ export class FileSystem {

public readJson<T>(
filePath: string,
options?: { encoding?: null; flag?: string }
options?: { encoding?: null; flag?: string },
): T {
const content = fs.readFileSync(filePath, options);
return JSON.parse(content.toString());
Expand Down