|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | +import tempfile |
| 8 | + |
| 9 | + |
| 10 | +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) |
| 11 | + |
| 12 | + |
| 13 | +def main(): |
| 14 | + archive = sys.argv[1] |
| 15 | + coffee_source_files = sys.argv[2:] |
| 16 | + |
| 17 | + output_dir = tempfile.mkdtemp() |
| 18 | + compile_coffee(coffee_source_files, output_dir) |
| 19 | + call_asar(archive, output_dir) |
| 20 | + shutil.rmtree(output_dir) |
| 21 | + |
| 22 | + |
| 23 | +def compile_coffee(coffee_source_files, output_dir): |
| 24 | + for source_file in coffee_source_files: |
| 25 | + output_filename = os.path.splitext(source_file)[0] + '.js' |
| 26 | + output_path = os.path.join(output_dir, output_filename) |
| 27 | + call_compile_coffee(source_file, output_path) |
| 28 | + |
| 29 | + |
| 30 | +def call_compile_coffee(source_file, output_filename): |
| 31 | + compile_coffee = os.path.join(SOURCE_ROOT, 'tools', 'compile-coffee.py') |
| 32 | + subprocess.check_call([sys.executable, compile_coffee, source_file, |
| 33 | + output_filename]) |
| 34 | + |
| 35 | + |
| 36 | +def call_asar(archive, output_dir): |
| 37 | + js_dir = os.path.join(output_dir, 'atom') |
| 38 | + asar = os.path.join(SOURCE_ROOT, 'node_modules', 'asar', 'bin', 'asar') |
| 39 | + subprocess.check_call([find_node(), asar, 'pack', js_dir, archive]) |
| 40 | + |
| 41 | + |
| 42 | +def find_node(): |
| 43 | + WINDOWS_NODE_PATHs = [ |
| 44 | + 'C:/Program Files (x86)/nodejs', |
| 45 | + 'C:/Program Files/nodejs', |
| 46 | + ] + os.environ['PATH'].split(os.pathsep) |
| 47 | + |
| 48 | + if sys.platform in ['win32', 'cygwin']: |
| 49 | + for path in WINDOWS_NODE_PATHs: |
| 50 | + full_path = os.path.join(path, 'node.exe') |
| 51 | + if os.path.exists(full_path): |
| 52 | + return full_path |
| 53 | + return 'node' |
| 54 | + |
| 55 | +if __name__ == '__main__': |
| 56 | + sys.exit(main()) |
0 commit comments