|
4 | 4 |
|
5 | 5 | # darklua
|
6 | 6 |
|
7 |
| -Transform Lua 5.1 and Roblox Lua scripts using [rules](RULES.md). |
| 7 | +Transform Lua 5.1 and Roblox Lua scripts using rules. |
8 | 8 |
|
| 9 | +# [Documentation](https://darklua.com/docs) |
9 | 10 |
|
10 |
| -# Installation |
11 |
| -darklua is a command line tool that can be installed using [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html). |
| 11 | +Visit https://darklua.com/docs to learn how to use darklua. |
12 | 12 |
|
13 |
| -``` |
14 |
| -cargo install darklua |
15 |
| -``` |
16 |
| - |
17 |
| -If you want to use the lastest darklua available, install it using the git url: |
18 |
| - |
19 |
| -``` |
20 |
| -cargo install --git https://gitlab.com/seaofvoices/darklua.git |
21 |
| -``` |
22 |
| - |
23 |
| - |
24 |
| -# Usage |
25 |
| -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: |
26 |
| -``` |
27 |
| -darklua help |
28 |
| -``` |
29 |
| -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: |
30 |
| -``` |
31 |
| -darklua minify --help |
32 |
| -``` |
33 |
| - |
34 |
| -## Process |
35 |
| -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](RULES.md) (the default rules or the one given in the configuration file) to each Lua file. |
36 |
| - |
37 |
| -``` |
38 |
| -darklua process <input-path> <output-path> |
39 |
| -
|
40 |
| -optional arguments: |
41 |
| - -c, --config-path <path> |
42 |
| - Path to a configuration file |
43 |
| -``` |
44 |
| - |
45 |
| -### Example |
46 |
| -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: |
47 |
| - |
48 |
| -``` |
49 |
| -darklua process src processed-src |
50 |
| -``` |
51 |
| - |
52 |
| -If a configuration file is found in the folder where the command is run, 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 must specify it with the `--config-path` argument: |
53 |
| - |
54 |
| -``` |
55 |
| -darklua process src processed-src --config-path ./path/config.json |
56 |
| -# or the shorter version: |
57 |
| -darklua process src processed-src -c ./path/config.json |
58 |
| -``` |
59 |
| - |
60 |
| -## Minify |
61 |
| -This command reads Lua code and reformats it to reduce the size of the code, measured in total bytes. The input path can be a single file name or a directory name. Given a directory, darklua will find all Lua files under that directory and output them following the same hierarchy. |
62 |
| - |
63 |
| -``` |
64 |
| -darklua minify <input-path> <output-path> |
65 |
| -
|
66 |
| -optional arguments: |
67 |
| - -c, --config-path <path> |
68 |
| - Path to a configuration file |
69 |
| -``` |
70 |
| - |
71 |
| -### Example |
72 |
| -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 Lua scripts into a new folder called `minified-src` using the following command: |
73 |
| - |
74 |
| -``` |
75 |
| -darklua minify src minified-src |
76 |
| -``` |
77 |
| - |
78 |
| -To specify the configuration file location, simply run: |
79 |
| - |
80 |
| -``` |
81 |
| -darklua minify src minified-src --config-path ./path/config.json |
82 |
| -# or the shorter version: |
83 |
| -darklua minify src minified-src -c ./path/config.json |
84 |
| -``` |
85 |
| - |
86 |
| - |
87 |
| -# Configuration file |
88 |
| -Some commands can be modified using the configuration file. darklua supports both configuration file written in the json or json5 standard file formats. When running darklua, if the directory in which the `darklua` command is executed contains a file named `.darklua.json` or `.darklua.json5`, it will automatically read the file to get the configuration values unless the `--config-path` option is given to override it. |
89 |
| - |
90 |
| -Any missing field will be replaced with its default value. |
91 |
| - |
92 |
| -```json5 |
93 |
| -{ |
94 |
| - // when outputting code, darklua will wrap the code on a new line after |
95 |
| - // this amount of characters. |
96 |
| - column_span: 80, |
97 |
| - // put the rules that you want to execute when calling the process command. |
98 |
| - // If you do not provide this field, the default list of rules is going to |
99 |
| - // be executed. |
100 |
| - process: ["remove_empty_do"], |
101 |
| -} |
102 |
| -``` |
103 |
| - |
104 |
| -## Rule format |
105 |
| -Rules can be written in two different formats: The shortest format consists of simply providing the rule name. Using this format, the default rule properties will be used. |
106 |
| - |
107 |
| -```json |
108 |
| -"remove_empty_do" |
109 |
| -``` |
110 |
| - |
111 |
| -If a rule can be configured with properties (specific values that tweak the behavior of the rule), 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. |
112 |
| - |
113 |
| -```json5 |
114 |
| -{ |
115 |
| - rule: "the_rule_name", |
116 |
| - my_property_name: 50 |
117 |
| -} |
118 |
| -``` |
119 |
| - |
120 |
| -For example, the two following examples define two configuration files that will execute the same rule, but written in the two different formats. |
121 |
| - |
122 |
| -```json5 |
123 |
| -{ |
124 |
| - process: ["remove_empty_do"], |
125 |
| -} |
126 |
| -``` |
127 |
| - |
128 |
| -```json5 |
129 |
| -{ |
130 |
| - process: [{ rule: "remove_empty_do" }], |
131 |
| -} |
132 |
| -``` |
133 |
| - |
134 |
| -Information on the built-in rules and their configuration properties can be found [here](RULES.md). |
| 13 | +# [Try It!](https://darklua.com/try-it) |
135 | 14 |
|
| 15 | +You can try darklua directly into your browser! Check out https://darklua.com/try-it. |
136 | 16 |
|
137 | 17 | # License
|
138 | 18 |
|
|
0 commit comments