diff --git a/index.js b/index.js new file mode 100644 index 0000000..2b0f4c5 --- /dev/null +++ b/index.js @@ -0,0 +1,22 @@ +const CMDjs = require('@codefeathers/cmd-js/index'); +const installer = require('./lib/installer'); +const { help, login, logout, commit } = require('./lib/commands.js'); + +const mark = input => { + const args = input.args; + if (args && args.length === 0) { + help(); + } + + const cmd = new CMDjs( + args, + ) + + cmd + .use( ['-h', '--help'], help ) + .use( 'login', login ) + .use( 'logout', logout ) + +} + +module.exports = mark; \ No newline at end of file diff --git a/lib/installer.js b/lib/installer.js new file mode 100644 index 0000000..4a11d09 --- /dev/null +++ b/lib/installer.js @@ -0,0 +1,35 @@ +// Native +const fs = require('fs'); +const { promisify } = require('util'); + +const open = promisify(fs.open); +const write = promisify(fs.writeFile); + +// Modules +const readline = require('readline-promise').default; + +// Constants +const CONSTANTS = require('../constants'); + +const read = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +const createFiles = () => { + return read.questionAsync('Username for your log: ') + .then(answer => { + const markrc = { + username: answer + }; + + return write(CONSTANTS.MARK_RC, JSON.stringify(markrc)); + }) +}; + +const installer = () => { + return open(CONSTANTS.MARK_RC, 'r+') + .catch(createFiles) +}; + +module.exports = installer; \ No newline at end of file