-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d97f8ce
commit aae573a
Showing
4 changed files
with
53 additions
and
50 deletions.
There are no files selected for viewing
50 changes: 8 additions & 42 deletions
50
packages/vscode-extension/src/project/applicationContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,26 @@ | ||
import { Disposable, window } from "vscode"; | ||
import { BuildCache, migrateOldBuildCachesToNewStorage } from "../builders/BuildCache"; | ||
import { Disposable } from "vscode"; | ||
import { BuildCache } from "../builders/BuildCache"; | ||
import { DependencyManager } from "../dependency/DependencyManager"; | ||
import { Logger } from "../Logger"; | ||
import { LaunchConfigController } from "../panels/LaunchConfigController"; | ||
import { findAppRootFolder } from "../utilities/extensionContext"; | ||
import { Platform } from "../utilities/platform"; | ||
import { setupPathEnv } from "../utilities/subprocess"; | ||
import { disposeAll } from "../utilities/disposables"; | ||
|
||
export class ApplicationContext implements Disposable { | ||
public appRootFolder: string; | ||
public dependencyManager: DependencyManager; | ||
public launchConfig: LaunchConfigController; | ||
public buildCache: BuildCache; | ||
private disposables: Disposable[] = []; | ||
|
||
constructor() { | ||
const newAppRoot = findAppRootFolder(); | ||
if (!newAppRoot) { | ||
window.showErrorMessage( | ||
"Failed to determine any application root candidates, you can set it up manually in launch configuration", | ||
"Dismiss" | ||
); | ||
Logger.error("[Project] The application root could not be found."); | ||
throw Error( | ||
"Couldn't find app root folder. The extension should not be activated without reachable app root." | ||
); | ||
} | ||
constructor(public appRootFolder: string) { | ||
this.dependencyManager = new DependencyManager(appRootFolder); | ||
|
||
Logger.info(`Found app root folder: ${newAppRoot}`); | ||
migrateOldBuildCachesToNewStorage(newAppRoot); | ||
this.launchConfig = new LaunchConfigController(appRootFolder); | ||
|
||
this.appRootFolder = newAppRoot; | ||
|
||
if (Platform.OS === "macos") { | ||
try { | ||
setupPathEnv(newAppRoot); | ||
} catch (error) { | ||
window.showWarningMessage( | ||
"Error when setting up PATH environment variable, RN IDE may not work correctly.", | ||
"Dismiss" | ||
); | ||
} | ||
} | ||
|
||
this.dependencyManager = new DependencyManager(newAppRoot); | ||
|
||
this.launchConfig = new LaunchConfigController(newAppRoot); | ||
|
||
this.buildCache = new BuildCache(newAppRoot); | ||
this.buildCache = new BuildCache(appRootFolder); | ||
|
||
this.disposables.push(this.launchConfig, this.dependencyManager); | ||
} | ||
|
||
public dispose() { | ||
this.disposables.forEach((disposable) => { | ||
disposable.dispose(); | ||
}); | ||
disposeAll(this.disposables); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/vscode-extension/src/utilities/findAndSetupNewAppRootFolder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { window } from "vscode"; | ||
import { migrateOldBuildCachesToNewStorage } from "../builders/BuildCache"; | ||
import { Logger } from "../Logger"; | ||
import { findAppRootFolder } from "./extensionContext"; | ||
import { Platform } from "./platform"; | ||
import { setupPathEnv } from "./subprocess"; | ||
|
||
export function findAndSetupNewAppRootFolder() { | ||
const newAppRoot = findAppRootFolder(); | ||
if (!newAppRoot) { | ||
window.showErrorMessage( | ||
"Failed to determine any application root candidates, you can set it up manually in launch configuration", | ||
"Dismiss" | ||
); | ||
Logger.error("[Project] The application root could not be found."); | ||
throw Error( | ||
"Couldn't find app root folder. The extension should not be activated without reachable app root." | ||
); | ||
} | ||
|
||
Logger.info(`Found app root folder: ${newAppRoot}`); | ||
migrateOldBuildCachesToNewStorage(newAppRoot); | ||
|
||
if (Platform.OS === "macos") { | ||
try { | ||
setupPathEnv(newAppRoot); | ||
} catch (error) { | ||
window.showWarningMessage( | ||
"Error when setting up PATH environment variable, RN IDE may not work correctly.", | ||
"Dismiss" | ||
); | ||
} | ||
} | ||
return newAppRoot; | ||
} |