pull/3475/head
filip mertens 2 years ago committed by Aniket
parent b141580542
commit b25e37a89f
  1. 30
      apps/remixdocgen/src/app/App.tsx
  2. 62
      apps/remixdocgen/src/app/docgen-client.ts
  3. 0
      apps/remixdocgen/src/app/docgen/common/helpers.ts
  4. 0
      apps/remixdocgen/src/app/docgen/common/properties.ts
  5. 0
      apps/remixdocgen/src/app/docgen/config.ts
  6. 0
      apps/remixdocgen/src/app/docgen/doc-item.ts
  7. 0
      apps/remixdocgen/src/app/docgen/render.ts
  8. 0
      apps/remixdocgen/src/app/docgen/site.ts
  9. 0
      apps/remixdocgen/src/app/docgen/templates.ts
  10. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/common.hbs
  11. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/contract.hbs
  12. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/enum.hbs
  13. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/error.hbs
  14. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/event.hbs
  15. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/function.hbs
  16. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/helpers.ts
  17. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/modifier.hbs
  18. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/page.hbs
  19. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/struct.hbs
  20. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/user-defined-value-type.hbs
  21. 0
      apps/remixdocgen/src/app/docgen/themes/markdown/variable.hbs
  22. 0
      apps/remixdocgen/src/app/docgen/utils/ItemError.ts
  23. 0
      apps/remixdocgen/src/app/docgen/utils/arrays-equal.ts
  24. 0
      apps/remixdocgen/src/app/docgen/utils/assert-equal-types.ts
  25. 0
      apps/remixdocgen/src/app/docgen/utils/clone.ts
  26. 0
      apps/remixdocgen/src/app/docgen/utils/ensure-array.ts
  27. 0
      apps/remixdocgen/src/app/docgen/utils/execall.ts
  28. 0
      apps/remixdocgen/src/app/docgen/utils/is-child.ts
  29. 0
      apps/remixdocgen/src/app/docgen/utils/item-type.ts
  30. 0
      apps/remixdocgen/src/app/docgen/utils/map-keys.ts
  31. 0
      apps/remixdocgen/src/app/docgen/utils/map-values.ts
  32. 0
      apps/remixdocgen/src/app/docgen/utils/memoized-getter.ts
  33. 0
      apps/remixdocgen/src/app/docgen/utils/natspec.ts
  34. 0
      apps/remixdocgen/src/app/docgen/utils/read-item-docs.ts
  35. 0
      apps/remixdocgen/src/app/docgen/utils/scope.ts
  36. 44
      apps/remixdocgen/src/app/plugins/docgen.ts

@ -5,6 +5,9 @@ import {
import './App.css' import './App.css'
import { DocGenClient } from './docgen-client' import { DocGenClient } from './docgen-client'
import { Build } from './docgen/site'
export const client = new DocGenClient()
export const getNewContractNames = (compilationResult: CompilationResult) => { export const getNewContractNames = (compilationResult: CompilationResult) => {
const compiledContracts = compilationResult.contracts const compiledContracts = compilationResult.contracts
@ -18,28 +21,35 @@ export const getNewContractNames = (compilationResult: CompilationResult) => {
} }
const App = () => { const App = () => {
const client = useMemo(() => new DocGenClient(), [])
const [themeType, setThemeType] = useState<string>('dark'); const [themeType, setThemeType] = useState<string>('dark');
const [hasBuild, setHasBuild] = useState<boolean>(false);
const [fileName, setFileName] = useState<string>('');
useEffect(() => { useEffect(() => {
const watchThemeSwitch = async () => { const watchThemeSwitch = async () => {
//await client.call("manager" as any, "activatePlugin", "ethdoc-viewer"); client.eventEmitter.on('themeChanged', (theme: string) => {
console.log('themeChanged', theme)
const currentTheme = await client.call('theme', 'currentTheme'); setThemeType(theme)
})
setThemeType(currentTheme.brightness || currentTheme.quality); client.eventEmitter.on('compilationFinished', (build: Build, fileName: string) => {
setHasBuild(true)
setFileName(fileName)
})
client.eventEmitter.on('docsGenerated', (docs: string[]) => {
console.log('docsGenerated', docs)
})
client.on("theme", "themeChanged", (theme: any) => {
setThemeType(theme.quality);
});
}; };
watchThemeSwitch(); watchThemeSwitch();
}, [client]); }, []);
return ( return (
<div> <div>
<h1>Remix Docgen</h1> <h1>Remix Docgen</h1>
{fileName && <h2>File: {fileName}</h2>}
{hasBuild && <button onClick={() => client.generateDocs()}>Generate doc</button>}
</div> </div>
) )
}; };

