Nostalgic Pickled Mango

npm

Need private packages and team management tools?Check out npm Orgs. »

js-row-num-cli

1.6.9 • Public • Published

js-row-num-cli

js-row-num-cli

Update all row numbers in all console.logs in JS code

Minimum Node version required Repository is on GitLab View dependencies as 2D chart Downloads/Month Code style: prettier MIT License

Other siblings of this package:

Table of Contents

Install

npm i -g js-row-num-cli

Then, call it from the command line using one of the following keywords:

jrn
jsrownum

Use it

Once installed, call it typing jsrownum or jrn in your terminal, like this:

jsrownum
# or 
jrn

or specify a glob pointing to some js files:

jsrownum "folder/*.js"
# or 
jrn "folder/*.js"

If jsrownum is too long, you can also type jrn; we wired up that as an alternative.

⬆ back to top

TLDR

It updates each console.log in your .js files...

from:

// something on row 1
// something on row 2
console.log('000 var = ' + var); // row 3
//           ^^^

to:

// ...
console.log('003 var = ' + var);
//           ^^^

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"

⚡️⚡️⚡️⚡️🔥🔥🔥🍻🍻🍻🍻🤩🤩💪🏼💪🏼💪🏼💪🏼💪🏼👊🏼👊🏼👊🏼👊🏼💥💥💥💥⚡️⚡️🌟🌟🌟🌟⚡️🍺🍺💪🏼💪🏼

⬆ back to top

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:
  1. ./src/main.js
  2. ./main.js
  3. ./cli.js
  4. ./index.js
  5. ./src/index.js

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 045 with 055.

🌟⚡️🍺🍺💪🏼💪🏼🍺

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.

⬆ back to top

API

Once installed globally, type in your terminal: jsrownum OR type jrn.

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:

  1. ./src/main.js
  2. ./main.js
  3. ./cli.js
  4. ./index.js
  5. ./src/index.js

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
-p or --pad jsrownum -p 3 or jrn --pad="4" Lets you set the row number padding. For example, console.log statement on row 3 with padding set to 4 would get 0003 added. Row 99 with padding of 1 would be still 99.
-t or --trigger jrn -t "log" Lets you change from "console.log" to any function's name, for example update "001" in log(\001 z = ${z}`);`

⬆ back to top

Using multiple flags

Command line applications have few rules. First, if you want to pass multiple values to a certain flag, put -* or --***** for each value:

GOOD:

jrn -f "log" -f "yo"

BAD:

jrn -f "log" "yo"

⬆ back to top

Escaping

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.

Updating it

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!

⬆ back to top

Contributing

  • 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", the "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 console.logs.

⬆ back to top

Licence

MIT License

Copyright (c) 2015-2019 Roy Revelt and other contributors

install

npm i js-row-num-cli

Downloadsweekly downloads

20

version

1.6.9

license

MIT

homepage

gitlab.com

repository

Gitgitlab

last publish

collaborators

  • avatar
Report a vulnerability