elong-build v1.0.10
elong-build 使用说明
这篇文章介绍 elong-build 1.0 版本基础功能
安装
npm install elong-build -g
目录
高级语法
执行 tc-build build --src 源码路径 --dist 目标路径
源码编译后将支持高级语法 修饰器、async await 、对象解构... 新 API Proxy、Reflect...
babel 配置如下
const defaultConfig = {
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions"]
}
}]
],
"plugins": [
"transform-object-rest-spread",
"transform-decorators-legacy",
]
};
ESLint
代码规范检查,支持 git 钩子关联
module.exports = {
extends: 'airbnb-base',
parserOptions: {
'ecmaVersion': 7,
'sourceType': 'module'
},
globals: {
'App': true,
'Page': true,
'getApp': true,
'getCurrentPages': true
},
rules: {
'no-extend-native': 'off',
'eol-last': 'off',
'spaced-comment': 'off',
'no-use-before-define': 'off',
'prefer-template': 'off',
'no-bitwise': 'off',
'no-unused-expressions': 'off',
'consistent-return': 'off',
'arrow-parens': 'off',
'prefer-spread': 'off',
'brace-style': 'off',
'dot-notation': 'off',
'no-underscore-dangle': 'off',
'no-restricted-syntax': 'off',
'guard-for-in': 'off',
'no-trailing-spaces': 'off',
'no-useless-return': 'off',
'no-else-return': 'off',
'prefer-const': 'off',
'comma-dangle': ['error', 'never'],
'func-names': 'off',
'max-len': ['error', 200],
'no-plusplus': 'off',
'no-param-reassign': 'off',
'one-var': 'off',
'one-var-declaration-per-line': 'off',
'no-undef': ["error", {"typeof": true}],
'no-nested-ternary': 'off',
'no-new': 'off',
'no-unneeded-ternary': 'off',
"class-methods-use-this": "off",
}
};
AB下线
执行 tc-build offline --src 源码路径
已废弃的 AB 实验,人工删除代码时容易出问题或遗忘,导致后续冗余代码堆积占用体积且难以维护
JS 使用规范——
//预加载配置(可选)
AB2['kanjia','xinke','kanjia2'];
//逻辑配置
AB2({
kanjia: {//实验 key
start(val) {//逻辑
},
A(sVal) {//实验项 A 逻辑,参数为 start 返回值
},
B(sVal) {
},
end(val){
}
},
xinke: {
start(val) {
},
A(sVal) {
},
B(sVal) {
}
}
},PageIns);
注意:配置 config 时,可根据需要为 AB 方法传递第二个参数——页面实例。如果提供,获取到的 AB 值将setData 到该实例中供 wxml 模板使用,这里 setData 的实验 key 默认会添加下划线 "_"(因为当前我们的实验 key 不符合变量规范),请使用时也按照此规则使用 —— {{ _kanjia }} 。
WXML 使用规范——
//wxml AB 使用规范
<block wx:if="{{_kanjia != 'A' }}">
<text >{{commentInfo.totalCount}}条点评</text>
</block>
<text class=" abc {{_kanjia === 'B' ? 'baa' : 'caa'}} {{_kanjia === 'C' ? 'daa' : 'eaa'}}">{{commentInfo.totalCount > 0 && kanjia == 'A' }} 条点评 </text>
后台管理系统 (开发中)
用于管理员配置 AB 实验
小程序Xpath
执行 tc-build wrap --src 源码路径 --dist 目标路径 --_x --id --reset
tc-build wrap --src 目录 --_x --id --reset
dist:可选,目标路径
_x:可选,是否生成 xpath
id:可选,是否生成构建 id
reset:可选,是否还原
src 格式——
/a/b/c
/a/b/c,/b/c/d
[/a/b/c,/b/c/d,/e/f/g]
dist 格式——
/a/b/c
/a/b/c,/b/c/d
[/a/b/c,/b/c/d,/e/f/g]
如果 src 为多个路径 ,指定的 dist 数量上需要与 src 对应,不对应的默认降级使用 src
//预加载
<view id="_x" style="width:100%;min-height:100%;" capture-bind:tap="_x" capture-bind:longpress="_x" data-_x="1">
<!--code-->
</view>
生成 xpath
<view id="_x" style="width:100%;min-height:100%;" capture-bind:tap="_x" capture-bind:longpress="_x" data-_x="1">
<view wx:if="{{2 > 2}}" data-_x="2"> 2 </view>
<view wx:else="" data-_x="3"> 3 </view>
<view class="container" data-_x="4">
<view class="userinfo" data-_x="5">
<wxs style="border:2px solid blue" data-_x="6">
刘杰666
</wxs>
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo" data-_x="7"> 获取头"{{'sdlfkj'}}"像昵称 </button>
<block wx:else="">
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover" data-_x="8" />
<text class="userinfo-nickname" data-_x="9">{{userInfo.nickName}}</text>
</block>
</view>
<view id="wx:for1" wx:for="{{[1,2,3]}}" data-_x="a[{{2+_0}}]" wx:for-index="_0">
<div class="{{_0}}" data-_x="a[{{2+_0}}]b">
<div style="display:block;" data-_x="a[{{2+_0}}]c">{{'index:'+_0}}</div>
<div id="wx:for1" style="display:block;" wx:for="{{[9,8,7]}}" wx:for-index="_1" class="{{_1}}" data-_x="a[{{2+_0}}]d[{{2+_1}}]">
{{'index_i:' + _1}}
<div id="wx:for1" style="display:block;" wx:for="{{[9,8,7]}}" wx:for-index="_2" class="{{_1}}" data-_x="a[{{2+_0}}]d[{{2+_1}}]e[{{1+_2}}]">
{{'index_2:' + _2}}
</div>
</div>
</div>
</view>
<view class="usermotto" data-_x="f">
<text class="user-motto" data-_x="g">{{motto}}</text>
</view>
</view>
</view>
mapping 映射
用于管理员配置 AB 实验
{
"p": 16,
"xpaths": {
"/view": "1",
"/view/view": "2",
"/view/view[2]": "3",
"/view/view[3]": "4",
"/view/view[3]/view": "5",
"/view/view[3]/view/script": "6",
"/view/view[3]/view/button": "7",
"/view/view[3]/view/image": "8",
"/view/view[3]/view/text": "9",
"/view/view[3]/view[@id=wx:for1]": "a",
"/div": "b",
"/div/div": "c",
"/div/div[@id=wx:for1]": "d",
"/div[@id=wx:for1]": "e",
"/view/view[3]/view[3]": "f",
"/view/view[3]/view[3]/text": "g"
},
"shorts": {
"1": "/view",
"2": "/view/view",
"3": "/view/view[2]",
"4": "/view/view[3]",
"5": "/view/view[3]/view",
"6": "/view/view[3]/view/script",
"7": "/view/view[3]/view/button",
"8": "/view/view[3]/view/image",
"9": "/view/view[3]/view/text",
"a": "/view/view[3]/view[@id=wx:for1]",
"b": "/div",
"c": "/div/div",
"d": "/div/div[@id=wx:for1]",
"e": "/div[@id=wx:for1]",
"f": "/view/view[3]/view[3]",
"g": "/view/view[3]/view[3]/text"
}
}
> 执行结果
/view/view[3]/view[@id=wx:for1][2]/div/div[@id=wx:for1][3]/div[@id=wx:for1][1]
a[2]d[3]e[1]
/view/view[3]/view[@id=wx:for1][2]/div/div[@id=wx:for1][4]/div[@id=wx:for1][3]
a[2]d[4]e[3]
/view/view[3]/view[@id=wx:for1][3]/div/div
a[3]c
/view/view[3]/view[@id=wx:for1][3]/div/div[@id=wx:for1][3]/div[@id=wx:for1][1]
a[3]d[3]e[1]
/view/view[3]/view[@id=wx:for1][3]/div/div[@id=wx:for1][3]/div[@id=wx:for1][2]
a[3]d[3]e[2]
自动拉分支 ci
项目目录执行 tc-build checkout --name 新分支名称
新分支固定基于 master-hotel 分支拉取 ,新分支拉取后程序将自动修改对应版本信息,并提前交远端
修改规则 —— APPVersion:当前分支名, commitId:当前commitId, buildVer:build供给版本号
import {
appVersion
} from '../../../util/config'
export default {
APPVersion: 'b180622',//用于对应迭代版本
pubAppVersion: appVersion,
commitId:'8dc4ac6',//用于对应客户端代码
buildVer:'1.0.4'//用于对应 mapping 版本
}