-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
54 lines (46 loc) · 1.09 KB
/
util.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const process = require("process");
const child_process = require("child_process");
const CYAN_FMT = "\x1b[36m%s\x1b[0m";
function hex(n, pad)
{
pad = pad || 0;
let s = n.toString(16).toUpperCase();
while(s.length < pad) s = "0" + s;
return s;
}
function mkdirpSync(dir)
{
fs.mkdirSync(dir, { recursive: true });
}
function get_switch_value(arg_switch)
{
const argv = process.argv;
const switch_i = argv.indexOf(arg_switch);
const val_i = switch_i + 1;
if(switch_i > -1 && val_i < argv.length)
{
return argv[switch_i + 1];
}
return null;
}
function get_switch_exist(arg_switch)
{
return process.argv.includes(arg_switch);
}
function finalize_table_rust(out_dir, name, contents)
{
const file_path = path.join(out_dir, name);
fs.writeFileSync(file_path, contents);
console.log(CYAN_FMT, `[+] Wrote table ${name}.`);
}
module.exports = {
hex,
mkdirpSync,
get_switch_value,
get_switch_exist,
finalize_table_rust,
};