@@ -11,6 +11,8 @@ import { logging } from '@angular-devkit/core';
11
11
import { camelize } from '@angular-devkit/core/src/utils/strings' ;
12
12
13
13
import * as yargsParser from 'yargs-parser' ;
14
+ import * as fs from 'fs' ;
15
+ import { join } from 'path' ;
14
16
15
17
export interface CommandMap {
16
18
[ key : string ] : CommandConstructor ;
@@ -74,6 +76,7 @@ export async function runCommand(commandMap: CommandMap,
74
76
return await runHelp ( command , options ) ;
75
77
} else {
76
78
verifyCommandInScope ( command , executionScope ) ;
79
+ verifyWorkspace ( command , executionScope , context . project . root ) ;
77
80
delete options . h ;
78
81
delete options . help ;
79
82
return await validateAndRunCommand ( command , options ) ;
@@ -204,6 +207,21 @@ function verifyCommandInScope(command: Command, scope = CommandScope.everywhere)
204
207
}
205
208
}
206
209
210
+ function verifyWorkspace ( command : Command , executionScope : CommandScope , root : string ) : void {
211
+ if ( command . scope === CommandScope . everywhere ) {
212
+ return ;
213
+ }
214
+ if ( executionScope === CommandScope . inProject ) {
215
+ if ( fs . existsSync ( join ( root , 'angular.json' ) ) ) {
216
+ return ;
217
+ }
218
+ if ( fs . existsSync ( join ( root , '.angular.json' ) ) ) {
219
+ return ;
220
+ }
221
+ throw new Error ( 'Invalid project: missing workspace file.' ) ;
222
+ }
223
+ }
224
+
207
225
// Execute a command's `printHelp`.
208
226
async function runHelp ( command : Command , options : any ) : Promise < void > {
209
227
return await command . printHelp ( options ) ;
0 commit comments