Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 308e4cd

Browse files
committed
Fix(state): state reset --plugins|--platforms was resetting both
fixes ionic-team/ionic-cli#399
1 parent 0d24e15 commit 308e4cd

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

lib/state.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,15 @@ State.checkAndSaveConfigXml = function checkAndSaveConfigXml(appDirectory, plugi
799799
State.resetState = function resetState(appDirectory, options) {
800800
var platformPath = path.join(appDirectory, 'platforms');
801801
var pluginPath = path.join(appDirectory, 'plugins');
802-
shelljs.rm('-rf', [platformPath, pluginPath]);
803-
logging.logger.info('Removed platforms and plugins'.blue.bold);
802+
var noOptions = !options.platforms && !options.plugins;
803+
if (options.platforms || noOptions) {
804+
shelljs.rm('-rf', [platformPath]);
805+
logging.logger.info('Removed platforms'.blue.bold);
806+
}
807+
if (options.plugins || noOptions) {
808+
shelljs.rm('-rf', [pluginPath]);
809+
logging.logger.info('Removed plugins'.blue.bold);
810+
}
804811
State.restoreState(appDirectory, options)
805812
.then(function() {
806813
logging.logger.info('Ionic reset state complete'.green.bold);

spec/state.spec.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,63 @@ describe('State', function() {
367367
});
368368

369369
describe('#resetState', function() {
370-
it('should call call rm on the platforms path', function() {
370+
it('should call call rm on the platforms ands plugins paths by default', function() {
371371
spyOn(shelljs, 'rm');
372372
spyOn(State, 'restoreState').andReturn(Q());
373373
State.resetState(tempDirectory, {});
374374

375375
var platformPath = path.join(tempDirectory, 'platforms');
376376
var pluginPath = path.join(tempDirectory, 'plugins');
377-
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath, pluginPath]);
377+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
378+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
378379
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {});
379380
});
381+
382+
it('should call call rm on the platforms ands plugins path if both passed', function() {
383+
spyOn(shelljs, 'rm');
384+
spyOn(State, 'restoreState').andReturn(Q());
385+
State.resetState(tempDirectory, {
386+
platforms: true,
387+
plugins: true
388+
});
389+
390+
var platformPath = path.join(tempDirectory, 'platforms');
391+
var pluginPath = path.join(tempDirectory, 'plugins');
392+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
393+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
394+
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
395+
platforms: true,
396+
plugins: true
397+
});
398+
});
399+
400+
it('should call call rm only on the platforms path if passed explicitly', function() {
401+
spyOn(shelljs, 'rm');
402+
spyOn(State, 'restoreState').andReturn(Q());
403+
State.resetState(tempDirectory, {
404+
platforms: true
405+
});
406+
407+
var platformPath = path.join(tempDirectory, 'platforms');
408+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
409+
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
410+
platforms: true
411+
});
412+
});
413+
414+
it('should call call rm only on the plugins path if passed explicitly', function() {
415+
spyOn(shelljs, 'rm');
416+
spyOn(State, 'restoreState').andReturn(Q());
417+
State.resetState(tempDirectory, {
418+
plugins: true
419+
});
420+
421+
var pluginPath = path.join(tempDirectory, 'plugins');
422+
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
423+
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
424+
plugins: true
425+
});
426+
});
380427
});
381428

382429
describe('#restorePlugins', function(){

0 commit comments

Comments
 (0)