-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Ethdoc plugin #3475
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
d4e187f
first commit
0368d26
prettier
dd4f8cd
remove legacy
2d6b4d9
fix build issues
18477ca
added docs
2977fc6
remove bootstrap for themes
c02de69
added docs
e34799f
fix rendering and document generation
0f5edcf
add activation
defiboy 6238412
prettier
defiboy af96b3f
updated docs
defiboy 1d65101
added retry mechanism
defiboy cf58e05
prettier
defiboy b538ace
updated docs
defiboy 813d11f
remove console log
defiboy 18d5238
improve code for debuggin and changee template rendering of dev funct…
defiboy 3b924d9
unused code
defiboy b7b0f39
prettier
defiboy 279bb35
remove tslint from husky
defiboy 3ef183e
updated docs
defiboy 9756280
added analytics
defiboy 2313462
update plugin and adapt for vscode
bunsenstraat f0ce6dc
provide link to results
bunsenstraat d18af4d
update remix plugin
bunsenstraat b3101c2
update remix plugin
bunsenstraat ad7a8c0
fix build
2689b4f
fix issue and theme
EdsonAlcala 5ccccc1
remove file
EdsonAlcala 71fba03
prettier
EdsonAlcala 22bf41e
fix style
EdsonAlcala 7dfcd4e
move plugin folders and files
joeizang c2bb678
change app folder name
joeizang 3f72add
move files around
joeizang 4cea6e2
add webpack config and tsconfig
joeizang 3f41d34
add required artifacts to have app work. remove redundancies
joeizang dbdf7c7
more plugin setup
joeizang 0902ed7
test text
joeizang f0efc2d
fix tsconfig path
joeizang fd132c2
move docgen plugin to new remixdocgen plugin
joeizang f79c9c8
update imports
joeizang 1bfc9e3
redo nod_modules
joeizang 5122f06
fix issues. make plugin self contained.
joeizang 2d0a6aa
fix issues
joeizang b141580
add docgen instance. move onload to class method
joeizang b25e37a
refactor
bunsenstraat 9203426
viewer
bunsenstraat 8b2b300
refactoring and cleanup
joeizang 6eaaf2c
remove redundant publis method
joeizang 4290ee4
cleanup
joeizang f3a6c6b
fix viewDoc method
joeizang 8e7b4f6
add docviewer plugin to show generated documentation
joeizang 7146254
create new plugin for doc viewer. cleanup
joeizang affa294
remove redundancies
joeizang 6fab2ee
add styles to docviewer view
joeizang d90382a
rename plugin folders
joeizang 96441de
change project.json
joeizang 3980133
fix plugin names and fix artefact folder
joeizang 3117afe
address comments from @lianahus and @bunsentraat
joeizang 8b56fe7
add doc-gen and doc-viewer back to app.js after rebase
joeizang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "/", | ||
"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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done