-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docz-core): watch gatsby config files
- Loading branch information
1 parent
4caa47a
commit 1539378
Showing
10 changed files
with
91 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { createResources } from './createResources' | ||
export { ensureDirs } from './ensureDirs' | ||
export { execDevCommand } from './execDevCommand' | ||
export { installDeps } from './installDeps' | ||
export { watchConfig } from './watchConfig' | ||
export { createResources } from './create-resources' | ||
export { ensureDirs } from './ensure-dirs' | ||
export { execDevCommand } from './exec-dev-command' | ||
export { installDeps } from './install-deps' | ||
export { watchConfigFiles } from './watch-config-files' |
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
core/docz-core/src/bundler/machine/services/watch-config-files.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as path from 'path' | ||
import { finds } from 'load-cfg' | ||
import sh from 'shelljs' | ||
|
||
import { Config } from '../../../config/argv' | ||
import * as paths from '../../../config/paths' | ||
import { createWatcher } from '../../../states/config' | ||
import { ServerMachineCtx as Context } from '../context' | ||
|
||
const createWatch = (args: Config) => ( | ||
glob: any, | ||
src: string, | ||
custom?: boolean | ||
) => { | ||
const watcher = createWatcher(glob, args) | ||
const srcPath = path.join(paths.root, src) | ||
const destPath = path.join( | ||
paths.docz, | ||
custom ? src.replace('.js', '.custom.js') : src | ||
) | ||
|
||
const copyFile = () => sh.cp(srcPath, destPath) | ||
const deleteFile = () => sh.rm(destPath) | ||
|
||
watcher | ||
.on('add', copyFile) | ||
.on('change', copyFile) | ||
.on('unlink', deleteFile) | ||
|
||
return () => watcher.close() | ||
} | ||
|
||
export const watchConfigFiles = ({ args }: Context) => () => { | ||
const watch = createWatch(args) | ||
const doczrc = watch(args.config || finds('docz'), 'doczrc.js') | ||
const gatsbyBrowser = watch(paths.gatsbyBrowser, 'gatsby-browser.js') | ||
const gatsbyNode = watch(paths.gatsbyNode, 'gatsby-node.js') | ||
const gatsbySSR = watch(paths.gatsbySSR, 'gatsby-ssr.js') | ||
const gatsbyConfig = watch(paths.gatsbyConfig, 'gatsby-config.js', true) | ||
|
||
return () => { | ||
doczrc() | ||
gatsbyConfig() | ||
gatsbyBrowser() | ||
gatsbyNode() | ||
gatsbySSR() | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
core/docz-core/src/bundler/machine/services/watchConfig.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters