CodinGame Merger (merges files from a folder into one file served by CodinGame
web plugin)
- Make sure before that you have
python3
installed (at least version3.5
) - Run
pip install cgmerger
- (alternative for 2.) You can also install it by downloading the package from
github
and 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-csharppython
sample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-pythontypescript
sample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-typescriptjavascript
sample project: https://github.com/ajakubo1/CGmerger-examples/tree/main/default-javascriptjava
sample 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
--workdir
argument (by default, that folder iscodingame
) - It takes all of the file names from that folder, filtered by
--file-regex
argument (by default.*
- every file inworkdir
folder). It does not search folders inworkdir
folder. - It copies the contents of all of the found files, excluding lines matched by
--exclude-line-regex
into single--output
file 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.py
file, 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 inoutput
file.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.cs
scripts lines starting with "using" should probably be excluded. This can be done by settingexclude_line_regex
to^using
.header
(optional) - file located relatively toworkdir
folder that will be copied before any other file in theworkdir
. It is ignored byfile_regex
setting. The contents of this file are not filetered byexclude_line_regex
setting.footer
(optional) - file located relatively toworkdir
that will be copied after any other file in theworkdir
(the last file added tooutput
). It is ignored byfile_regex
setting.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
.output
files will be added right after theheader
file (if it was specified). If any of the listed files are inheader
orfooter
- they will not be duplicated and its contents will be ignored (header
file andfooter
file has higher priority thanorder
). After all of the files fromorder
are copied, the script will copy the rest of the files according tofile_regex
.order
files themselves are not checked withfile_regex
.file_regex
(optional) - this is regex used to define which files fromworkdir
should be copied tooutput
file. 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..*.cs
files instead of.*.py
files)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.ts
scripts lines starting with "export" should be reformatted in such a way that we remove that export part. This can be done by settingremove_parts_regex
to^export
.