Skip to content

Commit 854936c

Browse files
authored
Merge pull request #12 from badsyntax/sln-file
Remove reliance on .sln file
2 parents 469fd8e + 91b9b6f commit 854936c

25 files changed

+161
-91
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
},
4747
"cSpell.language": "en-GB",
4848
"cSpell.words": [
49+
"ASPNETCORE",
4950
"color",
5051
"dbcontext",
5152
"efcore",

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,23 @@ A VS Code extension to manage Entity Framework migrations.
66

77
## Features
88

9-
![treeview](images/treeview-screenshot.png)
9+
![Entity Framework Migrations](images/treeview-screenshot.png)
1010

11-
- List dbContexts for all projects within a solution
11+
- List migrations by [DbContext](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext)
1212
- Add/remove/run/undo migrations
13+
- Export [DbContext](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext) as SQL script
1314

1415
## Requirements
1516

1617
- [dotnet sdk](https://dotnet.microsoft.com/download)
1718
- [efcore tools](https://learn.microsoft.com/en-us/ef/core/cli/dotnet)
18-
- A solution (`.sln`) file with projects
1919
- [Microsoft.EntityFrameworkCore.Design](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Design) must be installed in one of the projects
2020

2121
## Extension Settings
2222

2323
This extension contributes the following settings:
2424

25-
- `entityframework.env`: Custom environment vars, for example:
26-
```json
27-
{
28-
"entityframework.env": {
29-
"ASPNETCORE_ENVIRONMENT": "LocalDev",
30-
"TenantId": "12345"
31-
}
32-
}
33-
```
3425
- `entityframework.commands`: Custom commands, for example:
35-
3626
```json
3727
{
3828
"entityframework.commands": {
@@ -87,10 +77,24 @@ This extension contributes the following settings:
8777
}
8878
}
8979
```
80+
- `entityframework.env`: Custom environment variables, for example:
81+
```json
82+
{
83+
"entityframework.env": {
84+
"ASPNETCORE_ENVIRONMENT": "LocalDev",
85+
"TenantId": "12345"
86+
}
87+
}
88+
```
9089

9190
## Performance
9291

93-
The EF tools execute application code at design time to get information about the project, thus performance can be slow on large projects.
92+
The EF tools execute application code at design time to get information about the project, thus performance on large projects can be slow.
93+
94+
## Support
95+
96+
- 👉 [Submit a bug report](https://github.com/badsyntax/vscode-entity-framework/issues/new?assignees=badsyntax&labels=bug&template=bug_report.md&title=)
97+
- 👉 [Submit a feature request](https://github.com/badsyntax/vscode-entity-framework/issues/new?assignees=badsyntax&labels=enhancement&template=feature_request.md&title=)
9498

9599
## License
96100

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"Other"
3030
],
3131
"activationEvents": [
32-
"workspaceContains:**/*.sln"
32+
"workspaceContains:**/*.csproj"
3333
],
3434
"license": "SEE LICENSE IN LICENSE.md",
3535
"bugs": {

src/actions/GenerateScriptAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22

3-
import { extractDataFromStdOut } from '../cli/ef';
3+
import { getDataFromStdOut } from '../cli/ef';
44
import { getCommandsConfig } from '../config/config';
55
import type { TerminalProvider } from '../terminal/TerminalProvider';
66
import { TerminalAction } from './TerminalAction';
@@ -24,7 +24,7 @@ export class GenerateScriptAction extends TerminalAction {
2424
}
2525

2626
public async run() {
27-
const output = extractDataFromStdOut(await super.run());
27+
const output = getDataFromStdOut(await super.run());
2828
const uri = vscode.Uri.parse('ef-script:' + output);
2929
const doc = await vscode.workspace.openTextDocument(uri);
3030
await vscode.languages.setTextDocumentLanguage(doc, 'sql');

src/cli/ef.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@ import { promisify } from 'node:util';
33
import { getEnvConfig } from '../config/config';
44

55
const execAsync = promisify(exec);
6+
const NEWLINE_SEPARATOR = /\r\n|\r|\n/;
7+
const STDOUT_PREFIX = /^[a-z]+: /;
68

7-
export function extractDataFromStdOut(output: string): string {
9+
export function removePrefixFromStdOut(output: string): string {
810
return output
9-
.split(/\r\n|\r|\n/)
10-
.filter(line => line.startsWith('data: '))
11-
.map(line => line.replace('data: ', ''))
11+
.split(NEWLINE_SEPARATOR)
12+
.map(line => line.replace(STDOUT_PREFIX, ''))
1213
.join('\n');
1314
}
1415

15-
export function removePrefixFromStdOut(output: string): string {
16-
return output
17-
.split(/\r\n|\r|\n/)
18-
.map(line => line.replace(/^[a-z]+: /, ''))
19-
.join('\n');
16+
export function getDataFromStdOut(output: string): string {
17+
return removePrefixFromStdOut(
18+
output
19+
.split(NEWLINE_SEPARATOR)
20+
.filter(line => line.startsWith('data:'))
21+
.join('\n'),
22+
);
23+
}
24+
25+
export function getErrorsFromStdOut(output: string): string {
26+
return removePrefixFromStdOut(
27+
output
28+
.split(NEWLINE_SEPARATOR)
29+
.filter(line => line.startsWith('error:'))
30+
.join('\n'),
31+
);
2032
}
2133

2234
export async function execEF(

src/commands/AddMigrationCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class AddMigrationCommand extends Command {
1919
}
2020
return new AddMigrationAction(
2121
this.terminalProvider,
22-
this.item.solutionFile.workspaceRoot,
22+
this.item.workspaceRoot,
2323
this.item.label,
2424
this.item.project,
2525
).run();

src/commands/GenerateScriptCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class GenerateScriptCommand extends Command {
1919
}
2020
return new GenerateScriptAction(
2121
this.terminalProvider,
22-
this.item.solutionFile.workspaceRoot,
22+
this.item.workspaceRoot,
2323
this.item.label,
2424
this.item.project,
2525
).run();

src/commands/RemoveMigrationCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RemoveMigrationCommand extends Command {
1919
}
2020
return new RemoveMigrationAction(
2121
this.terminalProvider,
22-
this.item.solutionFile.workspaceRoot,
22+
this.item.workspaceRoot,
2323
this.item.dbContext,
2424
this.item.project,
2525
).run();

src/commands/RunMigrationCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RunMigrationCommand extends Command {
1919
}
2020
return new RunMigrationAction(
2121
this.terminalProvider,
22-
this.item.solutionFile.workspaceRoot,
22+
this.item.workspaceRoot,
2323
this.item.dbContext,
2424
this.item.project,
2525
this.item.migration.id,

src/commands/UndoMigrationCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class UndoMigrationCommand extends Command {
2222
return;
2323
}
2424
const cacheId = DbContextTreeItem.getCacheId(
25-
this.item.solutionFile.workspaceRoot,
25+
this.item.workspaceRoot,
2626
this.item.project,
2727
this.item.dbContext,
2828
);
@@ -33,7 +33,7 @@ export class UndoMigrationCommand extends Command {
3333
index === 0 ? '0' : migrations[index - 1].migration.id;
3434
return new RunMigrationAction(
3535
this.terminalProvider,
36-
this.item.solutionFile.workspaceRoot,
36+
this.item.workspaceRoot,
3737
this.item.dbContext,
3838
this.item.project,
3939
migrationId,

0 commit comments

Comments
 (0)