Skip to content

Commit

Permalink
fix(docz-core): write first imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 15, 2019
1 parent 289ca75 commit b856168
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions core/docz-core/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const build = async (args: Arguments<any>) => {

try {
await Entries.writeApp(config, true)
await Entries.writeImports(await entries.get())
await dataServer.start()
await run('onPreBuild', config)
await bundler.build(bundlerConfig)
Expand Down
1 change: 1 addition & 0 deletions core/docz-core/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const dev = async (args: Arguments<any>) => {

try {
await Entries.writeApp(config, true)
await Entries.writeImports(await entries.get())
} catch (err) {
logger.fatal('Failed to build your files')
logger.error(err)
Expand Down
6 changes: 6 additions & 0 deletions core/docz-core/src/lib/Entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class Entries {
await writeAppFiles(config, Boolean(dev))
}

public static async writeImports(map: EntryMap): Promise<void> {
const imports = await compiled(fromTemplates('imports.tpl.js'))
const rawImportsJs = imports({ entries: Object.values(map) })
await touch(path.join(paths.app, 'imports.js'), rawImportsJs)
}

public all: Map<string, EntryObj>
public get: () => Promise<EntryMap>
public repoEditUrl: string | null
Expand Down
12 changes: 2 additions & 10 deletions core/docz-core/src/states/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@ import * as path from 'path'
import chokidar from 'chokidar'
import equal from 'fast-deep-equal'
import { get } from 'lodash/fp'
import { touch, compiled } from 'docz-utils/lib/fs'

import { mapToArray } from './props'
import { Params, State } from '../lib/DataServer'
import { Entries, EntryMap, fromTemplates } from '../lib/Entries'
import { Entries } from '../lib/Entries'
import { Config } from '../config/argv'
import * as paths from '../config/paths'

const writeImports = async (map: EntryMap): Promise<void> => {
const imports = await compiled(fromTemplates('imports.tpl.js'))
const rawImportsJs = imports({ entries: Object.values(map) })

await touch(path.join(paths.app, 'imports.js'), rawImportsJs)
}

const updateEntries = (entries: Entries) => async (p: Params) => {
const prev = get('entries', p.getState())
const map = await entries.get()

if (map && !equal(prev, map)) {
await writeImports(map)
await Entries.writeImports(map)
p.setState('entries', mapToArray(map))
}
}
Expand Down

0 comments on commit b856168

Please sign in to comment.