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() export const client = new DocGenClient()
const App = () => { const App = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [themeType, setThemeType] = useState<string>('dark'); const [themeType, setThemeType] = useState<string>('dark');
const [hasBuild, setHasBuild] = useState<boolean>(false); const [hasBuild, setHasBuild] = useState<boolean>(false);
const [fileName, setFileName] = useState<string>(''); const [fileName, setFileName] = useState<string>('');

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api' import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import { createClient } from '@remixproject/plugin-webview' import { createClient } from '@remixproject/plugin-webview'
@ -15,6 +16,7 @@ export class DocGenClient extends PluginClient {
private build: Build private build: Build
public docs: string[] = [] public docs: string[] = []
private fileName: string = '' private fileName: string = ''
private contractPath: string = ''
constructor() { constructor() {
super() super()
@ -46,30 +48,23 @@ export class DocGenClient extends PluginClient {
input: input, input: input,
output: output output: output
} }
const test = normalizeContractPath(fileName) const test = normalizeContractPath(fileName, true)
console.log({ test }) this.fileName = typeof test === 'string' ? test : test[1]
this.fileName = test this.contractPath = typeof test === 'object' ? test[0] : ''
this.eventEmitter.emit('compilationFinished', this.build, test) this.eventEmitter.emit('compilationFinished', this.build, this.fileName)
}) })
} }
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 }) config.sourcesDir = this.contractPath.length > 0 ? this.contractPath : config.sourcesDir
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 pathArray = this.fileName.split('/') const pathArray = this.fileName.split('/')
console.log({ pathArray })
const temp = `${pathArray[pathArray.length - 1]}.${id.split('.')[1]}` 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)
@ -87,8 +82,6 @@ export class DocGenClient extends PluginClient {
} }
async generateDocs() { async generateDocs() {
const builds = [this.build] this.docgen([this.build])
console.log({ builds })
this.docgen(builds)
} }
} }

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

Loading…
Cancel
Save