1
0
Quellcode durchsuchen

Better nodejs README and slightly friendlier ntalkc script.

Göran Krampe vor 13 Jahren
Ursprung
Commit
18efc83e71
2 geänderte Dateien mit 66 neuen und 9 gelöschten Zeilen
  1. 31 4
      nodejs/README
  2. 35 5
      nodejs/ntalkc

+ 31 - 4
nodejs/README

@@ -1,8 +1,35 @@
-These are just some scripts and examples of using JTalk together with Node.js.
+JTalk + Node.js = Awesomeness
+=============================
+These are some experiments of using JTalk together with Node.js:
 
-ntalkc          - a bash script for compiling JTalk programs in/for Node.js.
-nodecompile.js  - Node.js code for compiling .st files, used by ntalkc
+ntalkc          - a bash script for compiling JTalk programs for Node.js.
+nodecompile.js  - trivial Node.js javascript code for compiling .st files, used by ntalkc.
 
 hello           - Hello world example with a simple Makefile
+trivialserver   - A slightly larger example.
 
-You will need "node" in your path.
+You will need "node" in your path to try examples.
+
+
+ntalkc
+======
+
+The "compiler" is simply a bash script that uses Nicolas' Exporter/Importer to compile .st files into .js files. The source code should be easy to follow but basically it does the following:
+
+1. Collect all listed (as arguments) .st and .js files. We also check in the JTalk js and st directories if not found.
+
+2. Create a "compiler" by concatenating these files (this means we always use freshest from git):
+        boot.js Kernel.js Parser.js Compiler.js init.js nodejs/nodecompile.js 
+
+3. Run this "compiler" using node and give .st files as command line arguments. This produces corresponding .js files. If not all .js files exist afterwards we abort.
+
+4. Build final program.js by concatenating:
+
+        boot.js
+        Kernel.js
+        ...all .js libraries collected in step 1.
+        ...all .js files produced from the .st files in step 3.
+        init.js (either locally or from JTalk js directory)
+        main.js (if found locally)
+
+5. Run program.js using node if "-r" was specified.

+ 35 - 5
nodejs/ntalkc

@@ -8,18 +8,31 @@ JTALK=`dirname ${0}`/..
 USAGE="Usage: $0 [-r] file1 file2 ... file3 Program
 
    Will compile a JTalk program into a single javascript file called
-   Program.js (last argument) by concatenating listed files using these rules:
+   <Program>.js by concatenating listed files using these rules:
 
      *.js files are concatenated as is. If not found we look in $JTALK/js
 
      *.st files are compiled into .js files. If not found we look in $JTALK/st.
-     Each file is considered to be a fileout of a single class category of
-     the same name as the file.
+     Each file is currently considered to be a fileout of a single class
+     category of the same name as the file.
 
      NOTE: boot.js and Kernel.js is always added first and init.js
      is always added last. Finally main.js is added if found.
 
      If -r is used we also run node with the resulting Program.js.
+
+     Example invocations:
+
+     Compile Hello.st to Hello.js and create
+     complete program called Program.js:
+
+        ntalkc Hello.st Program
+
+     Compile two different class categories into corresponding .js files,
+     link with two existing javascript libraries and create complete
+     program called Program.js:
+
+        ntalkc lib1.js lib2.js CategoryOne.st CategoryTwo.st Program
 "
 
 if [ "$#" == "0" ]; then
@@ -77,6 +90,7 @@ done
 cat $JTALK/js/boot.js $JTALK/js/Kernel.js $JTALK/js/Parser.js $JTALK/js/Compiler.js $JTALK/js/init.js $JTALK/nodejs/nodecompile.js > $TMPDIR/compiler-all.js
 
 # Compile all collected .st files to .js
+echo "Compiling$COMPILED ..."
 node $TMPDIR/compiler-all.js $COMPILE
 
 # Verify all .js files corresponding .st files were created, otherwise exit
@@ -89,20 +103,36 @@ do
   fi 
 done
 
+# We must have these first...
+echo "Adding boot.js and Kernel.js ..."
+BOOT="$JTALK/js/boot.js $JTALK/js/Kernel.js"
+
 # Compose the complete libs.js file from collected .js filenames.
 if [ -n "$LIBS" ]; then
-  echo "LIBS $LIBS"
+  echo "Adding libraries $LIBS ..."
   cat $LIBS > $TMPDIR/libs.js
   LIBS=$TMPDIR/libs.js
 fi
 
+# Check for init.js
+if [ -f "init.js" ]; then
+  echo "Adding init.js ..."
+  INIT="init.js"
+else
+  echo "Adding $JTALK/js/init.js ..."
+  INIT=$JTALK/js/init.js
+fi
+
 # Check for main.js
 if [ -f "main.js" ]; then
+  echo "Adding main.js ..."
   MAIN="main.js"
 fi
 
 # And finally concatenate Program.js
-cat $JTALK/js/boot.js $JTALK/js/Kernel.js $LIBS $COMPILED $JTALK/js/init.js $MAIN > $PROGRAM.js
+echo "Writing $PROGRAM.js ..."
+cat $BOOT $LIBS $COMPILED $INIT $MAIN > $PROGRAM.js
+echo "Done."
 
 # Optionally run Program and give all args left to it
 if [ -n "$RUN" ]; then