index.js 932 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1
const path = require('path')
fxy060608's avatar
fxy060608 已提交
2
const fs = require('fs-extra')
fxy060608's avatar
fxy060608 已提交
3

fxy060608's avatar
fxy060608 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
const validate = require('./validate')

const migraters = {
  'mp-weixin': require('./mp-weixin')
}

module.exports = function migrate(input, out, options = {
  platform: 'mp-weixin'
}) {
  const migrater = migraters[options.platform]
  if (!migrater) {
    return console.error(`错误: 目前支持 Object.keys(migraters).join(',') 转换`)
  }
  if (!validate(input, out, options)) {
    return
  }
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24 25 26 27 28 29 30
  const [files, assets] = migrater.transform(input, out, options)
  files.forEach(file => {
    console.log(`write: ${file.path}`)
    fs.outputFileSync(file.path, file.content)
  })
  const styleExtname = options.extname.style
  assets.forEach(asset => {
    const src = path.resolve(input, asset)
    const dest = path.resolve(out, asset.replace(styleExtname, '.css'))
    console.log(`copy: ${dest}`)
    fs.copySync(src, dest)
fxy060608's avatar
fxy060608 已提交
31 32
  })
}