Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
chore: some code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 18, 2018
1 parent 4535aef commit 00b7ab4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
11 changes: 4 additions & 7 deletions packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { BabelRC } from '../utils/babelrc'
import * as paths from '../config/paths'

const removeScope = (name: string) => name.replace(/^@.*\//, '')
const getInitialTitle = () => {
const getInitialTitle = (): string => {
const pkg = fs.readJsonSync(paths.packageJson, { throws: false })
const name = pkg && pkg.name ? pkg.name : 'MyDoc'

return titleize(humanize(removeScope(name)))
}

export type Env = 'production' | 'development'
export type ThemeConfig = Record<string, any>

export interface Argv {
/* io args */
base: string
Expand All @@ -38,12 +41,6 @@ export interface Argv {
indexHtml?: string
}

export type Env = 'production' | 'development'

export interface ThemeConfig {
[key: string]: any
}

export interface Config extends Argv {
hashRouter: boolean
plugins: Plugin[]
Expand Down
28 changes: 14 additions & 14 deletions packages/docz/src/components/DocPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ export const DefaultRender: RenderComponent = ({ component, code }) => (
</Fragment>
)

const loadImport = (imports: ImportMap, components: ComponentsMap) => (
path: string
) => async (): Promise<SFC<any>> => {
const { default: Component } = await imports[path]()
return props => <Component {...props} components={components} />
}

const defaultComponents: ComponentsMap = {
loading: DefaultLoading,
render: DefaultRender,
page: Identity,
notFound: Identity,
}

export interface ComponentsMap {
loading?: ComponentType
page?: ComponentType<PageProps>
Expand All @@ -62,6 +48,20 @@ export interface ComponentsMap {
[key: string]: any
}

const loadImport = (imports: ImportMap, components: ComponentsMap) => (
path: string
) => async (): Promise<SFC<any>> => {
const { default: Component } = await imports[path]()
return props => <Component {...props} components={components} />
}

const defaultComponents: ComponentsMap = {
loading: DefaultLoading,
render: DefaultRender,
page: Identity,
notFound: Identity,
}

export interface DocPreviewProps {
components: ComponentsMap
}
Expand Down
1 change: 1 addition & 0 deletions packages/docz/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CSSProperties, Component, SFC } from 'react'
export interface StylesMap {
[s: string]: CSSProperties
}

const styles: StylesMap = {
wrapper: {
overflowY: 'auto',
Expand Down
26 changes: 11 additions & 15 deletions packages/load-cfg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@ import findup from 'find-up'
import merge from 'deepmerge'
import esm from 'esm'

export const finds = (name: string): string[] => [
`${name}.json`,
`.${name}rc`,
`${name}rc.js`,
`${name}rc.json`,
`${name}.config.js`,
`${name}.config.json`,
]

export const loadFile = (
filepath: string,
defaultFile: any = {},
noCache?: boolean
) => {
export const loadFile = (filepath: string, noCache?: boolean) => {
let file
const require = esm(module, {
mode: 'all',
Expand Down Expand Up @@ -50,6 +37,15 @@ export const loadFile = (
return file
}

export const finds = (name: string): string[] => [
`${name}.json`,
`.${name}rc`,
`${name}rc.js`,
`${name}rc.json`,
`${name}.config.js`,
`${name}.config.json`,
]

export const load = (
name: string,
defaultConfig: any = {},
Expand All @@ -59,7 +55,7 @@ export const load = (
const filepath = findup.sync(finds(name))

if (filepath) {
file = loadFile(filepath, defaultConfig, noCache)
file = loadFile(filepath, noCache)
}

return defaultConfig !== null ? merge(defaultConfig, file) : file
Expand Down

0 comments on commit 00b7ab4

Please sign in to comment.