mirror of
https://github.com/zhigang1992/docz.git
synced 2026-05-13 05:59:43 +08:00
chore(docz-core): improve entries process
This commit is contained in:
@@ -4,4 +4,4 @@ import { doc } from 'docz'
|
||||
doc('Overview')
|
||||
.order(1)
|
||||
.route('/')
|
||||
.section(() => <div>This is just the Home!</div>)
|
||||
.section(() => <div>This is just the Home page!</div>)
|
||||
|
||||
@@ -102,8 +102,10 @@ export const createConfig = (args: ConfigArgs) => (): Configuration => {
|
||||
babelrc: false,
|
||||
cacheDirectory: true,
|
||||
highlightCode: true,
|
||||
plugins: [require.resolve('react-hot-loader/babel')],
|
||||
presets: [require.resolve('babel-preset-react-app')],
|
||||
plugins: [
|
||||
require.resolve('react-hot-loader/babel'),
|
||||
],
|
||||
})
|
||||
|
||||
config.module
|
||||
|
||||
@@ -49,7 +49,9 @@ export class Entries {
|
||||
|
||||
this.files = files
|
||||
this.config = config
|
||||
this.entries = files.filter(Entry.check).map(file => new Entry(file))
|
||||
this.entries = files
|
||||
.filter(Entry.check)
|
||||
.map(file => new Entry(file, config.src))
|
||||
}
|
||||
|
||||
public find(file: string): Entry | undefined {
|
||||
@@ -74,7 +76,7 @@ export class Entries {
|
||||
|
||||
public update(file: string): void {
|
||||
const idx = this.findIndex(file)
|
||||
const entry = new Entry(file)
|
||||
const entry = new Entry(file, this.config.src)
|
||||
|
||||
if (idx > -1) {
|
||||
this.entries.splice(idx, 1, entry)
|
||||
@@ -87,7 +89,7 @@ export class Entries {
|
||||
const wrappers = propOf(plugins, 'wrapper')
|
||||
const afterRenders = propOf(plugins, 'afterRender')
|
||||
const beforeRenders = propOf(plugins, 'beforeRender')
|
||||
const imports = this.entries.map(e => e.filepath.replace('.jsx', ''))
|
||||
const imports = this.entries.map(e => e.filepath)
|
||||
|
||||
const rawIndexHtml = html({
|
||||
title,
|
||||
|
||||
@@ -69,9 +69,11 @@ export class Entry {
|
||||
public name: string | null
|
||||
public sections: string[] | null
|
||||
|
||||
constructor(file: string) {
|
||||
constructor(file: string, src: string) {
|
||||
const filepath = path.relative(paths.root, file)
|
||||
|
||||
this.id = ulid()
|
||||
this.filepath = path.relative(paths.root, file)
|
||||
this.filepath = filepath
|
||||
this.name = Entry.parseName(file)
|
||||
this.sections = Entry.parseSections(file)
|
||||
}
|
||||
|
||||
@@ -82,29 +82,27 @@ export class Server {
|
||||
private processEntries(config: ConfigArgs): void {
|
||||
const entries = new Entries(config)
|
||||
|
||||
const update = () => entries.write()
|
||||
|
||||
const onUnlink = (file: string) => {
|
||||
entries.remove(file)
|
||||
entries.write()
|
||||
update()
|
||||
}
|
||||
|
||||
const onChange = (file: string) => {
|
||||
const name = Entry.parseName(file)
|
||||
const entry = entries.find(file)
|
||||
|
||||
if (name && !entry) {
|
||||
entries.add(new Entry(file))
|
||||
entries.write()
|
||||
}
|
||||
|
||||
if (name && entry) {
|
||||
entries.update(file)
|
||||
entries.write()
|
||||
if (name) {
|
||||
!entry && entries.add(new Entry(file))
|
||||
entry && entries.update(file)
|
||||
update()
|
||||
}
|
||||
}
|
||||
|
||||
this.watcher.on('unlink', onUnlink)
|
||||
this.watcher.on('change', onChange)
|
||||
|
||||
entries.write()
|
||||
update()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<% imports.forEach(imp => { %>import '<%- imp %>'
|
||||
<% }) %>
|
||||
import React from 'react'
|
||||
import { hot } from 'react-hot-loader'
|
||||
import { Theme } from '<%- theme %>'
|
||||
@@ -14,10 +16,10 @@ const recursiveWrappers = ([Wrapper, ...rest], props) => (
|
||||
const Wrapper = props =>
|
||||
_wrappers.length ? recursiveWrappers(_wrappers, props) : props.children
|
||||
|
||||
const WrappedTheme = () => (
|
||||
const App = () => (
|
||||
<Wrapper>
|
||||
<Theme data={data} />
|
||||
<Theme entries={data.entries} />
|
||||
</Wrapper>
|
||||
)
|
||||
|
||||
export const App = hot(module)(WrappedTheme)
|
||||
export default hot(module)(App)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { render } from 'react-dom'
|
||||
import { App } from './app'
|
||||
import App from './app'
|
||||
|
||||
const _beforeRenders = [<% if (beforeRenders) {%><%- beforeRenders %><%}%>]
|
||||
const _afterRenders = [<% if (afterRenders) {%><%- afterRenders %><%}%>]
|
||||
|
||||
@@ -31,8 +31,7 @@
|
||||
"prop-types": "^15.6.1",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"ulid": "^2.3.0",
|
||||
"unstated": "^1.1.0"
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.3.1",
|
||||
|
||||
78
yarn.lock
78
yarn.lock
@@ -1335,10 +1335,6 @@
|
||||
"@types/minimatch" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/graphql@0.12.6":
|
||||
version "0.12.6"
|
||||
resolved "https://registry.npmjs.org/@types/graphql/-/graphql-0.12.6.tgz#3d619198585fcabe5f4e1adfb5cf5f3388c66c13"
|
||||
|
||||
"@types/history@*":
|
||||
version "4.6.2"
|
||||
resolved "https://registry.npmjs.org/@types/history/-/history-4.6.2.tgz#12cfaba693ba20f114ed5765467ff25fdf67ddb0"
|
||||
@@ -1656,24 +1652,6 @@ anymatch@^2.0.0:
|
||||
micromatch "^3.1.4"
|
||||
normalize-path "^2.1.1"
|
||||
|
||||
apollo-link-schema@^1.0.2:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.npmjs.org/apollo-link-schema/-/apollo-link-schema-1.1.0.tgz#033fda26ffdbfc809d04892de554867f50e2af8e"
|
||||
dependencies:
|
||||
apollo-link "^1.2.2"
|
||||
|
||||
apollo-link@^1.2.1, apollo-link@^1.2.2:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.npmjs.org/apollo-link/-/apollo-link-1.2.2.tgz#54c84199b18ac1af8d63553a68ca389c05217a03"
|
||||
dependencies:
|
||||
"@types/graphql" "0.12.6"
|
||||
apollo-utilities "^1.0.0"
|
||||
zen-observable-ts "^0.8.9"
|
||||
|
||||
apollo-utilities@^1.0.0, apollo-utilities@^1.0.1:
|
||||
version "1.0.11"
|
||||
resolved "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-1.0.11.tgz#cd36bfa6e5c04eea2caf0c204a0f38a0ad550802"
|
||||
|
||||
aproba@^1.0.3, aproba@^1.1.1:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
|
||||
@@ -2987,10 +2965,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
|
||||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
create-react-context@^0.1.5:
|
||||
version "0.1.6"
|
||||
resolved "https://registry.npmjs.org/create-react-context/-/create-react-context-0.1.6.tgz#0f425931d907741127acc6e31acb4f9015dd9fdc"
|
||||
|
||||
cross-env@^5.1.4:
|
||||
version "5.1.4"
|
||||
resolved "https://registry.npmjs.org/cross-env/-/cross-env-5.1.4.tgz#f61c14291f7cc653bb86457002ea80a04699d022"
|
||||
@@ -3210,10 +3184,6 @@ depd@~1.1.1, depd@~1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
|
||||
|
||||
deprecated-decorator@^0.1.6:
|
||||
version "0.1.6"
|
||||
resolved "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz#00966317b7a12fe92f3cc831f7583af329b86c37"
|
||||
|
||||
des.js@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc"
|
||||
@@ -4289,30 +4259,6 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
|
||||
version "4.1.11"
|
||||
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
||||
|
||||
graphql-mock@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.npmjs.org/graphql-mock/-/graphql-mock-0.2.0.tgz#98ae4ea5d07fb3aa5845d29fa6abb666fb954907"
|
||||
dependencies:
|
||||
apollo-link-schema "^1.0.2"
|
||||
graphql "^0.12.3"
|
||||
graphql-tools "^2.18.0"
|
||||
|
||||
graphql-tools@^2.18.0:
|
||||
version "2.24.0"
|
||||
resolved "https://registry.npmjs.org/graphql-tools/-/graphql-tools-2.24.0.tgz#bbacaad03924012a0edb8735a5e65df5d5563675"
|
||||
dependencies:
|
||||
apollo-link "^1.2.1"
|
||||
apollo-utilities "^1.0.1"
|
||||
deprecated-decorator "^0.1.6"
|
||||
iterall "^1.1.3"
|
||||
uuid "^3.1.0"
|
||||
|
||||
graphql@^0.12.3:
|
||||
version "0.12.3"
|
||||
resolved "https://registry.npmjs.org/graphql/-/graphql-0.12.3.tgz#11668458bbe28261c0dcb6e265f515ba79f6ce07"
|
||||
dependencies:
|
||||
iterall "1.1.3"
|
||||
|
||||
gzip-size@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.npmjs.org/gzip-size/-/gzip-size-3.0.0.tgz#546188e9bdc337f673772f81660464b389dce520"
|
||||
@@ -5020,14 +4966,6 @@ isstream@~0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
|
||||
|
||||
iterall@1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.npmjs.org/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9"
|
||||
|
||||
iterall@^1.1.3:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.npmjs.org/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
|
||||
|
||||
js-tokens@^3.0.0, js-tokens@^3.0.1, js-tokens@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
||||
@@ -8059,12 +7997,6 @@ unset-value@^1.0.0:
|
||||
has-value "^0.3.1"
|
||||
isobject "^3.0.0"
|
||||
|
||||
unstated@^1.1.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.npmjs.org/unstated/-/unstated-1.2.0.tgz#5c57cc077473d2cce411ec0930da285cef3df306"
|
||||
dependencies:
|
||||
create-react-context "^0.1.5"
|
||||
|
||||
unzip-response@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/unzip-response/-/unzip-response-1.0.2.tgz#b984f0877fc0a89c2c773cc1ef7b5b232b5b06fe"
|
||||
@@ -8565,13 +8497,3 @@ yargs@~3.10.0:
|
||||
cliui "^2.1.0"
|
||||
decamelize "^1.0.0"
|
||||
window-size "0.1.0"
|
||||
|
||||
zen-observable-ts@^0.8.9:
|
||||
version "0.8.9"
|
||||
resolved "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-0.8.9.tgz#d3c97af08c0afdca37ebcadf7cc3ee96bda9bab1"
|
||||
dependencies:
|
||||
zen-observable "^0.8.0"
|
||||
|
||||
zen-observable@^0.8.0:
|
||||
version "0.8.8"
|
||||
resolved "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.8.tgz#1ea93995bf098754a58215a1e0a7309e5749ec42"
|
||||
|
||||
Reference in New Issue
Block a user