UNPKG

taitan

Version:

小程序开发辅助工具

69 lines (67 loc) 2.07 kB
const config = require('../config') const shell = require('shelljs') let cliName = `${config.wxappCliPath}/Contents/MacOS/cli` if(process.platform.toLocaleLowerCase().startsWith('win')){ //windows操作系统 cliName = `${config.wxappCliPath}` } const tools = { //在开发者工具中打开 open(projectDir,port,openid){ //是否能正常运行小程序cli工具 if(shell.which(cliName)){ let execStr = `${cliName} open --project ${projectDir}` if(port) { execStr += `--auto-port ${port}` } if(openid){ execStr += `--auto-account ${openid}` } return shell.exec(execStr) }else{ throw new Error(`请检查cli工具安装路径是否正确 可通过 'taitan set weapp-tool-path' 设置`) } }, //生成预览二维码 preview({projectDir,format,size='small',output,infoOutput,condition,query}){ if(shell.which(cliName)){ // tools.buildNpm(projectDir) let execStr = `${cliName} preview --project ${projectDir}` if(format) { execStr += ` --qr-format ${format}` } if(size){ execStr += ` --qr-size ${size}` } if(output){ execStr += ` --qr-output ${output}` } if(infoOutput){ execStr += ` --info-output ${infoOutput}` } if(condition){ let conditionObj = {pathName:condition} if(query) conditionObj.query = query execStr += ` --compile-condition '${JSON.stringify(conditionObj)}'` } return shell.exec(execStr) }else{ throw new Error(`请检查cli工具安装路径是否正确 可通过 'taitan set weapp-tool-path' 设置`) } }, //构建npm buildNpm(projectDir){ //是否能正常运行小程序cli工具 if(shell.which(cliName)){ let execStr = `${cliName} build-npm --project ${projectDir}` return shell.exec(execStr) }else{ throw new Error(`请检查cli工具安装路径是否正确 可通过 'taitan set weapp-tool-path' 设置`) } }, //清除缓存 } module.exports = tools