address comments from @lianahus and @bunsentraat

pull/3542/head
Joseph Izang 2 years ago
parent 74fa09e1f4
commit 55c08d273b
  1. 4
      .gitignore
  2. 5
      apps/doc-gen/src/app/App.tsx
  3. 6
      apps/doc-gen/src/app/docgen-client.ts
  4. 28
      apps/doc-gen/src/app/docgen/common/properties.ts
  5. 10
      apps/doc-gen/src/app/docgen/site.ts
  6. 11
      apps/doc-gen/src/app/docgen/templates.ts
  7. 1
      apps/doc-gen/src/index.html
  8. 5
      apps/doc-gen/webpack.config.js
  9. 1
      apps/doc-viewer/src/index.html
  10. 5
      apps/doc-viewer/webpack.config.js
  11. 3
      tsconfig.paths.json

4
.gitignore vendored

@ -57,7 +57,3 @@ testem.log
.DS_Store .DS_Store
.vscode/settings.json .vscode/settings.json
.vscode/launch.json .vscode/launch.json
libs/remix-node/
libs/remix-niks/
apps/remix-react

@ -35,9 +35,8 @@ const App = () => {
<h1>Remix Docgen</h1> <h1>Remix Docgen</h1>
{fileName && <h4>File: {fileName.split('/')[1].split('.')[0].concat('.sol')}</h4>} {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>} {hasBuild && <button className="btn btn-primary btn-block mt-4 rounded" onClick={() => client.generateDocs()}>Generate doc</button>}
</div> </div>
) )
}; }
export default App; export default App

@ -5,7 +5,7 @@ import EventEmitter from 'events'
import { Config, defaults } from './docgen/config' import { Config, defaults } from './docgen/config'
import { Build, buildSite } from './docgen/site' import { Build, buildSite } from './docgen/site'
import { loadTemplates } from './docgen/templates' import { loadTemplates } from './docgen/templates'
import {SolcInput, SolcOutput} from 'solidity-ast/solc' import { SolcInput, SolcOutput } from 'solidity-ast/solc'
import { render } from './docgen/render' import { render } from './docgen/render'
export class DocGenClient extends PluginClient { export class DocGenClient extends PluginClient {
@ -47,7 +47,6 @@ export class DocGenClient extends PluginClient {
} }
this.fileName = fileName this.fileName = fileName
this.eventEmitter.emit('compilationFinished', this.build, fileName) this.eventEmitter.emit('compilationFinished', this.build, fileName)
}) })
} }
@ -78,5 +77,4 @@ export class DocGenClient extends PluginClient {
async generateDocs() { async generateDocs() {
this.docgen([this.build]) this.docgen([this.build])
} }
}
}

