
ego-cli
Command Line Interface, which is designed to handle things, like Dev(Op) tasks, much faster.
Install
You can install it globally:
npm install -g ego-cli
Or for your project, from where your package.json
file is stored:
npm install --save-dev ego-cli
Execute
For example run the integrated Yeoman generator by executing:
ego new
Available commands
A (non complete) list of some interesting commands:
api # Runs an Express.js based REST API from current directory.
backup # Backups the current directory.
build # Shorthand for 'npm run build'.
csv-split # Splits one or more (huge) CSV file(s) into separates parts.
docker-stop # Stops all running Docker containers.
docker-up # Shorthand for 'docker-compose up'.
git-checkout # Checks out (to) a branch.
git-export # Clones a repository to the working directory and removes the '.git' subfolder.
git-pull # Pulls from all remotes to the current branch.
git-push # Pushes the current branch to all remotes.
git-sync # Syncs the current branch with all remotes.
job # Executes one or more scripts periodically.
new # Starts the e.GO generator for Yeoman.
node-install # Removes the 'node_modules' subfolder and executes 'npm install'.
run # Runs one or more Node.js based script file(s).
serve # Starts a HTTP server that shares files via a web interface.
ssl-new # Creates a new self-signed SSL certificate.
watch # Runs one or more scripts for file changes.
To list all available commands, simply run
ego
Custom commands
To implement a command, lets say my-command
, create a my-command.sh
(my-command.cmd
on Windows) file inside the .ego
subfolder of your home directory, give it enough rights to be executed and fill it with the code, you would like to execute.
To execute the new command, simply run
ego my-command ARG1 ARG2
All additional arguments, after my-command
, will be passed to the shell / batch script.
Scripts
With the help of run
command, you can implement Node.js based scripts.
Create a .js
file, like test.js
, and use the following skeleton:
exports.execute = async (context) => {
const docker = context.require('./docker');
const git = context.require('./git');
const util = context.require('./util');
util.writeLine('Hello, from ' + __filename);
};
You can run the script, by executing
ego run test.js
from the folder, that contains the file.
You are also able to store it globally, inside the .ego
subfolder, inside your user's home directory (${HOME}/.ego/test.js
).
API
api
command allows you to run a REST API, using Express.js framework, from current directory.
To start, create an index.js
file with the following skeleton:
exports.GET = async (req, res) => {
const CONTEXT = this;
return res.status(200)
.send('Hello, e.GO!');
};
Run a host instace, by executing
ego api
from that directory and open http://localhost:8080/api/ from browser to see the result of the endpoint.
Other methods
To use other HTTP methods, like POST
, PUT
or DELETE
, simply export functions with their names, in upper case characters:
exports.POST = async (req, res) => {
};
exports.PUT = async (req, res) => {
};
exports.PATCH = async (req, res) => {
};
exports.DELETE = async (req, res) => {
};
To handle any method, you only need to implement a request
function:
exports.request = async (req, res) => {
};
Routes
If you would like to implement an /foo/bar
endpoint, you have to create on of the following files
/foo/bar.js
- or
/foo/bar/index.js
Files with leading _
will be ignored, if you want to use them for endpoints.
Bootstrap and shutdown scripts
To define startup logic, create a _bootstrap.js
at the root of your API directory:
exports.execute = async (context, apiRouter, app) => {
};
You can do the same thing with a _shutdown.js
file.
SSL
Use ssl-new
to generate a new, self-signed certificate.
Contribute
The contribution guide explains, how to implement a new command, work with the code and open a pull request.
Copyright
That software makes use of free version of MD Bootstrap.