create new plugin for doc viewer. cleanup

pull/3475/head
Joseph Izang 2 years ago committed by Aniket
parent 8e7b4f6671
commit 7146254d3a
  1. 15
      apps/docviewer/src/app/App.tsx
  2. 39
      apps/docviewer/src/app/docviewer.ts
  3. 13
      apps/remixdocgen/src/app/App.tsx
  4. 22
      apps/remixdocgen/src/app/docgen-client.ts

@ -1,11 +1,26 @@
import React, { useEffect, useState } from "react"
import { DocViewer } from "./docviewer"
const client = new DocViewer()
export default function App() { export default function App() {
const [contents, setContents] = useState('')
useEffect(() => {
client.eventEmitter.on('contentsReady', (fileContents: string) => {
console.log('contentsReady', fileContents)
setContents(fileContents)
})
}, [])
return ( return (
<> <>
<h1>Documentation Viewer</h1> <h1>Documentation Viewer</h1>
<p> <p>
Show documentation of compiled contracts. Show documentation of compiled contracts.
</p> </p>
<p>
{contents && contents.length}
</p>
</> </>
) )
} }

@ -0,0 +1,39 @@
import { PluginClient } from '@remixproject/plugin'
import { createClient } from '@remixproject/plugin-webview'
import EventEmitter from 'events'
export class DocViewer extends PluginClient {
mdFile: string
fileContents: string
eventEmitter: EventEmitter
constructor() {
super()
this.eventEmitter = new EventEmitter()
this.methods = ['viewDocs']
createClient(this)
this.mdFile = ''
this.onload()
}
async setProperties() {
console.log('inside setProperties')
this.on('docgen' as any, 'docsGenerated', async (docs: string[]) => {
console.log('docsGenerated', docs)
this.mdFile = docs[0]
const contents = await this.call('fileManager', 'readFile', this.mdFile)
console.log({ contents })
this.fileContents = contents
this.eventEmitter.emit('docviewer', 'contentsReady', this.fileContents)
})
}
async viewDocs(docs: string[]) {
console.log('viewDocs', docs)
console.log('docsGenerated', docs)
this.mdFile = docs[0]
const contents = await this.call('fileManager', 'readFile', this.mdFile)
console.log({ contents })
this.fileContents = contents
this.eventEmitter.emit('contentsReady', contents)
}
}

@ -9,17 +9,6 @@ import { Build } from './docgen/site'
export const client = new DocGenClient() export const client = new DocGenClient()
export const getNewContractNames = (compilationResult: CompilationResult) => {
const compiledContracts = compilationResult.contracts
let result: string[] = []
for (const file of Object.keys(compiledContracts)) {
const newContractNames = Object.keys(compiledContracts[file])
result = [...result, ...newContractNames]
}
return result
}
const App = () => { const App = () => {
const [themeType, setThemeType] = useState<string>('dark'); const [themeType, setThemeType] = useState<string>('dark');
const [hasBuild, setHasBuild] = useState<boolean>(false); const [hasBuild, setHasBuild] = useState<boolean>(false);
@ -47,7 +36,7 @@ const App = () => {
<h1>Remix Docgen</h1> <h1>Remix Docgen</h1>
{fileName && <h2>File: {fileName}</h2>} {fileName && <h2>File: {fileName}</h2>}
{hasBuild && <button onClick={() => client.generateDocs()}>Generate doc</button>} {hasBuild && <button onClick={() => client.generateDocs()}>Generate doc</button>}
{hasBuild && <button onClick={() => client.viewDocs()}>Open docs</button>} {hasBuild && <button onClick={() => client.opendDocs(client.docs)}>Open docs</button>}
</div> </div>
) )
}; };

@ -12,11 +12,12 @@ export class DocGenClient extends PluginClient {
private currentTheme private currentTheme
public eventEmitter: EventEmitter public eventEmitter: EventEmitter
private build: Build private build: Build
public docs: string[] = []
constructor() { constructor() {
super() super()
this.eventEmitter = new EventEmitter() this.eventEmitter = new EventEmitter()
this.methods = ['generateDocs', 'viewDocs'] this.methods = ['generateDocs', 'opendDocs']
createClient(this) createClient(this)
this.onload().then(async () => { this.onload().then(async () => {
console.log('docgen client loaded') console.log('docgen client loaded')
@ -62,19 +63,22 @@ export class DocGenClient extends PluginClient {
docs.push(id) docs.push(id)
} }
this.eventEmitter.emit('docsGenerated', docs) this.eventEmitter.emit('docsGenerated', docs)
this.emit('docgen' as any, 'docsGenerated', docs)
this.docs = docs
await this.opendDocs(docs)
} }
async opendDocs() { async opendDocs(docs: string[]) {
console.log('docgen client openDocs') console.log('docgen client openDocs')
await this.call('manager', 'activatePlugin', 'docgenviewer') await this.call('manager', 'activatePlugin', 'docviewer')
await this.call('tabs' as any, 'focus', 'docgenviewer') await this.call('tabs' as any, 'focus', 'docviewer')
await this.call('docgenviewer' as any, 'viewDocs') await this.call('docviewer' as any, 'viewDocs', docs)
} }
async viewDocs() { // async viewDocs() {
console.log('docgen client viewDocs') // console.log('docgen client viewDocs')
await this.opendDocs() // await this.opendDocs()
} // }
async generateDocs() { async generateDocs() {
console.log('docgen client generateDocs') console.log('docgen client generateDocs')

Loading…
Cancel
Save