refactor based on @yann300 comments

pull/5370/head
Joseph Izang 2 years ago committed by Aniket
parent d4251c72b3
commit 3d9c3f25d7
  1. 2
      apps/doc-gen/src/app/App.tsx
  2. 2
      apps/doc-gen/src/app/docgen-client.ts
  3. 8
      apps/doc-gen/src/app/docgen/utils/normalizeContractPath.ts

@ -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.concat('.sol')}</h6>} {fileName && <h6>File: {fileName}</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>
) )

@ -48,7 +48,7 @@ export class DocGenClient extends PluginClient {
input: input, input: input,
output: output output: output
} }
const test = normalizeContractPath(fileName, true) const test = normalizeContractPath(fileName)
this.fileName = typeof test === 'string' ? test : test[test.length - 1] this.fileName = typeof test === 'string' ? test : test[test.length - 1]
this.contractPath = typeof test === 'object' ? test[0] : '' this.contractPath = typeof test === 'object' ? test[0] : ''
this.eventEmitter.emit('compilationFinished', this.build, this.fileName) this.eventEmitter.emit('compilationFinished', this.build, this.fileName)

@ -1,7 +1,7 @@
export function normalizeContractPath(contractPath: string, returnPath?: boolean): string | string[]{ export function normalizeContractPath(contractPath: string): string[]{
const paths = contractPath.split('/') const paths = contractPath.split('/')
const filename = paths[paths.length - 1].split('.')[0] const filename = paths[paths.length - 1]
let folders = '' let folders = ''
for (let i = 0; i < paths.length - 1; i++) { for (let i = 0; i < paths.length - 1; i++) {
if(i !== paths.length -1) { if(i !== paths.length -1) {
@ -9,9 +9,5 @@ export function normalizeContractPath(contractPath: string, returnPath?: boolean
} }
} }
const resultingPath = `${folders}${filename}` const resultingPath = `${folders}${filename}`
if(returnPath) {
return [folders,resultingPath, filename] return [folders,resultingPath, filename]
} else {
return resultingPath
}
} }

Loading…
Cancel
Save