@pwrs/cem 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -216
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -17,179 +17,13 @@ For more options, see [Installation docs][installationdocs]
|
|
|
17
17
|
|
|
18
18
|
### `cem generate`
|
|
19
19
|
|
|
20
|
-
- **Generates CEM files** from source code using syntax analysis powered by
|
|
21
|
-
[go][go] and [tree-sitter][treesitter].
|
|
22
|
-
- Identifies custom elements, classes, variables, functions, and exports.
|
|
23
|
-
- Supports elements written in idiomatic Lit typescript style, with a
|
|
24
|
-
`@customElement` decorator, and `@property` decorators on class fields.
|
|
25
|
-
|
|
26
20
|
> [!NOTE]
|
|
27
21
|
> `cem generate` best supports LitElements written in idiomatic style with
|
|
28
22
|
> TypeScript decorators. There is rudimentary support for `extends HTMLElement`,
|
|
29
23
|
> but it is not a high priority for development. If you need something more
|
|
30
24
|
> specific [open an issue][issuenew].
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
Use JSDoc comments to add metadata to your element classes, similar to other
|
|
34
|
-
tools. Add a description by separating the name of the item with ` - `
|
|
35
|
-
|
|
36
|
-
- `@attr` / `@attribute` — Custom element attributes
|
|
37
|
-
- `@csspart` — CSS shadow parts
|
|
38
|
-
- `@cssprop` / `@cssproperty` — Custom CSS properties
|
|
39
|
-
- `@cssstate` — Custom CSS states
|
|
40
|
-
- `@demo` — Demo URL
|
|
41
|
-
- `@deprecated` — Marks a feature or member as deprecated
|
|
42
|
-
- `@event` — Custom events dispatched by the element
|
|
43
|
-
- `@slot` — Named or default slots
|
|
44
|
-
- `@summary` — Short summary for documentation
|
|
45
|
-
|
|
46
|
-
See the [test-fixtures](tree/main/generate/test-fixtures/) directory for examples
|
|
47
|
-
|
|
48
|
-
#### HTML Template Analysis for Slots and Parts
|
|
49
|
-
|
|
50
|
-
- **Automatically detects `<slot>` elements and `part` attributes in your element’s
|
|
51
|
-
`render()` template.**
|
|
52
|
-
- Merges slot and part information found in templates with any provided
|
|
53
|
-
via JSDoc, ensuring comprehensive documentation in the generated manifest.
|
|
54
|
-
- **Deprecation and other metadata** for slots and parts can be specified via
|
|
55
|
-
YAML in HTML comments.
|
|
56
|
-
- **Supports documenting slots and parts inline in your template HTML** using
|
|
57
|
-
HTML comments with YAML blocks.
|
|
58
|
-
- YAML comments are not necessary to detect slots and parts, but help in
|
|
59
|
-
documenting them for your users.
|
|
60
|
-
|
|
61
|
-
##### Examples
|
|
62
|
-
```html
|
|
63
|
-
<!--
|
|
64
|
-
summary: The main slot for content
|
|
65
|
-
description: |
|
|
66
|
-
This slot displays user-provided content.
|
|
67
|
-
Supports multiline **markdown**.
|
|
68
|
-
deprecated: true
|
|
69
|
-
-->
|
|
70
|
-
<slot></slot>
|
|
71
|
-
<!-- slot:
|
|
72
|
-
summary: Named slot summary
|
|
73
|
-
part:
|
|
74
|
-
summary: Part summary
|
|
75
|
-
-->
|
|
76
|
-
<slot name="info" part="info-part"></slot>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### CSS Custom Properties
|
|
80
|
-
Supports CSS Custom Properties by scanning css files and css tagged-template-literals
|
|
81
|
-
|
|
82
|
-
- Custom properties beginning with `_` will be ignored (treated as "private")
|
|
83
|
-
e.g. `var(--_private)`
|
|
84
|
-
- If you provide a [Design Tokens Community Group][dtcg] format module (JSON) to
|
|
85
|
-
`cem` via the `--design-tokens` flag,
|
|
86
|
-
`cem` will add metadata from your design system to any matching css variables it
|
|
87
|
-
finds in your elements
|
|
88
|
-
- You can use jsdoc-like comment syntax before each var call to document your
|
|
89
|
-
variables
|
|
90
|
-
|
|
91
|
-
##### Example
|
|
92
|
-
|
|
93
|
-
```css
|
|
94
|
-
:host {
|
|
95
|
-
color:
|
|
96
|
-
/**
|
|
97
|
-
* custom color for use in this element
|
|
98
|
-
* @summary color
|
|
99
|
-
* @deprecated just use the `color` property
|
|
100
|
-
*/
|
|
101
|
-
var(--custom-color);
|
|
102
|
-
border:
|
|
103
|
-
1px
|
|
104
|
-
solid
|
|
105
|
-
/** Border color of the element */
|
|
106
|
-
var(--border-color);
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
#### Element Demos
|
|
113
|
-
|
|
114
|
-
`cem generate` supports documenting your elements' demos by linking directly
|
|
115
|
-
from JSDoc, or by configurable file-system based discovery.
|
|
116
|
-
|
|
117
|
-
##### 1. JSDoc `@demo` Tag
|
|
118
|
-
|
|
119
|
-
Add demos directly to your element class or members with the `@demo` tag:
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
/**
|
|
123
|
-
* @demo https://example.com/my-element-plain/
|
|
124
|
-
* @demo https://example.com/my-element-fancy/ - A fancier demo with description
|
|
125
|
-
*/
|
|
126
|
-
@customElement('my-element')
|
|
127
|
-
class MyElement extends LitElement {
|
|
128
|
-
// ...
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Demos defined this way will always appear in your manifest for the element.
|
|
133
|
-
|
|
134
|
-
##### 2. Demo Discovery
|
|
135
|
-
|
|
136
|
-
`cem` can automatically discover demos from your codebase based on your
|
|
137
|
-
repository structure and configuration.
|
|
138
|
-
|
|
139
|
-
#### Demo Discovery Options
|
|
140
|
-
|
|
141
|
-
Configure demo discovery with the `demoDiscovery` key in your `.config/cem.yaml` file
|
|
142
|
-
|
|
143
|
-
```yaml
|
|
144
|
-
sourceControlRootUrl: "https://github.com/your/repo/tree/main/"
|
|
145
|
-
generate:
|
|
146
|
-
demoDiscovery:
|
|
147
|
-
fileGlob: "demos/**/*.html"
|
|
148
|
-
urlPattern: "demos/(?P<tag>[\w-]+)/(?P<demo>[\w-]+).html"
|
|
149
|
-
urlTemplate: "https://example.com/elements/{tag}/{demo}/"
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**Demo discovery options:**
|
|
153
|
-
|
|
154
|
-
| Option | Type | Description |
|
|
155
|
-
| ---------------------- | ------ | -------------------------------------------------------------------------------------------- |
|
|
156
|
-
| `fileGlob` | string | Glob pattern for discovering demo files. |
|
|
157
|
-
| `sourceControlRootUrl` | string | Canonical public source control URL for your repository root (on the main branch). |
|
|
158
|
-
| `urlPattern` | string | Pattern for generating demo URLs, e.g. `"demos/{tag}.html"`. `{tag}` is replaced by tag name.|
|
|
159
|
-
| `urlTemplate` | string | (optional) Alternative URL template for demo links. |
|
|
160
|
-
|
|
161
|
-
#### Usage
|
|
162
|
-
|
|
163
|
-
Generate a custom elements manifest from your files:
|
|
164
|
-
|
|
165
|
-
```sh
|
|
166
|
-
cem generate \
|
|
167
|
-
"src/**/*.ts" \
|
|
168
|
-
--design-tokens npm:@my-ds/tokens/tokens.json \
|
|
169
|
-
--exclude "src/**/*.test.ts" \
|
|
170
|
-
--output custom-elements.json
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
For npm projects you can use `npx @pwrs/cem generate ...`.
|
|
174
|
-
|
|
175
|
-
##### Command Line Arguments
|
|
176
|
-
|
|
177
|
-
| Argument | Type | Description |
|
|
178
|
-
| ------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------- |
|
|
179
|
-
| `<files or globs>` | positional (array) | Files or glob patterns to include |
|
|
180
|
-
| `--output, -o` | string | Write the manifest to this file instead of stdout |
|
|
181
|
-
| `--exclude, -e` | array | Files or glob patterns to exclude |
|
|
182
|
-
| `--no-default-excludes` | bool | Do not exclude files by default (e.g., `.d.ts` files will be included unless excluded explicitly) |
|
|
183
|
-
| `--design-tokens, -t` | string | Path or npm specifier for DTCG-format design tokens |
|
|
184
|
-
| `--design-tokens-prefix, -p` | string | CSS custom property prefix for design tokens |
|
|
185
|
-
| `--demo-discovery-file-glob` | string | Glob pattern for discovering demo files |
|
|
186
|
-
| `--demo-discovery-url-pattern` | string | Go Regexp pattern with named capture groups for generating canonical demo urls |
|
|
187
|
-
| `--demo-discovery-url-template` | string | URL pattern string using {groupName} syntax to interpolate named captures from the URL pattern |
|
|
188
|
-
| `--source-control-root-url` | string | Glob pattern for discovering demo files |
|
|
189
|
-
| `--project-dir` | string | Specify the project root directory to use for resolving relative paths and configuration. |
|
|
190
|
-
|
|
191
|
-
By default, some files (like `.d.ts` TypeScript declaration files) are excluded from the manifest.
|
|
192
|
-
Use `--no-default-excludes` if you want to include all matching files and manage excludes yourself.
|
|
26
|
+
See more in the [Generate docs][generatedocs]
|
|
193
27
|
|
|
194
28
|
---
|
|
195
29
|
|
|
@@ -198,56 +32,9 @@ Use `--no-default-excludes` if you want to include all matching files and manage
|
|
|
198
32
|
The `cem list` command provides a fast, flexible way to inspect custom elements, their features, and their metadata directly from your manifest file.
|
|
199
33
|
With `cem list`, you can quickly explore and audit your custom elements API surface, making it easier to document, test, and share your components.
|
|
200
34
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
- `cem list tags` — Lists all custom element tag names in the project.
|
|
204
|
-
- `cem list -t <tag> attrs` — Lists all attributes for a given custom element tag.
|
|
205
|
-
- `cem list -t <tag> slots` — Lists all named and default slots for a tag.
|
|
206
|
-
- `cem list -t <tag> events` — Lists all custom events fired by a tag, including their types and descriptions.
|
|
207
|
-
- `cem list -t <tag> css-properties` — Lists CSS custom properties (CSS variables) for a tag.
|
|
208
|
-
- `cem list -t <tag> css-states` — Lists CSS custom states for a tag.
|
|
209
|
-
- `cem list -t <tag> css-parts` — Lists CSS shadow parts for a tag.
|
|
210
|
-
- `cem list -t <tag> methods` — Lists methods for a tag's DOM object.
|
|
211
|
-
|
|
212
|
-
#### Column Filtering and Output
|
|
213
|
-
|
|
214
|
-
- Use the `--columns,-c` flag to specify which columns to include in the output, e.g.:
|
|
215
|
-
|
|
216
|
-
```sh
|
|
217
|
-
cem list events my-element -c name -c summary -c type
|
|
218
|
-
cem list attrs my-element -c description --columns default
|
|
219
|
-
```
|
|
220
|
-
Note that the name column is always included, and that if a column is specified but contains only empty values for all rows, it is automatically omitted from the output for clarity.
|
|
35
|
+
See more in the [List docs][listdocs]
|
|
221
36
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
- By default, tables are shown in a human-readable table format.
|
|
225
|
-
- [ ] TODO: json, markdown, flat lists, etc
|
|
226
|
-
|
|
227
|
-
## Configuration Reference
|
|
228
|
-
|
|
229
|
-
You can configure CEM via `.config/cem.yaml`, relative to your project root,
|
|
230
|
-
or via CLI flags.
|
|
231
|
-
|
|
232
|
-
### Example Configuration
|
|
233
|
-
|
|
234
|
-
```yaml
|
|
235
|
-
sourceControlRootUrl: "https://github.com/your/repo/tree/main/"
|
|
236
|
-
generate:
|
|
237
|
-
files:
|
|
238
|
-
- "src/**/*.ts"
|
|
239
|
-
exclude:
|
|
240
|
-
- "src/**/*.test.ts"
|
|
241
|
-
output: "custom-elements.json"
|
|
242
|
-
noDefaultExcludes: false
|
|
243
|
-
designTokens:
|
|
244
|
-
spec: "npm:@my-ds/tokens/tokens.json"
|
|
245
|
-
prefix: "--my-ds"
|
|
246
|
-
demoDiscovery:
|
|
247
|
-
fileGlob: "demos/**/*.html"
|
|
248
|
-
urlPattern: "demos/(?P<tag>[\w-]+)/(?P<demo>[\w-]+).html"
|
|
249
|
-
urlTemplate: "https://example.com/elements/{tag}/{demo}/"
|
|
250
|
-
```
|
|
37
|
+
See the [Configuration Reference][configdocs] for more information.
|
|
251
38
|
|
|
252
39
|
---
|
|
253
40
|
|
|
@@ -271,3 +58,6 @@ the terms of the [GNU General Public License v3.0][gpl3].
|
|
|
271
58
|
[contributingmd]: ./CONTRIBUTING.md
|
|
272
59
|
[issuenew]: https://github.com/bennypowers/cem/issues/new
|
|
273
60
|
[installationdocs]: https://bennypowers.github.io/cem/installation/
|
|
61
|
+
[generatedocs]: https://bennypowers.github.io/cem/commands/generate/
|
|
62
|
+
[listdocs]: https://bennypowers.github.io/cem/commands/list/
|
|
63
|
+
[configdocs]: https://bennypowers.github.io/cem/configuration/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pwrs/cem",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI tool for generating and working with Custom Elements Manifests",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"postinstall": "node ./install-platform-binary.js"
|
|
14
14
|
},
|
|
15
15
|
"optionalDependencies": {
|
|
16
|
-
"@pwrs/cem-linux-x64": "0.
|
|
17
|
-
"@pwrs/cem-linux-arm64": "0.
|
|
18
|
-
"@pwrs/cem-darwin-x64": "0.
|
|
19
|
-
"@pwrs/cem-darwin-arm64": "0.
|
|
20
|
-
"@pwrs/cem-win32-x64": "0.
|
|
21
|
-
"@pwrs/cem-win32-arm64": "0.
|
|
16
|
+
"@pwrs/cem-linux-x64": "0.2.0",
|
|
17
|
+
"@pwrs/cem-linux-arm64": "0.2.0",
|
|
18
|
+
"@pwrs/cem-darwin-x64": "0.2.0",
|
|
19
|
+
"@pwrs/cem-darwin-arm64": "0.2.0",
|
|
20
|
+
"@pwrs/cem-win32-x64": "0.2.0",
|
|
21
|
+
"@pwrs/cem-win32-arm64": "0.2.0"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"bin/cem.js",
|