Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

very rough approach to an @import feature

  • Loading branch information...
commit 7504b6a4aca62ba4b3ab1ccda71969d4dce849a7 1 parent 8fe1493
@mikesmullin mikesmullin authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/buildr.coffee
View
16 lib/buildr.coffee
@@ -12,7 +12,7 @@ jsp = uglify.parser
pro = uglify.uglify
cwd = process.cwd()
watchTree = false
-
+alreadyImported = {}
# =====================================
@@ -1092,6 +1092,20 @@ class Buildr
try
switch extension
when '.coffee'
+ rx = /@import\s+['"](.+?)['"]/g
+ while m = rx.exec(src)
+ # Read @import file
+ data = ''
+ if !alreadyImported[m[1]]
+ fs.readFile m[1], (err,data) =>
+ return next err if err
+
+ src.replace(new Regex(m[0]), data) // replace first occurance with actual file contents
+
+ // TODO: how block this until after file read has completed?
+ src.replace(new Regex(m[0], 'g', '') // remove subsequent occurances
+ alreadyImported[m[1]] = true; // remember not to import again
+
result = coffee.compile src
when '.js'
result = src
Please sign in to comment.
Something went wrong with that request. Please try again.