Browse Source

Write js codes in coffee script.

Cheng Zhao 12 years ago
parent
commit
ee420b1590
7 changed files with 75 additions and 15 deletions
  1. 1 0
      .gitignore
  2. 29 6
      atom.gyp
  3. 7 0
      browser/atom/atom.coffee
  4. 0 9
      browser/atom/atom.js
  5. 14 0
      package.json
  6. 3 0
      script/bootstrap
  7. 21 0
      script/compile-coffee

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 .DS_Store
 build/
+node_modules/
 *.xcodeproj
 *.swp

+ 29 - 6
atom.gyp

@@ -5,6 +5,9 @@
     'app_sources': [
       'app/atom_main.cc',
     ],
+    'coffee_sources': [
+      'browser/atom/atom.coffee',
+    ],
     'lib_sources': [
       'app/atom_main_delegate.cc',
       'app/atom_main_delegate.h',
@@ -48,6 +51,7 @@
       'target_name': '<(project_name)',
       'type': 'executable',
       'dependencies': [
+        'generated_sources',
         '<(project_name)_lib',
       ],
       'sources': [
@@ -79,12 +83,6 @@
                 '<(PRODUCT_DIR)/<(product_name).framework',
               ],
             },
-            {
-              'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources',
-              'files': [
-                'browser/atom',
-              ],
-            },
           ],
           'postbuilds': [
             {
@@ -122,6 +120,31 @@
         'vendor',
       ],
     },
+    {
+      'target_name': 'generated_sources',
+      'type': 'none',
+      'sources': [
+        '<@(coffee_sources)',
+      ],
+      'rules': [
+        {
+          'rule_name': 'coffee',
+          'extension': 'coffee',
+          'inputs': [
+            'script/compile-coffee',
+          ],
+          'outputs': [
+            '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
+          ],
+          'action': [
+            'sh',
+            'script/compile-coffee',
+            '<(RULE_INPUT_PATH)',
+            '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
+          ],
+        },
+      ],
+    },
   ],
   'conditions': [
     ['OS=="mac"', {

+ 7 - 0
browser/atom/atom.coffee

@@ -0,0 +1,7 @@
+# Don't quit on fatal error.
+process.on "uncaughtException", (error) ->
+  console.error "uncaughtException:"
+  if error.stack?
+    console.error error.stack
+  else
+    console.error error.name + ": " + error.message

+ 0 - 9
browser/atom/atom.js

@@ -1,9 +0,0 @@
-process.on('uncaughtException', function(error) {
-  console.error('uncaughtException:');
-  if (error.stack)
-    console.error(error.stack);
-  else
-    console.error(error.name + ': ' + error.message);
-});
-
-console.log(process.atom_binding('window'));

+ 14 - 0
package.json

@@ -0,0 +1,14 @@
+{
+  "name"    : "atom",
+  "version" : "0.1.0",
+
+  "dependencies": {
+    "coffee-script": "1.6.2"
+  },
+
+  "private": true,
+
+  "scripts": {
+    "preinstall": "true"
+  }
+}

+ 3 - 0
script/bootstrap

@@ -23,6 +23,9 @@ BRIGHTRAY_DIR="${VENDOR_DIR}/brightray"
 git submodule sync --quiet
 git submodule update --init --recursive
 
+npm install npm --silent
+./node_modules/.bin/npm install --silent
+
 "${BRIGHTRAY_DIR}/script/bootstrap" "${BASE_URL}"
 
 "${SOURCE_ROOT}/script/update"

+ 21 - 0
script/compile-coffee

@@ -0,0 +1,21 @@
+#!/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"