Skip to content

Commit

Permalink
feat: add draft prop to document
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 15, 2020
1 parent e716842 commit d8736d2
Show file tree
Hide file tree
Showing 19 changed files with 256 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"program": "${workspaceFolder}/node_modules/.bin/jest",
"cwd": "${workspaceFolder}/core/webpack-compile",
"args": [
"subcomponents",
"draft",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
Expand Down
37 changes: 19 additions & 18 deletions core/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ $ npm install @component-controls/core --save-dev

# API

<tsdoc-typescript entry="./src/stories.ts,./src/controls.ts,./src/components.ts,./src/propsInfo.ts,./src/utility.ts,./src/configuration.ts"/>
<tsdoc-typescript entry="./src/document.ts,./src/controls.ts,./src/components.ts,./src/propsInfo.ts,./src/utility.ts,./src/configuration.ts"/>

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

## ArgUsageLocation

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L12)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L12)_



Expand All @@ -127,7 +127,7 @@ A documentation file's metadata.
For MDX files, fromtmatter is used to declare the document properties.
For ESM (ES Modules) documentation files, the default export is used.

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L165)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L165)_



Expand All @@ -145,6 +145,7 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro
| `dateModified` | [Date](#date) | optional date the document was last modified. If not assigned, the instrumentation process will use mtime |
| `decorators` | [StoryRenderFn](#storyrenderfn)\[] | array of wrapper functions (decorators) to be called when rendering each individual story. |
| `description` | string | documentation file description |
| `draft` | boolean | if set to true, the document will be hidden in production builds. |
| `fileName` | string | file name of the file of stories |
| `fullPage` | boolean | if true, will display the documentation page full size (pagecontainer.full theme variant) the default value is from the doc type configuration |
| `isMDXComponent` | boolean | custom prop set by mdxjs |
Expand All @@ -163,13 +164,13 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

list of story files, or groups

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L311)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L316)_

`title`\*: string: [Document](#document)

## SmartControls

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L62)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L62)_



Expand All @@ -185,7 +186,7 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

an identifier/variable.argument in the source code

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L8)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L8)_



Expand All @@ -200,15 +201,15 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

map of stories. The id is compatible with storybook's story ids

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L155)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L155)_

`id`\*: string: [Story](#story)

## StoriesStore

store of stories information in memory after the loader is applied

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L334)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L339)_



Expand All @@ -226,7 +227,7 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

Story interface - usually extracted by the AST instrumenting loader

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L80)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L80)_



Expand All @@ -253,7 +254,7 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

arguments passed to the 'story' function, extracted by an AST loader

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L36)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L36)_



Expand All @@ -270,29 +271,29 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro

list of components used in stories

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L304)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L309)_

`fileName`\*: string: [StoryComponent](#storycomponent)

## StoryPackages

list of repositories

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L327)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L332)_

`id`\*: string: [PackageInfo](#packageinfo)

## StoryStories

list of stories

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L320)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L325)_

`id`\*: string: [Story](#story)

## Pages

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L315)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L320)_

[Document](#document)\[]

Expand All @@ -301,19 +302,19 @@ _defined in [@component-controls/core/src/stories.ts](https://github.com/ccontro
list of story arguments. Each argument can be a deconstructed argument of itself
the first argument are the control 'values'

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L60)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L60)_

[StoryArgument](#storyargument)\[]

## defDocType

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L159)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L159)_



## dateToLocalString

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L294)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L299)_

