0

How do I compile multiple files using the sweet.js binary?

So that something like this: sjs -o out *.js...

...generates separate compiled files in the out directory:

out/one.js
out/two.js
out/three.js

This is for an npm module that require()'s several internal files.

Edit: I am motivated to do this in a single call to sjs because I am importing a sweetjs module with -m lambda-chop/macros which is slow. Running separate sjs -m lambda-chop/macros commands for every source file makes for an unnecessarily slow build process.

Raine Revere
  • 30,985
  • 5
  • 40
  • 52

1 Answers1

2

You can just use the power of your shell. Something like:

find *.js -type f -print | xargs  -L 1 -I % sjs -o out/% %

Edit:

Or a much better solution when speed is a concern is a proper build tool that can keep things in memory:

timdisney
  • 5,287
  • 9
  • 35
  • 31
  • This appears to simply compile each file in sequence, overwriting a file `out` each time, instead of outputting separate files into a directory `out`. – Raine Revere Aug 16 '15 at 23:13
  • My bad, just edited my answer to be a bit more right :) – timdisney Aug 18 '15 at 22:17
  • Thanks! If you were using external modules (like lambda-chop) and had dozens of source files to compile, wouldn't this be extremely slow? Is this what developers are using for large-scale projects? – Raine Revere Aug 20 '15 at 02:56
  • Maybe an incremental build system like [Broccoli](http://broccolijs.com/) would work well with sweetjs for this reason...? – Raine Revere Aug 20 '15 at 03:25
  • 1
    Ah yes! If you need speed definitely use grunt or broccoli. Looks like there's already a broccoli plugin for sweet: https://github.com/sindresorhus/broccoli-sweetjs – timdisney Aug 21 '15 at 21:24