I’m aware that there are a number of similar how-to’s available. But they go out of date really fast. I found it challenging to get this environment up and running so hopefully others will benefit from my experience.
I haven’t included blow by blow accounts of how to install the individual components. Many web resources provide detailed instructions which are often platform specific.
I am running this environment on OSX (Big Sur) and Ubuntu 18. It should run on most platforms although you may need to do some additional work if you want ZSH, Git and the ZSH Git plugin to work well together on windows.
I develop on a reasonably recent iMac (27") and a large screen laptop running Ubuntu 18. I have a QNAP NAS running Gogs and MariaDB in (separate) docker containers. Therefore my work-in-progress is held on the NAS, I can rapidly switch between the iMac and my laptop. Anything I want to publish goes to my GitHub account.
I have recently upgraded to ZSH on OSX and Ubuntu. I use Oh-my-zsh with the Git and History plugins. On the Mac I use the iTerm2 terminal and on Ubuntu I still use the standard terminal.
I currently use node versions 8, 10 and 12. Therefore all my node installations are managed by NVM.
Installing the individual components is reasonably straight forward and well covered by other resources. Therefore I will focus on the integration points.
Integrating the Components
The first challenge was the WebStorm terminal which continued to use BASH even though the host OS’s had been reconfigured to use Zsh. Simply running chsh from the WebStorm terminal (followed by a WebStorm restart) was sufficient to get the zsh prompt back with all the associated highlighting and plugin magic. WebStorm already has great integration with Git. You need to add a few plugins for things like Solidity support but this is straight forwards. The complicated part is to integrate with the node / truffle development environment.
Integrating Node / Truffle into WebStorm
The WebStorm IDE provides Edit Configurations under the Run menu. These configurations can be utilised by the Run and Debug commands. These commands can be fired from the Run Menu or buttons on the button bar. The “Edit Configurations” dialog (also on the Run menu) provides templates to integrate with numerous technologies including Mocha, Node.js, Nodeunit npm and Shell Scripts. I experimented with all of these points. However I achieved my best and simplest integration using the npm template.
First of all I configured a test.sh bash shell script to run from npm. This can be done within the package.json file as follows: -
Normally you can run commands like “npx truffle test test/unit/*.js” from your OS terminal or the WebStorm terminal and they work fine. However getting npx to run correctly from the IDE integration points is something of a challenge. By using this integration point you can write npx commands in the ./scripts/test.sh file and they work as expected. Once this integration is in place you can test it with “npm run” which should list your configured scripts. The script can now be run by “npm run test”.
My current project also has similar integration points to run the linter and coverage reports.
As you can see, this scripts relies on npx installed scripts start-chain and stop-chain. These utilise ganache-cli to start and stop the blockchain with whatever environment you need for your project.
There is also a dependency on a script get-network-config to return the port number. In this case this script simply returns the Ganache default port 8545.
This script can easily be tested as it is developed by executing “npm run test [test/sometest.js]” from the OS or WebStorm console.
Once this script is running successfully from the console we need to integrate it into the IDE. This is done by creating an Edit Configuration as follows using the npm template:
The biggest downside of this configuration is that you need to setup separate configurations for each version of node that you use. I would like the configurations to automatically pick up the terminal provided versions from the path. I haven’t figured out how to do this yet.
Happy hunting …