Skip to content

Commit

Permalink
Compiler working
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubie committed Mar 21, 2013
1 parent 2cfca9b commit 1f1f9de
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
lib/
node_modules/

lib/
test/
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
all:
DEBUG=maple/* node lib/main.js

build:
coffee -o lib -c src
coffee -o test_lib -c test_src

clean:
rm -rf lib test

.PHONY: test
10 changes: 10 additions & 0 deletions README.md
@@ -0,0 +1,10 @@
maple
-----

- a module exporting a `class` should only export class (can't export class and
a function)
- a test file for each module

# compilation
- `src -> lib`
- `test_src -> test`
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -10,8 +10,8 @@
"findit": "~0.1.2",
"mkdirp": "~0.3.5",
"underscore": "~1.4.4",
"set": "git://github.com/jdubie/set.git",
"async": "~0.2.6",
"should": "~1.2.2"
"should": "~1.2.2",
"module-deps": "~0.5.2"
}
}
17 changes: 8 additions & 9 deletions src/compiler.coffee
Expand Up @@ -8,18 +8,11 @@ debug = require 'debug'
findit = require 'findit'
_ = require 'underscore'

debug = debug('compiler')
debug = debug('maple/compiler')

exports = module.exports = class Compiler extends events.EventEmitter
constructor: (@dir, @include=/.*\.coffee$/, @exclude=/node_modules/) ->

# create `lib` directory
mkdirp.sync(path.join(@dir, 'lib'))

# create `test_lib` directory if `test_src` exists
if path.existsSync(path.join(@dir, 'test_src'))
mkdirp.sync(path.join(@dir, 'test_lib'))

event: (eventname, args...) ->
debug("#{eventname}: #{args.join(' ')}")
@emit(eventname, args)
Expand Down Expand Up @@ -61,9 +54,15 @@ exports = module.exports = class Compiler extends events.EventEmitter
getLibPath: (file) ->
relPath = file.split(@dir)[1]
srcPath = relPath.split(path.sep)[2..].join(path.sep)
dstPath = path.join(@dir, 'lib', srcPath)
dstPath = path.join(@dir, Compiler.getLib(relPath), srcPath)
path.join(path.dirname(dstPath), path.basename(dstPath, '.coffee') + '.js')

@getLib: (file) ->
switch file.split(path.sep)[1]
when 'src' then 'lib'
when 'test_src' then 'test'
else throw new Error("invalid folder: #{file}")

findSourceFiles: (callback) ->
files = []
finder = findit.find(@dir)
Expand Down
2 changes: 1 addition & 1 deletion src/main.coffee
Expand Up @@ -7,7 +7,7 @@ debug = require 'debug'
Tester = require './tester'
Compiler = require './compiler'

debug = debug('main')
debug = debug('maple/main')

dir = process.argv[2] ? process.cwd()

Expand Down
21 changes: 14 additions & 7 deletions src/tester.coffee
Expand Up @@ -3,9 +3,10 @@ path = require 'path'
debug = require 'debug'
findit = require 'findit'
async = require 'async'
mdeps = require 'module-deps'
Mocha = require 'mocha'

debug = debug('tester')
debug = debug('maple/tester')

exports = module.exports = class Tester extends events.EventEmitter
constructor: (@dir, @include=/.*\/lib\/.*\.js$/, @exclude=/node_modules/) ->
Expand Down Expand Up @@ -39,8 +40,15 @@ exports = module.exports = class Tester extends events.EventEmitter
], callback

updateDependants: (files) ->
(callback) ->
debug 'updateDependants', files
(callback) =>
async.map(files, @fileDependants, callback)

fileDependants: (file, callback) ->
debug 'updateDependants', file
deps = mdeps(file)
deps.on 'data', (data) ->
debug 'data', data.id, data.deps
deps.on('close', callback)

testDepedencies: (files) ->
(callback) ->
Expand Down Expand Up @@ -77,15 +85,14 @@ exports = module.exports = class Tester extends events.EventEmitter

testFile: (file, callback) =>
debug "testing #{@testName(file)}"
return callback()

mocha = new Mocha
mocha = new Mocha(reporter: 'base')

mocha.addFile(file)
runner = mocha.run()
runner.on 'pass', (test) ->
runner.on 'pass', (test) =>
@event 'pass', test
runner.on 'fail', (test, err) ->
runner.on 'fail', (test, err) =>
@event 'fail', test, err
runner.on('end', callback)

Expand Down
12 changes: 12 additions & 0 deletions test_src/compiler.coffee
@@ -1,3 +1,15 @@
Compiler = require('../lib/compiler')

describe 'Compiler', ->
describe '#testName', ->
it 'should work', ->
describe '#getLibPath', ->
#Compiler('..')
#it 'should work for `src` file`', ->
# p = compiler.getLibPath('/home/user/maple/src/file.coffee')
# p.should.eql '/home/user/maple/lib/file.js'
#it 'should work for `test_src` file`', ->
# p = compiler.getLibPath('/home/user/maple/test_src/file.coffee')
# p.should.eql '/home/user/maple/test_lib/file.js'
#describe '@getLib', ->
# Compiler.getLib(
2 changes: 2 additions & 0 deletions test_src/main.coffee
@@ -0,0 +1,2 @@
describe 'main', ->
it 'should work', ->
3 changes: 3 additions & 0 deletions test_src/tester.coffee
@@ -0,0 +1,3 @@
describe 'Tester', ->
describe '#testName', ->
it 'should work', ->

0 comments on commit 1f1f9de

Please sign in to comment.