mp-alipay.js 1.1 KB
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
const path = require('path')

const {
  parsePages,
  normalizePath
} = require('@dcloudio/uni-cli-shared')

const {
  hasOwn,
  parseStyle,
  parseTabBar
} = require('../util')

const pagesJson2AppJson = {
  'globalStyle': function (name, value, json) {
    json['window'] = parseStyle(value)
    if (json['window'].usingComponents) {
      json['usingComponents'] = json['window'].usingComponents
      delete json['window']['usingComponents']
    }
  },
  'tabBar': function (name, value, json) {
    json['tabBar'] = parseTabBar(value)
  }
}

function copyToJson (json, fromJson, options) {
  Object.keys(options).forEach(name => {
    if (hasOwn(fromJson, name)) {
      options[name](name, fromJson[name], json)
    }
  })
}

module.exports = function (pagesJson, manifestJson) {
  const app = {
    pages: []
  }

  parsePages(pagesJson, function (page) {
    app.pages.push(page.path)
  }, function (root, page) {
    app.pages.push(normalizePath(path.join(root, page.path)))
  })

  copyToJson(app, pagesJson, pagesJson2AppJson)

  return [{
    name: 'app',
    content: app
  }]
}