Update all row numbers in all console.logs in JS code
Other siblings of this package:
Table of Contents
- Use it
- What it does
- Using multiple flags
- A nifty setup idea
- Updating it
npm i -g js-row-num-cli
Then, call it from the command line using one of the following keywords:
Once installed, call it typing
jrn in your terminal, like this:
or specify a glob pointing to some
jsrownum "folder/*.js"# orjrn "folder/*.js"
jsrownum is too long, you can also type
jrn; we wired up that as an alternative.
It updates each
console.log in your
// something on row 1// something on row 2console; // row 3// ^^^
// ...console;// ^^^
Because it's on row 3. If you're not using
console.log, and are using for example
log(), put that under "-t" flag:
jrn -t "log"
or if specifying paths,
jrn "folder/*.js" -t "log"
What it does
First, it depends, did you specify a path or not.
- If you did, for example,
jsrownum "folder/*.js"it will process that file (or expand glob into a list of files).
- If you didn't, just typed
jsrownum, it will use the current folder where it was called from and look for files in this order:
Once it picks the file, it will look for
console.log statements, and replace the first chunk of an uninterrupted sequence of numbers with a number of a row it sits.
For exampe, on row number 55 there's a
console.log("045 var = " + var).
It will replace
The default padding is three characters, but you can override it, see the optional flags table below.
console.logs help to troubleshoot the code. These days Rollup builds are standard — having a source in ES Modules (and pointing unit tests to it) and using that source to build three types of applications: 1. ESM (same as source); 2. UMD (minified, for browsers and unpkg.com); 3. Common JS — transpiled to ES5, suitable for older platforms.
Now, you can use Rollup to remove comments and
console.logs automatically when producing production builds. During development builds, you can use CLI flags to skip
console.log removal. This way, you get all the goodness of
console.logs in the terminal, and there's no risk that they will spill into production.
Once installed globally, type in your terminal:
jsrownum OR type
If you won't pass any glob file/folder pattern or patterns, for example, just type
jrn, it will look for the following files in this priority order:
If you will pass some globs, for example:
jrn "src/*.js"jsrownum --pad="4" "dist/**/*.js test/ index.js"jrn "test1.js test2.js" -p 2
...it will expand the globs and catch all
.js files in the folders you specified and process them.
Optionally, you can pass the options, which match the API:
|CLI flag||For example,||What it does|
||Lets you set the row number padding. For example,
||Lets you change from "console.log" to any function's name, for example update "001" in
Using multiple flags
Command line applications have few rules. First, if you want to pass multiple values to a certain flag, put
--***** for each value:
jrn -f "log" -f "yo"
jrn -f "log" "yo"
If you want to put double quotes, escape it like using left slash:
jrn -f "zzz\"yyy"
A nifty setup idea
I set up an alias for
jsrownum, to piggyback on some common command I run often. For example,
git add . - this way all row numbers are processed automatically without any hassle.
When you install it globally, it will check occasionally, are there newer versions available, and if so, will show a message nagging you to update. Same tech that AVA or npm uses!
- If you see an error, raise an issue.
- If you want a new feature but can't code it up yourself, also raise an issue. Let's discuss it.
- If you tried to use this package, but something didn't work out, also raise an issue. We'll try to help.
- If you want to contribute some code, fork the monorepo via GitLab, then write code, then file a pull request on GitLab. We'll merge it in and release.
In monorepo, npm libraries are located in
packages/ folder. Inside, the source code is located either in
src/ folder (normal npm library) or in the root,
cli.js (if it's a command-line application).
The npm script "
"dev": "rollup -c --dev --silent" builds the development version retaining all
console.logs with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all
Copyright (c) 2015-2019 Roy Revelt and other contributors