@netlify/content-engine
Version:
37 lines • 1.45 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkLocalPlugin = checkLocalPlugin;
const fs_exists_cached_1 = require("fs-exists-cached");
const path_1 = require("../../../core-utils/path");
const path_2 = __importDefault(require("path"));
/**
* Checks if a plugin is a valid local plugin and returns the resolved path if it is.
*/
function checkLocalPlugin(plugin, rootDir) {
const pluginName = typeof plugin === `string` ? plugin : plugin.resolve;
// Make sure the plugin exists relatively
if ((0, fs_exists_cached_1.sync)(pluginName) || !rootDir) {
return {
validLocalPlugin: false,
};
}
const resolvedPath = (0, path_1.slash)(path_2.default.join(rootDir, `plugins/${pluginName}`));
if (!(0, fs_exists_cached_1.sync)(resolvedPath)) {
return {
validLocalPlugin: false,
};
}
const resolvedPackageJson = (0, fs_exists_cached_1.sync)(`${resolvedPath}/package.json`);
// package.json is a requirement for local plugins
if (!resolvedPackageJson) {
throw new Error(`Local plugin ${pluginName} requires a package.json file`);
}
return {
validLocalPlugin: true,
localPluginPath: resolvedPath,
};
}
//# sourceMappingURL=check-local-plugin.js.map
;