-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.js
More file actions
executable file
·40 lines (34 loc) · 1.14 KB
/
cmd.js
File metadata and controls
executable file
·40 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
/**
* unassert-cli
* CLI for unassert:
* Provides `unassert` command which compiles assertions away from target file.
*
* https://github.com/unassert-js/unassert-cli
*
* Copyright (c) 2016-2022 Takuto Wada
* Licensed under the MIT license.
* https://github.com/unassert-js/unassert-cli/blob/master/LICENSE
*/
'use strict';
const { createReadStream } = require('fs');
const concat = require('concat-stream');
const { parse } = require('acorn');
const { generate } = require('escodegen');
const { unassertAst, defaultOptions } = require('unassert');
// add `power-assert` to target modules to avoid breaking change
function generateUnassertOptions () {
const opts = defaultOptions();
opts.modules.push('power-assert');
return opts;
}
function transform (code) {
const ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
return generate(unassertAst(ast, generateUnassertOptions()));
}
const args = process.argv.slice(2);
const file = args[0];
const input = (file && file !== '-') ? createReadStream(file) : process.stdin;
input.pipe(concat((buf) => {
console.log(transform(buf.toString('utf8')));
}));