fix docgen bug

pull/5370/head
Joseph Izang 2 years ago committed by Aniket
parent 27f25e79a1
commit 5c41a8020e
  1. 1
      apps/doc-gen/src/app/App.tsx
  2. 23
      apps/doc-gen/src/app/docgen-client.ts
  3. 17
      apps/doc-gen/src/app/docgen/utils/normalizeContractPath.ts

@ -7,6 +7,7 @@ import { Build } from './docgen/site'
export const client = new DocGenClient()
const App = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [themeType, setThemeType] = useState<string>('dark');
const [hasBuild, setHasBuild] = useState<boolean>(false);
const [fileName, setFileName] = useState<string>('');

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { PluginClient } from '@remixproject/plugin'
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import { createClient } from '@remixproject/plugin-webview'
@ -15,6 +16,7 @@ export class DocGenClient extends PluginClient {
private build: Build
public docs: string[] = []
private fileName: string = ''
private contractPath: string = ''
constructor() {
super()
@ -46,30 +48,23 @@ export class DocGenClient extends PluginClient {
input: input,
output: output
}
const test = normalizeContractPath(fileName)
console.log({ test })
this.fileName = test
this.eventEmitter.emit('compilationFinished', this.build, test)
const test = normalizeContractPath(fileName, true)
this.fileName = typeof test === 'string' ? test : test[1]
this.contractPath = typeof test === 'object' ? test[0] : ''
this.eventEmitter.emit('compilationFinished', this.build, this.fileName)
})
}
async docgen(builds: Build[], userConfig?: Config): Promise<void> {
console.log('docgen called')
const config = { ...defaults, ...userConfig }
console.log({ config })
config.sourcesDir = this.contractPath.length > 0 ? this.contractPath : config.sourcesDir
const templates = await loadTemplates(config.theme, config.root, config.templates)
console.log({ templates })
const site = buildSite(builds, config, templates.properties ?? {})
console.log({ site })
const renderedSite = render(site, templates, config.collapseNewlines)
const docs: string[] = []
console.log('docs created!!')
console.log({ renderedSite })
for (const { id, contents } of renderedSite) {
const pathArray = this.fileName.split('/')
console.log({ pathArray })
const temp = `${pathArray[pathArray.length - 1]}.${id.split('.')[1]}`
console.log(temp)
const newFileName = `docs/${temp}`
await this.call('fileManager', 'setFile', newFileName , contents)
docs.push(newFileName)
@ -87,8 +82,6 @@ export class DocGenClient extends PluginClient {
}
async generateDocs() {
const builds = [this.build]
console.log({ builds })
this.docgen(builds)
this.docgen([this.build])
}
}

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

Loading…
Cancel
Save