Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethdoc plugin #3475

Merged
merged 59 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d4e187f
first commit
Jul 4, 2020
0368d26
prettier
Jul 4, 2020
dd4f8cd
remove legacy
Jul 4, 2020
2d6b4d9
fix build issues
Jul 4, 2020
18477ca
added docs
Jul 4, 2020
2977fc6
remove bootstrap for themes
Jul 10, 2020
c02de69
added docs
Jul 10, 2020
e34799f
fix rendering and document generation
Jul 10, 2020
0f5edcf
add activation
defiboy Jul 13, 2020
6238412
prettier
defiboy Jul 13, 2020
af96b3f
updated docs
defiboy Jul 28, 2020
1d65101
added retry mechanism
defiboy Jul 28, 2020
cf58e05
prettier
defiboy Jul 28, 2020
b538ace
updated docs
defiboy Jul 29, 2020
813d11f
remove console log
defiboy Jul 29, 2020
18d5238
improve code for debuggin and changee template rendering of dev funct…
defiboy Jul 29, 2020
3b924d9
unused code
defiboy Jul 29, 2020
b7b0f39
prettier
defiboy Jul 29, 2020
279bb35
remove tslint from husky
defiboy Jul 29, 2020
3ef183e
updated docs
defiboy Jul 30, 2020
9756280
added analytics
defiboy Aug 26, 2020
2313462
update plugin and adapt for vscode
bunsenstraat Mar 3, 2021
f0ce6dc
provide link to results
bunsenstraat Mar 4, 2021
d18af4d
update remix plugin
bunsenstraat Mar 8, 2021
b3101c2
update remix plugin
bunsenstraat Mar 8, 2021
ad7a8c0
fix build
Mar 8, 2021
2689b4f
fix issue and theme
EdsonAlcala May 24, 2021
5ccccc1
remove file
EdsonAlcala May 24, 2021
71fba03
prettier
EdsonAlcala May 24, 2021
22bf41e
fix style
EdsonAlcala May 24, 2021
7dfcd4e
move plugin folders and files
joeizang Mar 1, 2023
c2bb678
change app folder name
joeizang Mar 3, 2023
3f72add
move files around
joeizang Mar 3, 2023
4cea6e2
add webpack config and tsconfig
joeizang Mar 3, 2023
3f41d34
add required artifacts to have app work. remove redundancies
joeizang Mar 3, 2023
dbdf7c7
more plugin setup
joeizang Mar 4, 2023
0902ed7
test text
joeizang Mar 4, 2023
f0efc2d
fix tsconfig path
joeizang Mar 6, 2023
fd132c2
move docgen plugin to new remixdocgen plugin
joeizang Mar 6, 2023
f79c9c8
update imports
joeizang Mar 6, 2023
1bfc9e3
redo nod_modules
joeizang Mar 7, 2023
5122f06
fix issues. make plugin self contained.
joeizang Mar 8, 2023
2d0a6aa
fix issues
joeizang Mar 8, 2023
b141580
add docgen instance. move onload to class method
joeizang Mar 8, 2023
b25e37a
refactor
bunsenstraat Mar 8, 2023
9203426
viewer
bunsenstraat Mar 8, 2023
8b2b300
refactoring and cleanup
joeizang Mar 9, 2023
6eaaf2c
remove redundant publis method
joeizang Mar 9, 2023
4290ee4
cleanup
joeizang Mar 13, 2023
f3a6c6b
fix viewDoc method
joeizang Mar 13, 2023
8e7b4f6
add docviewer plugin to show generated documentation
joeizang Mar 13, 2023
7146254
create new plugin for doc viewer. cleanup
joeizang Mar 14, 2023
affa294
remove redundancies
joeizang Mar 14, 2023
6fab2ee
add styles to docviewer view
joeizang Mar 14, 2023
d90382a
rename plugin folders
joeizang Mar 15, 2023
96441de
change project.json
joeizang Mar 15, 2023
3980133
fix plugin names and fix artefact folder
joeizang Mar 15, 2023
3117afe
address comments from @lianahus and @bunsentraat
joeizang Mar 16, 2023
8b56fe7
add doc-gen and doc-viewer back to app.js after rebase
joeizang Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ testem.log
.DS_Store
.vscode/settings.json
.vscode/launch.json
libs/remix-node/
libs/remix-niks/

