file-transformer.js 753 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
const transformJson = require('./json-transformer')
const transformWxml = require('./wxml-transformer')
const transformWxss = require('./wxss-transformer')
const transformJs = require('./js-transformer')

module.exports = function transformFile(input, out, options) {
  const filepath = input.replace('.wxml', '')

  const [usingComponentsCode] = transformJson(filepath + '.json')

  const [templateCode, wxsCode = ''] = transformWxml(filepath + '.wxml')

  const styleCode = transformWxss(filepath + '.wxss') || ''
  const scriptCode = transformJs(filepath + '.js', usingComponentsCode, options)

  return `
<template>
${templateCode}
</template>
${wxsCode}
<script>
${scriptCode}
</script>
<style>
${styleCode}
</style>
`
}