 
 onErrorContinue = (err) -> console.log(err.stack); @emit 'end'
 task 'mocha', ->  src(files_mocha).pipe(mocha({reporter: 'dot'})).on("error", onErrorContinue)
-
-# removes content for karma, if need, please see the content in project peasy, and rewrite for taijiview.
-#files_karma_debug = 'twoside peasy linepeasy logicpeasy index '+\
-#  merge('samples/ statemachine dsl arithmatic arithmatic2')+' '+\
-#  merge('test/karma/ peasy logicpeasy samples-arithmatic samples-arithmatic samples-arithmatic')
-#files_karma_debug = for item in files_karma_debug.split(' ') then folders_dest+item+'.js'
-#files_karma_dist = 'twoside client/full-peasy-package samples/sample-concat test/karma/karma-concat'
-#files_karma_dist = for item in files_karma_dist.split(' ') then folders_dest+item+'.js'
-#karmaOnce = karma({configFile: folders_dest+'test/karma-conf.js', action: 'run'})
-#task 'karma1', -> src(files_karma_debug).pipe(karmaOnce)
-#task 'karma1/dist', -> src(files_karma_dist).pipe(karmaOnce)
-#karmaWatch = karma({configFile: folders_dest+'test/karma-conf.js', action: 'watch'})
-##console.log files_karma_dist.join(' ')
-#task 'karma', -> src(files_karma_debug).pipe(karmaWatch)
-#task 'karma/dist', -> src(files_karma_dist).pipe(karmaWatch)
 
 task 'runapp', shell.task ['node dist/examples/sockio/app.js']
 task 'express',  ->


merge = (files) -> files = files.split(' '); path = files[0]; (for file in files.splice(1) then path+file).join(' ')

client = folders_destClient

# remove twoside temporalily. add them when distributing.
#destLib = folders_dest+'lib/'
#destLibClient = destLib+'client/'
#files_taijiview = merge('nodes/ nodes index')+' '+'parser lex taijiview'
#files_taijiview = for item in files_taijiview.split(' ') then destLib+item+'.js'
#task 'transform:taijiview', (cb) ->
#  if not distributing then return src(files_taijiview).pipelog(twoside(destLib, 'taijiview')).to(destLib)
#  src(files_taijiview)
#  .pipelog(twoside(folders_dest, 'taijiview', {only_wrap_for_browser:true})).to(destLibClient)
#  .pipe(concat("taijiview-package.js")).pipe(size()).to(destLibClient)
#  #minify
#  .pipe(closureCompiler()).pipe(rename(suffix: "-min")).pipe(size()).to(destLibClient)

task 'make:samples', (cb) -> # twoside, concat
  # twoside and concat for samples
  files = 'some .js examples filename for taijiview'
  files = for name in files.split(' ') then folders_dest+'examples/'+name+'.js'
#  console.log files.join(' ')
  stream = src(files).pipelog(twoside(folders_dest+'examples', 'taijiview/examples')) #, {only_wrap_for_browser:true}
  if not distributing then return stream.to(folders_dest+'examples')
  stream.pipe(concat('examples-concat.js')).pipe(size()) # when debuggin, dont concat
  stream.to(folders_dest+'examples')

task 'make:test', (cb) -> # twoside, concat, minify
  # twoside and concat for test/karma
  stream = src(folders_dest+'test/karma/**/*.js')
  .pipelog(twoside(folders_dest+'test/karma', 'peasy/karma', {only_wrap_for_browser:true}))
  if not distributing then return  stream.to(folders_dest+'test/karma')
  stream.pipe(concat('karma-concat.js')) # when debugging, dont concat
  .to(folders_dest+'test/karma')

build = (callback) ->
  runSequence('clean', ['copy', 'coffee'], ['transform:taijiview', 'make:samples', 'make:test'], callback)
# make is for debugging and test, dont concat and minify
task 'make', (callback) -> distributing = false; build(callback)
# dist is for release, so concat and minify packages

task 'watch/all', -> ['watch/copy', 'watch/coffee', 'watch/mocha'] #  , 'watch/reload'

task 'mocha/auto', ['watch/copy', 'watch/coffee', 'watch/mocha']
task 'test', (callback) -> runSequence('make', ['mocha'], callback)
task 'test/dist', (callback) -> runSequence('dist', ['mocha'], callback)
task 'default',['test']

