Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--readme flag #93

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/analyzer/fixtures/cli-readme-flag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# `my-element.js`:

## class: `MyElement`, `my-element`

### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ----- | ------- | -------- | ------- | ----------- | -------------- |
| `foo` | | `string` | `'bar'` | | |

<hr/>

## class: `MyWindow`, `my-window`

### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

<hr/>

## Exports

| Kind | Name | Declaration | Module | Package |
| --------------------------- | ------------ | ----------- | ------------- | ------- |
| `custom-element-definition` | `my-foo` | MyFoo | /foo.js | |
| `custom-element-definition` | `my-bar` | MyBar | | foo |
| `custom-element-definition` | `my-element` | MyElement | my-element.js | |
| `custom-element-definition` | `my-window` | MyWindow | my-element.js | |
76 changes: 76 additions & 0 deletions packages/analyzer/fixtures/cli-readme-flag/custom-elements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"schemaVersion": "1.0.0",
"readme": "",
"modules": [
{
"kind": "javascript-module",
"path": "my-element.js",
"declarations": [
{
"kind": "class",
"description": "",
"name": "MyElement",
"members": [
{
"kind": "field",
"name": "foo",
"type": {
"text": "string"
},
"default": "'bar'"
}
],
"superclass": {
"name": "HTMLElement"
},
"tagName": "my-element",
"customElement": true
},
{
"kind": "class",
"description": "",
"name": "MyWindow",
"superclass": {
"name": "HTMLElement"
},
"tagName": "my-window",
"customElement": true
}
],
"exports": [
{
"kind": "custom-element-definition",
"name": "my-foo",
"declaration": {
"name": "MyFoo",
"module": "/foo.js"
}
},
{
"kind": "custom-element-definition",
"name": "my-bar",
"declaration": {
"name": "MyBar",
"package": "foo"
}
},
{
"kind": "custom-element-definition",
"name": "my-element",
"declaration": {
"name": "MyElement",
"module": "my-element.js"
}
},
{
"kind": "custom-element-definition",
"name": "my-window",
"declaration": {
"name": "MyWindow",
"module": "my-element.js"
}
}
]
}
]
}
36 changes: 36 additions & 0 deletions packages/analyzer/fixtures/cli-readme-flag/fixture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# `my-element.js`:

## class: `MyElement`, `my-element`

### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ----- | ------- | -------- | ------- | ----------- | -------------- |
| `foo` | | `string` | `'bar'` | | |

<hr/>

## class: `MyWindow`, `my-window`

### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

<hr/>

## Exports

| Kind | Name | Declaration | Module | Package |
| --------------------------- | ------------ | ----------- | ------------- | ------- |
| `custom-element-definition` | `my-foo` | MyFoo | /foo.js | |
| `custom-element-definition` | `my-bar` | MyBar | | foo |
| `custom-element-definition` | `my-element` | MyElement | my-element.js | |
| `custom-element-definition` | `my-window` | MyWindow | my-element.js | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"schemaVersion": "1.0.0",
"readme": "",
"modules": [
{
"kind": "javascript-module",
"path": "my-element.js",
"declarations": [
{
"kind": "class",
"description": "",
"name": "MyElement",
"members": [
{
"kind": "field",
"name": "foo",
"type": {
"text": "string"
},
"default": "'bar'"
}
],
"superclass": {
"name": "HTMLElement"
},
"tagName": "my-element",
"customElement": true
},
{
"kind": "class",
"description": "",
"name": "MyWindow",
"superclass": {
"name": "HTMLElement"
},
"tagName": "my-window",
"customElement": true
}
],
"exports": [
{
"kind": "custom-element-definition",
"name": "my-foo",
"declaration": {
"name": "MyFoo",
"module": "/foo.js"
}
},
{
"kind": "custom-element-definition",
"name": "my-bar",
"declaration": {
"name": "MyBar",
"package": "foo"
}
},
{
"kind": "custom-element-definition",
"name": "my-element",
"declaration": {
"name": "MyElement",
"module": "my-element.js"
}
},
{
"kind": "custom-element-definition",
"name": "my-window",
"declaration": {
"name": "MyWindow",
"module": "my-element.js"
}
}
]
}
]
}
36 changes: 36 additions & 0 deletions packages/analyzer/fixtures/cli-readme-flag/package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## `my-element.js`:

