2023-08-14 09:34:34 -04:00
|
|
|
import { customElementJetBrainsPlugin } from 'custom-element-jet-brains-integration';
|
2023-08-11 11:01:00 -04:00
|
|
|
import { customElementVsCodePlugin } from 'custom-element-vs-code-integration';
|
2024-06-17 16:17:09 -04:00
|
|
|
// import { customElementVuejsPlugin } from 'custom-element-vuejs-integration';
|
2021-12-06 10:57:54 -05:00
|
|
|
import { parse } from 'comment-parser';
|
2023-02-03 14:27:17 -05:00
|
|
|
import fs from 'fs';
|
2024-12-14 17:00:28 -05:00
|
|
|
import { pascalCase } from 'pascal-case';
|
2021-06-24 18:24:54 -04:00
|
|
|
|
|
|
|
|
const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
|
|
|
const { name, description, version, author, homepage, license } = packageData;
|
2024-09-11 10:25:42 -04:00
|
|
|
const outdir = 'dist-cdn';
|
2022-11-16 12:47:34 -05:00
|
|
|
|
2022-11-10 16:27:23 -05:00
|
|
|
function replace(string, terms) {
|
|
|
|
|
terms.forEach(({ from, to }) => {
|
|
|
|
|
string = string?.replace(from, to);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
}
|
2021-06-24 18:24:54 -04:00
|
|
|
|
|
|
|
|
export default {
|
2024-04-17 11:20:27 -04:00
|
|
|
globs: ['src/components/**/*.ts'],
|
2022-01-31 14:41:18 -05:00
|
|
|
exclude: ['**/*.styles.ts', '**/*.test.ts'],
|
2024-04-17 11:20:27 -04:00
|
|
|
litelement: true,
|
|
|
|
|
outdir,
|
2021-06-24 18:24:54 -04:00
|
|
|
plugins: [
|
|
|
|
|
// Append package data
|
|
|
|
|
{
|
2023-09-08 13:45:49 -04:00
|
|
|
name: 'wa-package-data',
|
2022-01-15 21:47:14 -08:00
|
|
|
packageLinkPhase({ customElementsManifest }) {
|
2021-06-24 18:24:54 -04:00
|
|
|
customElementsManifest.package = { name, description, version, author, homepage, license };
|
2024-12-14 17:08:29 -05:00
|
|
|
},
|
2021-06-24 18:24:54 -04:00
|
|
|
},
|
2023-12-06 16:26:15 -05:00
|
|
|
|
2021-06-24 18:24:54 -04:00
|
|
|
// Parse custom jsDoc tags
|
|
|
|
|
{
|
2023-09-08 13:45:49 -04:00
|
|
|
name: 'wa-custom-tags',
|
2022-01-15 21:47:14 -08:00
|
|
|
analyzePhase({ ts, node, moduleDoc }) {
|
2021-06-24 18:24:54 -04:00
|
|
|
switch (node.kind) {
|
2022-01-15 21:47:14 -08:00
|
|
|
case ts.SyntaxKind.ClassDeclaration: {
|
2021-07-06 10:29:58 -04:00
|
|
|
const className = node.name.getText();
|
2021-06-24 18:24:54 -04:00
|
|
|
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
|
2024-05-28 14:18:31 -04:00
|
|
|
const customTags = ['dependency', 'documentation', 'since', 'status', 'title'];
|
2021-06-24 18:24:54 -04:00
|
|
|
let customComments = '/**';
|
|
|
|
|
|
|
|
|
|
node.jsDoc?.forEach(jsDoc => {
|
|
|
|
|
jsDoc?.tags?.forEach(tag => {
|
|
|
|
|
const tagName = tag.tagName.getText();
|
|
|
|
|
|
|
|
|
|
if (customTags.includes(tagName)) {
|
|
|
|
|
customComments += `\n * @${tagName} ${tag.comment}`;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-24 13:00:07 -04:00
|
|
|
// This is what allows us to map JSDOC comments to ReactWrappers.
|
|
|
|
|
classDoc['jsDoc'] = node.jsDoc?.map(jsDoc => jsDoc.getFullText()).join('\n');
|
|
|
|
|
|
2022-01-15 21:47:14 -08:00
|
|
|
const parsed = parse(`${customComments}\n */`);
|
|
|
|
|
parsed[0].tags?.forEach(t => {
|
2021-06-24 18:24:54 -04:00
|
|
|
switch (t.tag) {
|
2021-06-25 09:58:26 -04:00
|
|
|
// Dependencies
|
2021-06-24 18:24:54 -04:00
|
|
|
case 'dependency':
|
|
|
|
|
if (!Array.isArray(classDoc['dependencies'])) {
|
|
|
|
|
classDoc['dependencies'] = [];
|
|
|
|
|
}
|
|
|
|
|
classDoc['dependencies'].push(t.name);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-06-25 09:58:26 -04:00
|
|
|
// Value-only metadata tags
|
2023-01-12 10:26:25 -05:00
|
|
|
case 'documentation':
|
2021-06-25 09:58:26 -04:00
|
|
|
case 'since':
|
|
|
|
|
case 'status':
|
2022-10-18 18:22:48 +02:00
|
|
|
case 'title':
|
2021-06-25 09:58:26 -04:00
|
|
|
classDoc[t.tag] = t.name;
|
|
|
|
|
break;
|
|
|
|
|
|
2021-06-24 18:24:54 -04:00
|
|
|
// All other tags
|
|
|
|
|
default:
|
|
|
|
|
if (!Array.isArray(classDoc[t.tag])) {
|
|
|
|
|
classDoc[t.tag] = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
classDoc[t.tag].push({
|
|
|
|
|
name: t.name,
|
|
|
|
|
description: t.description,
|
2024-12-14 17:08:29 -05:00
|
|
|
type: t.type || undefined,
|
2021-06-24 18:24:54 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-01-15 21:47:14 -08:00
|
|
|
}
|
2021-06-24 18:24:54 -04:00
|
|
|
}
|
2024-12-14 17:08:29 -05:00
|
|
|
},
|
2021-11-05 09:23:30 -04:00
|
|
|
},
|
2023-12-06 16:26:15 -05:00
|
|
|
|
2021-11-05 09:23:30 -04:00
|
|
|
{
|
2023-09-08 13:45:49 -04:00
|
|
|
name: 'wa-react-event-names',
|
2022-01-15 21:47:14 -08:00
|
|
|
analyzePhase({ ts, node, moduleDoc }) {
|
2021-11-05 09:23:30 -04:00
|
|
|
switch (node.kind) {
|
2022-01-15 21:47:14 -08:00
|
|
|
case ts.SyntaxKind.ClassDeclaration: {
|
2021-11-05 09:23:30 -04:00
|
|
|
const className = node.name.getText();
|
|
|
|
|
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
|
|
|
|
|
|
|
|
|
|
if (classDoc?.events) {
|
2022-01-15 21:47:14 -08:00
|
|
|
classDoc.events.forEach(event => {
|
2024-05-31 14:28:19 -04:00
|
|
|
if (!event.name) return;
|
2021-11-05 09:23:30 -04:00
|
|
|
event.reactName = `on${pascalCase(event.name)}`;
|
2023-07-13 03:31:27 +12:00
|
|
|
event.eventName = `${pascalCase(event.name)}Event`;
|
2021-11-05 09:23:30 -04:00
|
|
|
});
|
|
|
|
|
}
|
2022-01-15 21:47:14 -08:00
|
|
|
}
|
2021-11-05 09:23:30 -04:00
|
|
|
}
|
2024-12-14 17:08:29 -05:00
|
|
|
},
|
2022-11-10 15:28:08 -05:00
|
|
|
},
|
2023-12-06 16:26:15 -05:00
|
|
|
|
2022-11-10 15:28:08 -05:00
|
|
|
{
|
2023-09-08 13:45:49 -04:00
|
|
|
name: 'wa-translate-module-paths',
|
2022-11-10 16:27:23 -05:00
|
|
|
packageLinkPhase({ customElementsManifest }) {
|
|
|
|
|
customElementsManifest?.modules?.forEach(mod => {
|
|
|
|
|
//
|
|
|
|
|
// CEM paths look like this:
|
|
|
|
|
//
|
|
|
|
|
// src/components/button/button.ts
|
|
|
|
|
//
|
|
|
|
|
// But we want them to look like this:
|
|
|
|
|
//
|
|
|
|
|
// components/button/button.js
|
|
|
|
|
//
|
|
|
|
|
const terms = [
|
2023-02-03 14:36:17 -05:00
|
|
|
{ from: /^src\//, to: '' }, // Strip the src/ prefix
|
2024-12-14 17:08:29 -05:00
|
|
|
{ from: /\.(t|j)sx?$/, to: '.js' }, // Convert .ts to .js
|
2022-11-10 16:27:23 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
mod.path = replace(mod.path, terms);
|
|
|
|
|
|
|
|
|
|
for (const ex of mod.exports ?? []) {
|
|
|
|
|
ex.declaration.module = replace(ex.declaration.module, terms);
|
2022-11-10 15:28:08 -05:00
|
|
|
}
|
2022-11-10 16:27:23 -05:00
|
|
|
|
|
|
|
|
for (const dec of mod.declarations ?? []) {
|
|
|
|
|
if (dec.kind === 'class') {
|
|
|
|
|
for (const member of dec.members ?? []) {
|
|
|
|
|
if (member.inheritedFrom) {
|
|
|
|
|
member.inheritedFrom.module = replace(member.inheritedFrom.module, terms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-12-14 17:08:29 -05:00
|
|
|
},
|
2022-11-16 12:47:34 -05:00
|
|
|
},
|
2023-12-06 16:26:15 -05:00
|
|
|
|
2022-11-16 12:47:34 -05:00
|
|
|
// Generate custom VS Code data
|
2023-08-11 10:51:33 -04:00
|
|
|
customElementVsCodePlugin({
|
2022-11-16 12:47:34 -05:00
|
|
|
outdir,
|
2023-08-11 10:51:33 -04:00
|
|
|
cssFileName: null,
|
2023-08-11 11:01:00 -04:00
|
|
|
referencesTemplate: (_, tag) => [
|
|
|
|
|
{
|
|
|
|
|
name: 'Documentation',
|
2024-12-14 17:08:29 -05:00
|
|
|
url: `https://webawesome.com/docs/components/${tag.replace('wa-', '')}`,
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-08-14 09:34:34 -04:00
|
|
|
}),
|
2023-12-06 16:26:15 -05:00
|
|
|
|
2023-08-14 09:34:34 -04:00
|
|
|
customElementJetBrainsPlugin({
|
2024-09-11 10:25:42 -04:00
|
|
|
outdir: './dist-cdn',
|
2023-08-14 09:34:34 -04:00
|
|
|
excludeCss: true,
|
2023-11-02 08:53:17 -04:00
|
|
|
packageJson: false,
|
2023-08-14 09:34:34 -04:00
|
|
|
referencesTemplate: (_, tag) => {
|
|
|
|
|
return {
|
|
|
|
|
name: 'Documentation',
|
2024-12-14 17:08:29 -05:00
|
|
|
url: `https://webawesome.com/docs/components/${tag.replace('wa-', '')}`,
|
2023-08-14 09:34:34 -04:00
|
|
|
};
|
2024-12-14 17:08:29 -05:00
|
|
|
},
|
|
|
|
|
}),
|
2024-05-31 14:28:19 -04:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// TODO - figure out why this broke when events were updated
|
|
|
|
|
//
|
|
|
|
|
// customElementVuejsPlugin({
|
|
|
|
|
// outdir: './dist/types/vue',
|
|
|
|
|
// fileName: 'index.d.ts',
|
|
|
|
|
// componentTypePath: (_, tag) => `../../components/${tag.replace('wa-', '')}/${tag.replace('wa-', '')}.js`
|
|
|
|
|
// })
|
2024-12-14 17:08:29 -05:00
|
|
|
],
|
2021-06-24 18:24:54 -04:00
|
|
|
};
|