@@ -7,13 +7,13 @@ import { runInTerminal } from 'run-in-terminal';
77let outputChannel : vscode . OutputChannel ;
88
99export function activate ( context : vscode . ExtensionContext ) {
10- registerCommands ( context ) ;
11- outputChannel = vscode . window . createOutputChannel ( 'ng' ) ;
12- context . subscriptions . push ( outputChannel ) ;
13- }
1410
15- function registerCommands ( context : vscode . ExtensionContext ) {
16- let child ;
11+ // registerCommands(context);
12+ // outputChannel = vscode.window.createOutputChannel('ng');
13+ // context.subscriptions.push(outputChannel);
14+ // }
15+
16+ // function registerCommands(context: vscode.ExtensionContext) {
1717
1818 let ngnew = vscode . commands . registerCommand ( 'extension.ngNew' , ( ) => {
1919 let project = vscode . window . showInputBox ( { placeHolder : 'name of your project' } ) . then (
@@ -32,7 +32,7 @@ function registerCommands(context: vscode.ExtensionContext) {
3232 } ) ;
3333
3434 let ngversion = vscode . commands . registerCommand ( 'extension.ngVersion' , ( ) => {
35- child = cp . exec ( 'ng version' ) ;
35+ let child = cp . exec ( 'ng version' ) ;
3636 child . stdout . on ( 'data' , ( data ) => {
3737 console . log ( data ) ;
3838 } ) ;
@@ -66,12 +66,25 @@ function registerCommands(context: vscode.ExtensionContext) {
6666 runNgCommand ( [ 'format' ] , true ) ;
6767 } ) ;
6868
69- // let nggenerate = vscode.commands.registerCommand('extension.ngGenerate', () => {
70- // child = cp.exec('ng generate');
71- // child.stdout.on('data', (data) => {
72- // vscode.window.showInformationMessage(data);
73- // });
74- // });
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+ // vscode.window.showInformationMessage(data);
75+ param . push ( data ) ;
76+ vscode . window . showInputBox ( { placeHolder : 'name of the ' + data } ) . then (
77+ ( name ) => {
78+ param . push ( name ) ;
79+ runNgCommand ( param , false ) ;
80+ }
81+ )
82+ } )
83+ } ) ;
84+
85+ let ngtest = vscode . commands . registerCommand ( 'extension.ngTest' , ( ) => {
86+ runNgCommand ( [ 'test' ] , false ) ;
87+ } ) ;
7588
7689 // let ngget = vscode.commands.registerCommand('extension.ngGet', () => {
7790 // child = cp.exec('ng get');
@@ -95,12 +108,6 @@ function registerCommands(context: vscode.ExtensionContext) {
95108 // });
96109
97110
98- // let ngtest = vscode.commands.registerCommand('extension.ngTest', () => {
99- // child = cp.exec('ng test');
100- // child.stdout.on('data', (data) => {
101- // vscode.window.showInformationMessage(data);
102- // });
103- // });
104111
105112 context . subscriptions . push ( ngnew ) ;
106113 context . subscriptions . push ( nginit ) ;
@@ -111,46 +118,46 @@ function registerCommands(context: vscode.ExtensionContext) {
111118 context . subscriptions . push ( ngformat ) ;
112119 context . subscriptions . push ( nge2e ) ;
113120 context . subscriptions . push ( ngcompletion ) ;
121+ context . subscriptions . push ( nggenerate ) ;
122+ context . subscriptions . push ( ngtest ) ;
114123
115- // context.subscriptions.push(nggenerate);
116- // context.subscriptions.push(ngget);
117- // context.subscriptions.push(ngset);
118- // context.subscriptions.push(ngdeploy);
119- // context.subscriptions.push(ngtest);
124+ // context.subscriptions.push(ngget);
125+ // context.subscriptions.push(ngset);
126+ // context.subscriptions.push(ngdeploy);
120127
121128
122- function runCommandInOutputWindow ( args : string [ ] , cwd : string ) {
123- let cmd = 'ng ' + args . join ( ' ' ) ;
124- let p = cp . exec ( cmd , { cwd : cwd , env : process . env } ) ;
125- p . stderr . on ( 'data' , ( data : string ) => {
126- outputChannel . append ( data ) ;
127- } ) ;
128- p . stdout . on ( 'data' , ( data : string ) => {
129- outputChannel . append ( data ) ;
130- } ) ;
131- showOutput ( ) ;
132- }
129+ outputChannel = vscode . window . createOutputChannel ( 'ng' ) ;
130+ context . subscriptions . push ( outputChannel ) ;
133131
134- function showOutput ( ) : void {
135- outputChannel . show ( vscode . ViewColumn . Three ) ;
136- }
132+ }
133+
134+ function runCommandInOutputWindow ( args : string [ ] , cwd : string ) {
135+ let cmd = 'ng ' + args . join ( ' ' ) ;
136+ let p = cp . exec ( cmd , { cwd : cwd , env : process . env } ) ;
137+ p . stderr . on ( 'data' , ( data : string ) => {
138+ outputChannel . append ( data ) ;
139+ } ) ;
140+ p . stdout . on ( 'data' , ( data : string ) => {
141+ outputChannel . append ( data ) ;
142+ } ) ;
143+ showOutput ( ) ;
144+ }
145+
146+ function showOutput ( ) : void {
147+ outputChannel . show ( vscode . ViewColumn . Three ) ;
148+ }
137149
138- function runNgCommand ( args : string [ ] , useTerminal ?: boolean ) : void {
150+ function runNgCommand ( args : string [ ] , useTerminal ?: boolean ) : void {
139151
140- let cwd = vscode . workspace . rootPath ;
152+ let cwd = vscode . workspace . rootPath ;
141153
142- if ( useTerminal ) {
143- runCommandInTerminal ( args , cwd ) ;
144- } else {
145- runCommandInOutputWindow ( args , cwd ) ;
146- }
147- }
148- function runCommandInTerminal ( args : string [ ] , cwd : string ) : void {
149- runInTerminal ( 'ng' , args , { cwd : cwd , env : process . env } ) ;
154+ if ( useTerminal ) {
155+ runCommandInTerminal ( args , cwd ) ;
156+ } else {
157+ runCommandInOutputWindow ( args , cwd ) ;
150158 }
151-
152159}
153160
154- // this method is called when your extension is deactivated
155- export function deactivate ( ) {
156- }
161+ function runCommandInTerminal ( args : string [ ] , cwd : string ) : void {
162+ runInTerminal ( 'ng' , args , { cwd : cwd , env : process . env } ) ;
163+ }
0 commit comments