@ -10,11 +10,11 @@ import { itemType } from '../utils/item-type';
type TypeDefinition = StructDefinition | EnumDefinition | UserDefinedValueTypeDefinition; type TypeDefinition = StructDefinition | EnumDefinition | UserDefinedValueTypeDefinition;
export function type({ item }: DocItemContext): string { export function type ({ item }: DocItemContext): string {
return itemType(item); return itemType(item);
} }
export function natspec({ item }: DocItemContext): NatSpec { export function natspec ({ item }: DocItemContext): NatSpec {
return parseNatspec(item); return parseNatspec(item);
} }
@ -26,7 +26,7 @@ export function name({ item }: DocItemContext, original?: unknown): string {
} }
} }
export function fullName({ item, contract }: DocItemContext): string { export function fullName ({ item, contract }: DocItemContext): string {
if (contract) { if (contract) {
return `${contract.name}.${item.name}`; return `${contract.name}.${item.name}`;
} else { } else {
@ -34,7 +34,7 @@ export function fullName({ item, contract }: DocItemContext): string {
} }
} }
export function signature({ item }: DocItemContext): string | undefined { export function signature ({ item }: DocItemContext): string | undefined {
switch (item.nodeType) { switch (item.nodeType) {
case 'ContractDefinition': case 'ContractDefinition':
return undefined; return undefined;
@ -85,7 +85,7 @@ interface Param extends VariableDeclaration {
natspec?: string; natspec?: string;
}; };
function getParams(params: ParameterList, natspec: NatSpec['params'] | NatSpec['returns']): Param[] { function getParams (params: ParameterList, natspec: NatSpec['params'] | NatSpec['returns']): Param[] {
return params.parameters.map((p, i) => ({ return params.parameters.map((p, i) => ({
...p, ...p,
type: p.typeDescriptions.typeString!, type: p.typeDescriptions.typeString!,
@ -93,46 +93,46 @@ function getParams(params: ParameterList, natspec: NatSpec['params'] | NatSpec['
})); }));
} }
export function params({ item }: DocItemContext): Param[] | undefined { export function params ({ item }: DocItemContext): Param[] | undefined {
if ('parameters' in item) { if ('parameters' in item) {
return getParams(item.parameters, natspec(item[DOC_ITEM_CONTEXT]).params); return getParams(item.parameters, natspec(item[DOC_ITEM_CONTEXT]).params);
} }
} }
export function returns({ item }: DocItemContext): Param[] | undefined { export function returns ({ item }: DocItemContext): Param[] | undefined {
if ('returnParameters' in item) { if ('returnParameters' in item) {
return getParams(item.returnParameters, natspec(item[DOC_ITEM_CONTEXT]).returns); return getParams(item.returnParameters, natspec(item[DOC_ITEM_CONTEXT]).returns);
} }
} }
export function items({ item }: DocItemContext): DocItem[] | undefined { export function items ({ item }: DocItemContext): DocItem[] | undefined {
return (item.nodeType === 'ContractDefinition') return (item.nodeType === 'ContractDefinition')
? item.nodes.filter(isNodeType(docItemTypes)).filter(n => !('visibility' in n) || n.visibility !== 'private') ? item.nodes.filter(isNodeType(docItemTypes)).filter(n => !('visibility' in n) || n.visibility !== 'private')
: undefined; : undefined;
} }
export function functions({ item }: DocItemContext): FunctionDefinition[] | undefined { export function functions ({ item }: DocItemContext): FunctionDefinition[] | undefined {
return [...findAll('FunctionDefinition', item)].filter(f => f.visibility !== 'private'); return [...findAll('FunctionDefinition', item)].filter(f => f.visibility !== 'private');
} }
export function events({ item }: DocItemContext): EventDefinition[] | undefined { export function events ({ item }: DocItemContext): EventDefinition[] | undefined {
return [...findAll('EventDefinition', item)]; return [...findAll('EventDefinition', item)];
} }
export function modifiers({ item }: DocItemContext): ModifierDefinition[] | undefined { export function modifiers ({ item }: DocItemContext): ModifierDefinition[] | undefined {
return [...findAll('ModifierDefinition', item)]; return [...findAll('ModifierDefinition', item)];
} }
export function errors({ item }: DocItemContext): ErrorDefinition[] | undefined { export function errors ({ item }: DocItemContext): ErrorDefinition[] | undefined {
return [...findAll('ErrorDefinition', item)]; return [...findAll('ErrorDefinition', item)];
} }
export function variables({ item }: DocItemContext): VariableDeclaration[] | undefined { export function variables ({ item }: DocItemContext): VariableDeclaration[] | undefined {
return (item.nodeType === 'ContractDefinition') return (item.nodeType === 'ContractDefinition')
? item.nodes.filter(isNodeType('VariableDeclaration')).filter(v => v.stateVariable && v.visibility !== 'private') ? item.nodes.filter(isNodeType('VariableDeclaration')).filter(v => v.stateVariable && v.visibility !== 'private')
: undefined; : undefined;
} }
export function types({ item }: DocItemContext): TypeDefinition[] | undefined { export function types ({ item }: DocItemContext): TypeDefinition[] | undefined {
return [...findAll(['StructDefinition', 'EnumDefinition', 'UserDefinedValueTypeDefinition'], item)]; return [...findAll(['StructDefinition', 'EnumDefinition', 'UserDefinedValueTypeDefinition'], item)];
} }

@ -52,7 +52,7 @@ export interface DocItemContext {
build: BuildContext; build: BuildContext;
} }
export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: Properties = {}): Site { export function buildSite (builds: Build[], siteConfig: SiteConfig, properties: Properties = {}): Site {
const assign = typeof siteConfig.pages === 'string' ? pageAssigner[siteConfig.pages] : siteConfig.pages; const assign = typeof siteConfig.pages === 'string' ? pageAssigner[siteConfig.pages] : siteConfig.pages;
const seen = new Set<string>(); const seen = new Set<string>();
@ -106,20 +106,20 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
}; };
} }
function defineContext(item: DocItem, build: BuildContext, file: SourceUnit, page?: string, contract?: ContractDefinition): DocItemWithContext { function defineContext (item: DocItem, build: BuildContext, file: SourceUnit, page?: string, contract?: ContractDefinition): DocItemWithContext {
return Object.assign(item, { return Object.assign(item, {
[DOC_ITEM_CONTEXT]: { build, file, contract, page, item: item as DocItemWithContext }, [DOC_ITEM_CONTEXT]: { build, file, contract, page, item: item as DocItemWithContext },
}); });
} }
function defineProperties(item: DocItemWithContext, properties: Properties) { function defineProperties (item: DocItemWithContext, properties: Properties) {
for (const [prop, fn] of Object.entries(properties)) { for (const [prop, fn] of Object.entries(properties)) {
const original: unknown = (item as any)[prop]; const original: unknown = (item as any)[prop];
defineGetterMemoized(item as any, prop, () => fn(item.__item_context, original)); defineGetterMemoized(item as any, prop, () => fn(item.__item_context, original));
} }
} }
function assignIfIncludedSource( function assignIfIncludedSource (
assign: PageAssigner, assign: PageAssigner,
item: DocItem, item: DocItem,
file: SourceUnit, file: SourceUnit,
@ -130,7 +130,7 @@ function assignIfIncludedSource(
: undefined; : undefined;
} }
function isFileIncluded(file: string, config: SiteConfig) { function isFileIncluded (file: string, config: SiteConfig) {
return ( return (
isChild(file, config.sourcesDir) && isChild(file, config.sourcesDir) &&
config.exclude.every(e => !isChild(file, path.join(config.sourcesDir, e))) config.exclude.every(e => !isChild(file, path.join(config.sourcesDir, e)))

@ -84,12 +84,7 @@ async function readHelpers(name: string) {
* can't be imported directly. * can't be imported directly.
*/ */
async function readThemes(): Promise<Record<string, Required<Templates>>> { async function readThemes(): Promise<Record<string, Required<Templates>>> {
const themes: Record<string, Required<Templates>> = {}; const themes: Record<string, Required<Templates>> = {}
themes['markdown'] = await readTemplates()
return themes
themes['markdown'] = await readTemplates();
return themes;
} }

@ -4,7 +4,6 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Remix Docgen</title> <title>Remix Docgen</title>
<base href="/" /> <base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" />
</head> </head>

@ -40,8 +40,6 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
// add public path // add public path
config.output.publicPath = '/' config.output.publicPath = '/'
// add copy & provide plugin // add copy & provide plugin
config.plugins.push( config.plugins.push(
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
@ -63,7 +61,6 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings
// set minimizer // set minimizer
config.optimization.minimizer = [ config.optimization.minimizer = [
new TerserPlugin({ new TerserPlugin({
@ -82,4 +79,4 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
]; ];
return config; return config;
}); })

@ -4,7 +4,6 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Doc Viewer</title> <title>Doc Viewer</title>
<base href="/" /> <base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico" />
</head> </head>

@ -40,8 +40,6 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
// add public path // add public path
config.output.publicPath = '/' config.output.publicPath = '/'
// add copy & provide plugin // add copy & provide plugin
config.plugins.push( config.plugins.push(
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
@ -63,7 +61,6 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings
// set minimizer // set minimizer
config.optimization.minimizer = [ config.optimization.minimizer = [
new TerserPlugin({ new TerserPlugin({
@ -82,4 +79,4 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
]; ];
return config; return config;
}); })

@ -148,9 +148,6 @@
"@remix-ui/solidity-uml-gen": [ "@remix-ui/solidity-uml-gen": [
"libs/remix-ui/solidity-uml-gen/src/index.ts" "libs/remix-ui/solidity-uml-gen/src/index.ts"
], ],
"@remix-ui/docgenclient-ui": [
"libs/remix-ui/docgenclient-ui/src/index.ts"
],
"@remix-project/ghaction-helper": [ "@remix-project/ghaction-helper": [
"libs/ghaction-helper/src/index.ts" "libs/ghaction-helper/src/index.ts"
], ],

Loading…
Cancel
Save