js-dev-tool
v1.2.2
Published
A collection of command-line tools to assist in JavaScript project development.
Maintainers
Readme
js-dev-tool
A collection of command-line tools to assist in JavaScript project development.
This utility, jstool, provides various functions for file manipulation, versioning, and building.
Usage
The primary way to use these tools is through the jstool command, which is an alias for node tools.js.
# General syntax
node tools.js -cmd <command_name> [options]
# Or if installed globally or via package.json scripts
jstool -cmd <command_name> [options]To see the help for a specific command:
node tools.js -help <command_name>Basic Types
Optional: a small bag of legacy-ish utility types.
You probably don’t need this — but if you do, it’s handy.
/// <reference types="js-dev-tool/basic-types"/>Related Libraries
literate-regex
literate-regex was originally developed as part of this project, but it has now been separated into an independent library.
It allows you to write readable, commented regular expressions and provides powerful type-level normalization.
Commands
Here is a list of available commands registered in ToolFunctions:
rws
Records the size of webpack bundles or other files. The name stands for (r)ecord(W)ebpack(S)ize.
- Usage:
jstool -cmd rws -webpack lib/webpack.js -dest "./dev-extras/webpack-size.json"
cjbm
Converts JavaScript files to browser-compatible modules. The name stands for (C)onvert (J)S to (B)rowser (M)odule.
- Usage:
jstool -cmd cjbm -basePath <source_dir> -targets "['file1.js', 'file2.js']"
cmtTrick
Toggles "comment tricks" in the code, useful for conditional code execution during development.
- Usage:
jstool -cmd cmtTrick -basePath <source_dir> -targets "['file1.js', 'file2.js']"
replace
Performs generic string replacement on a set of target files using a regular expression.
- Usage:
jstool -cmd replace [-after <replacement>] -regex "<regex>" [-targets "<path1>,<path2>" | <file1> <file2> ...] - Note: It's often better to pass target files as direct arguments instead of using the
-targetsoption.
version
Bumps the version number in package.json and optionally in other files.
- Usage:
jstool -cmd version [-major | -minor] [-pkgJsons "./package.json,../other/package.json"] [-extras "file.html"] - Note: Bumps the patch version by default. Use
-majoror-minorto bump those instead.
minify
Minifies JavaScript files using Terser.
- Usage:
jstool -cmd minify -basePath <source_dir> [-test "<regex>"] [-suffix ".min"] - Note:
basePathcan be a comma-separated list. The default suffix is.mini.
rmc
Removes C-style comments from files.
- Usage:
jstool -cmd rmc -basePath "./dist/cjs,./dist/other" -test "/\\.(js|d\\.ts)$/" - Note: Use the
-rmc4tsflag for special handling of TypeScript comments (e.g.,/// <reference>).
zip
Creates a zip archive of specified files.
- Usage:
jstool -cmd zip [-comment "the comment"] file1.js file2.js ...
zip help: jstool -cmd zip [-comment "the comment"] lib/webpack.js lib/type-ids.js
rws help: (R)ecord(W)ebpack(S)ize
ex - jstool -cmd rws [-webpack lib/webpack.js -umd umd/webpack.js -dest "./dev-extras/webpack-size.json"] [-rws-tags "web/login:./dist/es/web/login.mjs,webpack-esm:./dist/webpack-esm/index.mjs"]
note:
webpack - if not specified then apply "./dist/webpack/index.js"
umd - if not specified then apply "./dist/umd/index.js"
bin - if not specified then apply "./dist/bin/index.js"
rws-tags - It is treated as parameter array separated by ":", e.g - "web/login:./dist/es/web/login.mjs,webpack-esm:./dist/webpack-esm/index.mjs"
dest - if not specified then apply "./logs/webpack-size.json"
cjbm help: (C)onvert (J)S to (B)rowser (M)odule
ex - jstool -cmd cjbm [-root ./build | -basePath "./dist/esm,extra-tests/mini-semaphore"] [-ext js] [-test /\.js$/] [-targets "['core.js', 'object.js']"]
note:
root - Recursively searches for files.
This option is useful, but if there are directories that need to be avoided, use the 'basePath' option
basePath - can be "<path>,<path>,..." (array type arg)
ext - specifies the module extension for import/export clauses. default is "js"
test - Any file extension can be specified. (The default is /\.js$/)
targets - specify this if you want to apply it only to a specific file.
the file specified here should be directly under `basePath`!
value must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
cmtTrick help: Do comment trick toggle
It recognizes three markers: `ctt | comment-toggle-trick | https://coderwall`
jstool -cmd cmtTrick[:clean] (-base <source dir> | -bases "<source dir>,<source dir>,...") [-test re/\\.js$/]
note:
:clean - remove comment token etc leaving the currently enabled code
base (or root) - scan single source folder
bases - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
test - terget extension, default is /\\.js$/
replace help: jstool -cmd replace [-after <replacement>] -regex "/^\s+<!--[\s\S]+?-->(?:\r?\n)?/gm" [-targets "<path>,<path>,..." | <args: file, file file...>]
note:
targets - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
note: targets - can use args parameter instead
It is better to use the <args: file, file file...>
e.g - jstool -cmd replace -after ".." -regex "re/(?<=reference path=")(\.)(?=\/index.d.ts")/" build/**/*.js
^^^^^^^^^^^^^
version help: jstool -cmd version [-major | -minor] [-pkgJsons "./package.json,../package.json"] [-extras "test/web/index.html"]
bump top level package.json version(can specify "package.json" paths by `pkgJsons` option if need), specify patch version is unnecessary.
note:
extras - can be "<path>,<path>,..." (array type arg)
minify help: jstool -cmd minify -basePath extra-tests/web/mini-semaphore [-test "re/\.js$/"] [-suffix ".mini"]
note:
basePath - can be "<path>,<path>,..." (array type arg)
test - can be omit, default is `/\.js$/`
suffix - can be omit, default is ".mini"
rmc help: $ jstool -cmd rmc [-rmc4ts[:keepBangLine]] -basePath "./dist/cjs,./dist/cjs/gulp" -test "/\.(js|d\.ts)$/"
note: basePath - can be "<path>,<path>,..." (array type arg)
test - can be omit, defulat `/.js$/`
rmc4ts- for typescript source.
keep comment that start with "/*" when "*/" end mark appears in same line.
if start with "/*-" remove it
rmc4ts=keepBangLine (2025/12/24)
- In addition to the "rmc4ts" processing, it also preserves line comments that start with "//!".
📜 License
Released under the MIT License.
See LICENSE for details.
