3 ms·
I was hoping for an article on how to use Node.js for normal scripting, since it's already pretty close to what it's shown in this library. I've written two lib
by franciscop 5y ago
I was hoping for an article on how to use Node.js for normal scripting, since it's already pretty close to what it's shown in this library. I've written two libraries to help with scripting in Node.js:
`files`: https://github.com/franciscop/files/ https://github.com/franciscop/files/
import { read, walk } from 'files';
// Find all of the readmes
const readmes = await walk('demo')
.filter(/\/readme\.md$/) // Works as expected!
.map(read);
console.log(readmes);
// ['# files', '# sub-dir', ...]
`atocha`: simplest cli runner (no escaping though!) https://github.com/franciscop/atocha/ https://github.com/franciscop/atocha/
import cmd from 'atocha';
// Any basic command will work
console.log(await cmd('ls'));
// Using a better Promise interface, see the lib `swear`
console.log(await cmd('ls').split('\n'));
// Can pipe commands as normal
console.log(await cmd('sort record.txt | uniq'));
Both of them are wrapped with Swear, a "promise extension" (totally compatible with native promises!) so that's why the first example works. You can build operations on top of the return of the promise, so that these two are equivalent:
// Without `swear`:
const list = await walk('demo');
const readmes = list.filter(item => /\/readme\.md$/.test(file));
const content = await Promise.all(readmes.map(read);
// With `swear`:
constn content = await walk('demo').filter(/\/readme\.md$/).map(read);
- hackerbrother 5y agoDeno is great for this also! (https://deno.land/ https://deno.land/) This short wrapper is great for doing asynchronous SSH commands. https://github.com/gpasq/deno-exec https://github.com/gpasq/deno-exec