Getting Started with the JSDefender CLI
JSDefender CLI is a wrapper around the PreEmptive Protection™ JSDefender™ engine. It allows you to run JSDefender as an executable from the command line.
To use the tool, you need to install the
@preemptive/jsdefender-core packages, as described in the Installation section.
You can run the JSDefender CLI without specifying arguments:
In this case, JSDefender checks for an implicit configuration file,
jsdefender.config.json in the current working directory, and applies the options specified there. If you have no configuration file in the working directory, JSDefender will error.
jsdefender myJsBundle.js myProtectedScript.js
JSDefender still looks for the implicit configuration file in the working directory (
jsdefender.config.json) and applies it, if found; otherwise, it uses the default protection settings.
JSDefender does not allow specifying input both in the configuration file and command line arguments.
If you specify only one argument, it will be treated as the configuration file.
If you specify more than one argument, they should be the input and output files provided at the same time and/or the CLI flags.
You can also run JSDefender with an explicit configuration file that contains specific protection settings:
jsdefender myJsBundle.js myProtectedScript.js -c myConfig.json jsdefender myJsBundle.js myProtectedScript.js --config myConfig.json
--configcommand line options are identical.
If you put all protection settings, including the input file name(s), into the configuration file, you can omit the
--config options and use the configuration name as the single command line argument:
Instead of using a configuration file, you can apply settings from the command line. For example, either of the following commands run JSDefender with string literal extraction and encoding turned on:
jsdefender myJsBundle.js myProtectedScript.js -e jsdefender myJsBundle.js myProtectedScript.js --extstr
--extstrcommand line options are identical.
When using both command line options and the configuration file, the command line options override the settings read from the file. For example, the following command turns on string literal extraction, even if this setting is turned off in the configuration file:
jsdefender myJsBundle.js myProtectedScript.js -c myConfig.json --extstr
The command line provides options that can turn settings off. The next example uses the
--extstroff options (they are identical) to turn off string literal extraction (even if the configuration file turns them on):
jsdefender myJsBundle.js myProtectedScript.js -c myConfig.json -E jsdefender myJsBundle.js myProtectedScript.js -c myConfig.json --extstroff
In this case, JSDefender determines the final set of protection settings as follows:
- The initial set is read from
- The command line arguments (e.g.
-E) options override the configuration settings.