@mendix/pluggable-widgets-tools
Version:
Mendix Pluggable Widgets Tools
49 lines (48 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.widgetId = exports.widgetVersion = exports.packageName = exports.widgetOrganization = exports.widgetName = exports.json = exports.path = exports.dir = void 0;
const fs_1 = require("fs");
const validation_1 = require("../utils/validation");
const path_1 = require("path");
const process_1 = require("process");
/**
* The full path to the root directory of the widget package
*/
exports.dir = (0, process_1.cwd)();
/**
* The full path to the widget's package.json file
*/
exports.path = (0, path_1.join)(exports.dir, "package.json");
if (!(0, fs_1.existsSync)(exports.path)) {
throw new Error(`"Could not locate the widget's package.json at "${exports.path}"`);
}
/**
* The contents of the widget's package.json
*/
exports.json = JSON.parse((0, fs_1.readFileSync)(exports.path, "utf-8"));
/**
* The name of the widget
*/
exports.widgetName = exports.json.widgetName;
if (!exports.widgetName) {
throw new Error("Widget does not define widgetName in its package.json");
}
(0, validation_1.throwOnIllegalChars)(exports.widgetName, "a-zA-Z", "The `widgetName` property in package.json");
/**
* The organization name of the widget as defined by the `packagePath` package.json property.
*/
exports.widgetOrganization = exports.json.packagePath;
(0, validation_1.throwOnIllegalChars)(exports.widgetOrganization, "a-zA-Z0-9_.-", "The `packagePath` property in package.json");
(0, validation_1.throwOnNoMatch)(exports.widgetOrganization, /^([a-zA-Z0-9_-]+.)*[a-zA-Z0-9_-]+$/, "The `packagePath` property in package.json");
/**
* The name of the widget package
*/
exports.packageName = exports.json.name;
/**
* The version of the widget package.
*/
exports.widgetVersion = exports.json.version;
/**
* The ID of the widget
*/
exports.widgetId = [exports.widgetOrganization, exports.packageName, exports.widgetName].join(".");