forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(misc): add watch mode to dep-graph command (nrwl#6043)
- Loading branch information
1 parent
377fca4
commit 98ac32e
Showing
42 changed files
with
4,742 additions
and
77,967 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
dep-graph/dep-graph/src/app/fetch-project-graph-service.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,20 @@ | ||
import { DepGraphClientResponse } from '@nrwl/workspace'; | ||
import { ProjectGraphService } from './models'; | ||
|
||
export class FetchProjectGraphService implements ProjectGraphService { | ||
async getHash(): Promise<string> { | ||
const request = new Request('currentHash', { mode: 'no-cors' }); | ||
|
||
const response = await fetch(request); | ||
|
||
return response.json(); | ||
} | ||
|
||
async getProjectGraph(url: string): Promise<DepGraphClientResponse> { | ||
const request = new Request(url, { mode: 'no-cors' }); | ||
|
||
const response = await fetch(request); | ||
|
||
return response.json(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
dep-graph/dep-graph/src/app/local-project-graph-service.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,12 @@ | ||
import { DepGraphClientResponse } from '@nrwl/workspace'; | ||
import { ProjectGraphService } from './models'; | ||
|
||
export class LocalProjectGraphService implements ProjectGraphService { | ||
async getHash(): Promise<string> { | ||
return new Promise((resolve) => resolve('some-hash')); | ||
} | ||
|
||
async getProjectGraph(url: string): Promise<DepGraphClientResponse> { | ||
return new Promise((resolve) => resolve(window.projectGraphResponse)); | ||
} | ||
} |
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,94 @@ | ||
import { ProjectGraphDependency } from '@nrwl/devkit'; | ||
import { DepGraphClientProject, DepGraphClientResponse } from '@nrwl/workspace'; | ||
import { ProjectGraphService } from '../app/models'; | ||
|
||
export class MockProjectGraphService implements ProjectGraphService { | ||
private response: DepGraphClientResponse = { | ||
hash: '79054025255fb1a26e4bc422aef54eb4', | ||
layout: { | ||
appsDir: 'apps', | ||
libsDir: 'libs', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'existing-app-1', | ||
type: 'app', | ||
data: { | ||
root: 'apps/app1', | ||
tags: [], | ||
}, | ||
}, | ||
{ | ||
name: 'existing-lib-1', | ||
type: 'lib', | ||
data: { | ||
root: 'libs/lib1', | ||
tags: [], | ||
}, | ||
}, | ||
], | ||
dependencies: { | ||
'existing-app-1': [ | ||
{ | ||
source: 'existing-app-1', | ||
target: 'existing-lib-1', | ||
type: 'statis', | ||
}, | ||
], | ||
'existing-lib-1': [], | ||
}, | ||
changes: { | ||
added: [], | ||
}, | ||
affected: [], | ||
focus: null, | ||
exclude: [], | ||
groupByFolder: false, | ||
}; | ||
|
||
constructor(updateFrequency: number = 7500) { | ||
setInterval(() => this.updateResponse(), updateFrequency); | ||
} | ||
|
||
async getHash(): Promise<string> { | ||
return new Promise((resolve) => resolve(this.response.hash)); | ||
} | ||
|
||
getProjectGraph(url: string): Promise<DepGraphClientResponse> { | ||
return new Promise((resolve) => resolve(this.response)); | ||
} | ||
|
||
private createNewProject(): DepGraphClientProject { | ||
const type = Math.random() > 0.25 ? 'lib' : 'app'; | ||
const name = `${type}-${this.response.projects.length + 1}`; | ||
|
||
return { | ||
name, | ||
type, | ||
data: { | ||
root: type === 'app' ? `apps/${name}` : `libs/${name}`, | ||
tags: [], | ||
}, | ||
}; | ||
} | ||
|
||
private updateResponse() { | ||
const newProject = this.createNewProject(); | ||
const libProjects = this.response.projects.filter( | ||
(project) => project.type === 'lib' | ||
); | ||
|
||
const targetDependency = | ||
libProjects[Math.floor(Math.random() * libProjects.length)]; | ||
const newDependency: ProjectGraphDependency[] = [ | ||
{ | ||
source: newProject.name, | ||
target: targetDependency.name, | ||
type: 'static', | ||
}, | ||
]; | ||
this.response.projects.push(newProject); | ||
this.response.dependencies[newProject.name] = newDependency; | ||
this.response.changes.added.push(newProject.name); | ||
} | ||
} |
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,13 +1,35 @@ | ||
import { ProjectGraphCache } from '@nrwl/workspace'; | ||
import { DepGraphClientResponse } from '@nrwl/workspace'; | ||
|
||
export interface ProjectGraphList { | ||
id: string; | ||
label: string; | ||
graph: ProjectGraphCache; | ||
workspaceLayout: WorkspaceLayout; | ||
url: string; | ||
} | ||
|
||
export interface WorkspaceLayout { | ||
libsDir: string; | ||
appsDir: string; | ||
} | ||
|
||
export interface ProjectGraphService { | ||
getHash: () => Promise<string>; | ||
getProjectGraph: (url: string) => Promise<DepGraphClientResponse>; | ||
} | ||
export interface Environment { | ||
environment: 'dev' | 'dev-watch' | 'release'; | ||
appConfig: AppConfig; | ||
} | ||
|
||
export interface AppConfig { | ||
showDebugger: boolean; | ||
projectGraphs: ProjectGraphList[]; | ||
defaultProjectGraph: string; | ||
projectGraphService: ProjectGraphService; | ||
} | ||
|
||
export const DEFAULT_CONFIG: AppConfig = { | ||
showDebugger: false, | ||
projectGraphs: [], | ||
defaultProjectGraph: null, | ||
projectGraphService: null, | ||
}; |
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
Oops, something went wrong.