Skip to content

Commit

Permalink
feat: docz migration compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 7, 2020
1 parent 38dbd25 commit 7cbba59
Show file tree
Hide file tree
Showing 53 changed files with 4,850 additions and 1,998 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Accessibility testing plugin using the [axe-core](https://github.com/dequelabs/a
Some of the design goals:

- Test at the component-level.
- Provide a dashboard view to quickly see the errors and tests for the compnnt.
- Provide a dashboard view to quickly see the errors and tests for the component.
- Ability to select and outline the sub-elements generating the errors.
- Ability to see details from the errors and passed rules.

Expand Down
16 changes: 8 additions & 8 deletions core/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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#L21)_
_defined in [@component-controls/config/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/config/src/index.ts#L26)_



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

from the glob list of documents, extract require.context array of props

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



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

## optionsFileNames

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



## configRequireContext

convert glob patters from config file into require.context objects

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

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

Expand All @@ -93,7 +93,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#L90)_
_defined in [@component-controls/config/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/config/src/index.ts#L98)_

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

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

## fixGlob

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

**function** fixGlob(`golbExpr`\*: string): string;

Expand All @@ -123,7 +123,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#L32)_
_defined in [@component-controls/config/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/config/src/index.ts#L37)_

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

Expand All @@ -138,7 +138,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#L53)_
_defined in [@component-controls/config/src/index.ts](https://github.com/ccontrols/component-controls/tree/master/core/config/src/index.ts#L58)_

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

Expand Down
4 changes: 4 additions & 0 deletions core/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"license": "MIT",
"dependencies": {
"@component-controls/core": "^1.24.6",
"esm": "^3.2.25",
"glob": "^7.1.6",
"glob-base": "^0.3.0",
"micromatch": "^4.0.2",
Expand All @@ -48,6 +49,9 @@
"eslint": "^6.5.1",
"jest": "^26.4.2"
},
"esm": {
"cjs": true
},
"browser": {
"fs": false
},
Expand Down
78 changes: 47 additions & 31 deletions core/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { makeRe } from 'micromatch';
import yargs from 'yargs';
import { BuildConfiguration } from '@component-controls/core';

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

export const optionsFileNames = [
'runtime.js',
Expand Down Expand Up @@ -69,8 +74,11 @@ export const loadConfiguration = (
optionsFileNames.includes(file.toLowerCase()),
);
if (buildConfigFile) {
const config = require('esm')(module)(
path.resolve(configPath, buildConfigFile),
);
return {
config: require(path.resolve(configPath, buildConfigFile)),
config: config.default || config,
optionsFilePath: optionsFile
? path.resolve(configPath, optionsFile)
: undefined,
Expand All @@ -91,16 +99,22 @@ export const extractDocuments = ({
config,
configPath,
}: ConfigrationResult): string[] | undefined => {
const documents =
config && config.stories
? config.stories.reduce((acc: string[], storyRg: string) => {
const matches = globSync(path.resolve(configPath, fixGlob(storyRg)));
if (!matches.length) {
throw new Error(`${storyRg} did not match any files`);
}
return [...acc, ...matches];
}, [])
: undefined;
const stories = config ? config.stories || config.files : undefined;
const files = typeof stories === 'string' ? [stories] : stories;
const documents = files
? files.reduce((acc: string[], storyRg: string) => {
const matches = globSync(path.resolve(configPath, fixGlob(storyRg)));
if (!matches.length) {
throw new Error(`${storyRg} did not match any files`);
}
const ignore = config.ignore || [];
const files = matches.filter(filename => {
const basename = path.basename(filename).toLowerCase();
return !ignore.includes(basename);
});
return [...acc, ...files];
}, [])
: undefined;
return documents;
};

Expand All @@ -119,24 +133,26 @@ export const configRequireContext = ({
config,
configPath,
}: ConfigrationResult): RequireContextProps[] | undefined => {
const contexts =
config && config.stories
? config.stories.reduce((acc: RequireContextProps[], storyRg: string) => {
const base = globBase(fixGlob(storyRg));
const useSubdirectories = base.glob.startsWith('**');
const glob = useSubdirectories ? base.glob.substr(3) : base.glob;
const regExp = base.isGlob
? RegExp(makeRe(glob).source.substr(1))
: new RegExp(glob);
return [
...acc,
{
directory: path.resolve(configPath, base.base),
useSubdirectories,
regExp,
},
];
}, [])
: undefined;
const stories = config ? config.stories || config.files : undefined;
const files = typeof stories === 'string' ? [stories] : stories;

const contexts = files
? files.reduce((acc: RequireContextProps[], storyRg: string) => {
const base = globBase(fixGlob(storyRg));
const useSubdirectories = base.glob.startsWith('**');
const glob = useSubdirectories ? base.glob.substr(3) : base.glob;
const regExp = base.isGlob
? RegExp(makeRe(glob).source.substr(1))
: new RegExp(glob);
return [
...acc,
{
directory: path.resolve(configPath, base.base),
useSubdirectories,
regExp,
},
];
}, [])
: undefined;
return contexts;
};
Loading

0 comments on commit 7cbba59

Please sign in to comment.