Skip to content

Latest commit

 

History

History
79 lines (59 loc) · 1.81 KB

CONTRIBUTING.md

File metadata and controls

79 lines (59 loc) · 1.81 KB

Introduction and prerequisites

Truffle uses lerna to manage multi-package repositories. Each Truffle module is defined in its own npm package in the packages/ directory.

The entry point of these modules is truffle-core. This is where the command line parser is setup.

Install lerna:

$ npm install -g lerna
$ npm install -g yarn

Add a new command in truffle

Create a new lerna package

$ lerna create truffle-mycmd

Add the package to truffle-core

$ lerna add truffle-mycmd --scope=truffle-core

Create a new command in truffle-core

Create a new file in packages/truffle-core/lib/commands/, let's call it mycmd.js.

$ cat << EOF > truffle-core/lib/commands/mycmd.js
const command = {
  command: "mycmd",
  description: "Run mycmd",
  builder: {},
  help: {
    usage: "truffle mycmd",
    options: []
  },
  run: function(options, done) {
    const mycmd = require("truffle-mycmd");
    // TODO: write the run command here, something like:
    // mycmd(options, done)
  }
};

module.exports = command;
EOF

Link it from the commands/index.js file

--- packages/truffle-core/lib/commands/index.js
+++ packages/truffle-core/lib/commands/index.js
@@ -1,4 +1,5 @@
 module.exports = {
+  mycmd: require("./mycmd"),

From there, you should see it in the help screen:

$ cd packages/truffle-core
$ node cli.js
Truffle v5.0.0-beta.1 - a development framework for Ethereum

Usage: truffle <command> [options]

Commands:
  mycmd     Run mycmd
  build     Execute build pipeline (if configuration present)
[...]

Write your module/command

The setup is done, you can now write your command and organize your module as you want in: packages/truffle-mycmd/. You can have a look at packages/truffle-box/ which is a good starting example to follow.