From 5524adcda2f59a796d1f0a2a5857486c8906a858 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 22 Jan 2020 12:36:39 -0500 Subject: [PATCH] feature(@embark/utils): add method to verify if a plugin is installed & configured --- packages/core/utils/src/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/core/utils/src/index.ts b/packages/core/utils/src/index.ts index c7d6a0837..48b901184 100644 --- a/packages/core/utils/src/index.ts +++ b/packages/core/utils/src/index.ts @@ -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; +} \ No newline at end of file