@ -1,22 +1,72 @@
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import { createClient } from '@remixproject/plugin-webview' import { createClient } from '@remixproject/plugin-webview'
import { DocGen } from './plugins/docgen' import EventEmitter from 'events'
import { Config, defaults } from './docgen/config'
import { Build, buildSite } from './docgen/site'
import { loadTemplates } from './docgen/templates'
import {SolcInput, SolcOutput} from 'solidity-ast/solc'
import { render } from './docgen/render'
export class DocGenClient extends PluginClient { export class DocGenClient extends PluginClient {
private client private currentTheme
private docgen public eventEmitter: EventEmitter
private build: Build
constructor() { constructor() {
super() super()
this.client = createClient(this) this.eventEmitter = new EventEmitter()
createClient(this)
// this.docgen = new DocGen() // this.docgen = new DocGen()
this.methods = ['generateDocs', 'publishDocs'] this.methods = ['generateDocs', 'publishDocs']
this.onload().then(async () => {
console.log('docgen client loaded')
await this.setListeners()
})
} }
loadClient() {
this.client.onload() async setListeners() {
this.currentTheme = await this.call('theme', 'currentTheme');
this.on("theme", "themeChanged", (theme: any) => {
this.currentTheme = theme
this.eventEmitter.emit('themeChanged', this.currentTheme)
});
this.eventEmitter.emit('themeChanged', this.currentTheme)
this.on('solidity', 'compilationFinished', (fileName: string, source: SourceWithTarget, languageVersion: string, data: CompilationResult) => {
console.log('docgen client compilationFinished', data, source)
const input: SolcInput = {
sources: source.sources
}
const output: SolcOutput = {
sources: data.sources as any
} }
this.build = {
input: input,
output: output
}
this.eventEmitter.emit('compilationFinished', this.build, fileName)
})
}
async docgen(builds: Build[], userConfig?: Config): Promise<void> {
const config = { ...defaults, ...userConfig }
const templates = await loadTemplates(config.theme, config.root, config.templates)
const site = buildSite(builds, config, templates.properties ?? {})
const renderedSite = render(site, templates, config.collapseNewlines)
const docs: string[] = []
for (const { id, contents } of renderedSite) {
await this.call('fileManager', 'setFile', id, contents)
docs.push(id)
}
this.eventEmitter.emit('docsGenerated', docs)
}
async generateDocs() { async generateDocs() {
console.log('docgen client generateDocs') console.log('docgen client generateDocs')
this.docgen([this.build])
} }
async publishDocs() { async publishDocs() {

@ -1,44 +0,0 @@
'use strict'
import { Plugin } from '@remixproject/engine'
import { Build, buildSite } from './docgen/site';
import { render } from './docgen/render';
import { Config, defaults } from './docgen/config';
import { loadTemplates } from './docgen/templates';
import { SolcInput, SolcOutput } from 'solidity-ast/solc';
const profile = {
name: 'docgen',
desciption: 'solidity doc gen plugin for Remix',
methods: ['docgen'],
events: [''],
version: '0.0.1'
}
export class DocGen extends Plugin {
constructor() {
super(profile)
}
onActivation(): void {
//this.docgen([{ output: example, input: inp }])
this.on('solidity', 'compilationFinished', (file, source, languageVersion, data, input, version) => {
this.docgen([{ output: data, input: JSON.parse(input) }])
})
}
async docgen(builds: Build[], userConfig?: Config): Promise<void> {
const config = { ...defaults, ...userConfig }
const templates = await loadTemplates(config.theme, config.root, config.templates)
const site = buildSite(builds, config, templates.properties ?? {})
const renderedSite = render(site, templates, config.collapseNewlines)
console.log({ renderedSite })
for (const { id, contents } of renderedSite) {
await this.call('fileManager', 'setFile', id, contents)
}
}
}
Loading…
Cancel
Save