Skip to content

Commit 88e519b

Browse files
filipesilvakieronqtran
authored andcommitted
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. Close angular#2739
1 parent 7c40811 commit 88e519b

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

packages/angular-cli/addon/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222
'serve': require('../commands/serve').default,
2323
'new': require('../commands/new').default,
2424
'generate': require('../commands/generate').default,
25+
'destroy': require('../commands/destroy').default,
2526
'init': require('../commands/init').default,
2627
'test': require('../commands/test').default,
2728
'e2e': require('../commands/e2e').default,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Command = require('ember-cli/lib/models/command');
2+
const SilentError = require('silent-error');
3+
4+
5+
const DestroyCommand = Command.extend({
6+
name: 'destroy',
7+
aliases: ['d'],
8+
works: 'insideProject',
9+
10+
anonymousOptions: [
11+
'<blueprint>'
12+
],
13+
14+
run: function() {
15+
return Promise.reject(new SilentError('The destroy command is not supported by Angular-CLI.'));
16+
}
17+
});
18+
19+
export default DestroyCommand;
20+
DestroyCommand.overrideCore = true;

packages/angular-cli/commands/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const lookupCommand = require('ember-cli/lib/cli/lookup-command');
77

88
const commandsToIgnore = [
99
'easter-egg',
10+
'destroy',
1011
'github-pages-deploy' // errors because there is no base github-pages command
1112
];
1213

tests/acceptance/destroy.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const ng = require('../helpers/ng');
4+
const tmp = require('../helpers/tmp');
5+
const conf = require('ember-cli/tests/helpers/conf');
6+
const SilentError = require('silent-error');
7+
const expect = require('chai').expect;
8+
9+
describe('Acceptance: ng destroy', function () {
10+
before(conf.setup);
11+
12+
after(conf.restore);
13+
14+
beforeEach(function () {
15+
this.timeout(10000);
16+
return tmp.setup('./tmp').then(function () {
17+
process.chdir('./tmp');
18+
}).then(function () {
19+
return ng(['new', 'foo', '--skip-npm', '--skip-bower']);
20+
});
21+
});
22+
23+
afterEach(function () {
24+
return tmp.teardown('./tmp');
25+
});
26+
27+
it('without args should fail', function () {
28+
return ng(['destroy']).then(() => {
29+
throw new SilentError('ng destroy should fail.');
30+
}, (err) => {
31+
expect(err.message).to.equal('The destroy command is not supported by Angular-CLI.');
32+
});
33+
});
34+
35+
it('with args should fail', function () {
36+
return ng(['destroy', 'something']).then(() => {
37+
throw new SilentError('ng destroy something should fail.');
38+
}, (err) => {
39+
expect(err.message).to.equal('The destroy command is not supported by Angular-CLI.');
40+
});
41+
});
42+
});

0 commit comments

Comments
 (0)