Setup your development environment

A tutorial describing how to setup your development environment for the DojoCLI.

Introduction

This tutorial describes how to setup your development environment for building the Dojo CLI by detailing the prerequisites and dependencies needed.

Technologies

The cli is built using NodeJS and NPM.

The programming language used is Typescript v5.

Prerequisites

In order to build the cli you will need the following tools:

  • NodeJS (version 18 or higher)
  • NPM (version 10 or higher)

Install NodeJS and NPM by following the instructions on the official website. Or via Node Version Manager (NVM) by following the instructions on the official website.

Dependencies

The CLI is packaged using pkg. This means that all the dependencies are bundled in the final binary.

Here are the main dependencies used by the cli (you don't need to install them manually or globally on your system):

  • Axios: a promise-based HTTP client for the browser and Node.js. It is used to make HTTP(S) requests to the Dojo backend and Gitlab.
  • Boxen: used to display messages in a box in the terminal.
  • Chalk: used to add colors to the messages in the terminal.
  • Commander.js: a library to write command-line interfaces.
  • Dotenv: used to load environment variables from a .env file.
  • Dotenv-vault: a CLI to sync .env files across machines, environments, and team members.
  • Inquirer: used to ask perform to the interactive command line user interfaces.
  • JsonWebToken: used to generate and validate JSON Web Tokens.
  • ora: used to display elegantly in the terminal.
  • zod: a TypeScript-first schema validation with static type inference. Used in the projet to validate json files created by the user.

Installation

First of all, you need to clone the repository:

git clone --recurse-submodule https://gitedu.hesge.ch/dojo_project/projects/ui/dojocli.git

Then, you need to move to the project's directory:

cd NodeApp

To install the dependencies listed above you can use the following command in the base directory of the project:

npm install

Environment variables

Environment variables are used to store sensitive information such as API keys, passwords, etc. They are also used to store configuration information that can be changed without modifying the code.

You can decrypt env var stored in the .env.vault file with the following commands in the project's main folder:

> npx dotenv-vault local keys
 environment DOTENV_KEY
 ─────────── ─────────────────────────────────────────────────────────────────────────
 development dotenv://:key_1234@dotenv.local/vault/.env.vault?environment=development

Set DOTENV_KEY on your server

> npx dotenv-vault local decrypt dotenv://:key_1234@dotenv.local/vault/.env.vault?environment=development > .env.development

The .env.keys file have to be requested to the project maintainer: Michaël Minelli.

Run the cli

To run the cli (in dev mode) you can use the following command in the base directory of the project:

npm run start:dev -- COMMAND

Where COMMAND is the command you want to run.

For example, if you want to test the exercise creation command you can use the following command:

npm run start:dev -- exercise create -a "Technique de compilation - TP" --members_username michael.minelli