From 79c64bc893a6cca34e18e1932c43c5a8c1a3df03 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Mon, 17 Oct 2016 10:41:08 +0100 Subject: [PATCH] chore(commands): override ng destroy It's common for users to try and do `ng destroy component name` and have it only partially work. Since we don't support the command, it's better to not have it do any partial operations. --- packages/angular-cli/addon/index.js | 1 + packages/angular-cli/commands/destroy.ts | 20 +++++++++++ packages/angular-cli/commands/help.ts | 1 + tests/acceptance/destroy.spec.js | 42 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 packages/angular-cli/commands/destroy.ts create mode 100644 tests/acceptance/destroy.spec.js diff --git a/packages/angular-cli/addon/index.js b/packages/angular-cli/addon/index.js index 3a2d7abb1850..8b294f9a2718 100644 --- a/packages/angular-cli/addon/index.js +++ b/packages/angular-cli/addon/index.js @@ -22,6 +22,7 @@ module.exports = { 'serve': require('../commands/serve').default, 'new': require('../commands/new').default, 'generate': require('../commands/generate').default, + 'destroy': require('../commands/destroy').default, 'init': require('../commands/init').default, 'test': require('../commands/test').default, 'e2e': require('../commands/e2e').default, diff --git a/packages/angular-cli/commands/destroy.ts b/packages/angular-cli/commands/destroy.ts new file mode 100644 index 000000000000..fb1b5c30edf8 --- /dev/null +++ b/packages/angular-cli/commands/destroy.ts @@ -0,0 +1,20 @@ +const Command = require('ember-cli/lib/models/command'); +const SilentError = require('silent-error'); + + +const DestroyCommand = Command.extend({ + name: 'destroy', + aliases: ['d'], + works: 'insideProject', + + anonymousOptions: [ + '' + ], + + run: function() { + return Promise.reject(new SilentError('The destroy command is not supported by Angular-CLI.')); + } +}); + +export default DestroyCommand; +DestroyCommand.overrideCore = true; diff --git a/packages/angular-cli/commands/help.ts b/packages/angular-cli/commands/help.ts index c2a64771a183..7dd1412c295f 100644 --- a/packages/angular-cli/commands/help.ts +++ b/packages/angular-cli/commands/help.ts @@ -7,6 +7,7 @@ const lookupCommand = require('ember-cli/lib/cli/lookup-command'); const commandsToIgnore = [ 'easter-egg', + 'destroy', 'github-pages-deploy' // errors because there is no base github-pages command ]; diff --git a/tests/acceptance/destroy.spec.js b/tests/acceptance/destroy.spec.js new file mode 100644 index 000000000000..90230e8ee309 --- /dev/null +++ b/tests/acceptance/destroy.spec.js @@ -0,0 +1,42 @@ +'use strict'; + +const ng = require('../helpers/ng'); +const tmp = require('../helpers/tmp'); +const conf = require('ember-cli/tests/helpers/conf'); +const SilentError = require('silent-error'); +const expect = require('chai').expect; + +describe('Acceptance: ng destroy', function () { + before(conf.setup); + + after(conf.restore); + + beforeEach(function () { + this.timeout(10000); + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); + }); + + afterEach(function () { + return tmp.teardown('./tmp'); + }); + + it('without args should fail', function () { + return ng(['destroy']).then(() => { + throw new SilentError('ng destroy should fail.'); + }, (err) => { + expect(err.message).to.equal('The destroy command is not supported by Angular-CLI.'); + }); + }); + + it('with args should fail', function () { + return ng(['destroy', 'something']).then(() => { + throw new SilentError('ng destroy something should fail.'); + }, (err) => { + expect(err.message).to.equal('The destroy command is not supported by Angular-CLI.'); + }); + }); +});