Skip to content

Commit 469fd8e

Browse files
authored
Merge pull request #11 from badsyntax/sln-file
Generate script in new file
2 parents 78fd146 + eea82c8 commit 469fd8e

File tree

13 files changed

+81
-22
lines changed

13 files changed

+81
-22
lines changed

.vscode/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,13 @@
4545
"editor.defaultFormatter": "esbenp.prettier-vscode"
4646
},
4747
"cSpell.language": "en-GB",
48-
"cSpell.words": ["dbcontext", "efcore", "entityframework", "richardwillis"]
48+
"cSpell.words": [
49+
"color",
50+
"dbcontext",
51+
"efcore",
52+
"entityframework",
53+
"NLCR",
54+
"Pseudoterminal",
55+
"richardwillis"
56+
]
4957
}

.vscodeignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ src/**
66
.gitignore
77
.yarnrc
88
webpack.config.js
9-
vsc-extension-quickstart.md
109
**/tsconfig.json
1110
**/.eslintrc.json
1211
**/*.map
1312
**/*.ts
14-
**/.prettierrc.js
15-
**/.gitattributes
16-
**/.editorconfig
13+
.prettierrc.js
14+
.prettierignore
15+
.gitattributes
16+
.editorconfig
17+
.github/**
18+
images/**

src/actions/AddMigrationAction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export class AddMigrationAction extends TerminalAction {
3535
prompt: 'For example: MigrationName',
3636
});
3737
if (!migrationName) {
38-
return;
38+
return '';
3939
}
40-
await super.run({
40+
const output = await super.run({
4141
...this.params,
4242
migrationName,
4343
});
@@ -51,5 +51,6 @@ export class AddMigrationAction extends TerminalAction {
5151
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
5252
false,
5353
);
54+
return output;
5455
}
5556
}

src/actions/GenerateScriptAction.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as vscode from 'vscode';
2+
3+
import { extractDataFromStdOut } from '../cli/ef';
14
import { getCommandsConfig } from '../config/config';
25
import type { TerminalProvider } from '../terminal/TerminalProvider';
36
import { TerminalAction } from './TerminalAction';
@@ -19,4 +22,13 @@ export class GenerateScriptAction extends TerminalAction {
1922
workspaceRoot,
2023
);
2124
}
25+
26+
public async run() {
27+
const output = extractDataFromStdOut(await super.run());
28+
const uri = vscode.Uri.parse('ef-script:' + output);
29+
const doc = await vscode.workspace.openTextDocument(uri);
30+
await vscode.languages.setTextDocumentLanguage(doc, 'sql');
31+
await vscode.window.showTextDocument(doc, { preview: false });
32+
return output;
33+
}
2234
}

src/actions/IAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface IAction {
2-
run(): Promise<void>;
2+
run(): Promise<string>;
33
}

src/actions/RemoveMigrationAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class RemoveMigrationAction extends TerminalAction {
2828
}
2929

3030
public async run() {
31-
await super.run();
31+
const output = await super.run();
3232
const cacheId = DbContextTreeItem.getCacheId(
3333
this.workspaceRoot,
3434
this.project,
@@ -39,5 +39,6 @@ export class RemoveMigrationAction extends TerminalAction {
3939
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
4040
false,
4141
);
42+
return output;
4243
}
4344
}

src/actions/RunMigrationAction.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class RunMigrationAction extends TerminalAction {
2929
);
3030
}
3131

32-
public async run(params = this.params): Promise<void> {
33-
await super.run(params);
32+
public async run(params = this.params): Promise<string> {
33+
const output = await super.run(params);
3434

3535
const cacheId = DbContextTreeItem.getCacheId(
3636
this.workspaceRoot,
@@ -43,5 +43,7 @@ export class RunMigrationAction extends TerminalAction {
4343
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
4444
false,
4545
);
46+
47+
return output;
4648
}
4749
}

src/actions/TerminalAction.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export abstract class TerminalAction implements IAction {
99
private readonly workingFolder: string,
1010
) {}
1111

12-
public async run(params = this.params): Promise<void> {
12+
public async run(params = this.params): Promise<string> {
1313
const terminal = this.terminalProvider.provideTerminal();
14-
terminal.setCmdARgs(this.getInterpolatedArgs(params));
15-
await terminal.exec(this.workingFolder);
14+
terminal.setCmdARgs(
15+
this.getInterpolatedArgs(params).concat(['--prefix-output']),
16+
);
17+
return await terminal.exec(this.workingFolder);
1618
}
1719

1820
private getInterpolatedArgs(params = this.params) {

src/cli/ef.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ const execAsync = promisify(exec);
77
export function extractDataFromStdOut(output: string): string {
88
return output
99
.split(/\r\n|\r|\n/)
10-
.filter(line => line.startsWith('data:'))
11-
.map(line => line.replace('data:', '').trim())
12-
.join('');
10+
.filter(line => line.startsWith('data: '))
11+
.map(line => line.replace('data: ', ''))
12+
.join('\n');
13+
}
14+
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');
1320
}
1421

1522
export async function execEF(

src/commands/Command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export abstract class Command {
22
public static commandName: string;
3-
public run(): Promise<void> {
3+
public run(): Promise<void | string> {
44
throw new Error('Not implemented');
55
}
66
}

0 commit comments

Comments
 (0)