-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add a generator for dotnet restore
Add a generator to restore packages and tools for builders to use
- Loading branch information
Ben Callaghan
committed
May 18, 2021
1 parent
6ab5d4a
commit 96082a1
Showing
5 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
|
||
import { prompt } from 'inquirer'; | ||
|
||
import { updateConfig, getNxDotnetProjects } from '@nx-dotnet/utils'; | ||
|
||
import generator from './generator'; | ||
|
||
import PromptUI = require('inquirer/lib/ui/prompt'); | ||
|
||
jest.mock('../../../../dotnet/src/lib/core/dotnet.client'); | ||
jest.mock('../../../../utils/src/lib/utility-functions/workspace'); | ||
jest.mock('inquirer'); | ||
|
||
describe('restore generator', () => { | ||
let appTree: Tree; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace(); | ||
updateConfig(appTree, { nugetPackages: {} }); | ||
|
||
(prompt as jest.MockedFunction<typeof prompt>) | ||
.mockReset() | ||
.mockImplementation((async () => { | ||
return {}; | ||
}) as () => Promise<unknown> & { ui: PromptUI }); | ||
|
||
(getNxDotnetProjects as jest.MockedFunction<typeof getNxDotnetProjects>) | ||
.mockReset() | ||
.mockImplementation(() => new Map()); | ||
}); | ||
|
||
it('should run successfully', async () => { | ||
await generator(appTree); | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
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,21 @@ | ||
import { Tree } from '@nrwl/devkit'; | ||
import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet'; | ||
import { | ||
getNxDotnetProjects, | ||
getProjectFilesForProject, | ||
} from '@nx-dotnet/utils'; | ||
|
||
export default async function ( | ||
host: Tree, | ||
dotnetClient = new DotNetClient(dotnetFactory()), | ||
) { | ||
const projects = getNxDotnetProjects(host); | ||
for (const project of projects.values()) { | ||
const projectFiles = getProjectFilesForProject(host, project); | ||
for (const file of projectFiles) { | ||
dotnetClient.restorePackages(file); | ||
} | ||
} | ||
|
||
dotnetClient.restoreTools(); | ||
} |
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,9 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"id": "Restore", | ||
"title": "", | ||
"type": "object", | ||
"description": "Restores NuGet packages and .NET tools used by the workspace.", | ||
"properties": {} | ||
} |
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