progene
v1.0.0
Published
Customize and reuse parametrizable commands across projects.
Downloads
5
Readme
Progene
Customize and reuse parametrizable Node.js commands accessible from terminal across software projects.
Index
Installation
$ npm i --g progene
Usage
To see the help of a command, run progene
or any of its commands with the --help
flag.
Explanation
you write your own Node.js commands (separated by a namespace).
you start
progene
in any project you are developing.you add your created
progene
command namespaces.you run any of the commands you have coded before, comfortably from your fresh project.
Commands
[...]
: optional parameters.
<...>
: required parameters.
progene init [directory]
progene add <namespace-path> [options]
progene run <namespace/command> [options]
progene remove <namespace> [options]
Initialize progene
$ progene init .
Write commands
File: commands/namespace/progene.json
Contents:
{}
File: commands/namespace/first.js
Contents:
module.exports = function(options) {
console.log(options.one + " - " + options.two);
};
File: commands/namespace/hello.js
Contents:
module.exports = function(options) {
console.log("Hello " + (options.name || "world") + "!");
};
Add commands
$ progene add commands/namespace
Run commands
$ progene run namespace/first --one 1 2 3 --two a b c
It prints: 1 2 3 - a b c
$ progene run namespace/hello --name developer
It prints: Hello developer!
How it works
Progene creates a .progene
folder when you run progene init
.
Under the .progene
folder, you find the namespaces of your commands.
Under each namespace folder, you find its corresponding commands, as *.js
files.
Under each namespace folder, you also find its corresponding progene.json
metadata file.
The progene.js
only has to be a valid JSON file, nothing is required inside.
This way, one can reuse all the commands that it writes in one project, for different projects.
Workflow
The idea is that you start having:
path/to/project
And, on the other hand, your commands:
path/to/commands/namespace/progene.json
: a valid JSON file.path/to/commands/namespace/command-1.js
: amodule.exports = function(options) {...}
file.path/to/commands/namespace/command-2.js
: amodule.exports = function(options) {...}
file.path/to/commands/namespace/command-3.js
: amodule.exports = function(options) {...}
file.
Then you initialize progene
:
$ cd path/to/project
$ progene init
...in order to have:
path/to/project/.progene
: a folder for all the currently available commands in a project.
Then you add progene
command namespaces:
progene add path/to/commands/namespace
...in order to have:
path/to/project/.progene/namespace
: a namespace of commands.path/to/project/.progene/namespace/command-1.js
: a command.path/to/project/.progene/namespace/command-2.js
: a command.path/to/project/.progene/namespace/command-3.js
: a command.
Then you run progene
commands:
$ progene run namespace/command-1 --one 1 --two 2 --three 3
$ progene run namespace/command-2 --one 1 --two 2 --three 3
$ progene run namespace/command-3 --one 1 --two 2 --three 3
This way, you can reuse your commands across projects, polluting the least your projects' workspace.
API
You can also use the programmatic API.
Usage
The API module works almost the same way that the command-line interface, but passing objects to every method, instead.
1. Import module
const Progene = require("progene");
2. Use the commands as static methods
To initialize a project:
Progene.init();
Or, alternatively, specify the directory:
Progene.init({
base: __dirname + "/my/project" // 'base' is by default: process.cwd()
});
To add commands to the project:
Progene.add({
command: "/path/of/commands/namespace",
base: __dirname + "/my/project" // 'base' is by default: process.cwd()
});
To run a command:
Progene.add({
command: "namespace/command",
base: __dirname + "/my/project", // 'base' is by default: process.cwd()
name: "Nobody",
surname: "None",
age: 88,
place: "The World"
});
Note: what the function at /my/project/.progene/namespace/command.js
returns is what this method will return.
To remove a command:
Progene.remove({
command: "namespace/command",
base: __dirname + "/my/project", // 'base' is by default: process.cwd()
});
All the methods are chainable because they return the Progene
class again.
All the methods are chainable, except the Progene.run({ ... })
, which returns what the specified command itself returns, letting you use your own command-line interface also as programmatic APIs.
Issues
Expose any issue here.
Visit open issues here.
License
This is a project under WTFL, which means basically that you can do whatever you want with it.
Collaboration
Feel free to create your own branches.