let gulp = require('gulp')
let path = require('path')
let tap = require('gulp-tap')
let fs = require('fs')
let jsx2wxml = require('./jsx2wxml')


function buildComponent(code) {
  return `
class WeElement {
  render () {
    return ${code}
  }
}
`
}


const baseOptions = {
  isRoot: false,
  isApp: false,
  sourcePath: __dirname,
  outputPath: __dirname,
  code: '',
  isTyped: false
}


gulp.task('watch', () => {
  gulp.watch('src-mp/**/*', () => {
    gulp.start('copyThen')
  })
})

//加 cache？同样的字符串返回同样的结果
gulp.task('cp', () => {
  return gulp
    .src('../**/*.jsx')
    .pipe(
      tap(file => {

        let dir = path.dirname(file.path)

        let template = jsx2wxml.default({
          ...baseOptions,
          code: buildComponent(file.contents.toString())
        }).template

        file.contents = new Buffer(template)
        console.log(file.contents.toString())
      })
    )
    .pipe(gulp.dest('build'))
})

gulp.task('default', ['cp'])

gulp.start('default')

@@ -642,16 +642,91 @@
 e.path)%0A
+        let arr = dir.split(/%5C%5C%7C%5C//)%0A        let name = arr%5Barr.length - 1%5D
 %0A       
@@ -929,16 +929,88 @@
 ole.log(
+'%E7%BC%96%E8%AF%91' + file.path)%0A%0A        fs.writeFileSync(dir + '/' + name + '.wxml', 
 file.con
@@ -1046,37 +1046,8 @@
   )%0A
-    .pipe(gulp.dest('build'))
 %0A%7D)%0A

update gulp task