Skip to content

Commit

Permalink
feat: add props-info react-docgen and react-docgen-typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 10, 2020
1 parent 11cecc3 commit 8159202
Show file tree
Hide file tree
Showing 54 changed files with 4,172 additions and 24 deletions.
50 changes: 48 additions & 2 deletions core/instrument/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ___

### parseMDX

**parseMDX**(`source`: string, `filePath`: string, `options?`: [InstrumentOptions](#instrumentoptions)): *Promise‹StoriesStore›*
**parseMDX**(`source`: string, `filePath`: string, `optionsMDX?`: [InstrumentOptionsMDX](#instrumentoptionsmdx)): *Promise‹StoriesStore›*

Parse and instrument an MDX file of stories

Expand All @@ -59,7 +59,7 @@ Name | Type | Description |
------ | ------ | ------ |
`source` | string | Source of the file to be instrumented |
`filePath` | string | Resolved file path name. |
`options?` | [InstrumentOptions](#instrumentoptions) | Instrumenting options |
`optionsMDX?` | [InstrumentOptionsMDX](#instrumentoptionsmdx) | Instrumenting options |

**Returns:** *Promise‹StoriesStore›*

Expand Down Expand Up @@ -126,6 +126,19 @@ passing a value of false as prettier option will disabled prettifying

Options to control resolving filenames.

___

## InstrumentOptionsMDX

extends [InstrumentOptions](#instrumentoptions)) and adds options for `mdx-js`.

### Properties

**mdx**? : *[MDXOptions](#mdxoptions)*

Options for mdx-js compiling


___

## ComponentOptions
Expand Down Expand Up @@ -447,6 +460,39 @@ how to read files synchronously (defaults to fs.readFileSync)

___

# MDXOptions

Options to control `mdx-js`.

*Defined in [@types/resolve/index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/82af14cb371792e3f98e9f10b176de8cf78fd858/types/resolve/index.d.ts#L104)*


**footnotes**? : *boolean*

enable footnotes


**mdPlugins**? : *any[]*

specify remark plugins


**hastPlugins**? : *any[]*

specify rehype plugins


**compilers**? : *any[]*

specify markdown compilers


**blocks**? : *string[]*

regex for blocks, defaults to ['[a-z\\.]+(\\.){0,1}[a-z\\.]']

___

## PackageInfoOptions

Options for finding and extracting package.json informtation, applies both for components and stories.
Expand Down
6 changes: 4 additions & 2 deletions core/instrument/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { extractSotreComponent } from './babel/extract-component';
import { packageInfo } from './project/packageInfo';
import {
InstrumentOptions,
InstrumentOptionsMDX,
ParserOptions,
defaultParserOptions,
ResolveOptions,
Expand Down Expand Up @@ -200,9 +201,10 @@ export const parseCSF = async (
export const parseMDX = async (
source: string,
filePath: string,
options?: InstrumentOptions,
optionsMDX?: InstrumentOptionsMDX,
): Promise<StoriesStore> => {
const code = await mdx(source);
const { mdx: mdxOptions, ...options } = optionsMDX || {};
const code = await mdx(source, mdxOptions);

const ast = parser.parse(code, {
sourceType: 'module',
Expand Down
35 changes: 35 additions & 0 deletions core/instrument/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,38 @@ export interface InstrumentOptions {
*/
stories?: StoriesOptions;
}

/**
* mdx-js options
*/
export interface MDXOptions {
/**
* enable footnotes
*/

footnotes?: boolean;
/**
* specify remark plugins
*/
mdPlugins?: any[];
/**
* specify rehype plugins
*/
hastPlugins?: any[];
/**
* specify markdown compilers
*/
compilers?: any[];

/**
* regex for blocks, defaults to ['[a-z\\.]+(\\.){0,1}[a-z\\.]']
*/
blocks?: string[];
}

/**
* instrument MDX has additional mdx options
*/
export interface InstrumentOptionsMDX extends InstrumentOptions {
mdx?: MDXOptions;
}
7 changes: 5 additions & 2 deletions core/loader/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { InstrumentOptions } from '@component-controls/instrument';
import {
InstrumentOptions,
InstrumentOptionsMDX,
} from '@component-controls/instrument';

export type LoaderOptions = {
type?: 'csf' | 'mdx';
} & InstrumentOptions;
} & (InstrumentOptions | InstrumentOptionsMDX);
57 changes: 42 additions & 15 deletions core/specification/src/components.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,66 @@
import { CodeLocation, Repository } from './utility';

export type TypeValue =
| 'any'
| 'boolean'
| 'number'
| 'string'
| 'array'
| 'object'
| 'enum'
| 'union'
| 'literal'
| 'symbol'
| 'function'
| string;

export interface TypeInformatiom {
name: TypeValue;

/**
* type value
* elements of enum, array, fields of object
* return value of function
*/
value?: TypeInformatiom[] | any;

/**
* raw type code
*/
raw?: string;

/**
* argument types of function
*/
arguments?: TypeInformatiom[] | any;
}

/**
* docgen generated property types
* mapped to common types to be consumed by component-controls
* check props-info packages for implementations
*/
export interface PropType {
/**
* default value for the property
*/
defaultValue: { value?: string | boolean; computed: boolean };
defaultValue?: any;
/**
* propertty type
*/
type: { name?: string };
type: TypeInformatiom;
/**
* is the property required
*/
required: boolean;
/**
* description of the property
*/
description: string;
description?: string;
/**
* where was the propetyy declared
* name of the parent/inherited property
*/
parent?: {
/**
* file name where the parent property was declared
*/
fileName: string;

/**
* name of the parent/inherited property
*/
name: string;
};
parentName?: string;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"lerna": "3.1.3",
"packages": [
"core/**/*",
"props-info/**/*",
"integrations/**/*",
"ui/**/*"
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"packages": [
"core/*",
"integrations/*",
"props-info/*",
"ui/*",
"examples/*"
]
Expand Down
13 changes: 13 additions & 0 deletions props-info/react-docgen-typescript/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
1 change: 1 addition & 0 deletions props-info/react-docgen-typescript/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
3 changes: 3 additions & 0 deletions props-info/react-docgen-typescript/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: 'docz-ts',
}
21 changes: 21 additions & 0 deletions props-info/react-docgen-typescript/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Atanas Stoyanov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file.
63 changes: 63 additions & 0 deletions props-info/react-docgen-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@component-controls/react-docgen-typescript-info",
"version": "0.6.0",
"private": true,
"description": "Component controls addon to read react-docgen-typescript props informtion",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"files": [
"dist/",
"package.json",
"README.md"
],
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
"dev": "yarn cross-env NODE_ENV=development yarn build -w",
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
"test": "yarn jest"
},
"homepage": "https://github.com/ccontrols/component-controls",
"bugs": {
"url": "https://github.com/ccontrols/component-controls/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/ccontrols/component-controls.git",
"directory": "frameworks/react"
},
"license": "MIT",
"dependencies": {
"@component-controls/specification": "^0.6.0",
"react": "^16.12.0",
"react-docgen-typescript": "^1.16.1"
},
"devDependencies": {
"@types/jest": "^25.1.2",
"@types/react": "^16.9.23",
"cross-env": "^5.2.1",
"docz-rollup": "^2.1.0",
"eslint": "^6.5.1",
"eslint-config-docz-ts": "^2.1.0",
"jest": "^24.9.0",
"typescript": "3.5.3"
},
"peerDependencies": {
"@component-controls/specification": "*",
"react": "*"
},
"jest": {
"testEnvironment": "node",
"roots": [
"."
]
},
"publishConfig": {
"access": "public"
},
"authors": [
"Atanas Stoyanov"
]
}
5 changes: 5 additions & 0 deletions props-info/react-docgen-typescript/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { config } from 'docz-rollup';

export default config({
input: ['./src/index.ts'],
});
Loading

0 comments on commit 8159202

Please sign in to comment.