From 37b73c6b5e65813896a2dd88e8f6fd707f318c5d Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Tue, 26 Feb 2019 00:44:11 -0300 Subject: [PATCH] fix(gatsby-theme-docz): use createPages instead of createPagesStatefully --- core/docz-core/src/states/props.ts | 9 --- core/gatsby-theme-docz/gatsby-node.js | 2 +- core/gatsby-theme-docz/index.js | 1 + .../src/node/createPagesStatefully.js | 68 ------------------- 4 files changed, 2 insertions(+), 78 deletions(-) create mode 100644 core/gatsby-theme-docz/index.js delete mode 100644 core/gatsby-theme-docz/src/node/createPagesStatefully.js diff --git a/core/docz-core/src/states/props.ts b/core/docz-core/src/states/props.ts index 300af9925..04acd20e0 100644 --- a/core/docz-core/src/states/props.ts +++ b/core/docz-core/src/states/props.ts @@ -3,7 +3,6 @@ import chokidar from 'chokidar' import fastglob from 'fast-glob' import { State, Params } from '../lib/DataServer' import { flatten, get } from 'lodash/fp' -import { Signale } from 'signale' import * as paths from '../config/paths' import { Config } from '../config/argv' @@ -26,9 +25,7 @@ export const mapToArray = (map: any = []) => const initial = (config: Config) => async (p: Params) => { const pattern = getPattern(config) const files = await fastglob(pattern, { cwd: paths.root }) - console.time('initial') const metadata = await docgen(files, config) - console.timeEnd('initial') p.setState('props', flatten(mapToArray(metadata))) } @@ -61,14 +58,8 @@ export const state = (config: Config): State => { return { id: 'props', start: async params => { - const interactive = new Signale({ interactive: true, scope: 'props' }) - interactive.await( - 'Parsing initial props from your components (this could take a while)' - ) const addInitial = initial(config) await addInitial(params) - interactive.success('Props parsed successfuly') - watcher.on('change', add(params, config)) watcher.on('unlink', remove(params)) }, diff --git a/core/gatsby-theme-docz/gatsby-node.js b/core/gatsby-theme-docz/gatsby-node.js index f53c76d77..fe07be32f 100644 --- a/core/gatsby-theme-docz/gatsby-node.js +++ b/core/gatsby-theme-docz/gatsby-node.js @@ -1,4 +1,4 @@ -exports.createPagesStatefully = require('./src/node/createPagesStatefully') +exports.createPages = require('./src/node/createPages') exports.onCreateBabelConfig = require('./src/node/onCreateBabelConfig') exports.onPreInit = require('./src/node/onPreInit') exports.sourceNodes = require('./src/node/sourceNodes') diff --git a/core/gatsby-theme-docz/index.js b/core/gatsby-theme-docz/index.js new file mode 100644 index 000000000..172f1ae6a --- /dev/null +++ b/core/gatsby-theme-docz/index.js @@ -0,0 +1 @@ +// noop diff --git a/core/gatsby-theme-docz/src/node/createPagesStatefully.js b/core/gatsby-theme-docz/src/node/createPagesStatefully.js deleted file mode 100644 index cd7def2c8..000000000 --- a/core/gatsby-theme-docz/src/node/createPagesStatefully.js +++ /dev/null @@ -1,68 +0,0 @@ -const path = require('path') -const chokidar = require('chokidar') -const { Entries } = require('docz-core') -const { parseConfig } = require('../utils/parseConfig') -const { get } = require('lodash/fp') - -const getEntry = async (filepath, entries) => { - const map = await entries.get() - return get(filepath, map) -} - -const mountRoute = (base = '/', route) => { - return `${base === '/' ? '' : base}${route}` -} - -module.exports = async ({ store, actions }, opts) => { - const { createPage, deletePage } = actions - const { paths, ...config } = await parseConfig(opts) - const src = path.relative(paths.root, config.src) - const files = path.join(src, config.files) - const entries = new Entries(config) - const watcher = chokidar.watch(files, { - cwd: paths.root, - ignored: /(((^|[\/\\])\..+)|(node_modules))/, - persistent: true, - }) - - const handleCreatePage = async filepath => { - const entry = await getEntry(filepath, entries) - const component = path.join(paths.root, filepath) - - if (entry) { - createPage({ - component, - path: mountRoute(config.base, entry.route), - context: { - entry, - }, - }) - } - } - - const handleDeletePage = filepath => { - const { pages } = store.getState() - const page = Array.from(pages.values()).find( - page => page.context.entry && page.context.entry.filepath === filepath - ) - - if (page) { - deletePage(page) - } - } - - const allEntries = await entries.get() - await Promise.all( - Object.values(allEntries).map(async value => { - handleCreatePage(value.filepath) - }) - ) - - return new Promise((resolve, reject) => { - watcher - .on('add', handleCreatePage) - .on('unlink', handleDeletePage) - .on('ready', () => resolve()) - .on('error', err => reject(err)) - }) -}