Skip to content

Commit

Permalink
Merge pull request #319 from alephium/clean-dead-ral-json-files
Browse files Browse the repository at this point in the history
Remove dead ral json files and dead genereated ts files
  • Loading branch information
polarker authored Feb 26, 2024
2 parents afcf204 + 9ff8a83 commit 421af27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/cli/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,10 @@ export function sortByName<T extends { artifact: { name: string } }>(artifacts:
export function codegen(artifactDir: string) {
const outDirTemp = path.join(artifactDir, 'ts')
const outDir = path.isAbsolute(outDirTemp) ? outDirTemp : path.resolve(outDirTemp)
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir, { recursive: true })
if (fs.existsSync(outDir)) {
fs.rmSync(outDir, { recursive: true, force: true })
}
fs.mkdirSync(outDir, { recursive: true })

const exports: string[] = []
try {
Expand Down
20 changes: 20 additions & 0 deletions packages/web3/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,23 @@ export class ProjectArtifact {
}
}

function removeOldArtifacts(dir: string) {
const files = fs.readdirSync(dir)
files.forEach((file) => {
const filePath = path.join(dir, file)
const stat = fs.statSync(filePath)
if (stat.isDirectory()) {
removeOldArtifacts(filePath)
} else if (filePath.endsWith('.ral.json') || filePath.endsWith('.ral')) {
fs.unlinkSync(filePath)
}
})

if (fs.readdirSync(dir).length === 0) {
fs.rmdirSync(dir)
}
}

export class Project {
sourceInfos: SourceInfo[]
contracts: Map<string, Compiled<Contract>>
Expand Down Expand Up @@ -731,6 +748,9 @@ export class Project {
projectArtifact === undefined ||
projectArtifact.needToReCompile(nodeCompilerOptions, sourceFiles, fullNodeVersion)
) {
if (fs.existsSync(artifactsRootDir)) {
removeOldArtifacts(artifactsRootDir)
}
console.log(`Compiling contracts in folder "${contractsRootDir}"`)
Project.currentProject = await Project.compile(
fullNodeVersion,
Expand Down

0 comments on commit 421af27

Please sign in to comment.