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

Feature request: extract code from examples #59

Closed
ext opened this issue Sep 9, 2024 · 0 comments
Closed

Feature request: extract code from examples #59

ext opened this issue Sep 9, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed triaged

Comments

@ext
Copy link
Contributor

ext commented Sep 9, 2024

Add a way to extract all code examples and support running external tools on the code:

  • Compile with typescript
  • Lint with ESLint

It should include a mechanism to configure such tools, e.g. a way to set which eslint rules to use or the path configuration for typescript.

Given a library my-awesome-lib with a function add(a: number, b: number):

```ts
import { add } from "my-awesome-lib";

const sum = add(1);
```

This example would be compiled with a tsconfig "paths": { "my-awesome-lib": "./dist" } and thus yield an error about missing the second argument to the add function.

Similarly eslint would yield an error about unused variable sum.

If the source is temporary stored on the filesystem the filenames should be traceable to where they originates from, both which file but also which example within that file. Something automagical that does not require explicit tagging. ${basename}-${index}-${hash}.${lang}?

There should be an override to prevent examples to be extracted, e.g.:

```ts nocompile
```

Should be language agnostic but preferably configurable which langauges to extract, possibly even map them to extensions:

Hypotetical processor:

extractExamplesProcessor({
    outdir: "docs/examples",
    languages: ["ts", "vue"],
}),

Where docs/examples contains a tsconfig.json but is otherwise gitignored and a postbuild script runts tsc -b docs/examples. Eslint runs as usual.

This is a major showstopper for migration for my projects.

@ext ext added the enhancement New feature or request label Sep 9, 2024
@Marie-Jakobsson Marie-Jakobsson added help wanted Extra attention is needed triaged labels Oct 7, 2024
ext added a commit that referenced this issue Nov 2, 2024
ext added a commit that referenced this issue Nov 2, 2024
ext added a commit that referenced this issue Nov 3, 2024
ext added a commit that referenced this issue Nov 3, 2024
ext added a commit that referenced this issue Nov 4, 2024
@ext ext closed this as completed in 2559b06 Nov 4, 2024
github-actions bot pushed a commit that referenced this issue Nov 4, 2024
## [2.13.0](v2.12.0...v2.13.0) (2024-11-04)

### Features

* allow to cut snippets from examples ([db07585](db07585))
* new `extractExamplesProcessor` ([2559b06](2559b06)), closes [#59](#59)
* strip eslint comments from examples ([5dd604e](5dd604e))

### Bug Fixes

* `cacheFolder` is optional ([e4ad918](e4ad918))
* `exampleFolders` is optional ([bf4893d](bf4893d))
* `markdown.messagebox` is optional ([d558a90](d558a90))
* `motdProcessor` options is optional ([d43c0cb](d43c0cb))
* `outputFolder` is optional ([53dde23](53dde23))
* only match filenames when matching source files ([aec08fa](aec08fa))

### Performance Improvements

* reuse same manifest `md` instance for all calls ([616f226](616f226))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed triaged
Projects
None yet
Development

No branches or pull requests

2 participants