From 308e4cd0581d2f788b97c6f2da87ea9e0617c8f3 Mon Sep 17 00:00:00 2001 From: jakub-g Date: Wed, 17 Feb 2016 13:45:09 +0100 Subject: [PATCH] Fix(state): state reset --plugins|--platforms was resetting both fixes https://github.com/driftyco/ionic-cli/issues/399 --- lib/state.js | 11 ++++++++-- spec/state.spec.js | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/lib/state.js b/lib/state.js index b21ca63..ccde68b 100644 --- a/lib/state.js +++ b/lib/state.js @@ -799,8 +799,15 @@ State.checkAndSaveConfigXml = function checkAndSaveConfigXml(appDirectory, plugi State.resetState = function resetState(appDirectory, options) { var platformPath = path.join(appDirectory, 'platforms'); var pluginPath = path.join(appDirectory, 'plugins'); - shelljs.rm('-rf', [platformPath, pluginPath]); - logging.logger.info('Removed platforms and plugins'.blue.bold); + var noOptions = !options.platforms && !options.plugins; + if (options.platforms || noOptions) { + shelljs.rm('-rf', [platformPath]); + logging.logger.info('Removed platforms'.blue.bold); + } + if (options.plugins || noOptions) { + shelljs.rm('-rf', [pluginPath]); + logging.logger.info('Removed plugins'.blue.bold); + } State.restoreState(appDirectory, options) .then(function() { logging.logger.info('Ionic reset state complete'.green.bold); diff --git a/spec/state.spec.js b/spec/state.spec.js index db2217c..7f0364a 100644 --- a/spec/state.spec.js +++ b/spec/state.spec.js @@ -367,16 +367,63 @@ describe('State', function() { }); describe('#resetState', function() { - it('should call call rm on the platforms path', function() { + it('should call call rm on the platforms ands plugins paths by default', function() { spyOn(shelljs, 'rm'); spyOn(State, 'restoreState').andReturn(Q()); State.resetState(tempDirectory, {}); var platformPath = path.join(tempDirectory, 'platforms'); var pluginPath = path.join(tempDirectory, 'plugins'); - expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath, pluginPath]); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]); expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {}); }); + + it('should call call rm on the platforms ands plugins path if both passed', function() { + spyOn(shelljs, 'rm'); + spyOn(State, 'restoreState').andReturn(Q()); + State.resetState(tempDirectory, { + platforms: true, + plugins: true + }); + + var platformPath = path.join(tempDirectory, 'platforms'); + var pluginPath = path.join(tempDirectory, 'plugins'); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]); + expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, { + platforms: true, + plugins: true + }); + }); + + it('should call call rm only on the platforms path if passed explicitly', function() { + spyOn(shelljs, 'rm'); + spyOn(State, 'restoreState').andReturn(Q()); + State.resetState(tempDirectory, { + platforms: true + }); + + var platformPath = path.join(tempDirectory, 'platforms'); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]); + expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, { + platforms: true + }); + }); + + it('should call call rm only on the plugins path if passed explicitly', function() { + spyOn(shelljs, 'rm'); + spyOn(State, 'restoreState').andReturn(Q()); + State.resetState(tempDirectory, { + plugins: true + }); + + var pluginPath = path.join(tempDirectory, 'plugins'); + expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]); + expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, { + plugins: true + }); + }); }); describe('#restorePlugins', function(){