const fs = require('fs')
const path = require('path')

const fileDirName =  process.argv[2] ? `${process.argv[2]}` : `index`
const fileName =  process.argv[3] ? `${process.argv[3]}` : `index`

const templates = {
    js: 
`Page({

})
`,
    json: 
`{
    "navigationBarTitleText": "${fileName}"
}
`,
    wxml: 
`
<import src=".. /.. /.. /common/head.wxml" />
<import src=".. /.. /.. /common/foot.wxml" />

<view class="container">
    <template is="head"/>

    <template is="foot" />
</view>
`,
    wxss: 
`@import ".. /.. /.. /common/lib/weui.wxss";
`
}

const baseUrl = `page/component`
const appJsonPath = `./app.json`
const fileDir = `./${baseUrl}/${fileDirName}`
const fileFullPath = `./${baseUrl}/${fileDirName}/${fileName}`

const pages = [
    "page/pages/index/index"."page/pages/recently/recently"."page/pages/liveback/liveback"."page/pages/liveshow/liveshow"."page/pages/myCourse/myCourse"."page/pages/popShare/popShare"."page/pages/sharepage/sharepage"."page/pages/myReward/myReward"."page/pages/myStudents/myStudents"."page/pages/studentDetail/studentDetail"."page/pages/aboutUs/aboutUs"."page/pages/livePractice/livePractice"."page/pages/parentTalk/parentTalk"."page/pages/extension/extension"."page/pages/company/company"."page/pages/activity/activity"."page/component/index"."page/component/pages/view/view"."page/component/pages/scroll-view/scroll-view"."page/component/pages/swiper/swiper"."page/component/pages/text/text"."page/component/pages/icon/icon"."page/component/pages/progress/progress"."page/component/pages/button/button"."page/component/pages/checkbox/checkbox"."page/component/pages/form/form"."page/component/pages/input/input"."page/component/pages/label/label"."page/component/pages/picker/picker"."page/component/pages/radio/radio"."page/component/pages/slider/slider"."page/component/pages/switch/switch"."page/component/pages/textarea/textarea"."page/component/pages/navigator/navigator"."page/component/pages/navigator/navigate"."page/component/pages/navigator/redirect"."page/component/pages/image/image"."page/component/pages/audio/audio"."page/component/pages/video/video"."page/component/pages/map/map"."page/component/pages/canvas/canvas"."page/API/index"."page/API/index/index"."page/API/pages/login/login"."page/API/pages/get-user-info/get-user-info"."page/API/pages/request-payment/request-payment"."page/API/pages/share/share"."page/API/pages/custom-message/custom-message"."page/API/pages/template-message/template-message"."page/API/pages/set-navigation-bar-title/set-navigation-bar-title"."page/API/pages/navigation-bar-loading/navigation-bar-loading"."page/API/pages/navigator/navigator"."page/API/pages/pull-down-refresh/pull-down-refresh"."page/API/pages/animation/animation"."page/API/pages/action-sheet/action-sheet"."page/API/pages/modal/modal"."page/API/pages/toast/toast"."page/API/pages/get-network-type/get-network-type"."page/API/pages/get-system-info/get-system-info"."page/API/pages/on-compass-change/on-compass-change"."page/API/pages/make-phone-call/make-phone-call"."page/API/pages/scan-code/scan-code"."page/API/pages/request/request"."page/API/pages/web-socket/web-socket"."page/API/pages/upload-file/upload-file"."page/API/pages/download-file/download-file"."page/API/pages/image/image"."page/API/pages/voice/voice"."page/API/pages/file/file"."page/API/pages/on-accelerometer-change/on-accelerometer-change"."page/API/pages/canvas/canvas"."page/API/pages/background-audio/background-audio"."page/API/pages/video/video"."page/API/pages/get-location/get-location"."page/API/pages/open-location/open-location"."page/API/pages/choose-location/choose-location"."page/API/pages/storage/storage"."page/component/index/index"
]

pages.push(path.dirname(`${baseUrl}/${fileDirName}/${fileName}/${fileName}`))
const app = {
    pages,
    "window": {
      "navigationBarTextStyle": "#ffffff"."navigationBarTitleText": "Presentation"."navigationBarBackgroundColor": "#3E3F43"."backgroundColor": "#F8F8F8"
    },
    "tabBar": {
      "color": "#7A7E83"."selectedColor": "#3cc51f"."borderStyle": "black"."backgroundColor": "#ffffff"."list": [{
        "pagePath": "page/component/index"."iconPath": "image/icon_component.png"."selectedIconPath": "image/icon_component_HL.png"."text": "Component"
      }, {
        "pagePath": "page/API/index"."iconPath": "image/icon_API.png"."selectedIconPath": "image/icon_API_HL.png"."text": "Interface"}},"networkTimeout": {
      "request": 10000,
      "connectSocket": 10000,
      "uploadFile": 10000,
      "downloadFile": 10000}."debug": false
}  

function createWxComponent(fileDir,filePath, templates,  cb) {
    fs.mkdir(fileDir, 0777, (err) => {
        if (err) throw err
        Object.entries(templates).map(([k, v]) => {
            cb(`${filePath}.${k}`, v)
        })
    })
}

function geneateFile(filePath, str) {
    fs.writeFile(filePath, str, (err) => {
        if (err) throw err;
        console.log('file created! ')
    })
}


createWxComponent(fileDir, `${fileFullPath}`, templates, geneateFile)

geneateFile(appJsonPath, JSON.stringify(app, ' ', 4))

Copy the code