Node Radic
radic
Overview
radic
is the core library and application for many of my node applications.
- It exports a variety of objects, classes and instances for external use.
radic
is also a stand-alone application which manages global configuration and such.
How to use
Documentation
Installation
# Globally install radic for using radic command line tools
sudo npm install -g radic
# Local install into project for using libraries and helpers
npm install --save radic
Overview
Module | Description |
---|---|
config | persitent file based configuration |
db | file based database. Uses models/schemas with validation |
git | local commands like add, commit etc. also includes API for github/bitbucket |
util | extends the core util functionality with extras |
ui | .. |
cli | cli commands, output, input etc |
net | network functionality, like downloading |
sh | shell exec, execsync, execlist etc |
binwraps | wraps cli commands in a nice coat. |
google api functions |
Basic usage
Config
var radic = require('radic'),
Config = radic.Config,
config = new Config('config', { /** options */ });
var abc = config.get('a.b.c');
config.set('a.b', 'c');
config.set('a', { b: 'c' }, true); // saves the modified configuration to file
config.del('a.b');
config.clear();
config.save(); // or this
Cli
#!/usr/bin/env node
var radic = require('radic'),
cli = radic.cli;
cli.command('version OR version :type')
.description('Shows current version')
.usage('radic version minor', 'shows version')
.method(function (cmd) {
cli.log.info(cli.red.bold('1.0.0'));
});
cli.parse(process.argv);
SH
var radic = require('radic');
var result;
// Synchronous exec
result = radic.sh.execSync('apt-cache search mono | grep develop');
console.log(result.code); console.log(result.stdout);
// Inline scripts
result = radic.sh.inlineScript('echo "hai"\n\
echo "bai" \n\
echo "draai"');
console.log(result.code);
console.log(result.stdout);
result = radic.sh.inlineScript(function(){/*
echo "hai"
echo "bai"
echo "draai"
#apt-cache search mono
*/});
console.log(result.code);
console.log(result.stdout);
Net
var radic = require('radic');
radic.net.download('http://download.gigabyte.ru/driver/mb_driver_marvell_bootdisk_w7w8.exe', __dirname, { /* options */ }, function(){
// optional callback to make function execute asynchronously
});
Binwraps
var radic = require('radic');
var binwraps = radic.binwraps;
binwraps.createBinWrap('VBoxManage');
var vbox = binwraps.vboxmanage;
var result = vbox('createvm', {
name: ops.name,
ostype: 'Debian_64',
basefolder: path.resolve(process.cwd()),
register: true
});
console.log(result.stdout, result.code);
binwraps.autoSyncExec = false;
vbox('createvm', {
name: ops.name,
ostype: 'Debian_64',
basefolder: path.resolve(process.cwd()),
register: true
}, function(){
// callllback
});
var commands = binwraps.getCommands();
binwraps[ commands[0] ]('arg', { weed: 'bad' }); // just an example..
DB
File based database
var db = new require('radic').DB('myfileDB4', {
path: 'HOMEDIR/.radic/stores',
ext: '.db',
onLoaded: function(){}
});
var user = db.model('user', {
type: 'object',
properties: {
username: { type: 'string', eq: 'ipsum' },
email: { type: 'string', eq: 'ipsum' },
password: {
type: 'array',
items: { type: 'number' }
}
}
});
License
Copyright 2014 Robin Radic