Rewrite compile-coffee script in python.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 24 Jun 2013 08:24:19 +0000 (16:24 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 24 Jun 2013 08:24:19 +0000 (16:24 +0800)
atom.gyp
script/compile-coffee [deleted file]
script/compile-coffee.py [new file with mode: 0755]
script/lib/util.py

index 6205810..9430bb7 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
           'rule_name': 'coffee',
           'extension': 'coffee',
           'inputs': [
-            'script/compile-coffee',
+            'script/compile-coffee.py',
           ],
           'outputs': [
             '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
           ],
           'action': [
-            'sh',
-            'script/compile-coffee',
+            'python',
+            'script/compile-coffee.py',
             '<(RULE_INPUT_PATH)',
             '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
           ],
diff --git a/script/compile-coffee b/script/compile-coffee
deleted file mode 100755 (executable)
index 2c15358..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-set -e
-
-# Because of the way xcodebuild invokes external scripts we need to load
-# The Setup's environment ourselves. If this isn't done, things like the
-# node shim won't be able to find the stuff they need.
-
-node --version > /dev/null 2>&1 || {
-  if [ -e /opt/github/env.sh ]; then
-    source /opt/github/env.sh
-  else
-    # Try Constructicon's PATH.
-    export PATH="/usr/local/Cellar/node/0.8.21/bin:${PATH}"
-  fi
-}
-
-INPUT_FILE="${1}"
-OUTPUT_DIR=`dirname "$2"`
-
-node_modules/.bin/coffee -c -o "$OUTPUT_DIR" "$INPUT_FILE"
diff --git a/script/compile-coffee.py b/script/compile-coffee.py
new file mode 100755 (executable)
index 0000000..35642c9
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import os
+import subprocess
+import sys
+
+from lib.util import *
+
+
+SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
+
+
+def main():
+  input_file = sys.argv[1]
+  output_dir = os.path.dirname(sys.argv[2])
+
+  node = get_node_path()
+  coffee = os.path.join(SOURCE_ROOT, 'node_modules', '.bin', 'coffee')
+  subprocess.check_call([node, coffee, '-c', '-o', output_dir, input_file])
+
+
+if __name__ == '__main__':
+  sys.exit(main())
index ab33187..7060f1a 100644 (file)
@@ -68,3 +68,10 @@ def safe_mkdir(path):
   except OSError as e:
     if e.errno != errno.EEXIST:
       raise
+
+
+def get_node_path():
+  node = os.path.join(os.path.dirname(__file__), '..', '..', 'node', 'node')
+  if sys.platform == 'win32' or sys.platform == 'cygwin':
+    node += '.exe'
+  return node