feature(@embark/utils): add method to verify if a plugin is installed & configured

This commit is contained in:
Iuri Matias 2020-01-22 12:36:39 -05:00
parent f5db7fe88d
commit 5524adcda2
1 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,8 @@ const shelljs = require('shelljs');
const clipboardy = require('clipboardy');
import { canonicalHost } from './host';
import * as findUp from 'find-up';
import * as fs from 'fs-extra';
export { canonicalHost, defaultCorsHost, defaultHost, dockerHostSwap, isDocker } from './host';
export { downloadFile, findNextPort, getJson, httpGet, httpsGet, httpGetJson, httpsGetJson, pingEndpoint } from './network';
export { testRpcWithEndpoint, testWsEndpoint } from './check';
@ -53,6 +55,10 @@ export {
} from './pathUtils';
export { setUpEnv } from './env';
import {
dappPath
} from './pathUtils';
const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils;
export { compact, last, recursiveMerge, groupBy } from './collections';
@ -298,3 +304,23 @@ export function isConstructor(obj) {
export function isEs6Module(module) {
return (typeof module === 'function' && isConstructor(module)) || (typeof module === 'object' && typeof module.default === 'function' && module.__esModule);
}
export function warnIfPackageNotDefinedLocally(packageName, warnFunc) {
const packageIsResolvable = findUp.sync("node_modules/" + packageName, {cwd: dappPath()});
if (!packageIsResolvable) {
return warnFunc("== WARNING: it seems " + packageName + " is not defined in your dapp package.json; In future versions of embark this package should be a local dependency and configured as a plugin");
}
const dappPackage = fs.readJSONSync(dappPath("package.json"));
const { dependencies, devDependencies } = dappPackage;
if (!((dependencies && dependencies[packageName]) || (devDependencies && devDependencies[packageName]))) {
return warnFunc("== WARNING: it seems " + packageName + " is not defined in your dapp package.json dependencies; In future versions of embark this package should be a local dependency and configured as a plugin");
}
const embarkConfig = fs.readJSONSync(dappPath("embark.json"));
if (!embarkConfig.plugins[packageName]) {
return warnFunc("== WARNING: it seems " + packageName + " is not defined in your dapp embark.json plugins; In future versions of embark this package should be a local dependency and configured as a plugin");
}
return true;
}