Skip to content
Open
Changes from all 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
53 changes: 32 additions & 21 deletions src/extension/exponent/exponentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/// <reference path="exponentHelper.d.ts" />

import * as path from "path";
import * as fs from "fs";
import * as semver from "semver";
import * as vscode from "vscode";
import { sync as globSync } from "glob";
Expand Down Expand Up @@ -40,13 +39,26 @@ const DBL_SLASHES = /\\/g;

const NGROK_PACKAGE = "@expo/ngrok";

interface ExpoAppConfig {
expo?: {
owner?: string;
name?: string;
extra?: {
eas?: {
projectId?: string;
};
};
};
}

export class ExponentHelper {
private workspaceRootPath: string;
private projectRootPath: string;
private fs: FileSystem;
private hasInitialized: boolean;
private nodeModulesGlobalPathAddedToEnv: boolean;
private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
private appConfigCache?: { mtimeMs: number; config: ExpoAppConfig };

public constructor(
workspaceRootPath: string,
Expand Down Expand Up @@ -507,34 +519,33 @@ require('${entryPoint}');`;
}

public async getExpoEasProjectOwner(): Promise<string | null> {
const appJsonPath = this.pathToFileInWorkspace(APP_JSON);
try {
return JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.owner == undefined
? null
: JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.owner;
} catch {
return null;
}
const config = await this.getAppJsonConfig();
return config?.expo?.owner ?? null;
}

public async getExpoEasProjectId(): Promise<string | null> {
const appJsonPath = this.pathToFileInWorkspace(APP_JSON);
try {
return JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.extra.eas.projectId ==
undefined
? null
: JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.extra.eas.projectId;
} catch {
return null;
}
const config = await this.getAppJsonConfig();
return config?.expo?.extra?.eas?.projectId ?? null;
}

public async getExpoEasProjectName(): Promise<string | null> {
const config = await this.getAppJsonConfig();
return config?.expo?.name ?? null;
}

private async getAppJsonConfig(): Promise<ExpoAppConfig | null> {
const appJsonPath = this.pathToFileInWorkspace(APP_JSON);
try {
return JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.name == undefined
? null
: JSON.parse(fs.readFileSync(appJsonPath, "utf-8")).expo.name;
const { mtimeMs } = await this.fs.stat(appJsonPath);
if (this.appConfigCache?.mtimeMs === mtimeMs) {
return this.appConfigCache.config;
}

const config = JSON.parse(
(await this.fs.readFile(appJsonPath, "utf-8")).toString(),
) as ExpoAppConfig;
this.appConfigCache = { mtimeMs, config };
return config;
} catch {
return null;
}
Expand Down