刘建东 031ff697c6 微信小程序 zanui web 文档 (#142)
* [new feature]微信小程序 zanui web 文档

* fix: 修复绝对路径问题,对UI小优化

* fix: update config
2018-03-19 14:09:13 +08:00

29 lines
845 B
JavaScript

const path = require('path')
const fs = require('fs')
const file = require('./file')
const demoPath = path.join(__dirname, '../example/pages')
function getDemoFiles (demoDir) {
if (!file.hasFile(demoDir)) return {}
let files = file.getFiles(demoDir)
let conf = {}
files.forEach(_file => {
let ext = file.getExtname(_file)
conf[ext] = fs.readFileSync(_file, 'utf-8')
})
return conf
}
function getDemoDir (docFile) {
return path.join(demoPath, docFile.split('/').pop())
}
module.exports = function (template) {
let demoDir = getDemoDir(this.context)
let demoConf = getDemoFiles(demoDir)
template = Object.keys(demoConf).reduce((res, key) => {
res += `\n~~~ ${key}\n${demoConf[key]}~~~`
return res
}, template + `<wxapp-demo demo-types="${Object.keys(demoConf)}">\n`)
return template + '\n</wxapp-demo>'
}