Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support flattening every files under contracts directory #5047

Open
tornadocontrib opened this issue Mar 30, 2024 · 0 comments
Open

Support flattening every files under contracts directory #5047

tornadocontrib opened this issue Mar 30, 2024 · 0 comments
Assignees
Labels
status:ready This issue is ready to be worked on type:feature Feature request

Comments

@tornadocontrib
Copy link

Describe the feature

Could we support this simple task?

I am doing it with the following, but would be great if it could be supported as a default task

task('flatten:all', 'Flatten all contracts each file under flatten directory')
  .setAction(async (taskArgs, hre) => {
    const allFilesAndFolders = fs.readdirSync('contracts', { recursive: true }) as Array<string>;
    const allFolders = allFilesAndFolders.filter(f => fs.statSync(path.join('contracts', f)).isDirectory());
    const allFiles = allFilesAndFolders.filter(f => !allFolders.includes(f));

    fs.rmSync('flatten', { force: true, recursive: true });
    fs.mkdirSync('flatten');
    allFolders.forEach(f => {
      fs.mkdirSync(path.join('flatten', f), { recursive: true });
    });

    await Promise.all(allFiles.map(async (f) => {
      const contract = path.join('contracts', f);
      const contractTo = path.join('flatten', f);
      try {
        const flatten = await hre.run('flatten:get-flattened-sources', { files: [contract] });
        fs.writeFileSync(contractTo, flatten);
        console.log(`Wrote ${contractTo} contract`);
      } catch (e) {
        // Catching circular contracts
        console.log(`Failed to write ${contractTo} contract`);
        console.log(e);
      }
    }));
  });

Search terms

No response

@kanej kanej added type:feature Feature request status:ready This issue is ready to be worked on and removed status:triaging labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on type:feature Feature request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants