2023-09-22 21:50:55 +02:00
|
|
|
const customElementsManifest = require('../../dist/custom-elements.json');
|
2023-10-27 17:21:27 +02:00
|
|
|
const fs = require('fs');
|
2024-01-05 17:52:09 +01:00
|
|
|
const path = require('path');
|
2024-06-15 14:50:07 +02:00
|
|
|
const customElementsManifestShoelace = require('../custom-elements-shoelace.json');
|
2023-09-22 21:50:55 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Export it here so we can import it elsewhere and use the same version
|
|
|
|
//
|
|
|
|
module.exports.customElementsManifest = customElementsManifest;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Gets all components from custom-elements.json and returns them in a more documentation-friendly format.
|
|
|
|
//
|
|
|
|
module.exports.getAllComponents = function ()
|
|
|
|
{
|
2024-06-15 14:50:07 +02:00
|
|
|
//
|
|
|
|
// Find a Shoelace class declaration from their custom-elements.json
|
|
|
|
//
|
|
|
|
// for Et2* classes, we also look recursive, if they inherit from a Shoelace class
|
|
|
|
//
|
|
|
|
const getSlClass = function(superclass)
|
|
|
|
{
|
|
|
|
let sl_class;
|
|
|
|
if (superclass && superclass.package === "@shoelace-style/shoelace")
|
|
|
|
{
|
|
|
|
customElementsManifestShoelace.modules.find(module =>
|
|
|
|
sl_class = module.declarations.find(declaration => declaration.kind === "class" && declaration.name === superclass.name));
|
|
|
|
}
|
|
|
|
else if (superclass && superclass.name.substring(0, 3) === "Et2")
|
|
|
|
{
|
|
|
|
customElementsManifest.modules.find(module =>
|
|
|
|
sl_class = module.declarations.find(declaration => declaration.name === superclass.name));
|
|
|
|
if (sl_class) sl_class = getSlClass(sl_class.superclass);
|
|
|
|
}
|
|
|
|
//console.log("getSlClass("+superclass.name+") returning ", sl_class ? sl_class.name+" with attributes: "+sl_class.attributes?.map(attribute => attribute.name).join(", ") : "undefined");
|
|
|
|
return sl_class;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Sort by not deprecated and name
|
|
|
|
//
|
|
|
|
const compareNotDeprecatedAndName = function(a, b)
|
|
|
|
{
|
|
|
|
if (a.deprecated && !b.deprecated) return 1;
|
|
|
|
if (!a.deprecated && b.deprecated) return -1;
|
|
|
|
if (a.name[0] === '_' && b.name[0] !== '_') return 1;
|
|
|
|
if (a.name[0] !== '_' && b.name[0] === '_') return -1;
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
}
|
|
|
|
const debug='declaration.name'; // set to declaration.name to get more logging for that component
|
2023-09-22 21:50:55 +02:00
|
|
|
const allComponents = [];
|
|
|
|
|
|
|
|
customElementsManifest.modules?.forEach(module =>
|
|
|
|
{
|
|
|
|
module.declarations?.forEach(declaration =>
|
|
|
|
{
|
|
|
|
if (declaration.customElement)
|
|
|
|
{
|
2024-06-15 14:50:07 +02:00
|
|
|
// check if we have a Shoelace superclass
|
|
|
|
const sl_class = declaration.superclass ? getSlClass(declaration.superclass) : undefined;
|
|
|
|
if (debug === declaration.name) console.log(declaration.name+": superclass=", declaration.superclass, sl_class ? "found: "+sl_class.name : "not found");
|
|
|
|
|
2023-09-22 21:50:55 +02:00
|
|
|
// Generate the dist path based on the src path and attach it to the component
|
|
|
|
declaration.path = module.path.replace(/^src\//, 'dist/').replace(/\.ts$/, '.js');
|
|
|
|
|
|
|
|
// Remove members that are private or don't have a description
|
2024-06-15 14:50:07 +02:00
|
|
|
//
|
|
|
|
let members = declaration.members?.filter(member => member.description && member.privacy !== 'private') || [];
|
|
|
|
// add non-private and not overwritten Shoelace superclass members
|
|
|
|
if (debug === declaration.name) console.log("found members: "+members.map(member => member.name).join(", "));
|
|
|
|
if (sl_class)
|
|
|
|
{
|
|
|
|
const sl_members = sl_class.members?.filter(member =>
|
|
|
|
member.description && member.privacy !== 'private' && !members.find(egw => member.name === egw.name))/*.map(member => {
|
|
|
|
return {...member, inheritedFrom: {name: sl_class.name, module: "@shoelace-style/shoelace"}};
|
|
|
|
})*/;
|
|
|
|
if (debug === declaration.name) console.log("adding members from "+sl_class.name+": "+sl_members.map(member => member.name).join(", "));
|
|
|
|
members = members.concat(sl_members);
|
|
|
|
}
|
|
|
|
let methods = members?.filter(prop => prop.kind === 'method' && prop.privacy !== 'private') || [];
|
|
|
|
if (declaration.name === "Et2ButtonScroll") console.log("found methods: "+methods.map(method => method.name).join(", "));
|
|
|
|
// add non-private and not overwritten Shoelace superclass methods
|
|
|
|
/* ToDo disabled, as it gives an error later (only copies 8 files and generates none)
|
|
|
|
if (sl_class)
|
|
|
|
{
|
|
|
|
const sl_methods = sl_class.members?.filter(prop =>
|
|
|
|
prop.kind === 'method' && prop.privacy !== 'private' && !methods.find(egw => prop.name === egw.name))/*.map(method => {
|
|
|
|
return {...method, inheritedFrom: {name: sl_class.name, module: "@shoelace-style/shoelace"}};
|
|
|
|
});
|
|
|
|
if (debug === declaration.name) console.log("adding methods from "+sl_class.name+": "+sl_methods.map(method => method.name).join(", "));
|
|
|
|
methods = methods.concat(sl_methods);
|
|
|
|
}*/
|
|
|
|
methods = methods.sort(compareNotDeprecatedAndName);
|
2023-09-22 21:50:55 +02:00
|
|
|
const properties = members?.filter(prop =>
|
|
|
|
{
|
2024-06-15 14:50:07 +02:00
|
|
|
if (debug === declaration.name) console.log("Asserting "+declaration.name+" property", prop);
|
2023-09-22 21:50:55 +02:00
|
|
|
// Look for a corresponding attribute
|
2024-06-15 14:50:07 +02:00
|
|
|
const attribute = (declaration.attributes||[]).concat(sl_class?.attributes || []).find(attr => attr.fieldName === prop.name);
|
2023-09-22 21:50:55 +02:00
|
|
|
if (attribute)
|
|
|
|
{
|
|
|
|
prop.attribute = attribute.name || attribute.fieldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop.kind === 'field' && prop.privacy !== 'private';
|
2024-06-15 14:50:07 +02:00
|
|
|
}).sort(compareNotDeprecatedAndName);
|
|
|
|
if (debug === declaration.name) console.log("found properties: "+properties.map(property => property.name).join(", "));
|
2023-09-22 21:50:55 +02:00
|
|
|
allComponents.push({
|
|
|
|
...declaration,
|
|
|
|
methods,
|
2024-06-15 14:50:07 +02:00
|
|
|
properties,
|
|
|
|
attributes: declaration.attributes?.concat(sl_class?.attributes?.filter(attribute => !declaration.attributes.find(attr => attr.name === attribute.name))
|
|
|
|
/*.map(attribute => {
|
|
|
|
return {...attribute, inheritedFrom: {name: sl_class.name, module: "@shoelace-style/shoelace"}};
|
|
|
|
})*/)
|
2023-09-22 21:50:55 +02:00
|
|
|
});
|
2024-06-15 14:50:07 +02:00
|
|
|
if (debug === declaration.name) console.log("added attributes", allComponents[allComponents.length - 1].attributes);
|
2023-09-22 21:50:55 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2024-06-15 14:50:07 +02:00
|
|
|
console.log('Build dependency graphs');
|
2023-09-22 21:50:55 +02:00
|
|
|
// Build dependency graphs
|
|
|
|
allComponents.forEach(component =>
|
|
|
|
{
|
|
|
|
const dependencies = [];
|
|
|
|
|
|
|
|
// Recursively fetch sub-dependencies
|
|
|
|
function getDependencies(tag)
|
|
|
|
{
|
|
|
|
const cmp = allComponents.find(c => c.tagName === tag);
|
|
|
|
if (!cmp || !Array.isArray(component.dependencies))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmp.dependencies?.forEach(dependentTag =>
|
|
|
|
{
|
|
|
|
if (!dependencies.includes(dependentTag))
|
|
|
|
{
|
|
|
|
dependencies.push(dependentTag);
|
|
|
|
}
|
|
|
|
getDependencies(dependentTag);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getDependencies(component.tagName);
|
|
|
|
|
|
|
|
component.dependencies = dependencies.sort();
|
|
|
|
});
|
2024-06-15 14:50:07 +02:00
|
|
|
console.log('Add custom docs');
|
2024-01-05 17:52:09 +01:00
|
|
|
// Add custom docs - not monitored for file changes
|
|
|
|
allComponents.forEach(component =>
|
|
|
|
{
|
|
|
|
// Check for custom docs
|
|
|
|
const docPath = path.join('..', '..', path.dirname(component.path), component.name + ".md");
|
|
|
|
|
|
|
|
// Stick it in a variable so we can use the content filters
|
|
|
|
if (fs.existsSync(path.resolve(docPath)))
|
|
|
|
{
|
|
|
|
fs.readFile(docPath, (err, data) => component.content = data.toString());
|
|
|
|
}
|
|
|
|
})
|
2024-06-15 14:50:07 +02:00
|
|
|
console.log("return allComponentes sorted by name")
|
2023-09-22 21:50:55 +02:00
|
|
|
// Sort by name
|
|
|
|
return allComponents.sort((a, b) =>
|
|
|
|
{
|
|
|
|
if (a.name < b.name)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
};
|
2023-10-27 17:21:27 +02:00
|
|
|
|
|
|
|
module.exports.getShoelaceVersion = function ()
|
|
|
|
{
|
|
|
|
const shoelace = "@shoelace-style/shoelace"
|
|
|
|
|
|
|
|
const package = JSON.parse(fs.readFileSync('../../package.json', "utf8")) || {dependencies: {}}
|
|
|
|
return package.dependencies[shoelace] || "";
|
|
|
|
}
|