**function** dateToLocalString(`date`: [Date](#date)): string;

Expand Down Expand Up @@ -1141,7 +1142,7 @@ _defined in [@component-controls/core/src/configuration.ts](https://github.com/c
list of story arguments. Each argument can be a deconstructed argument of itself
the first argument are the control 'values'

_defined in [@component-controls/core/src/stories.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/stories.ts#L60)_
_defined in [@component-controls/core/src/document.ts](https://github.com/ccontrols/component-controls/tree/master/core/core/src/document.ts#L60)_

[StoryArgument](#storyargument)\[]

Expand Down
2 changes: 1 addition & 1 deletion core/core/src/controls-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ControlTypes,
} from './controls';

import { Story } from './stories';
import { Story } from './document';

const mergeValue = (control: ComponentControl, value: any): any => {
if (control && control.type === ControlTypes.OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toId, storyNameFromExport } from '@storybook/csf';
import { PagesOnlyRoutes, DocType, PageConfiguration } from './configuration';
import { Document, defDocType } from './stories';
import { Document, defDocType } from './document';

export const strToId = (str: string) => str.replace(/\W/g, '-').toLowerCase();

Expand Down
5 changes: 5 additions & 0 deletions core/core/src/stories.ts → core/core/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export interface Document {
*/
dateModified?: Date;

/**
* if set to true, the document will be hidden in production builds.
*/
draft?: boolean;

/**
* comma-separated list of document tags, used for search
*/
Expand Down
4 changes: 2 additions & 2 deletions core/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export * from './controls';
export * from './controls-utils';
export * from './deepMerge';
export * from './propsInfo';
export * from './stories';
export * from './stories-utils';
export * from './document';
export * from './document-utils';
export * from './utility';
export { randomizeData } from './controls-randomize';
export * from './controls-smart';
Expand Down
9 changes: 9 additions & 0 deletions core/instrument/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const parseSource = async (
}
if (store.doc) {
const doc = store.doc;
if (doc.draft === true && process.env.NODE_ENV === 'production') {
return undefined;
}

if (options.stories.storeSourceFile) {
doc.source = originalSource;
}
Expand Down Expand Up @@ -152,6 +156,11 @@ export const parseStories = async (
filePath,
mergedOptions,
);
if (!store) {
return {
transformed: code,
};
}
const { stories, doc, components, exports, packages } = store || {};
const exportsSource = extractStoryExports(exports);
let transformed = `
Expand Down
2 changes: 1 addition & 1 deletion core/loader/src/replaceSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ${stories
for (let i = 0; i < store.stores.length; i+= 1) {
const s = store.stores[i];
const doc = s.doc;
if (imports.hasOwnProperty(doc.fileName)) {
if (doc && imports.hasOwnProperty(doc.fileName)) {
const exports = imports[doc.fileName];
try {
Object.keys(exports).forEach(key => {
Expand Down
1 change: 0 additions & 1 deletion core/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
"dev": "yarn cross-env NODE_ENV=development rollup -cw",
"docs": "ts-md",
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
Expand Down
11 changes: 9 additions & 2 deletions core/webpack-compile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [chalk](#chalk)
- [compile](#compile)
- [watch](#watch)
- [CompileProps](#compileprops)
Expand Down Expand Up @@ -35,12 +36,18 @@ $ npm install @component-controls/webpack-compile --save-dev

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

## chalk

_defined in [@component-controls/webpack-compile/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/src/index.ts#L1)_



## compile

compile the stories with webpack
returns the stories store object

_defined in [@component-controls/webpack-compile/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/src/index.ts#L8)_
_defined in [@component-controls/webpack-compile/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/src/index.ts#L9)_

**function** compile(`__namedParameters`\*: **configPath**: string**outputFolder**: string**presets**: string | [RuleOptions](#ruleoptions)\[]**webPack**: [Configuration](#configuration)): Promise&lt;[CompileResults](#compileresults)>;

Expand All @@ -56,7 +63,7 @@ _defined in [@component-controls/webpack-compile/src/index.ts](https://github.co
compile the stories with webpack and launch watching for changes
returns the stories store object

_defined in [@component-controls/webpack-compile/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/src/index.ts#L27)_
_defined in [@component-controls/webpack-compile/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/src/index.ts#L32)_

**function** watch(`__namedParameters`\*: **configPath**: string**outputFolder**: string**presets**: string | [RuleOptions](#ruleoptions)\[]**watchOptions**: [WatchOptions](#watchoptions)**webPack**: [Configuration](#configuration)): Promise&lt;[CompileResults](#compileresults)>;

Expand Down
2 changes: 1 addition & 1 deletion core/webpack-compile/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
const chalk = require('chalk');
import { CompileProps, CompileResults, WatchProps } from './types';
import { runCompiler } from './utilities';
export * from './types';
Expand Down
99 changes: 99 additions & 0 deletions core/webpack-compile/tests/__snapshots__/draft.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test draft compile 1`] = `
Store {
"_docpaths": undefined,
"_homepaths": undefined,
"buildConfig": Object {
"categories": Array [
"author",
"tags",
],
"pages": Object {
"author": Object {
"basePath": "authors/",
},
"blog": Object {
"basePath": "blogs/",
},
"page": Object {
"basePath": "pages/",
},
"story": Object {
"basePath": "docs/",
"storyPaths": true,
"tabs": Array [
Object {
"route": "page",
},
Object {
"route": "test",
},
],
},
"tags": Object {
"basePath": "tags/",
},
},
"stories": Array [
"./*.stories.(js|jsx|tsx|mdx)",
],
},
"buildDocPaths": [Function],
"buildHomePaths": [Function],
"components": Object {},
"config": Object {},
"getDocPage": [Function],
"getDocPaths": [Function],
"getDocs": [Function],
"getHomePage": [Function],
"getHomePaths": [Function],
"getIndexPage": [Function],
"getUniquesByField": [Function],
"packages": Object {
"69197a205ad99a63b97e2a2015a91298": Object {
"dependencies": Object {
"@component-controls/loader": "^1.8.0",
"@component-controls/webpack-configs": "^1.8.0",
"chalk": "^4.0.0",
"memory-fs": "^0.5.0",
"typescript": "^3.8.3",
"webpack": "^4.43.0",
},
"devDependencies": Object {
"@component-controls/ts-markdown-docs": "^1.5.0",
"@types/jest": "^25.1.2",
"@types/memory-fs": "^0.3.2",
"cross-env": "^5.2.1",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"webpack-bundle-analyzer": "^3.7.0",
},
"fileHash": "69197a205ad99a63b97e2a2015a91298",
"name": "@component-controls/webpack-compile",
"peerDependencies": undefined,
"repository": Object {
"browse": "https://github.com/ccontrols/component-controls/tree/master/core/webpack-compile/tests/fixtures/draft/mdx.stories.mdx",
"docs": "https://github.com/ccontrols/component-controls/tree/master#readme",
"issues": "https://github.com/ccontrols/component-controls/issues",
},
"version": "1.8.0",
},
},
"stores": Array [
Object {
"doc": Object {
"componentsLookup": Object {},
"date": 2020-07-15T17:02:54.230Z,
"dateModified": 2020-07-15T17:03:09.895Z,
"draft": true,
"fileName": "/Users/atanasster/component-controls/core/webpack-compile/tests/fixtures/draft/mdx.stories.mdx",
"package": "69197a205ad99a63b97e2a2015a91298",
"title": "Library/Components/Spinner",
},
"filePath": "/Users/atanasster/component-controls/core/webpack-compile/tests/fixtures/draft/mdx.stories.mdx",
"stories": Object {},
},
],
}
`;
Loading

0 comments on commit d8736d2

Please sign in to comment.