Prepare yourselfs…

In this tutorial we will prepare a Nodejs project, that will make use of the macro-command package.  To keep any user code separated from the package itself, we have to create a simple directory structure, in which we can store our files. And finally we have to let the macro-command know where to look for it.
When everything is set up correctly, we can start building our own commands and eventually our own macro’s.

Create a new Nodejs project

First open a terminal and create a new directory and initialize it with npm:

Just hit ‘enter’ several times, to accept all of the default values. This will create the package.json into the root directory of your project. Then install the macro-command package by running the following command in the terminal:

Now, when you open the package.json, you will see that the macro-command is added as a dependency of your project.

(Note that your version might differ from mine, but that’s ok.)

Create a directory structure

The second thing to do,  is to create some directories. The macro-command requires three directories to be configured up-front:

  1. The commands directory – required
    • This is the directory where you will store all your commands. Subdirectories are allowed to organize your commands and called ‘namespaces’ whitin the context of the macro-command package. (not to be confused with js namespaces!)
  2. The configuration directory – required
    • Here you will store your configuration file(s).
  3. The helper directory – optional
    • Any module that supports your commands can be stored here.

Besides the three directories, I have created a config.json file. This is the last requirement of the macro-command. This file, will finally hold all the macro configurations.
The ‘bin’ directory is just a good place to store any scripts that need to be executed. It is a convention and something you’ll find in lots of applications.
The ‘mc’-subdirectory is just there to separate the macro-command files from any other stuff in your bin directory. In this way you can keep your project structure clean and well organized.

Configure the macro-command package

Finally we have to tell the macro-command about the directory structure we’ve just created. Therefore, we have to edit the ‘config.json’ file of the macro-command package, which you can find here:

By default it looks like this:

So…, were done here! Each (relative) path that need to be specified, is already mapped to one of the directories in our project. So were good to go.

What’s next?

Now were all set and ready for action! Go to the next part of this tutorial to learn how to write your first command.

< Previous part    |    Next part >