UNPKG

1.21 kBJavaScriptView Raw
1'use strict';
2
3const Cnyks = require('./index');
4const parseargs = require('nyks/process/parseArgs');
5const read = require('read');
6
7
8const COLS = 96;
9
10// args can shift pre-imposed design, like ['--ir://start=hi', '--ir://run=']
11module.exports = function(module, module_name, args = []) {
12 const cmdline = [...args, ...process.argv.slice(2)];
13 const cmdline_parsed = parseargs(cmdline);
14
15 cmdline_parsed.dict['ir://name'] = module_name || module.name || "app";
16 cmdline_parsed.dict['ir://stderr'] = process.stderr.write.bind(process.stderr);
17 cmdline_parsed.dict['ir://stdout'] = process.stdout.write.bind(process.stdout);
18 cmdline_parsed.dict['ir://prompt'] = read;
19
20 cmdline_parsed.dict['ir://cols'] = Math.min(process.stdout.columns - 2, COLS);
21
22 let cnyks = Cnyks.start(module, cmdline_parsed.dict, cmdline_parsed.args, function(err) {
23 if(err) {
24 setTimeout(() => {
25 console.error(err, err && err.stack || '');
26 throw "Failure in cnyks";
27 });
28 }
29 if(process.stdin.unref)
30 process.stdin.unref();
31 process.emit('cnyksEnd');
32 });
33
34 process.stdout.on("resize", () => {
35 cnyks.cols = Math.min(process.stdout.columns - 2, COLS);
36 });
37};