pull/3591/head
Joseph Izang 2 years ago committed by Aniket
parent a0bc9d50ca
commit 7ef4323f7a
  1. 6
      apps/doc-gen/src/app/App.tsx
  2. 22
      apps/doc-gen/src/app/docgen-client.ts
  3. 16
      apps/doc-gen/src/app/docgen/utils/normalizeContractPath.ts
  4. 3
      apps/remix-ide/src/app/plugins/contractFlattener.tsx
  5. 4
      apps/remix-ide/src/app/plugins/solidity-umlgen.tsx
  6. 2
      libs/remix-ui/solidity-compiler/src/lib/logic/flattenerUtilities.ts

@ -17,11 +17,11 @@ const App = () => {
setThemeType(theme) setThemeType(theme)
}) })
client.eventEmitter.on('compilationFinished', (build: Build, fileName: string) => { client.eventEmitter.on('compilationFinished', (build: Build, fileName: string) => {
const temp = fileName.split('/')[fileName.split('/').length - 1]
setHasBuild(true) setHasBuild(true)
setFileName(fileName) setFileName(temp)
}) })
client.eventEmitter.on('docsGenerated', (docs: string[]) => { client.eventEmitter.on('docsGenerated', (docs: string[]) => {
console.log('docsGenerated', docs)
}) })
} }
watchThemeSwitch() watchThemeSwitch()
@ -30,7 +30,7 @@ const App = () => {
return ( return (
<div className="p-3"> <div className="p-3">
<h3>Compile a solidity contract in order to build documentation as markdown.</h3> <h3>Compile a solidity contract in order to build documentation as markdown.</h3>
{fileName && <h6>File: {fileName.split('/')[1].split('.')[0].concat('.sol')}</h6>} {fileName && <h6>File: {fileName.concat('.sol')}</h6>}
{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>
) )

@ -7,6 +7,7 @@ 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'
import { normalizeContractPath } from './docgen/utils/normalizeContractPath'
export class DocGenClient extends PluginClient { export class DocGenClient extends PluginClient {
private currentTheme private currentTheme
@ -45,19 +46,30 @@ export class DocGenClient extends PluginClient {
input: input, input: input,
output: output output: output
} }
this.fileName = fileName const test = normalizeContractPath(fileName)
this.eventEmitter.emit('compilationFinished', this.build, fileName) console.log({ test })
this.fileName = test
this.eventEmitter.emit('compilationFinished', this.build, test)
}) })
} }
async docgen(builds: Build[], userConfig?: Config): Promise<void> { async docgen(builds: Build[], userConfig?: Config): Promise<void> {
console.log('docgen called')
const config = { ...defaults, ...userConfig } const config = { ...defaults, ...userConfig }
console.log({ config })
const templates = await loadTemplates(config.theme, config.root, config.templates) const templates = await loadTemplates(config.theme, config.root, config.templates)
console.log({ templates })
const site = buildSite(builds, config, templates.properties ?? {}) const site = buildSite(builds, config, templates.properties ?? {})
console.log({ site })
const renderedSite = render(site, templates, config.collapseNewlines) const renderedSite = render(site, templates, config.collapseNewlines)
const docs: string[] = [] const docs: string[] = []
console.log('docs created!!')
console.log({ renderedSite })
for (const { id, contents } of renderedSite) { for (const { id, contents } of renderedSite) {
const temp = `${this.fileName.split('/')[1].split('.')[0]}.${id.split('.')[1]}` const pathArray = this.fileName.split('/')
console.log({ pathArray })
const temp = `${pathArray[pathArray.length - 1]}.${id.split('.')[1]}`
console.log(temp)
const newFileName = `docs/${temp}` const newFileName = `docs/${temp}`
await this.call('fileManager', 'setFile', newFileName , contents) await this.call('fileManager', 'setFile', newFileName , contents)
docs.push(newFileName) docs.push(newFileName)
@ -75,6 +87,8 @@ export class DocGenClient extends PluginClient {
} }
async generateDocs() { async generateDocs() {
this.docgen([this.build]) const builds = [this.build]
console.log({ builds })
this.docgen(builds)
} }
} }

@ -0,0 +1,16 @@
export function normalizeContractPath(contractPath: string): string {
let paths = contractPath.split('/')
let filename = paths[paths.length - 1].split('.')[0]
let folders = ''
for (let i = 0; i < paths.length - 1; i++) {
if(i !== paths.length -1) {
folders += `${paths[i]}/`
}
}
const resultingPath = `${folders}${filename}`
// cleanup variables
paths = null
filename = null
folders = null
return resultingPath
}

@ -50,7 +50,8 @@ export class ContractFlattener extends Plugin {
*/ */
async flattenContract (source: { sources: any, target: string }, async flattenContract (source: { sources: any, target: string },
filePath: string, data: { contracts: any, sources: any }): Promise<string> { filePath: string, data: { contracts: any, sources: any }): Promise<string> {
const path = normalizeContractPath(filePath) const appendage = '_flattened.sol'
const path = `${normalizeContractPath(filePath)}${appendage}`
const ast = data.sources const ast = data.sources
let dependencyGraph let dependencyGraph
let sorted let sorted

@ -140,7 +140,9 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen {
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
async flattenContract (source: any, filePath: string, data: any) { async flattenContract (source: any, filePath: string, data: any) {
const result = await this.call('contractflattener', 'flattenContract', source, filePath, data) const appendage = '_flattened.sol'
const temp = await this.call('contractflattener', 'flattenContract', source, filePath, data)
const result = `${temp}${appendage}`
return result return result
} }

@ -177,7 +177,7 @@ export function normalizeContractPath(contractPath: string): string {
folders += `${paths[i]}/` folders += `${paths[i]}/`
} }
} }
const resultingPath = `${folders}${filename}_flattened.sol` const resultingPath = `${folders}${filename}`
// cleanup variables // cleanup variables
paths = null paths = null
filename = null filename = null

Loading…
Cancel
Save