From 73075b7235a2f2ed88cbbf5759aca0d1093c83c7 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 11 Apr 2018 15:21:59 -0700 Subject: [PATCH] fix(@angular/cli): on postinstall show a message if using an old version of CLI Fix #10258 --- .../@angular/cli/bin/ng-update-message.js | 43 +++++++++++++++++++ .../@angular/cli/models/command-runner.ts | 11 ++--- packages/@angular/cli/package.json | 3 ++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100755 packages/@angular/cli/bin/ng-update-message.js diff --git a/packages/@angular/cli/bin/ng-update-message.js b/packages/@angular/cli/bin/ng-update-message.js new file mode 100755 index 0000000000..2f135eccac --- /dev/null +++ b/packages/@angular/cli/bin/ng-update-message.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node +'use strict'; + +// Check if the current directory contains '.angular-cli.json'. If it does, show a message to the user that they +// should use the migration script. + +const fs = require('fs'); +const path = require('path'); + + +let found = false; +let current = path.dirname(path.dirname(__dirname)); +while (current !== path.dirname(current)) { + if (fs.existsSync(path.join(current, 'angular-cli.json')) + || fs.existsSync(path.join(current, '.angular-cli.json'))) { + found = true; + break; + } + if (fs.existsSync(path.join(current, 'angular.json')) + || fs.existsSync(path.join(current, '.angular.json')) + || fs.existsSync(path.join(current, 'package.json'))) { + break; + } + + current = path.dirname(current); +} + + +if (found) { + // ------------------------------------------------------------------------------------------ + // If changing this message, please update the same message in + // `packages/@angular/cli/models/command-runner.ts` + + // eslint-disable-next-line no-console + console.error(`\u001b[31m + ${'='.repeat(80)} + An old CLI configuration has been detected, which needs to be updated to the latest version. + + Please run the following command to update this workspace: + ng update @angular/cli --migrate-only --from=1 + ${'='.repeat(80)} + \u001b[39m`.replace(/^ {4}/gm, '')); +} diff --git a/packages/@angular/cli/models/command-runner.ts b/packages/@angular/cli/models/command-runner.ts index 67c101bdef..21fe83f129 100644 --- a/packages/@angular/cli/models/command-runner.ts +++ b/packages/@angular/cli/models/command-runner.ts @@ -298,13 +298,14 @@ function verifyWorkspace(command: Command, executionScope: CommandScope, root: s // If an old configuration file is found, throw an exception. if (oldConfigFilePath) { + // ------------------------------------------------------------------------------------------ + // If changing this message, please update the same message in + // `packages/@angular/cli/bin/ng-update-message.js` throw new SilentError(tags.stripIndent` - An old project has been detected, which needs to be updated to Angular CLI 6. + An old CLI configuration has been detected, which needs to be updated to the latest version. - Please run the following commands to update this project. - - ng update @angular/cli --migrate-only --from=1.7.1 - npm i + Please run the following command to update this workspace: + ng update @angular/cli --migrate-only --from=1 `); } diff --git a/packages/@angular/cli/package.json b/packages/@angular/cli/package.json index 719bb33aa9..1f47493182 100644 --- a/packages/@angular/cli/package.json +++ b/packages/@angular/cli/package.json @@ -12,6 +12,9 @@ "angular-cli", "Angular CLI" ], + "scripts": { + "postinstall": "node ./bin/ng-update-message.js" + }, "repository": { "type": "git", "url": "https://github.com/angular/angular-cli.git"