### class: `MyElement`, `my-element`

#### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

#### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ----- | ------- | -------- | ------- | ----------- | -------------- |
| `foo` | | `string` | `'bar'` | | |

<hr/>

### class: `MyWindow`, `my-window`

#### Superclass

| Name | Module | Package |
| ------------- | ------ | ------- |
| `HTMLElement` | | |

<hr/>

### Exports

| Kind | Name | Declaration | Module | Package |
| --------------------------- | ------------ | ----------- | ------------- | ------- |
| `custom-element-definition` | `my-foo` | MyFoo | /foo.js | |
| `custom-element-definition` | `my-bar` | MyBar | | foo |
| `custom-element-definition` | `my-element` | MyElement | my-element.js | |
| `custom-element-definition` | `my-window` | MyWindow | my-element.js | |
12 changes: 12 additions & 0 deletions packages/analyzer/fixtures/cli-readme-flag/package/my-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {MyFoo} from './foo.js';
import {MyBar} from 'foo';

class MyElement extends HTMLElement {
foo = 'bar';
}
class MyWindow extends HTMLElement {}

customElements.define('my-foo', MyFoo);
customElements.define('my-bar', MyBar);
customElements.define('my-element', MyElement);
window.customElements.define('my-window', MyWindow);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "my-el",
"customElements": "../custom-elements.json"
}
35 changes: 20 additions & 15 deletions packages/analyzer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import chokidar from 'chokidar';
import debounce from 'debounce';

import { create } from './src/create.js';
import {
getUserConfig,
getCliConfig,
addFrameworkPlugins,
import {
getUserConfig,
getCliConfig,
addFrameworkPlugins,
addReadmePlugin,
addCustomElementsPropertyToPackageJson,
mergeGlobsAndExcludes,
timestamp,
Expand All @@ -24,7 +25,7 @@ import {
const mainDefinitions = [{ name: 'command', defaultOption: true }];
const mainOptions = commandLineArgs(mainDefinitions, { stopAtFirstUnknown: true });
const argv = mainOptions._unknown || [];

if (mainOptions.command === 'analyze') {

const cliConfig = getCliConfig(argv)
Expand All @@ -41,31 +42,35 @@ import {
async function run() {
/**
* Create modules for `create()`
*
*
* By default, the analyzer doesn't actually compile a users source code with the TS compiler
* API. This means that by default, the typeChecker is not available in plugins.
*
*
* If users want to use the typeChecker, they can do so by adding a `overrideModuleCreation` property
* in their custom-elements-manifest.config.js. `overrideModuleCreation` is a function that should return
* an array of sourceFiles.
*/
const modules = userConfig?.overrideModuleCreation
const modules = userConfig?.overrideModuleCreation
? userConfig.overrideModuleCreation({ts, globs})
: globs.map(glob => {
const relativeModulePath = path.relative(process.cwd(), glob);
const source = fs.readFileSync(relativeModulePath).toString();

return ts.createSourceFile(
relativeModulePath,
source,
ts.ScriptTarget.ES2015,
true,
);
});

let plugins = await addFrameworkPlugins(mergedOptions);
plugins = [...plugins, ...(userConfig?.plugins || [])];

plugins = [
...plugins,
...await addReadmePlugin(mergedOptions),
...(userConfig?.plugins || [])
];

/**
* Create the manifest
*/
Expand Down Expand Up @@ -93,9 +98,9 @@ import {
*/
if(mergedOptions.watch) {
const fileWatcher = chokidar.watch(globs);

const onChange = debounce(run, 100);

fileWatcher.addListener('change', onChange);
fileWatcher.addListener('unlink', onChange);
}
Expand All @@ -108,4 +113,4 @@ import {
} else {
console.log(MENU);
}
})();
})();
1 change: 1 addition & 0 deletions packages/analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"command-line-args": "^5.1.2",
"comment-parser": "^1.1.5",
"custom-elements-manifest": "^1.0.0",
"cem-plugin-readme": "0.1.2",
"debounce": "^1.2.1",
"globby": "^11.0.4",
"typescript": "^4.3.2"
Expand Down
Loading