Skip to content

Commit

Permalink
fix(docz-core): config passed on argv
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 17, 2019
1 parent a5a9f1d commit 12f6385
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/docz-core/src/states/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path'
import * as fs from 'fs-extra'
import { load, finds } from 'load-cfg'
import { load, loadFrom, finds } from 'load-cfg'
import chokidar from 'chokidar'
import get from 'lodash/get'

Expand Down Expand Up @@ -37,14 +38,18 @@ const getInitialConfig = (config: Config): Payload => {
}
}

const update = async (params: Params, initial: Payload) => {
const next = load('docz', initial, true, true)
const update = async (params: Params, initial: Payload, { config }: Config) => {
const next = config
? loadFrom(path.resolve(config), initial, true, true)
: load('docz', initial, true, true)

params.setState('config', next)
}

export const state = (config: Config): State => {
const initial = getInitialConfig(config)
const watcher = chokidar.watch(finds('docz'), {
const glob = config.config || finds('docz')
const watcher = chokidar.watch(glob, {
cwd: paths.root,
ignored: /(((^|[\/\\])\..+)|(node_modules))/,
persistent: true,
Expand All @@ -55,8 +60,8 @@ export const state = (config: Config): State => {
return {
id: 'config',
start: async params => {
const fn = async () => update(params, initial)
await update(params, initial)
const fn = async () => update(params, initial, config)
await update(params, initial, config)
watcher.on('add', fn)
watcher.on('change', fn)
watcher.on('unlink', fn)
Expand Down

0 comments on commit 12f6385

Please sign in to comment.