TrueFiEng/Waffle

Add a flattener for contracts

sz-piotr opened this issue · 1 comments

Add a flattener for contracts

Current Waffle CLI usage

Waffle CLI is currently used by passing in a path to a config file and doesn't have any meaningful options.

Usage:

    waffle [config-file] [options]

    Compiles solidity source code

  Config file:

    Read more about the configuration file in the documentation
    https://ethereum-waffle.readthedocs.io

  Options:

    --help, -h      Display this message

Possible solutions

1. Add waffle flatten and waffle compile CLI options and make waffle invocation default to waffle compile.

Usage:

    waffle [compile|flatten] [config-file] [options]
    
  Config file:

    Read more about the configuration file in the documentation
    https://ethereum-waffle.readthedocs.io

  Options:

    --help, -h      Display this message

Pros:

  • Easy to transform into third approach

Cons:

  • User must provide multiple configs (for compile and flatten)
  • Increased complexity: compile and flatten configs should have separate formats to not introduce confusion. Not every field from compile config is used for flattening (e.g. compilerVersion or outputType)

2. Add single option to waffle config flattenOutputDirectory.

Usage would be the same as currently

Cons:

  • if we add flattenOutputDirectory it would make more sense to rename outputDirectory -> compileOutputDirectory
  • user may want to flatten only some of the files from sourceDirectory and would end up creating a separate config file anyway

3. Add support for multiple configurations along with waffle flatten and waffle compile commands (involves: #209)

The configuration format would now allow adding multiple configurations in an array. Passing a single configuration object would still be possible to maintain backwards compatibility.

[
  {
    name: "old contracts",
    type: "compile",
    compilerVersion: "0.4.19",
    sourceDirectory: "src/old-contracts",
    outputDirectory: "dist/old-contracts",
  },
  {
    name: "new contracts",
    type: "compile",
    compilerVersion: "0.6.3",
    sourceDirectory: "src/new-contracts",
    outputDirectory: "dist/new-contracts",
  },
  {
    name: "flatten",
    type: "flatten",
    sourceDirectory: "src/new-contracts",
    outputDirectory: "dist/new-contracts/flat",
  },
]

New optional configuration fields would be added:

  • name (default: #1 position in array) - for better printing of waffle processing progress
  • type (default: compile) - for choosing processing action: compilation or flattening of contracts from sourceDirectory

The new usage of Waffle CLI would look as follows:

Usage:

    waffle [compile|flatten] [config-file] [options]
    
  Config file:

    Read more about the configuration file in the documentation
    https://ethereum-waffle.readthedocs.io

  Options:

    --help, -h      Display this message

Invoking waffle compile command would run only configs with type compile.
Invoking waffle flatten would run only configs with type flatten.
Invoking waffle would run all specified configurations.