2021-06-24 22:24:54 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import commentParser from 'comment-parser';
|
|
|
|
|
|
|
|
const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
|
|
const { name, description, version, author, homepage, license } = packageData;
|
2021-09-21 02:05:27 +00:00
|
|
|
const noDash = string => string.replace(/^\s?-/, '').trim();
|
2021-06-24 22:24:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
globs: ['src/components/**/*.ts'],
|
|
|
|
exclude: ['**/*.test.ts'],
|
|
|
|
plugins: [
|
|
|
|
// Append package data
|
|
|
|
{
|
|
|
|
name: 'shoelace-package-data',
|
|
|
|
packageLinkPhase({ customElementsManifest, context }) {
|
|
|
|
customElementsManifest.package = { name, description, version, author, homepage, license };
|
|
|
|
}
|
|
|
|
},
|
2021-06-25 13:58:26 +00:00
|
|
|
|
2021-06-24 22:24:54 +00:00
|
|
|
// Parse custom jsDoc tags
|
|
|
|
{
|
|
|
|
name: 'shoelace-custom-tags',
|
|
|
|
analyzePhase({ ts, node, moduleDoc, context }) {
|
|
|
|
switch (node.kind) {
|
|
|
|
case ts.SyntaxKind.ClassDeclaration:
|
2021-07-06 14:29:58 +00:00
|
|
|
const className = node.name.getText();
|
2021-06-24 22:24:54 +00:00
|
|
|
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
|
|
|
|
const customTags = ['animation', 'dependency', 'since', 'status'];
|
|
|
|
let customComments = '/**';
|
|
|
|
|
|
|
|
node.jsDoc?.forEach(jsDoc => {
|
|
|
|
jsDoc?.tags?.forEach(tag => {
|
|
|
|
const tagName = tag.tagName.getText();
|
|
|
|
|
|
|
|
if (customTags.includes(tagName)) {
|
|
|
|
customComments += `\n * @${tagName} ${tag.comment}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const parsed = commentParser.parse(customComments + '\n */');
|
|
|
|
parsed[0].tags?.map(t => {
|
|
|
|
switch (t.tag) {
|
2021-06-25 13:58:26 +00:00
|
|
|
// Animations
|
|
|
|
case 'animation':
|
|
|
|
if (!Array.isArray(classDoc['animations'])) {
|
|
|
|
classDoc['animations'] = [];
|
|
|
|
}
|
|
|
|
classDoc['animations'].push({
|
|
|
|
name: t.name,
|
2021-09-21 02:05:27 +00:00
|
|
|
description: noDash(t.description)
|
2021-06-25 13:58:26 +00:00
|
|
|
});
|
2021-06-24 22:24:54 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-25 13:58:26 +00:00
|
|
|
// Dependencies
|
2021-06-24 22:24:54 +00:00
|
|
|
case 'dependency':
|
|
|
|
if (!Array.isArray(classDoc['dependencies'])) {
|
|
|
|
classDoc['dependencies'] = [];
|
|
|
|
}
|
|
|
|
classDoc['dependencies'].push(t.name);
|
|
|
|
break;
|
|
|
|
|
2021-06-25 13:58:26 +00:00
|
|
|
// Value-only metadata tags
|
|
|
|
case 'since':
|
|
|
|
case 'status':
|
|
|
|
classDoc[t.tag] = t.name;
|
|
|
|
break;
|
|
|
|
|
2021-06-24 22:24:54 +00:00
|
|
|
// All other tags
|
|
|
|
default:
|
|
|
|
if (!Array.isArray(classDoc[t.tag])) {
|
|
|
|
classDoc[t.tag] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
classDoc[t.tag].push({
|
|
|
|
name: t.name,
|
|
|
|
description: t.description,
|
|
|
|
type: t.type || undefined
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|