@jnxplus/common
Version:
This library was generated with [Nx](https://nx.dev).
70 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProject = getProject;
exports.getProjectRoot = getProjectRoot;
exports.getProjectSourceRoot = getProjectSourceRoot;
exports.normalizeName = normalizeName;
exports.getPluginName = getPluginName;
exports.getTargetName = getTargetName;
exports.clearEmpties = clearEmpties;
exports.getPluginVersion = getPluginVersion;
const fs_1 = require("fs");
const path = require("path");
function getProject(context) {
var _a;
if (!context.projectName) {
throw new Error('No project name found in context');
}
const project = (_a = context === null || context === void 0 ? void 0 : context.projectsConfigurations) === null || _a === void 0 ? void 0 : _a.projects[context.projectName];
if (!project) {
throw new Error(`No project found in project graph for ${context.projectName}`);
}
return project;
}
function getProjectRoot(context) {
const project = getProject(context);
return project.root;
}
function getProjectSourceRoot(context) {
const project = getProject(context);
return project.sourceRoot;
}
function normalizeName(name) {
return name.replace(/[^0-9a-zA-Z]/g, '-');
}
function getPluginName(context) {
var _a, _b;
return (_b = (_a = context.target) === null || _a === void 0 ? void 0 : _a.executor) === null || _b === void 0 ? void 0 : _b.split(':')[0];
}
function titleCase(str) {
return str
.toLowerCase()
.split(' ')
.map(function (word) {
return word.replace(word[0], word[0].toUpperCase());
})
.join(' ');
}
function getTargetName(context) {
if (!context.targetName) {
throw new Error('TargetName not found in context');
}
return titleCase(context.targetName.replace(/-+/g, ' '));
}
function clearEmpties(o) {
for (const k in o) {
if (!o[k] || typeof o[k] !== 'object') {
continue; // If null or not an object, skip to the next iteration
}
// The property is an object
if (Object.keys(o[k]).length === 0) {
delete o[k]; // The object had no properties, so delete that property
}
}
return o;
}
function getPluginVersion(d) {
const packageJson = JSON.parse((0, fs_1.readFileSync)(path.join(d, '..', '..', '..', 'package.json')).toString());
return packageJson.version;
}
//# sourceMappingURL=index.js.map