CodinGame Merger (merges files from a folder into one file served by CodinGame
web plugin)
- Make sure before that you have
python3installed (at least version3.5) - Run
pip install cgmerger - (alternative for 2.) You can also install it by downloading the package from
githuband runningpip install <folder where CGMerger is located>
After installation, the script can be run by simply typing cgmerger command from
the project folder that you use for CodinGame.
Because the tool setup is not trivial, I've created a couple of sample projects that should help anyone out with starting with the project. Simply copy the example folder from those languages and you should be able to use the script:
C#sample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-csharppythonsample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-pythontypescriptsample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-typescriptjavascriptsample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-javascriptjavasample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-java
Please - share your successful setup of the script by opening a PR to https://github.com/ajakubo1/CGmerger-examples/
I use the script with PyCharm. I define a new file watcher that is using
cgmerger command. It works perfectly for the python env.
The script works in general as follows:
- It searches all of the files in folder specified by
--workdirargument (by default, that folder iscodingame) - It takes all of the file names from that folder, filtered by
--file-regexargument (by default.*- every file inworkdirfolder). It does not search folders inworkdirfolder. - It copies the contents of all of the found files, excluding lines matched by
--exclude-line-regexinto single--outputfile in directory where the script runs (by default the file is namedcodingame.volatile.py)
The script does not create any folders and files on it's own. It checks if
--output file exists and informs the user if it doesn't (same thing for
--workdir). This is as intended - I do not want to mess with project file
structure, I only touch files that actually exist.
You can write your own config file for a project. In the beginning of the run, the
script will search for cgmerger.conf file and reads the configuration from it.
You can still override the values provided by that script by specifying arguments
in command line.
Instead of writing your own cgmerger.conf, you can simply run the
cgmerger --write command. This will create a cgmerger.conf from currently
loaded (probably default) settings. Next time you run the script, you don't have to
specify any arguments in the command line, settings from that file will be loaded.
For examples of config file, refer to https://github.com/ajakubo1/CGmerger-examples
project (you will find there example settings for a C# and python)
If you want to know more about parameters, you can issue --help command. More
explanations on each of the options:
For re-adjusting the script for different languages, you probably need to re-adjust those settings parameters:
output- the default is a.pyfile, you should change it to something more aligned with the language usedcomment- this is the comment character (or characters) used in the language (e.g.#inpython,//inC#). It is obligatory to set it unless project usespython. This value is used to create nice separators inoutputfile.exclude_line_regex(optional) - this is regex used when script starts to copy file contents line-by-line to exclude some of the unneeded lines. E.g. in.csscripts lines starting with "using" should probably be excluded. This can be done by settingexclude_line_regexto^using.header(optional) - file located relatively toworkdirfolder that will be copied before any other file in theworkdir. It is ignored byfile_regexsetting. The contents of this file are not filetered byexclude_line_regexsetting.footer(optional) - file located relatively toworkdirthat will be copied after any other file in theworkdir(the last file added tooutput). It is ignored byfile_regexsetting.order(optional) - List of files separated by comma, specified in order of which they should be copied to theoutput. Example:one.cs,two.cs,three.cs.outputfiles will be added right after theheaderfile (if it was specified). If any of the listed files are inheaderorfooter- they will not be duplicated and its contents will be ignored (headerfile andfooterfile has higher priority thanorder). After all of the files fromorderare copied, the script will copy the rest of the files according tofile_regex.orderfiles themselves are not checked withfile_regex.file_regex(optional) - this is regex used to define which files fromworkdirshould be copied tooutputfile. By default, the command will copy the contents of all of the files in that folder. You can change it to target different file types (e.g..*.csfiles instead of.*.pyfiles)remove_parts_regex(optional) - this is regex used when script starts to copy file contents line-by-line to replace some of the unneeded strings. E.g. in.tsscripts lines starting with "export" should be reformatted in such a way that we remove that export part. This can be done by settingremove_parts_regexto^export.