14 releases

new 0.4.1 May 3, 2021
0.4.0 Jul 29, 2020
0.3.6 May 22, 2020
0.3.1 Apr 22, 2020
0.1.0 Feb 11, 2020

#177 in Command line utilities

Download history 4/week @ 2021-01-26 15/week @ 2021-02-09 91/week @ 2021-02-16 1/week @ 2021-02-23 2/week @ 2021-03-02 6/week @ 2021-03-09 27/week @ 2021-03-23 26/week @ 2021-03-30 13/week @ 2021-04-06 51/week @ 2021-04-13 12/week @ 2021-04-20 18/week @ 2021-04-27

83 downloads per month

MIT license

300KB
8K SLoC

pipeline status version license

darklua

Transform Lua 5.1 scripts using rules.

Installation

darklua is a command line tool that can be installed using cargo.

cargo install darklua

If you want to use the lastest darklua available, install it using the git url:

cargo install --git https://gitlab.com/jeparlefrancais/darklua.git

Usage

The following section will detail the different commands of darklua. You can also get a list of the available commands and options using the command line tool itself, simply run:

darklua help

To get help on a specific command, simply append --help (or -h) to the command name. For example, to get help on the minify command:

darklua minify --help

Process

The process command is similar to the minify command: it takes an input path and generates code at the output path. This command will apply rules (the default rules or the one given in the configuration file) to each Lua file.

darklua process <input-path> <output-path>

optional arguments:
  -c, --config-path <path>
  Path to a configuration file

Example

If you have a src folder that contains a bunch of Lua scripts (files ending with .lua), you can process all the files with the default configuration (or with the configuration file located in the same folder where you are running the command) into a new folder called processed-src using the following command:

darklua process src processed-src

If a configuration file is found in the folder where the command is ran, darklua will automatically use it. If your configuration file is not named .darklua.json or .darklua.json5, or not located in the folder where you are running the command, you can specify it with the --config-path argument:

darklua process src processed-src --config-path ./path/config.json
# or the shorter version:
darklua process src processed-src -c ./path/config.json

Minify

This command reads Lua code and only reformat it in a more compact way. The input path can be a file or directory. Given a directory, darklua will find all Lua files under that directory and output them following the same hierarchy.

darklua minify <input-path> <output-path>

optional arguments:
  -c, --config-path <path>
  Path to a configuration file

Example

If you have a src folder that contains a bunch of Lua scripts (files ending with .lua), you can generate the minified version of these scripts into a new folder called minified-src using the following command:

darklua minify src minified-src

To specify the configuration file location, simply run:

darklua minify src minified-src --config-path ./path/config.json
# or the shorter version:
darklua minify src minified-src -c ./path/config.json

Configuration file

Some commands can be modified using the configuration file. darklua supports both configuration file written in json or json5. When running darklua, if the folder where the command is executed contains a file named .darklua.json or .darklua.json5, it will automatically read the file to get the configuration values.

Any missing field will be replaced with its default value.

{
    // when outputting code, darklua will wrap the code on a new line after
    // this amount of characters.
    column_span: 80,
    // put the rules that you want to execute when calling the process command.
    // If you do not provide this field, the default list of rules is going to
    // be executed.
    process: ["remove_empty_do"],
}

Rule format

Rules can be written in two different format. The shortest one consist of simply providing the rule name. Using this format, the default rule properties will be used.

"remove_empty_do"

If a rule can be configured with properties, the table format can be used to override each properties. The rule name must be specified with a field named rule. Then, simply enumerate the property name associated with its value.

{
    rule: "the_rule_name",
    property: 50
}

For example, the two following snippets will define two configuration files that will execute the same rule, but written in the two different formats.

{
    process: ["remove_empty_do"],
}
{
    process: [{ rule: "remove_empty_do" }],
}

More informations can be found for each rule here.

License

darklua is available under the MIT license. See LICENSE.txt for details.

Dependencies

~3.5MB
~71K SLoC