@kiwicom/orbit-tracking
Version:
Tracking for orbit design system
94 lines (85 loc) • 3.4 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunkBIWDSGJQcjs = require('./chunk-BIWDSGJQ.cjs');
var _chunkPHZK36Z6cjs = require('./chunk-PHZK36Z6.cjs');
// src/orbitProcessor.ts
var _zx = require('zx');
var isIcon = (instance) => instance.importInfo.moduleName.includes("/icons");
var orbitProcessor_default = ({ forEachComponent, deprecated, sortObjectKeysByValue, output }) => {
let result = {};
forEachComponent(({ componentName: name, component }) => {
const { instances } = component;
if (!instances)
return;
const { REPO_URL = "", OUTPUT_DIR = "" } = process.env;
result[name] = {
instances: instances.length,
sources: instances.map((instance) => ({
url: _zx.path.join(REPO_URL.replace(/\.git$/, ""), "-/blob/master", `${_zx.path.relative(OUTPUT_DIR, instance.location.file)}#L${instance.location.start.line}`).replace("https:/", "https://"),
props: Object.entries(instance.props).map(([k, v]) => ({
name: k,
value: v === null ? "null" : v
}))
})),
props: {},
category: _chunkBIWDSGJQcjs.getCategory.call(void 0, name),
isDeprecated: false,
icon: false
};
for (const instance of instances) {
const { imported } = instance.importInfo;
if (deprecated.includes(imported)) {
result[name].isDeprecated = true;
}
if (isIcon(instance)) {
result[name].icon = true;
result[name].category = "icons";
}
for (const prop in instance.props) {
if (prop) {
const propValue = instance.props[prop];
if (result[name].props[prop] === void 0) {
result[name].props[prop] = {
used: 0,
values: {}
};
}
if (result[name].props[prop].used === void 0) {
result[name].props[prop].used = 0;
} else {
result[name].props[prop].used += 1;
}
if (result[name].props[prop].values[propValue] === void 0) {
result[name].props[prop].values[propValue] = {
value: propValue,
used: 1
};
} else {
result[name].props[prop].values[propValue].used += 1;
}
result[name].props = sortObjectKeysByValue(result[name].props, (property) => property.used);
result[name].props[prop].values = sortObjectKeysByValue(result[name].props[prop].values, (value) => value.used);
}
}
}
});
result = sortObjectKeysByValue(result, (component) => component.instances);
const outputData = [];
for (const [name, value] of Object.entries(result)) {
const properties = [];
for (const [key, used] of Object.entries(value.props)) {
const values = [];
for (const propName of Object.keys(used.values)) {
values.push({ name: propName, used: used.values[propName].used });
}
properties.push(_chunkPHZK36Z6cjs.__spreadProps.call(void 0, _chunkPHZK36Z6cjs.__spreadValues.call(void 0, {
name: key
}, used), {
values
}));
}
outputData.push(_chunkPHZK36Z6cjs.__spreadProps.call(void 0, _chunkPHZK36Z6cjs.__spreadValues.call(void 0, { name }, value), { props: properties }));
}
output(JSON.stringify(outputData));
return outputData;
};
exports.orbitProcessor_default = orbitProcessor_default;