0.0.9 • Published 2 years ago
nv-cli-log-catch-param v0.0.9
nv-cli-log-catch-param
- cli-tool
- insert a self-defined log in catchClause Body
- this use RegExp + parser, so its slow IF too many files in path-dir, such as node_modules
- for test macro IN nvlang
insert position
this cli tool will insert a fixed-format log-function at the first-line of CatchCaluse block:
catch(e) {
@INSERTED_LOG_FUNC@
}
catch([a0,a1....]) {
@INSERTED_LOG_FUNC@
}
catch({k0,k1....}) {
@INSERTED_LOG_FUNC@
}
log func format
(function ___log_catchclause() {
let ___catchclause_param___ = <CatchClause.param'shape auto calculated when parsing>
let ___nvlog = globalThis.___NVLOG ?? ( // ___NVLOG is your self-defined function of shape:
// (path:string,start:Dict,end:Dict,<CatchClause.param'shape auto calculated when parsing>)=>ANY
content => {
console.dir(content, {depth: null});
}
);
___nvlog(
"/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js", // auto calculated when parsing
{"line": 11,"column": 2}, // auto calculated when parsing
{"line": 15,"column": 1}, //auto calculated when parsing
___catchclause_param___
);
})();
install
- npm install nv-cli-log-catch-param -g
usage
Usage: nv_cli_log_catch_param [options]
Options:
-i, --insert insert mode, default true
-d, --delete delete mode, default false
-p, --path path to search ,default ./
-r, --regex strlit name regexp pattern
-u, --suffixes default js ts json
-h, --help usage
example
insert
for example , a project TEST have 2 files:
nv-cli-log-catch-param# tree TEST/
TEST/
├── c0.js
└── subdir
└── c1.js
1 directory, 2 files
nv-cli-log-catch-param# cat TEST/c0.js
try {} catch (e) {
let a = 111;
}
nv-cli-log-catch-param# cat TEST/subdir/c1.js
try {} catch ([e0, e1]) {
let a = 111;
}
try {} catch ({
k0,
k1
}) {
let a = 111;
}
nv_cli_log_catch_param -p "./TEST" -i
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/c0.js
Position { line: 2, column: 3 } Position { line: 4, column: 3 }
before:
try {} catch (e) {
let a = 111;
}
-----
after:
try {} catch (e) {
(function ___log_catchclause() {
let ___catchclause_param___ = e;
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/c0.js", {
"line": 2,
"column": 3
}, {
"line": 4,
"column": 3
}, ___catchclause_param___);
})();
let a = 111;
}
==================
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js
Position { line: 2, column: 2 } Position { line: 6, column: 1 }
before:
try {} catch ([e0, e1]) {
let a = 111;
}
-----
after:
try {} catch ([e0, e1]) {
(function ___log_catchclause() {
let ___catchclause_param___ = [e0, e1];
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js", {
"line": 2,
"column": 2
}, {
"line": 6,
"column": 1
}, ___catchclause_param___);
})();
let a = 111;
}
==================
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js
Position { line: 11, column: 2 } Position { line: 15, column: 1 }
before:
try {} catch ({
k0,
k1
}) {
let a = 111;
}
-----
after:
try {} catch ({
k0,
k1
}) {
(function ___log_catchclause() {
let ___catchclause_param___ = {
k0,
k1
};
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js", {
"line": 11,
"column": 2
}, {
"line": 15,
"column": 1
}, ___catchclause_param___);
})();
let a = 111;
}
==================
delete
nv_cli_log_catch_param -p "./TEST" -d
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/c0.js
Position { line: 1, column: 7 } Position { line: 21, column: 1 }
before:
try {} catch (e) {
(function ___log_catchclause() {
let ___catchclause_param___ = e;
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/c0.js", {
"line": 2,
"column": 3
}, {
"line": 4,
"column": 3
}, ___catchclause_param___);
})();
let a = 111;
}
-----
after:
try {} catch (e) {
let a = 111;
}
==================
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js
Position { line: 1, column: 7 } Position { line: 21, column: 1 }
before:
try {} catch ([e0, e1]) {
(function ___log_catchclause() {
let ___catchclause_param___ = [e0, e1];
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js", {
"line": 2,
"column": 2
}, {
"line": 6,
"column": 1
}, ___catchclause_param___);
})();
let a = 111;
}
-----
after:
try {} catch ([e0, e1]) {
let a = 111;
}
==================
/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js
Position { line: 23, column: 7 } Position { line: 49, column: 1 }
before:
try {} catch ({
k0,
k1
}) {
(function ___log_catchclause() {
let ___catchclause_param___ = {
k0,
k1
};
let ___nvlog = globalThis.___NVLOG ?? (content => {
console.dir(content, {
depth: null
});
});
___nvlog("/mnt/sdb/NV5/NV5_/nvcli-/pkgs/JSCODING/nv-cli-log-catch-param/TEST/subdir/c1.js", {
"line": 11,
"column": 2
}, {
"line": 15,
"column": 1
}, ___catchclause_param___);
})();
let a = 111;
}
-----
after:
try {} catch ({
k0,
k1
}) {
let a = 111;
}
==================
LICENSE
- ISC
0.0.9
2 years ago