Skip to content

Commit 5bc4aec

Browse files
committed
seperate commands in files
1 parent 1f5ac0b commit 5bc4aec

File tree

17 files changed

+231
-129
lines changed

17 files changed

+231
-129
lines changed

src/extension.ts

Lines changed: 22 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
'use strict';
22

33
import * as vscode from 'vscode';
4-
import * as cp from 'child_process';
5-
import { runInTerminal } from 'run-in-terminal';
4+
5+
import { runNgCommand } from './ng/run';
6+
import { ngnew } from './ng/new';
7+
import { nginit } from './ng/init';
8+
import { ngversion } from './ng/version';
9+
import { ngserve } from './ng/serve';
10+
import { ngdoc } from './ng/doc';
11+
import { nglint } from './ng/lint';
12+
import { ngcompletion } from './ng/completion';
13+
import { nge2e } from './ng/e2e';
14+
import { ngformat } from './ng/format';
15+
import { ngtest } from './ng/test';
16+
import { nggenerate } from './ng/generate';
17+
import { nghelp } from './ng/help';
18+
19+
// import { ngset } from './ng/set';
20+
// import { ngdeploy } from './ng/deploy';
21+
// import { ngget } from './ng/get';
622

723
let outputChannel: vscode.OutputChannel;
824

@@ -15,99 +31,6 @@ export function activate(context: vscode.ExtensionContext) {
1531

1632
function registerCommands(context: vscode.ExtensionContext) {
1733

18-
let ngnew = vscode.commands.registerCommand('extension.ngNew', () => {
19-
let project = vscode.window.showInputBox({ placeHolder: 'name of your project' }).then(
20-
(data) => {
21-
runNgCommand(['new', data], true);
22-
}
23-
)
24-
});
25-
26-
let nginit = vscode.commands.registerCommand('extension.ngInit', () => {
27-
let project = vscode.window.showInputBox({ placeHolder: 'name of your project' }).then(
28-
(data) => {
29-
runNgCommand(['init', data], true);
30-
}
31-
)
32-
});
33-
34-
let ngversion = vscode.commands.registerCommand('extension.ngVersion', () => {
35-
let child = cp.exec('ng version');
36-
child.stdout.on('data', (data) => {
37-
console.log(data);
38-
});
39-
});
40-
41-
let ngserve = vscode.commands.registerCommand('extension.ngServe', () => {
42-
runNgCommand(['serve'], true);
43-
});
44-
45-
let ngdoc = vscode.commands.registerCommand('extension.ngDoc', () => {
46-
vscode.window.showInputBox({ placeHolder: 'search for' }).then(
47-
(data) => {
48-
runNgCommand(['doc', data], false);
49-
}
50-
)
51-
});
52-
53-
let nglint = vscode.commands.registerCommand('extension.ngLint', () => {
54-
runNgCommand(['lint'], true);
55-
});
56-
57-
let ngcompletion = vscode.commands.registerCommand('extension.ngCompletion', () => {
58-
runNgCommand(['completion'], false);
59-
});
60-
61-
let nge2e = vscode.commands.registerCommand('extension.ngE2e', () => {
62-
runNgCommand(['e2e'], true);
63-
});
64-
65-
let ngformat = vscode.commands.registerCommand('extension.ngFormat', () => {
66-
runNgCommand(['format'], true);
67-
});
68-
69-
let nggenerate = vscode.commands.registerCommand('extension.ngGenerate', () => {
70-
let param: string[] = ['generate']
71-
let items = ['component', 'directive', 'route', 'pipe', 'service'];
72-
let options = { matchOnDescription: false, placeHolder: "select Type" };
73-
vscode.window.showQuickPick(items, options).then((data) => {
74-
param.push(data);
75-
vscode.window.showInputBox({ placeHolder: 'name of the ' + data }).then(
76-
(name) => {
77-
param.push(name);
78-
runNgCommand(param, false);
79-
}
80-
)
81-
})
82-
});
83-
84-
let ngtest = vscode.commands.registerCommand('extension.ngTest', () => {
85-
runNgCommand(['test'], false);
86-
});
87-
88-
// let ngget = vscode.commands.registerCommand('extension.ngGet', () => {
89-
// child = cp.exec('ng get');
90-
// child.stdout.on('data', (data) => {
91-
// vscode.window.showInformationMessage(data);
92-
// });
93-
// });
94-
95-
// let ngset = vscode.commands.registerCommand('extension.ngSet', () => {
96-
// child = cp.exec('ng set');
97-
// child.stdout.on('data', (data) => {
98-
// vscode.window.showInformationMessage(data);
99-
// });
100-
// });
101-
102-
// let ngdeploy = vscode.commands.registerCommand('extension.ngDeploy', () => {
103-
// child = cp.exec('ng github-pages:deploy');
104-
// child.stdout.on('data', (data) => {
105-
// vscode.window.showInformationMessage(data);
106-
// });
107-
// });
108-
109-
110-
11134
context.subscriptions.push(ngnew);
11235
context.subscriptions.push(nginit);
11336
context.subscriptions.push(ngversion);
@@ -119,40 +42,10 @@ function registerCommands(context: vscode.ExtensionContext) {
11942
context.subscriptions.push(ngcompletion);
12043
context.subscriptions.push(nggenerate);
12144
context.subscriptions.push(ngtest);
45+
context.subscriptions.push(nghelp);
12246

123-
// context.subscriptions.push(ngget);
124-
// context.subscriptions.push(ngset);
125-
// context.subscriptions.push(ngdeploy);
126-
127-
}
128-
129-
function runCommandInOutputWindow(args: string[], cwd: string) {
130-
let cmd = 'ng ' + args.join(' ');
131-
let p = cp.exec(cmd, { cwd: cwd, env: process.env });
132-
p.stderr.on('data', (data: string) => {
133-
outputChannel.append(data);
134-
});
135-
p.stdout.on('data', (data: string) => {
136-
outputChannel.append(data);
137-
});
138-
showOutput();
139-
}
140-
141-
function showOutput(): void {
142-
outputChannel.show(vscode.ViewColumn.Three);
143-
}
144-
145-
function runNgCommand(args: string[], useTerminal?: boolean): void {
146-
147-
let cwd = vscode.workspace.rootPath;
148-
149-
if (useTerminal) {
150-
runCommandInTerminal(args, cwd);
151-
} else {
152-
runCommandInOutputWindow(args, cwd);
153-
}
154-
}
47+
// context.subscriptions.push(ngset);
48+
// context.subscriptions.push(ngget);
49+
// context.subscriptions.push(ngdeploy);
15550

156-
function runCommandInTerminal(args: string[], cwd: string): void {
157-
runInTerminal('ng', args, { cwd: cwd, env: process.env });
15851
}

src/ng/completion.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var ngcompletion = vscode.commands.registerCommand('extension.ngCompletion', () => {
7+
runNgCommand(['completion'], false);
8+
});

src/ng/deploy.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import * as cp from 'child_process';
5+
6+
export var ngdeploy = vscode.commands.registerCommand('extension.ngDeploy', () => {
7+
let child = cp.exec('ng github-pages:deploy');
8+
child.stdout.on('data', (data) => {
9+
vscode.window.showInformationMessage(data);
10+
});
11+
});

src/ng/doc.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var ngdoc = vscode.commands.registerCommand('extension.ngDoc', () => {
7+
vscode.window.showInputBox({ placeHolder: 'search for' }).then(
8+
(data) => {
9+
runNgCommand(['doc', data], false);
10+
}
11+
)
12+
});

src/ng/e2e.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var nge2e = vscode.commands.registerCommand('extension.ngE2e', () => {
7+
runNgCommand(['e2e'], true);
8+
});

src/ng/format.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var ngformat = vscode.commands.registerCommand('extension.ngFormat', () => {
7+
runNgCommand(['format'], true);
8+
});

src/ng/generate.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run';
5+
6+
export var nggenerate = vscode.commands.registerCommand('extension.ngGenerate', () => {
7+
let param: string[] = ['generate']
8+
let items = ['component', 'directive', 'route', 'pipe', 'service'];
9+
let options = { matchOnDescription: false, placeHolder: "select Type" };
10+
vscode.window.showQuickPick(items, options).then((data) => {
11+
param.push(data);
12+
vscode.window.showInputBox({ placeHolder: 'name of the ' + data }).then(
13+
(name) => {
14+
param.push(name);
15+
runNgCommand(param, true);
16+
}
17+
)
18+
})
19+
});

src/ng/get.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import * as cp from 'child_process';
5+
6+
export var ngget = vscode.commands.registerCommand('extension.ngGet', () => {
7+
vscode.window.showInputBox({ placeHolder: 'name of the Parameter' }).then(
8+
(name) => {
9+
let child = cp.exec('ng get ' + name);
10+
child.stdout.on('data', (data) => {
11+
console.log('data', data);
12+
vscode.window.showInformationMessage(data);
13+
});
14+
}
15+
);
16+
});

src/ng/help.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var nghelp = vscode.commands.registerCommand('extension.ngHelp', () => {
7+
let param: string[] = ['help']
8+
runNgCommand(param, true);
9+
});

src/ng/init.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { runNgCommand } from './run'
5+
6+
export var nginit = vscode.commands.registerCommand('extension.ngInit', () => {
7+
let project = vscode.window.showInputBox({ placeHolder: 'any options?' }).then(
8+
(data) => {
9+
runNgCommand(['init', data], true);
10+
}
11+
)
12+
});

0 commit comments

Comments
 (0)