Skip to content

Commit

Permalink
feat: typescript run-time config
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 30, 2020
1 parent 9867416 commit 4d17a90
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 160 deletions.
8 changes: 4 additions & 4 deletions core/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ npm install @component-controls/config --save-dev

## ConfigrationResult

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



Expand Down Expand Up @@ -59,7 +59,7 @@ _defined in [@component-controls/config/src/index.ts](https://github.com/ccontro
find the story files out of a configuration file
using glob for the regex file search

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

**function** extractStories(`__namedParameters`\*: **config**: [BuildConfiguration](#buildconfiguration)**configPath**: string): string\[] | undefined;

Expand All @@ -76,7 +76,7 @@ return the configration folder from command-line parameters
command line accepts -c/ -config parameter for config path
the config file is assumed named main.js/main.ts

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

**function** getConfigurationArg(`args`\*: string\[]): string | undefined;

Expand All @@ -91,7 +91,7 @@ _defined in [@component-controls/config/src/index.ts](https://github.com/ccontro

given a base project folder and a configuration folder, returns the configuration file

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

**function** loadConfiguration(`baseFolder`\*: string, `configFolder`: string, `args`: string\[]): [ConfigrationResult](#configrationresult) | undefined;

Expand Down
10 changes: 8 additions & 2 deletions core/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { BuildConfiguration } from '@component-controls/core';

export const buildConfigFileNames = ['buildtime.js', 'build.js', 'main.js'];

export const optionsFileNames = ['runtime.js', 'options.js'];
export const optionsFileNames = [
'runtime.js',
'options.js',
'runtime.ts',
'runtime.tsx',
'options.ts',
'options.tsx',
];
export interface ConfigrationResult {
config: BuildConfiguration;
configPath: string;
Expand Down Expand Up @@ -57,7 +64,6 @@ export const loadConfiguration = (
const optionsFile = allFiles.find(file =>
optionsFileNames.includes(file.toLowerCase()),
);

if (buildConfigFile) {
return {
config: require(path.resolve(configPath, buildConfigFile)),
Expand Down
14 changes: 7 additions & 7 deletions core/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ _defined in [@component-controls/core/src/configuration.ts](https://github.com/c

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

'story' | 'blog' | 'page' | 'tags' | 'author'
'story' | 'blog' | 'page' | 'tags' | 'author' | string

## PagesConfiguration

Expand Down Expand Up @@ -1104,10 +1104,10 @@ _defined in [@component-controls/core/src/configuration.ts](https://github.com/c

### properties

| Name | Type | Description |
| ------------- | --------------------- | ----------- |
| `categories*` | 'tags' \| 'author'\[] | |
| `pages*` | object | |
| Name | Type | Description |
| ------------- | --------- | ----------- |
| `categories*` | string\[] | |
| `pages*` | object | |

## defaultRunConfig

Expand Down Expand Up @@ -1148,7 +1148,7 @@ _defined in [@component-controls/core/src/utility.ts](https://github.com/ccontro

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

'story' | 'blog' | 'page' | 'tags' | 'author'
'story' | 'blog' | 'page' | 'tags' | 'author' | string

## RunConfiguration

Expand Down Expand Up @@ -1259,6 +1259,6 @@ _defined in [@component-controls/core/src/configuration.ts](https://github.com/c

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

'story' | 'blog' | 'page' | 'tags' | 'author'
'story' | 'blog' | 'page' | 'tags' | 'author' | string

<!-- END-TSDOC-TYPESCRIPT -->
2 changes: 1 addition & 1 deletion core/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface TabConfiguration {

export type PageTabs = TabConfiguration[];

export type PageType = 'story' | 'blog' | 'page' | 'tags' | 'author';
export type PageType = 'story' | 'blog' | 'page' | 'tags' | 'author' | string;

export interface PageConfiguration {
/**
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 @@ -83,7 +83,7 @@ ${stories
const newContent = `
${imports}
${storeConst}
store.config = configJSON;
store.config = configJSON.default || configJSON;
store.buildConfig = ${config ? JSON.stringify(config) : '{}'};
${loadStories}
${hmr}
Expand Down
Loading

0 comments on commit 4d17a90

Please sign in to comment.