Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpx转化快手小程序 #997

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
jd: 'readonly',
qa: 'readonly',
dd: 'readonly',
ks: 'readonly',
Component: 'readonly',
Page: 'readonly',
App: 'readonly',
Expand Down
4 changes: 3 additions & 1 deletion packages/api-proxy/src/common/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const handleSuccess = (opts, getOptions = noop, thisObj) => {

function genFromMap () {
const result = {}
const platforms = ['wx', 'ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd']
const platforms = ['wx', 'ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ks']
platforms.forEach((platform) => {
result[`__mpx_src_mode_${platform}__`] = platform
})
Expand All @@ -71,6 +71,8 @@ function getEnvObj () {
return qa
case 'dd':
return dd
case 'ks':
return ks
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// declaration for mpx mode
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd'
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'ks'

// declaration for mpx env
declare let __mpx_env__: string
Expand Down
2 changes: 1 addition & 1 deletion packages/core/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ interface MpxConfig {
webRouteConfig: object
}

type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa' | 'ks'

interface ImplementOptions {
modes?: Array<SupportedMode>
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/convertor/convertor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import wxToQqRule from './wxToQq'
import wxToTtRule from './wxToTt'
import wxToDdRule from './wxToDd'
import wxToJdRule from './wxToJd'
import wxToKsRule from './wxToKs'

// 根据当前环境获取的默认生命周期信息
let lifecycleInfo
Expand Down Expand Up @@ -55,7 +56,8 @@ const rulesMap = {
wxToQq: { ...defaultConvertRule, ...wxToQqRule },
wxToTt: { ...defaultConvertRule, ...wxToTtRule },
wxToDd: { ...defaultConvertRule, ...wxToDdRule },
wxToJd: { ...defaultConvertRule, ...wxToJdRule }
wxToJd: { ...defaultConvertRule, ...wxToJdRule },
wxToKs: { ...defaultConvertRule, ...wxToKsRule }
}

export function getConvertRule (convertMode) {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/convertor/getConvertMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const convertModes = {
'wx-qq': 'wxToQq',
'wx-tt': 'wxToTt',
'wx-jd': 'wxToJd',
'wx-dd': 'wxToDd'
'wx-dd': 'wxToDd',
'wx-ks':'wxToKs'
}

export function getConvertMode (srcMode) {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/convertor/wxToKs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const BEHAVIORS_MAP = {
'wx://form-field': 'ks://form-field',
'wx://form-field-group': 'ks://form-field-group',
'wx://form-field-button': 'ks://form-field-button',
'wx://component-export': 'ks://component-export'
}

export default {
convert (options) {
if (options.behaviors) {
options.behaviors.forEach((behavior, idx) => {
if (typeof behavior === 'string' && BEHAVIORS_MAP[behavior]) {
options.behaviors.splice(idx, 1, BEHAVIORS_MAP[behavior])
}
})
}
}
}
2 changes: 2 additions & 0 deletions packages/core/src/helper/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export function getEnvObj () {
return qa
case 'dd':
return dd
case 'ks':
return ks
}
}
6 changes: 3 additions & 3 deletions packages/core/src/platform/builtInMixins/renderHelperMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isObject } from '../../helper/utils'
export default function renderHelperMixin () {
return {
methods: {
_i (val, handler) {
i (val, handler) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

快手不支持下划线开头的方法是吧

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的

let i, l, keys, key
if (Array.isArray(val) || typeof val === 'string') {
for (i = 0, l = val.length; i < l; i++) {
Expand All @@ -21,11 +21,11 @@ export default function renderHelperMixin () {
}
}
},
_c (key, value) {
c (key, value) {
this.__mpxProxy.renderData[key] = value
return value
},
_r () {
r () {
this.__mpxProxy.renderWithData()
}
}
Expand Down
58 changes: 58 additions & 0 deletions packages/webpack-plugin/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,5 +556,63 @@ module.exports = {
ref: 'dd:ref',
show: 'dd:show'
}
},
ks:{
typeExtMap: {
json: '.json',
script: '.js',
template: '.ksml',
styles: '.css'
},
tabBar: {
itemKey: 'list',
iconKey: 'iconPath',
activeIconKey: 'selectedIconPath'
},
event: {
parseEvent (attr) {
let match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
if (match) {
return {
prefix: match[1],
eventName: match[2],
modifier: match[3]
}
}
},
getEvent (eventName, prefix = 'bind') {
return prefix + eventName
},
defaultModelProp: 'value',
defaultModelEvent: 'input',
defaultModelValuePath: 'value',
shallowStringify (obj) {
let arr = []
for (let key in obj) {
let value = obj[key]
if (Array.isArray(value)) {
value = `[${value.join(',')}]`
}
arr.push(`${key}:${value}`)
}
return ` {${arr.join(',')}} `
}
},
wxs: {},
directive: {
if: 'ks:if',
elseif: 'ks:elif',
else: 'ks:else',
for: 'ks:for',
dynamicClass: 'class',
dynamicStyle: 'style',
ref: 'ks:ref',
show: 'ks:show',
model: 'ks:model',
modelProp: 'ks:model-prop',
modelEvent: 'ks:model-event',
modelValuePath: 'ks:model-value-path',
modelFilter: 'ks:model-filter'
}
}
}
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function loader (content, prevOptions) {
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot))
}

let publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}`
let publicPath = options.mode === 'ks'&& queryObj?.currentName ==='app' ? JSON.stringify(url) :`__webpack_public_path__ + ${JSON.stringify(url)}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentName哪来的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app中不能用绝对路径?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在file-loader中加的currentName 这个我可能没复制全 app中的路径用绝对路径解析不出来


if (options.publicPath) {
if (typeof options.publicPath === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ module.exports = function (content) {
let ctor = 'App'
if (ctorType === 'page') {
// swan也默认使用Page构造器
if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan') {
if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan' || mode === 'ks') {
Copy link
Collaborator

@hiyuki hiyuki Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

快手不支持component构造页面吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我再确认一下

ctor = 'Page'
} else {
ctor = 'Component'
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/platform/json/wx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function getSpec ({ warn, error }) {
}

const spec = {
supportedModes: ['ali', 'swan', 'qq', 'tt', 'jd', 'qa', 'dd'],
supportedModes: ['ali', 'swan', 'qq', 'tt', 'jd', 'qa', 'dd', 'ks'],
normalizeTest,
page: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function ({ print }) {
const qqValueWarningLog = print({ platform: 'qq', type: 'value', tag: TAG_NAME, isError: false })
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' })
const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
props: [
Expand All @@ -33,6 +34,10 @@ module.exports = function ({ print }) {
baiduValueWarningLog({ name: 'type', value: obj.value })
}
return obj
},
ks (obj) {
obj.name = 'type'
return obj
}
},
{
Expand All @@ -42,7 +47,8 @@ module.exports = function ({ print }) {
{
test: /^(ad-intervals|ad-theme)$/,
qq: qqPropLog,
swan: baiduPropLog
swan: baiduPropLog,
ks: ksPropLog
}
],
event: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function ({ print }) {
const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' })
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' })
const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
props: [
Expand Down Expand Up @@ -46,7 +47,8 @@ module.exports = function ({ print }) {
},
{
test: /^(resolution|frame-size)$/,
qq: qqPropLog
qq: qqPropLog,
ks: ksPropLog
},
{
test: /^(frame-size|device-position)$/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,27 @@ module.exports = function ({ print }) {
'longtap': 'longTap'
}
return eventMap[eventName]
},
ks(eventName){
const eventMap = {
'touchstart': 'canvastouchstart',
'touchmove': 'canvastouchmove',
'touchend': 'canvastouchend',
'touchcancel': 'canvastouchcancel',
'longtap': 'canvaslongtap '
}
return eventMap[eventName]
}
},
{
test: /^(error)$/,
ali: aliEventLog
ali: aliEventLog,
ks(eventName){
const eventMap = {
'error': 'canvaserror',
}
return eventMap[eventName]
}
},
{
test: /^(longtap|error)$/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const TAG_NAME = 'cover-image'

module.exports = function ({ print }) {
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
web (tag, { el }) {
Expand All @@ -17,6 +18,10 @@ module.exports = function ({ print }) {
web (prop, { el }) {
el.isBuiltIn = true
}
},
{
test:/^referrer-policy$/,
ks:ksPropLog
}
],
event: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function ({ print }) {
const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false })
const webPropLog = print({ platform: 'web', tag: TAG_NAME, isError: false })
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })

const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
web (tag, { el }) {
Expand All @@ -26,7 +26,8 @@ module.exports = function ({ print }) {
{
test: /^(report-submit|report-submit-timeout)$/,
web: webPropLog,
qa: qaPropLog
qa: qaPropLog,
ks: ksPropLog
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function ({ print }) {
const webEventLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'event' })
const webValueLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'value' })
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })

const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
return {
test: TAG_NAME,
web (tag, { el }) {
Expand All @@ -37,6 +37,10 @@ module.exports = function ({ print }) {
test: /^(hold-keyboard)$/,
jd: jdPropLog
},
{
test: /^(placeholder-class|cursor-spacing|always-embed|cursor|selection-start|selection-end|safe-password-cert-path|safe-password-length|safe-password-time-stamp|safe-password-nonce|safe-password-salt|safe-password-custom-hash)$/,
ks: ksPropLog
},
{
test: 'type',
web (prop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const TAG_NAME = 'movable-view'
module.exports = function ({ print }) {
const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' })
const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false })
const ksEventLog = print({ platform: 'ks', tag: TAG_NAME, isError: false, type: 'event' })
return {
test: TAG_NAME,
web (tag, { el }) {
Expand All @@ -18,7 +19,8 @@ module.exports = function ({ print }) {
event: [
{
test: /^(htouchmove|vtouchmove)$/,
ali: aliEventLog
ali: aliEventLog,
ks: ksEventLog
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function ({ print }) {
const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false })
const jdEventLog = print({ platform: 'jd', tag: TAG_NAME, isError: false, type: 'event' })
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })

const ksEventLog = print({ platform: 'ks', tag: TAG_NAME, isError: false, type: 'event' })
return {
test: TAG_NAME,
web (tag, { el }) {
Expand Down Expand Up @@ -43,6 +43,14 @@ module.exports = function ({ print }) {
}
obj.name = propsMap[obj.name]
return obj
},
ks (obj) {
const propsMap = {
'activeColor': 'active-color',
'backgroundColor': 'background-color'
}
obj.name = propsMap[obj.name]
return obj
}
},
{
Expand All @@ -64,7 +72,8 @@ module.exports = function ({ print }) {
ali: aliEventLog,
swan: baiduEventLog,
tt: ttEventLog,
jd: jdEventLog
jd: jdEventLog,
ks: ksEventLog
}
]
}
Expand Down
Loading