validate.js 955 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4
const fs = require('fs')
const path = require('path')

const migraters = {
fxy060608's avatar
fxy060608 已提交
5
  'mp-weixin': require('./mp-weixin')
fxy060608's avatar
fxy060608 已提交
6 7
}

fxy060608's avatar
fxy060608 已提交
8
module.exports = function validate (input, out, options) {
fxy060608's avatar
fxy060608 已提交
9 10 11
  if (!fs.existsSync(input)) {
    return console.error(`错误: '${input}' 不存在`)
  }
fxy060608's avatar
fxy060608 已提交
12 13
  Object.assign(options, migraters[options.platform].options)
  const templateExtname = options.extname.template
fxy060608's avatar
fxy060608 已提交
14 15 16

  const stat = fs.lstatSync(input)
  if (stat.isFile()) {
fxy060608's avatar
fxy060608 已提交
17 18
    if (path.extname(input) !== templateExtname) {
      return console.error(`错误: 单文件转换需要传入 ${templateExtname.substr(1)} 文件地址`)
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32
    }
    options.target = 'file'
  } else if (stat.isDirectory()) {
    options.base = input
    if (fs.existsSync(path.resolve(input, 'app.json'))) {
      options.target = 'app'
    } else {
      options.target = 'folder'
    }
  } else {
    return console.error(`错误: '${input}' 不支持转换`)
  }
  return true
}