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

NEXT: Automated Documentation #2399

Open
7 of 12 tasks
endigo9740 opened this issue Jan 3, 2024 · 2 comments
Open
7 of 12 tasks

NEXT: Automated Documentation #2399

endigo9740 opened this issue Jan 3, 2024 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@endigo9740
Copy link
Contributor

endigo9740 commented Jan 3, 2024

This will act as a hub to centralize this information.

Goal

We need to determine a framework-agnostic solution to retrieve and document props, events, and children within each component. This will replace our Svelte-only option used in previous versions of Skeleton, called Sveld.

Solutions

Svelte:

React:

Not Used:

Todo

  • Create a prototype using Astro and a simple test component and type
  • Create a reusable doc component to scaffold an API block on demand
  • Test implementation with the Avatar component
  • Update contribution instructions

Feedback

If you have additional updates or requests for this feature, please do so in the comments section below.

@endigo9740 endigo9740 added enhancement New feature or request feature request Request a feature or introduce and update to the project. labels Jan 3, 2024
@endigo9740 endigo9740 added this to the v3.0 (Next) milestone Jan 3, 2024
@endigo9740 endigo9740 added administration Items related to the project but outside the code. and removed enhancement New feature or request feature request Request a feature or introduce and update to the project. labels Jan 3, 2024
@endigo9740 endigo9740 pinned this issue Mar 14, 2024
@endigo9740 endigo9740 changed the title NEXT: Automated Documentation (Sveld Replacement) NEXT: Automated Documentation (ex: Sveld) Mar 14, 2024
@endigo9740 endigo9740 changed the title NEXT: Automated Documentation (ex: Sveld) NEXT: Automated Documentation Mar 14, 2024
@endigo9740 endigo9740 unpinned this issue Mar 20, 2024
@endigo9740 endigo9740 pinned this issue Apr 1, 2024
@endigo9740 endigo9740 added documentation Improvements or additions to documentation and removed administration Items related to the project but outside the code. labels Apr 11, 2024
@endigo9740 endigo9740 linked a pull request Apr 12, 2024 that will close this issue
@endigo9740
Copy link
Contributor Author

endigo9740 commented May 16, 2024

Sharing this for future reference. @Hugos68 implemented a programmatic way to generate schema via a custom Node script using vega/ts-json-schema-generator. Which is a more modern fork than we're using atm. While super cool, this is probably overkill for the time being. It's also blocked by this PR, which is preventing Windows users at the moment.

import glob from "fast-glob";
import { join } from "path";
import { createGenerator } from "ts-json-schema-generator";
import { promises as fs } from "fs";
import { performance } from "perf_hooks";

/**
 *    Generate schema for a ts file
 * @param {string} path
 * @returns {ReturnType<ReturnType<typeof createGenerator>['createSchema']>}
 */
function generate_schema(path) {
    /** @type {import('ts-json-schema-generator/dist/src/Config').Config} */
    const config = {
        path,
        type: "*",
        skipTypeCheck: true,
    };
    const generator = createGenerator(config);
    const schema = generator.createSchema(config.type);
    return schema;
}

/**
 * @param configuration Configuration object
 * @param configuration.matcher The glob pattern to match the files.
 * @param configuration.output_name The name of the output schema file.
 */
async function main({ matcher, output_name }) {
    /**
     * @type {Array<Promise<void>>}
     */
    const promises = [];
    const files = await glob(matcher);
    for (const file of files) {
        const promise = new Promise((resolve) => {
            const start = performance.now();
            const file_path = join(import.meta.dirname, file);
            const schema_path = file_path.replace("types.ts", output_name);
            const schema = generate_schema(file_path);
            fs.writeFile(schema_path, JSON.stringify(schema, null, 2)).then(() => {
                const end = performance.now();
                console.log(`Schema generated for: "${file_path}"
Schema saved at: "${schema_path}"
Time taken: ${(end - start).toFixed("2")}ms
`);
                resolve();
            });
        });
        promises.push(promise);
    }
    await Promise.all(promises);
}

await main({
    matcher: "**/src/components/**/types.ts",
    output_name: "schema.json",
});

@endigo9740
Copy link
Contributor Author

Just a quick update for this...

We've now implemented support for React component auto-docs via:
https://github.com/YousefED/typescript-json-schema?tab=readme-ov-file

This allows for everything but automatically fetching the default value. A new table component has been introduced to display the schema information per all existing component pages.

In the future, we'll revisit this to handle Svelte 5, likely using:
https://github.com/ghostdevv/extractinator

We'll also look at migrating React to following tool, or whatever solution allows us to populate the default values:
https://github.com/vega/ts-json-schema-generator

This tool operates in a similar manner, but is a more recent "fork" with some improvements.

@endigo9740 endigo9740 unpinned this issue May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants