Skip to content

Commit

Permalink
feat: initial checkin typedoc for api
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 25, 2020
1 parent e335483 commit 47064cb
Show file tree
Hide file tree
Showing 40 changed files with 4,939 additions and 341 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
# Table of contents

- [Core packages](#core-packages)
- [@component-controls/specification](#component-controlsspecification)
- [@component-controls/core](#component-controlscore)
- [@component-controls/instrument](#component-controlsinstrument)
- [@component-controls/loader](#component-controlsloader)
- [UI packages](#ui-packages)
- [@component-controls/components](#component-controlscomponents)
- [@component-controls/editors](#component-controlseditors)
- [@component-controls/blocks](#component-controlsblocks)
- [Props info](#props-info)
- [@component-controls/react-docgen-info](#component-controlsreact-docgen-info)
- [@component-controls/react-docgen-typescript-info](#component-controlsreact-docgen-typescript-info)

# Core packages

<package-section file="./core/specification/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/specification](https://github.com/ccontrols/component-controls/blob/master/core/specification)

Component controls specification with typescript definitions

Typescript definitions of the component-controls specification.

<!-- END-PACKAGE-SECTION -->

<package-section file="./core/core/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/core](https://github.com/ccontrols/component-controls/blob/master/core/core)

Component controls core utility routines

<!-- END-PACKAGE-SECTION -->

<package-section file="./core/instrument/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->
Expand All @@ -34,6 +62,16 @@ Parsing a source file will generate the following information:

<!-- END-PACKAGE-SECTION -->

<package-section file="./core/loader/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/loader](https://github.com/ccontrols/component-controls/blob/master/core/loader)

Webpack loader for component controls instrumentation

<!-- END-PACKAGE-SECTION -->

# UI packages

<package-section file="./ui/components/README.md" section="overview" />
Expand Down Expand Up @@ -97,3 +135,33 @@ Some of the guiding design goals for this library:
- Compnents that deal with source code (story or component source) display actions to browse their respective repositories.

<!-- END-PACKAGE-SECTION -->

# Props info

<package-section file="./props-info/react-docgen/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/react-docgen-info](https://github.com/ccontrols/component-controls/blob/master/frameworks/react)

Component controls react-docgen props info loader

Extract props info from react components. Although the latest version of `react-docgen` does support typescript, the typescript support still lags and is not recommended for use

- Uses [react-docgen](https://github.com/reactjs/react-docgen)

<!-- END-PACKAGE-SECTION -->

<package-section file="./props-info/react-docgen-typescript/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/react-docgen-typescript-info](https://github.com/ccontrols/component-controls/blob/master/frameworks/react)

Component controls react-docgen-typescript props info loader

Extract props info from react typescript components:

- Uses [react-docgen-typescript](https://github.com/styleguidist/react-docgen-typescript)

<!-- END-PACKAGE-SECTION -->
18 changes: 12 additions & 6 deletions core/instrument/src/misc/propsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import * as path from 'path';
import * as os from 'os';
import { createHash } from 'crypto';
import findCacheDir from 'find-cache-dir';
import { ComponentInfo } from '@component-controls/specification';
import { PropsLoaderConfig, PropsInfoExtractorFunction } from '../types';
import {
ComponentInfo,
PropsInfoExtractorFunction,
} from '@component-controls/specification';
import { PropsLoaderConfig } from '../types';

export const propsInfo = async (
options: PropsLoaderConfig[],
Expand Down Expand Up @@ -58,10 +61,13 @@ export const propsInfo = async (
}
const propsLoaderName = loaders.length === 1 ? loaders[0] : undefined;
if (propsLoaderName) {
const propsLoader: PropsInfoExtractorFunction = require(propsLoaderName.name)(
propsLoaderName.options,
);
result = await propsLoader(filePath, componentName, source);
const { run } = require(propsLoaderName.name);
if (run) {
const propsLoader: PropsInfoExtractorFunction = run(
propsLoaderName.options,
);
result = await propsLoader(filePath, componentName, source);
}
}
fs.writeFileSync(cachedFileName, JSON.stringify(result || {}));
return result;
Expand Down
25 changes: 0 additions & 25 deletions core/instrument/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Options,
ResolveConfigOptions as ResolvePrettierConfigOptions,
} from 'prettier';
import { ComponentInfo } from '@component-controls/specification';

type PrettierOptions = Options & {
resolveConfigOptions?: ResolvePrettierConfigOptions;
Expand All @@ -24,30 +23,6 @@ export const defaultMDXOptions: MDXOptions = {
test: /\.mdx$/,
};

/**
* callback function to extract props info table - ie docgen type libraries
* used to extract displayName, and props tables for a component
*/
export type PropsInfoExtractorFunction = (
/**
* full name and path of the component path
* react-docgen needs it to extract babel configurations
*/
fileName: string,
/**
* optional component name
* react-docgen-typescript supports multiple exports for a file
* react-docgne does not use it
*/
componentName?: string,
/**
* optional soure, saves time if its already loaded
* react-docgen accepts source as input parameter
* react-docgen-typescript does not use it
*/
source?: string,
) => Promise<ComponentInfo | undefined>;

/**
* settings to load component props tables
* each component file extension must resolve to only 1 props info loader
Expand Down
41 changes: 41 additions & 0 deletions core/specification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Table of contents

- [Overview](#overview)
- [Installation](#installation)
- [API](#api)
- [PropsInfoExtractorFunction](#propsinfoextractorfunction)

# Overview

Typescript definitions of the component-controls specification.

# Installation

This package is usually installed as part of the @component-controls package, but you can also install it standalone:

```bash
$ npm install @component-controls/specification --save-dev
```

# API

<tsdoc-typescript entry="./src/propsinfo.ts"/>

<!-- START-TSDOC-TYPESCRIPT -->

## PropsInfoExtractorFunction

callback function to extract props info table - ie docgen type libraries
used to extract displayName, and props tables for a component

(`fileName`\*: string, `componentName`: undefined | string, `source`: undefined | string): Promise&lt;[ComponentInfo](#componentinfo) | undefined> | [ComponentInfo](#componentinfo) | undefined;

### parameters

| Name | Type | Description |
| --------------- | ------------------- | ----------- |
| `fileName*` | string | |
| `componentName` | undefined \| string | |
| `source` | undefined \| string | |

<!-- END-TSDOC-TYPESCRIPT -->
1 change: 1 addition & 0 deletions core/specification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
"dev": "yarn cross-env NODE_ENV=development yarn build -w",
"docs": "ts-node -O '{\"module\": \"commonjs\"}' ../../scripts/docs.ts",
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
Expand Down
1 change: 1 addition & 0 deletions core/specification/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './components';
export * from './controls';
export * from './propsInfo';
export * from './stories';
export * from './utility';

Expand Down
17 changes: 17 additions & 0 deletions core/specification/src/propsInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ComponentInfo } from './components';

/**
* callback function to extract props info table - ie docgen type libraries
* used to extract displayName, and props tables for a component
*
* @param fileName full name and path of the component path react-docgen needs it to extract babel configurations.
* @param componentName optional component name react-docgen-typescript supports multiple exports for a file react-docgne does not use it.
* @param source optional soure, saves time if its already loaded react-docgen accepts source as input parameter react-docgen-typescript does not use it.
*
* @returns async or normal function that loads ComponentInfo props info.
*/
export type PropsInfoExtractorFunction = (
fileName: string,
componentName?: string,
source?: string,
) => Promise<ComponentInfo | undefined> | ComponentInfo | undefined;
Loading

0 comments on commit 47064cb

Please sign in to comment.