Skip to content

Commit

Permalink
Merge pull request #125 from break-stuff/add-global-configurations
Browse files Browse the repository at this point in the history
Add global configurations
  • Loading branch information
break-stuff authored May 19, 2024
2 parents 710b3de + d02d55b commit a3f078b
Show file tree
Hide file tree
Showing 65 changed files with 1,242 additions and 579 deletions.
1,365 changes: 913 additions & 452 deletions demo/lit-app/custom-elements.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/cem-inheritance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.0

- Added the ability to hide logs
- Added the ability to skip the plugin

## 1.0.0

- Initial release
4 changes: 4 additions & 0 deletions packages/cem-inheritance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ interface Options {
ignore?: string[];
/** External CEMs that your components extend */
externalManifests?: any[];
/** Hides logs produced by the plugin */
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/cem-inheritance/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-elements-manifest-inheritance",
"version": "1.0.0",
"version": "1.1.0",
"description": "A tool for mapping inherited content (including class members, attributes, CSS parts, CSS variables, slots, and events) from parent classes in the Custom Elements Manifest",
"main": "index.js",
"module": "index.js",
Expand Down
5 changes: 0 additions & 5 deletions packages/cem-inheritance/src/cem-inheritance-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { updateCemInheritance } from "./cem-inheritance.js";
import type { Options, Params } from "./types.js";
import { logGreen } from "../../../tools/integrations/index.js";

export function cemInheritancePlugin(options: Options = {}) {
return {
name: "cem-inheritance",
packageLinkPhase({ customElementsManifest }: Params) {
console.log(
"[cem-inheritance-generator] - Updating Custom Elements Manifest..."
);
updateCemInheritance(customElementsManifest, options);
logGreen("[cem-inheritance-generator] - Custom Elements Manifest update complete.");
},
};
}
10 changes: 7 additions & 3 deletions packages/cem-inheritance/src/cem-inheritance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CEM, Component } from "../../../tools/cem-utils/index.js";
import { createOutDir, logBlue, saveFile } from "../../../tools/integrations";
import { createOutDir, logBlue, logYellow, saveFile } from "../../../tools/integrations";
import { Options } from "./types.js";

const completedClasses: string[] = [];
Expand All @@ -10,15 +10,19 @@ let externalComponents: Component[] = [];
let updatedCEM: any = {};

export function updateCemInheritance(cem: CEM, options: Options = {}) {
logBlue("[cem-inheritance-generator] - Updating Custom Elements Manifest...");
if(options.skip) {
logYellow("[cem-inheritance-generator] - Skipped", options.hideLogs)
}

logBlue("[cem-inheritance-generator] - Updating Custom Elements Manifest...", options.hideLogs);
const newCem = generateUpdatedCem(cem, options);
createOutDir(userConfig.outdir!);
saveFile(
userConfig.outdir!,
userConfig.fileName!,
JSON.stringify(newCem, null, 2)
);
logBlue("[cem-inheritance-generator] - Custom Elements Manifest updated.");
logBlue("[cem-inheritance-generator] - Custom Elements Manifest updated.", options.hideLogs);
}

