mirror of
https://github.com/bdnugget/CodinGame-CLI.git
synced 2026-11-07 08:57:29 +00:00
haskell support (thanks @RaphyJake), cleaner readline for JS, size tool
This commit is contained in:
1 parent
afc39f3b34
commit
c90aab329c
5 files changed
+33
-27
No files matched your search
@@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
testing
|
||||
@@ -9,7 +9,10 @@ const run = require('./runner');
|
||||
const { fatal, failed } = require('./errors');
|
||||
|
||||
const args = parseArgs(process.argv.slice(2), {
|
||||
alias: { t: 'test' }
|
||||
alias: {
|
||||
t: 'test',
|
||||
s: 'size'
|
||||
}
|
||||
});
|
||||
|
||||
const readTests = () => {
|
||||
@@ -49,4 +52,16 @@ const main = tests => {
|
||||
}
|
||||
};
|
||||
|
||||
if (args.size) {
|
||||
const files = Array.isArray(args.size)
|
||||
? args.size
|
||||
: [ args.size ];
|
||||
// eslint-disable-next-line global-require
|
||||
const { statSync } = require('fs');
|
||||
files.forEach(file =>
|
||||
console.log(
|
||||
file + ': ' +
|
||||
statSync(file).size + ' bytes'));
|
||||
}
|
||||
|
||||
readTests().then(main);
|
||||
@@ -1,10 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const { createInterface } = require('readline');
|
||||
|
||||
const rl = createInterface({ input: process.stdin });
|
||||
|
||||
rl.once('line', line => {
|
||||
process.stdout.write(line);
|
||||
process.stdin.pause();
|
||||
});
|
||||
+14
-7
@@ -1,14 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const { join } = require('path');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { readSync } = require('fs');
|
||||
|
||||
const readline = () => {
|
||||
const { stdout } = spawnSync(
|
||||
'node',
|
||||
[ join(__dirname, 'child.js') ],
|
||||
{ stdio: [ 'inherit', 'pipe', 'ignore' ] });
|
||||
return String(stdout);
|
||||
let line = '';
|
||||
let char = '';
|
||||
const buf = Buffer.alloc(1);
|
||||
while (char !== '\r' && char !== '\n') {
|
||||
line += char;
|
||||
try {
|
||||
readSync(process.stdin.fd, buf, 0, 1);
|
||||
} catch (err) {
|
||||
return line;
|
||||
}
|
||||
char = String(buf);
|
||||
}
|
||||
return line;
|
||||
};
|
||||
|
||||
module.exports = readline;
|
||||
+2
-9
@@ -29,15 +29,8 @@ const runners = {
|
||||
: [],
|
||||
'-r', join(__dirname, 'setup.js'), path
|
||||
], input),
|
||||
hs: (path, input) => {
|
||||
const [ cout, cerr, code ] = spawn(
|
||||
'ghc',
|
||||
[ path ]);
|
||||
if (code > 0) {
|
||||
return [ cout, cerr ];
|
||||
}
|
||||
return spawn(basename(path, '.hs'), [], input);
|
||||
}
|
||||
hs: (path, input) =>
|
||||
spawn('runhaskell', [ path ], input)
|
||||
};
|
||||
|
||||
const run = (path, input = null) => {
|
||||
|
||||
Reference in new issue
Block a user