@@ -7,13 +7,16 @@ import {
77 ArgumentStrategy
88} from '../models/command' ;
99import { oneLine } from 'common-tags' ;
10- import { logging } from '@angular-devkit/core' ;
10+ import { logging , normalize , tags } from '@angular-devkit/core' ;
1111import { camelize } from '@angular-devkit/core/src/utils/strings' ;
12+ import { findUp } from '../utilities/find-up' ;
1213
1314import * as yargsParser from 'yargs-parser' ;
1415import * as fs from 'fs' ;
1516import { join } from 'path' ;
1617
18+ const SilentError = require ( 'silent-error' ) ;
19+
1720export interface CommandMap {
1821 [ key : string ] : CommandConstructor ;
1922}
@@ -204,7 +207,7 @@ function verifyCommandInScope(command: Command, scope = CommandScope.everywhere)
204207 } else {
205208 errorMessage = `This command can not be run inside of a CLI project.` ;
206209 }
207- throw new Error ( errorMessage ) ;
210+ throw new SilentError ( errorMessage ) ;
208211 }
209212 }
210213}
@@ -220,7 +223,30 @@ function verifyWorkspace(command: Command, executionScope: CommandScope, root: s
220223 if ( fs . existsSync ( join ( root , '.angular.json' ) ) ) {
221224 return ;
222225 }
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.' ) ;
224250 }
225251}
226252
@@ -233,7 +259,7 @@ async function runHelp(command: Command, options: any): Promise<void> {
233259async function validateAndRunCommand ( command : Command , options : any ) : Promise < any > {
234260 const isValid = await command . validate ( options ) ;
235261 if ( isValid !== undefined && ! isValid ) {
236- throw new Error ( `Validation error. Invalid command` ) ;
262+ throw new SilentError ( `Validation error. Invalid command` ) ;
237263 }
238264 return await command . run ( options ) ;
239265}
0 commit comments