@@ -7,13 +7,16 @@ import {
7
7
ArgumentStrategy
8
8
} from '../models/command' ;
9
9
import { oneLine } from 'common-tags' ;
10
- import { logging } from '@angular-devkit/core' ;
10
+ import { logging , normalize , tags } from '@angular-devkit/core' ;
11
11
import { camelize } from '@angular-devkit/core/src/utils/strings' ;
12
+ import { findUp } from '../utilities/find-up' ;
12
13
13
14
import * as yargsParser from 'yargs-parser' ;
14
15
import * as fs from 'fs' ;
15
16
import { join } from 'path' ;
16
17
18
+ const SilentError = require ( 'silent-error' ) ;
19
+
17
20
export interface CommandMap {
18
21
[ key : string ] : CommandConstructor ;
19
22
}
@@ -204,7 +207,7 @@ function verifyCommandInScope(command: Command, scope = CommandScope.everywhere)
204
207
} else {
205
208
errorMessage = `This command can not be run inside of a CLI project.` ;
206
209
}
207
- throw new Error ( errorMessage ) ;
210
+ throw new SilentError ( errorMessage ) ;
208
211
}
209
212
}
210
213
}
@@ -220,7 +223,30 @@ function verifyWorkspace(command: Command, executionScope: CommandScope, root: s
220
223
if ( fs . existsSync ( join ( root , '.angular.json' ) ) ) {
221
224
return ;
222
225
}
223
- throw new Error ( 'Invalid project: missing workspace file.' ) ;
226
+
227
+ // Check if there's an old config file meaning that the project has not been updated
228
+ const oldConfigFileNames = [
229
+ normalize ( '.angular-cli.json' ) ,
230
+ normalize ( 'angular-cli.json' ) ,
231
+ ] ;
232
+ const oldConfigFilePath = ( root && findUp ( oldConfigFileNames , root , true ) )
233
+ || findUp ( oldConfigFileNames , process . cwd ( ) , true )
234
+ || findUp ( oldConfigFileNames , __dirname , true ) ;
235
+
236
+ // If an old configuration file is found, throw an exception.
237
+ if ( oldConfigFilePath ) {
238
+ throw new SilentError ( tags . stripIndent `
239
+ An old project has been detected, which needs to be updated to Angular CLI 6.
240
+
241
+ Please run the following commands to update this project.
242
+
243
+ ng update @angular/cli --migrate-only --from=1.7.1
244
+ npm i
245
+ ` ) ;
246
+ }
247
+
248
+ // If no configuration file is found (old or new), throw an exception.
249
+ throw new SilentError ( 'Invalid project: missing workspace file.' ) ;
224
250
}
225
251
}
226
252
@@ -233,7 +259,7 @@ async function runHelp(command: Command, options: any): Promise<void> {
233
259
async function validateAndRunCommand ( command : Command , options : any ) : Promise < any > {
234
260
const isValid = await command . validate ( options ) ;
235
261
if ( isValid !== undefined && ! isValid ) {
236
- throw new Error ( `Validation error. Invalid command` ) ;
262
+ throw new SilentError ( `Validation error. Invalid command` ) ;
237
263
}
238
264
return await command . run ( options ) ;
239
265
}
0 commit comments