2 # Simple bundler of files into string constants.
4 # Usage: bundle_resources.py foo.inc a.js path/b.css ...
5 # Produces foo.inc containing:
6 # const char a_js[] = "...";
7 # const char b_css[] = "...";
12 infiles
= sys
.argv
[2:]
14 with
open(outfile
, 'w') as out
:
15 for filename
in infiles
:
16 varname
= os
.path
.basename(filename
).replace('.', '_')
17 out
.write("const char " + varname
+ "[] = \n");
18 # MSVC limits each chunk of string to 2k.
19 # Not quite enough for the JS file, so split by lines.
20 # The overall limit is 64k, which ought to be enough for anyone.
21 for line
in open(filename
).read().split('\n'):
22 out
.write(' R"x(' + line
+ ')x" "\\n"\n' )