function updateOptions(options: Options = {}) {
Expand Down
4 changes: 4 additions & 0 deletions packages/cem-inheritance/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface Options {
ignore?: string[];
/** External CEMs that your components extend */
externalManifests?: any[];
/** Hides logs produced by the plugin */
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
}

export interface Params {
Expand Down
5 changes: 5 additions & 0 deletions packages/custom-jsdoc-tags/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.0

- Added the ability to hide logs
- Added the ability to skip the plugin

## 1.0.2

- Prevent crash when no tags exist
Expand Down
4 changes: 4 additions & 0 deletions packages/custom-jsdoc-tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ interface Options {
isArray?: boolean;
};
};
/** Hides logs produced by the plugin */
hideLogs: boolean;
/** Prevents plugin from executing */
skip: boolean;
}
```
Expand Down
2 changes: 1 addition & 1 deletion packages/custom-jsdoc-tags/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cem-plugin-custom-jsdoc-tags",
"version": "1.0.2",
"version": "1.1.0",
"description": "Translates custom JSDoc tags to the Custom Elements Manifest",
"main": "index.js",
"module": "index.js",
Expand Down
45 changes: 30 additions & 15 deletions packages/custom-jsdoc-tags/src/cem-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { parse } from 'comment-parser';
import type { CEM, Component } from "../../../tools/cem-utils";
import { parse } from "comment-parser";
import type { Component } from "../../../tools/cem-utils";
import { logBlue, logYellow } from "../../../tools/integrations";

export interface Options {
tags?: CustomTag;
/** Hides logs produced by the plugin */
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
}

export interface CustomTag {
Expand All @@ -22,7 +27,7 @@ interface CEMTag {
}

let userOptions: Options = {
tags: {}
tags: {},
};

/**
Expand All @@ -35,19 +40,27 @@ export function customJSDocTagsPlugin(
tags: {},
}
) {
if(options.skip) {
logYellow("[custom-jsdoc-tags] - Skipped", options.hideLogs);
return;
}

logBlue("[custom-jsdoc-tags] - Updating Custom Elements Manifest...", options.hideLogs);
userOptions = options;

return {
name: "custom-jsdoc-tags-plugin",
analyzePhase({ ts, node, moduleDoc }: any) {
if(node.kind !== ts.SyntaxKind.ClassDeclaration) {
if (node.kind !== ts.SyntaxKind.ClassDeclaration) {
return;
}

const className = node.name.getText();
const component = moduleDoc?.declarations?.find((declaration: Component) => declaration.name === className);
const component = moduleDoc?.declarations?.find(
(declaration: Component) => declaration.name === className
);
const customTags = Object.keys(userOptions.tags || {});
let customComments = '/**';
let customComments = "/**";

node.jsDoc?.forEach((jsDoc: any) => {
jsDoc?.tags?.forEach((tag: any) => {
Expand All @@ -60,22 +73,22 @@ export function customJSDocTagsPlugin(
});

const parsed = parse(`${customComments}\n */`);
parsed[0]?.tags?.forEach(tagMeta => {
const tagOptions = userOptions.tags![tagMeta.tag]
if(!tagOptions) {
parsed[0]?.tags?.forEach((tagMeta) => {
const tagOptions = userOptions.tags![tagMeta.tag];
if (!tagOptions) {
return;
}

const propName = tagOptions.mappedName || tagMeta.tag;
const existingProp = component[propName];
const cemTag: CEMTag = {
name: tagMeta.name === '-' ? '' : tagMeta.name,
name: tagMeta.name === "-" ? "" : tagMeta.name,
default: tagMeta.default,
description: tagMeta.description.replace(/^\s?-/, '').trim(), // removes leading dash
type: tagMeta.type ? { text: tagMeta.type } : undefined
description: tagMeta.description.replace(/^\s?-/, "").trim(), // removes leading dash
type: tagMeta.type ? { text: tagMeta.type } : undefined,
};

if(!existingProp && tagOptions.isArray) {
if (!existingProp && tagOptions.isArray) {
component[propName] = [cemTag];
} else if (Array.isArray(component[propName])) {
component[propName].push(cemTag);
Expand All @@ -85,6 +98,8 @@ export function customJSDocTagsPlugin(
component[propName] = cemTag;
}
});
}
}

logBlue("[custom-jsdoc-tags] - Custom Elements Manifest updated.", options.hideLogs);
},
};
}
5 changes: 5 additions & 0 deletions packages/deprecator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.0

- Added the ability to hide logs
- Added the ability to skip the plugin

## 1.0.0

- Initial release
4 changes: 4 additions & 0 deletions packages/deprecator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ interface Options {
outdir?: string;
/** Class names of any components you would like to exclude from inheritance */
exclude?: string[];
/** Hides logs produced by the plugin */
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/deprecator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-elements-manifest-deprecator",
"version": "1.0.0",
"version": "1.1.0",
"description": "A tool for marking Custom Elements Manifest data as 'deprecated'",
"main": "index.js",
"module": "index.js",
Expand Down
5 changes: 0 additions & 5 deletions packages/deprecator/src/deprecator-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { updateCemDeprecations } from "./deprecator.js";
import type { Options, Params } from "./types.js";
import { logGreen } from "../../../tools/integrations/index.js";

export function cemDeprecatorPlugin(options: Options = {}) {
return {
name: "cem-deprecator",
packageLinkPhase({ customElementsManifest }: Params) {
console.log(
"[cem-deprecator] - Updating Custom Elements Manifest..."
);
updateCemDeprecations(customElementsManifest, options);
logGreen("[cem-deprecator] - Custom Elements Manifest update complete.");
},
};
}
4 changes: 2 additions & 2 deletions packages/deprecator/src/deprecator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { Options } from "./types.js";
let userConfig: Options = {};

export function updateCemDeprecations(cem: CEM, options: Options = {}) {
logBlue("[cem-inheritance-generator] - Updating Custom Elements Manifest...");
logBlue("[cem-deprecator] - Updating Custom Elements Manifest...", options.hideLogs);
const newCem = generateUpdatedCem(cem, options);
createOutDir(userConfig.outdir!);
saveFile(
userConfig.outdir!,
userConfig.fileName!,
JSON.stringify(newCem, null, 2)
);
logBlue("[cem-inheritance-generator] - Custom Elements Manifest updated.");
logBlue("[cem-deprecator] - Custom Elements Manifest updated.", options.hideLogs);
}

function updateOptions(options: Options = {}) {
Expand Down
5 changes: 4 additions & 1 deletion packages/deprecator/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ export interface Options {
outdir?: string;
/** Class names of any components you would like to exclude from inheritance */
exclude?: string[];
/** Hides logs produced by the plugin */
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
}

export interface Params {
customElementsManifest: CEM;
}


export interface Omit {
[key: string]: {
cssProperties?: string[];
Expand Down
Loading

0 comments on commit a3f078b

Please sign in to comment.