apps/remix-react
34 changes: 34 additions & 0 deletions apps/doc-gen/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"extends": [
"plugin:@nrwl/nx/react",
"../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
13 changes: 13 additions & 0 deletions apps/doc-gen/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"arrowParens": "avoid",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"endOfLine": "lf"
}
59 changes: 59 additions & 0 deletions apps/doc-gen/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "doc-gen",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/doc-gen/src",
"projectType": "application",
"implicitDependencies": [
],
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "development",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/doc-gen",
"index": "apps/doc-gen/src/index.html",
"baseHref": "/",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"./" is needed for IPFS publishing otherwise it will try find it all in / while it's on /ipfs/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"main": "apps/doc-gen/src/main.tsx",
"tsConfig": "apps/doc-gen/tsconfig.app.json",
"assets": [
"apps/doc-gen/src/favicon.ico"
],
"styles": [],
"scripts": [],
"webpackConfig": "apps/doc-gen/webpack.config.js"
},
"configurations": {
"development": {
},
"production": {
"fileReplacements": [
{
"replace": "apps/doc-gen/src/environments/environment.ts",
"with": "apps/doc-gen/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"executor": "@nrwl/webpack:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "doc-gen:build",
"hmr": true
},
"configurations": {
"development": {
"buildTarget": "doc-gen:build:development",
"port": 6003
},
"production": {
"buildTarget": "doc-gen:build:production"
}
}
}
},
"tags": []
}
3 changes: 3 additions & 0 deletions apps/doc-gen/src/app/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
margin: 0;
}
42 changes: 42 additions & 0 deletions apps/doc-gen/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState, useEffect } from 'react'
import {
CompilationResult,
} from '@remixproject/plugin-api/'

import './App.css'
import { DocGenClient } from './docgen-client'
import { Build } from './docgen/site'

export const client = new DocGenClient()

const App = () => {
const [themeType, setThemeType] = useState<string>('dark');
const [hasBuild, setHasBuild] = useState<boolean>(false);
const [fileName, setFileName] = useState<string>('');

useEffect(() => {
const watchThemeSwitch = async () => {
client.eventEmitter.on('themeChanged', (theme: string) => {
setThemeType(theme)
})
client.eventEmitter.on('compilationFinished', (build: Build, fileName: string) => {
setHasBuild(true)
setFileName(fileName)
})
client.eventEmitter.on('docsGenerated', (docs: string[]) => {
console.log('docsGenerated', docs)
})
}
watchThemeSwitch()
}, [])

return (
<div className="p-3">
<h1>Remix Docgen</h1>
{fileName && <h4>File: {fileName.split('/')[1].split('.')[0].concat('.sol')}</h4>}
{hasBuild && <button className="btn btn-primary btn-block mt-4 rounded" onClick={() => client.generateDocs()}>Generate doc</button>}
</div>
)
}

export default App
80 changes: 80 additions & 0 deletions apps/doc-gen/src/app/docgen-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { PluginClient } from '@remixproject/plugin'
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import { createClient } from '@remixproject/plugin-webview'
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 {
private currentTheme
public eventEmitter: EventEmitter
private build: Build
public docs: string[] = []
private fileName: string = ''

constructor() {
super()
this.eventEmitter = new EventEmitter()
this.methods = ['generateDocs', 'opendDocs']
createClient(this)
this.onload().then(async () => {
await this.setListeners()
})
}

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) => {
const input: SolcInput = {
sources: source.sources
}
const output: SolcOutput = {
sources: data.sources as any
}
this.build = {
input: input,
output: output
}
this.fileName = fileName
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) {
const temp = `${this.fileName.split('/')[1].split('.')[0]}.${id.split('.')[1]}`
const newFileName = `docs/${temp}`
await this.call('fileManager', 'setFile', newFileName , contents)
docs.push(newFileName)
}
this.eventEmitter.emit('docsGenerated', docs)
this.emit('docgen' as any, 'docsGenerated', docs)
this.docs = docs
await this.opendDocs(docs)
}

async opendDocs(docs: string[]) {
await this.call('manager', 'activatePlugin', 'doc-viewer')
await this.call('tabs' as any, 'focus', 'doc-viewer')
await this.call('doc-viewer' as any, 'viewDocs', docs)
}

async generateDocs() {
this.docgen([this.build])
}
}
22 changes: 22 additions & 0 deletions apps/doc-gen/src/app/docgen/common/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { VariableDeclaration } from "solidity-ast";

export function trim(text: string) {
if (typeof text === 'string') {
return text.trim();
}
}

export function joinLines(text?: string) {
if (typeof text === 'string') {
return text.replace(/\n+/g, ' ');
}
}

/**
* Format a variable as its type followed by its name, if available.
*/
export function formatVariable(v: VariableDeclaration): string {
return [v.typeName?.typeDescriptions.typeString].concat(v.name || []).join(' ');
}

export const eq = (a: unknown, b: unknown) => a === b;
Loading