| 1 | #!/usr/bin/env python3 |
| 2 | # Simple bundler of files into string constants. |
| 3 | # |
| 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[] = "..."; |
| 8 | import os |
| 9 | import sys |
| 10 | |
| 11 | outfile = sys.argv[1] |
| 12 | infiles = sys.argv[2:] |
| 13 | |
| 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' ) |
| 23 | out.write(' ;\n'); |