refactor metadata fetching

pull/479/head
Cory LaViska 2021-06-28 08:34:37 -04:00
rodzic 12b0365ce0
commit 5e7fcdd105
2 zmienionych plików z 19 dodań i 29 usunięć

Wyświetl plik

@ -248,7 +248,14 @@
metadata.modules.map(module => {
module.exports.find(ex => {
if (ex.kind === 'custom-element-definition') {
allComponents.push(getComponent(metadata, ex.name));
const tagName = ex.name;
const className = ex.declaration.name;
const component = Object.assign(
{ className, tagName },
module?.declarations.find(dec => dec.name === 'default')
);
allComponents.push(component);
}
});
});
@ -256,18 +263,8 @@
return allComponents;
}
function getComponent(metadata, tag) {
const module = metadata.modules.find(module => {
return module.exports.find(ex => {
return ex.kind === 'custom-element-definition' && ex.name === tag;
});
});
const component = module?.declarations.find(dec => dec.name === 'default');
const definition = module.exports.filter(ex => ex.kind === 'custom-element-definition' && ex.name === tag)[0];
const tagName = definition?.name;
const className = definition?.declaration?.name;
return Object.assign({ className, tagName }, component);
function getComponent(metadata, tagName) {
return getAllComponents(metadata).find(component => (component.tagName = tagName));
}
function getMetadata() {

Wyświetl plik

@ -11,25 +11,18 @@ const metadata = JSON.parse(fs.readFileSync('./dist/custom-elements.json', 'utf8
function getAllComponents() {
const allComponents = [];
const getComponent = tagName => {
const module = metadata.modules.find(module => {
return module.exports.find(ex => {
return ex.kind === 'custom-element-definition' && ex.name === tagName;
});
});
const component = module?.declarations.find(dec => dec.name === 'default');
const tag = module.exports.filter(ex => ex.kind === 'custom-element-definition' && ex.name === tagName)[0]?.name;
return Object.assign({ tag }, component);
};
metadata.modules.map(module => {
module.exports.find(ex => {
if (ex.kind === 'custom-element-definition') {
if (typeof ex.name === 'string') {
allComponents.push(getComponent(ex.name));
}
const tagName = ex.name;
const className = ex.declaration.name;
const component = Object.assign(
{ className, tagName },
module?.declarations.find(dec => dec.name === 'default')
);
allComponents.push(component);
}
});
});
@ -83,4 +76,4 @@ components.map(component => {
fs.writeFileSync('./dist/vscode.html-custom-data.json', JSON.stringify(vscode, null, 2), 'utf8');
console.log(chalk.cyan(`Successfully generated IntelliSense data for VS Code 🔮\n`));
console.log(chalk.cyan(`Successfully generated custom data for VS Code 🔮\n`));