From 108d72cfb5c75f9edb92a6f4108cb76bb668633d Mon Sep 17 00:00:00 2001 From: cyace84 Date: Wed, 25 Jan 2023 04:45:10 +0100 Subject: [PATCH] remove ast dir after docgen --- src/ast-builder/compile-ast.ts | 7 +++++++ src/main.ts | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/ast-builder/compile-ast.ts b/src/ast-builder/compile-ast.ts index 3984c87f..3925ffe5 100644 --- a/src/ast-builder/compile-ast.ts +++ b/src/ast-builder/compile-ast.ts @@ -1,6 +1,8 @@ +import fs from 'fs'; import { execSync } from 'child_process'; import { Config } from '../config'; import { getAstsFromSources, getContractsList } from './getters'; +import path from 'path'; /** * It takes the config object, gets a list of contracts, and then compiles the AST for each contract @@ -8,6 +10,11 @@ import { getAstsFromSources, getContractsList } from './getters'; */ export const compileAst = async (config: Config) => { const contracts = getContractsList(config.sourcesDir!); + + if (fs.existsSync(config.astOutputDir!)) { + fs.rm(path.resolve(config.root!, config.astOutputDir!), () => {}); + } + contracts.forEach(contract => { execSync( `${config.compilerPath} --ast-compact-json $PWD/${config.sourcesDir}/${contract} --output-dir=$PWD/${config.astOutputDir}`, diff --git a/src/main.ts b/src/main.ts index d62cc0c8..1c46abac 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,4 +29,8 @@ export async function main( await fs.mkdir(path.dirname(outputFile), { recursive: true }); await fs.writeFile(outputFile, contents); } + + await fs.rm(path.resolve(config.root, config.astOutputDir), { + recursive: true, + }); }