UNPKG

mib-cli

Version:

CLI tool to manage projects

108 lines (77 loc) 1.76 kB
#! /usr/bin/node 'use strict'; /******************* * Variable *******************/ const Vorpal = require('vorpal'), delimiter = require('./util/delimiter'), config = require('./util/config'), projects = require('./util/projects'), autoComplete = require('./util/auto-complete'), git = require('./util/git'), async = require('async'), fs = require('fs'), path = require('path'); /******************* * Class *******************/ /* * Constructor */ function App() { this.vorpal = Vorpal(); config.setVorpal(this.vorpal); projects.setVorpal(this.vorpal); autoComplete.setVorpal(this.vorpal); delimiter.setVorpal(this.vorpal); git.setVorpal(this.vorpal); } /* * Load vorpal configuration */ App.prototype.load = function (callback) { let self = this; this.vorpal .localStorage('mib') .history(); delimiter.refresh(); async.series([ function localCommands(cb) { fs.readdir('./commands', function(err, commands) { if(err) return cb(err); commands.forEach(function (command) { self.vorpal.use(path.join(__dirname, 'commands', command)); }); cb(); }); }, function registeredCommands(cb) { let commands = self.vorpal.localStorage.getItem('mixin-commands'); if(commands instanceof Array) { commands.forEach(function(command) { self.vorpal.use(command); }); } process.nextTick(cb); }], callback); } /* * Show the vorpal prompt */ App.prototype.show = function (cb) { this.vorpal.show(); process.nextTick(cb); } /******************* * Init *******************/ let app = new App(); app.load(function(err) { if(err) { console.log('Cannot load CLI'); console.log(err); return ; } app.show(function started() { }); });