Skip to content

Commit

Permalink
check installed is actually enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
vutran committed Oct 8, 2016
1 parent 17948b9 commit 045ac28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
10 changes: 5 additions & 5 deletions __tests__/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import api from '../../src/api';
import utils from '../../src/utils';
import {
ERR_MODULE_DOWNLOAD_ERROR,
ERR_MODULE_INSTALLED,
ERR_MODULE_ENABLED,
ERR_MODULE_NOT_FOUND,
ERR_MODULE_NOT_INSTALLED,
ERR_MODULE_NOT_ENABLED,
ERR_MODULE_REMOVE_FAILED,
ERR_THEME_ALREADY_ACTIVE,
} from '../../src/errors';
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('plugins', () => {
try {
await api.install('SHOULD_EXIST', '/jest/test');
} catch (err) {
expect(err).toBe(ERR_MODULE_INSTALLED);
expect(err).toBe(ERR_MODULE_ENABLED);
}
});

Expand Down Expand Up @@ -114,7 +114,7 @@ describe('plugins', () => {
try {
await api.uninstall('INVALID_MODULE', '/jest/test');
} catch (err) {
expect(err).toBe(ERR_MODULE_NOT_INSTALLED);
expect(err).toBe(ERR_MODULE_NOT_ENABLED);
}
});
});
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('themes', () => {
try {
await api.setTheme('foobar');
} catch (err) {
expect(err).toBe(ERR_MODULE_NOT_INSTALLED);
expect(err).toBe(ERR_MODULE_NOT_ENABLED);
}
});

Expand Down
20 changes: 10 additions & 10 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const rimraf = require('rimraf');
const npmName = require('npm-name');
const {
ERR_MODULE_DOWNLOAD_ERROR,
ERR_MODULE_INSTALLED,
ERR_MODULE_ENABLED,
ERR_MODULE_NOT_FOUND,
ERR_MODULE_NOT_INSTALLED,
ERR_MODULE_NOT_ENABLED,
ERR_MODULE_REMOVE_FAILED,
ERR_THEME_ALREADY_ACTIVE,
} = require('../errors');
Expand All @@ -28,15 +28,15 @@ const checkOnNpm = plugin => new Promise((resolve) => {
});

/**
* Installs a plugin/package and saves it to the given directory
* Installs and enabled a plugin/package and saves it to the given directory
*
* @param {String} plugin - The name of the plugin/package
* @param {String} outputDir - The directory to install the plugin/package
* @return {Promise}
*/
const install = (plugin, outputDir) => new Promise((resolve, reject) => {
if (plugins.isInstalled(plugin)) {
reject(ERR_MODULE_INSTALLED);
if (plugins.isEnabled(plugin)) {
reject(ERR_MODULE_ENABLED);
return;
}

Expand Down Expand Up @@ -70,8 +70,8 @@ const install = (plugin, outputDir) => new Promise((resolve, reject) => {
* @return {Promise}
*/
const uninstall = (plugin, srcDir) => new Promise((resolve, reject) => {
if (!plugins.isInstalled(plugin)) {
reject(ERR_MODULE_NOT_INSTALLED);
if (!plugins.isEnabled(plugin)) {
reject(ERR_MODULE_NOT_ENABLED);
return;
}

Expand Down Expand Up @@ -138,9 +138,9 @@ const setTheme = theme => new Promise((resolve, reject) => {
reject(ERR_THEME_ALREADY_ACTIVE);
}

// if theme plugin is not installed
if (!plugins.isInstalled(theme)) {
reject(ERR_MODULE_NOT_INSTALLED);
// if theme plugin is not enabled
if (!plugins.isEnabled(theme)) {
reject(ERR_MODULE_NOT_ENABLED);
}

config.set('theme', theme);
Expand Down
6 changes: 3 additions & 3 deletions src/api/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const config = new Conf();
const getAll = () => config.get('plugins') || [];

/**
* Checks if the plugin is already installed
* Checks if the plugin is already enabled
*
* @param {String} plugin - The plugin name
* @return {Boolean}
*/
const isInstalled = plugin => getAll().indexOf(plugin) > -1;
const isEnabled = plugin => getAll().indexOf(plugin) > -1;

/**
* Enables the plugin by adding it to the config
Expand All @@ -37,7 +37,7 @@ const disable = (plugin) => {

module.exports = {
getAll,
isInstalled,
isEnabled,
enable,
disable,
};
2 changes: 2 additions & 0 deletions src/errors/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
exports.ERR_MODULE_DOWNLOAD_ERROR = 'ERR_MODULE_DOWNLOAD_ERROR';
exports.ERR_MODULE_INSTALLED = 'ERR_MODULE_INSTALLED';
exports.ERR_MODULE_ENABLED = 'ERR_MODULE_ENABLED';
exports.ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
exports.ERR_MODULE_NOT_ENABLED = 'ERR_MODULE_NOT_ENABLED';
exports.ERR_MODULE_NOT_INSTALLED = 'ERR_MODULE_NOT_INSTALLED';
exports.ERR_MODULE_REMOVE_FAILED = 'ERR_MODULE_REMOVE_FAILED';
exports.ERR_THEME_ALREADY_ACTIVE = 'ERR_THEME_ALREADY_ACTIVE';

0 comments on commit 045ac28

Please sign in to comment.