@dcloudio/uni-mp-jd 2.0.1-33920220121001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +11 -0
- package/dist/index.js +2055 -0
- package/lib/uni.compiler.js +119 -0
- package/lib/uni.config.js +24 -0
- package/package.json +21 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const compiler = require('@dcloudio/uni-mp-weixin/lib/uni.compiler.js')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const t = require('@babel/types')
|
|
4
|
+
const uniI18n = require('@dcloudio/uni-cli-i18n')
|
|
5
|
+
|
|
6
|
+
function generateJsCode (properties = '{}') {
|
|
7
|
+
return `
|
|
8
|
+
jd.createComponent({
|
|
9
|
+
generic:true,
|
|
10
|
+
props: ${properties},
|
|
11
|
+
render: function(){}
|
|
12
|
+
})
|
|
13
|
+
`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function generateCssCode (filename) {
|
|
17
|
+
return `
|
|
18
|
+
@import "./${filename}"
|
|
19
|
+
`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasOwn (obj, key) {
|
|
23
|
+
return Object.prototype.hasOwnProperty.call(obj, key)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = Object.assign({}, compiler, {
|
|
27
|
+
directive: 'jd:',
|
|
28
|
+
resolveScopedSlots (slotName, {
|
|
29
|
+
genCode,
|
|
30
|
+
generate,
|
|
31
|
+
ownerName,
|
|
32
|
+
parentName,
|
|
33
|
+
parentNode,
|
|
34
|
+
resourcePath,
|
|
35
|
+
paramExprNode,
|
|
36
|
+
returnExprNodes,
|
|
37
|
+
traverseExpr
|
|
38
|
+
}, state) {
|
|
39
|
+
if (!state.scopedSlots) {
|
|
40
|
+
state.scopedSlots = {}
|
|
41
|
+
}
|
|
42
|
+
const baseName = `${ownerName}-${parentName}-${slotName}`
|
|
43
|
+
let componentName = baseName
|
|
44
|
+
if (!hasOwn(state.scopedSlots, baseName)) {
|
|
45
|
+
state.scopedSlots[baseName] = 0
|
|
46
|
+
}
|
|
47
|
+
if (state.scopedSlots[baseName]) {
|
|
48
|
+
componentName = baseName + state.scopedSlots[baseName]
|
|
49
|
+
}
|
|
50
|
+
state.scopedSlots[baseName]++
|
|
51
|
+
parentNode.attr['generic:scoped-slots-' + slotName] = componentName
|
|
52
|
+
if (state.options.platform.name === 'mp-weixin') {
|
|
53
|
+
parentNode.attr['data-vue-generic'] = 'scoped'
|
|
54
|
+
}
|
|
55
|
+
if (!parentNode.attr.generic) {
|
|
56
|
+
parentNode.attr.generic = {}
|
|
57
|
+
}
|
|
58
|
+
parentNode.attr.generic[slotName] = true
|
|
59
|
+
|
|
60
|
+
// 生成 scopedSlots 文件,包括 json,js,wxml,wxss,还需要更新 owner 的 usingComponents
|
|
61
|
+
if (!state.files) {
|
|
62
|
+
state.files = {}
|
|
63
|
+
}
|
|
64
|
+
const extname = path.extname(resourcePath)
|
|
65
|
+
|
|
66
|
+
// TODO 需要存储 resourcePath 相关 json
|
|
67
|
+
|
|
68
|
+
const templateFile = resourcePath.replace(ownerName + extname, componentName + extname)
|
|
69
|
+
const templateContent = generate(traverseExpr(returnExprNodes, state), state)
|
|
70
|
+
|
|
71
|
+
state.files[templateFile] = templateContent
|
|
72
|
+
|
|
73
|
+
const jsFile = resourcePath.replace(ownerName + extname, componentName + '.js')
|
|
74
|
+
|
|
75
|
+
const objectProperties = []
|
|
76
|
+
|
|
77
|
+
if (t.isObjectPattern(paramExprNode)) {
|
|
78
|
+
paramExprNode.properties.forEach(property => {
|
|
79
|
+
const key = property.key
|
|
80
|
+
const value = property.value
|
|
81
|
+
const valueObjectProperties = [
|
|
82
|
+
t.objectProperty(t.identifier('type'), t.nullLiteral())
|
|
83
|
+
]
|
|
84
|
+
if (t.isIdentifier(value)) {
|
|
85
|
+
if (value.name !== key.name) {
|
|
86
|
+
state.errors.add(uniI18n.__('mpWeChat.slotPropNoSupportReanme', { 0: key.name, 1: value.name }))
|
|
87
|
+
}
|
|
88
|
+
} else if (t.isAssignmentPattern(value)) {
|
|
89
|
+
valueObjectProperties.push(t.objectProperty(t.identifier('default'), value.right))
|
|
90
|
+
}
|
|
91
|
+
objectProperties.push(t.objectProperty(key, t.objectExpression(valueObjectProperties)))
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
state.errors.add(uniI18n.__('mpWeChat.onlySupportDestructuringSlot', { 0: paramExprNode.name, 1: 'v-slot="{ user }"' }))
|
|
95
|
+
}
|
|
96
|
+
const jsContent = generateJsCode(genCode(t.objectExpression(objectProperties), true))
|
|
97
|
+
state.files[jsFile] = jsContent
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
// TODO 使用 getPlatformExts 在单元测试报错,改从 state.options.platform 判断
|
|
101
|
+
const {
|
|
102
|
+
getPlatformExts
|
|
103
|
+
} = require('@dcloudio/uni-cli-shared')
|
|
104
|
+
const styleExtname = getPlatformExts().style
|
|
105
|
+
const styleFile = resourcePath.replace(ownerName + extname, componentName + styleExtname)
|
|
106
|
+
const styleContent = generateCssCode(ownerName + styleExtname)
|
|
107
|
+
|
|
108
|
+
state.files[styleFile] = styleContent
|
|
109
|
+
} catch (error) { }
|
|
110
|
+
|
|
111
|
+
if (!state.generic) {
|
|
112
|
+
state.generic = []
|
|
113
|
+
}
|
|
114
|
+
// 存储,方便后续生成 json
|
|
115
|
+
state.generic.push(componentName)
|
|
116
|
+
|
|
117
|
+
return ''
|
|
118
|
+
}
|
|
119
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
options: {
|
|
3
|
+
cssVars: {
|
|
4
|
+
'--status-bar-height': '25px',
|
|
5
|
+
'--window-top': '0px',
|
|
6
|
+
'--window-bottom': '0px',
|
|
7
|
+
'--window-left': '0px',
|
|
8
|
+
'--window-right': '0px'
|
|
9
|
+
},
|
|
10
|
+
extnames: {
|
|
11
|
+
style: '.jxss',
|
|
12
|
+
template: '.jxml'
|
|
13
|
+
},
|
|
14
|
+
subPackages: false,
|
|
15
|
+
project: 'project.config.json'
|
|
16
|
+
},
|
|
17
|
+
copyWebpackOptions (platformOptions, vueOptions) {
|
|
18
|
+
const copyOptions = ['jdcomponents']
|
|
19
|
+
global.uniModules.forEach(module => {
|
|
20
|
+
copyOptions.push('uni_modules/' + module + '/jdcomponents')
|
|
21
|
+
})
|
|
22
|
+
return copyOptions
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/uni-mp-jd",
|
|
3
|
+
"version": "2.0.1-33920220121001",
|
|
4
|
+
"description": "uni-app mp-jd",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
9
|
+
"directory": "packages/uni-mp-jd"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"author": "shixiaolei6",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"uni-app": {
|
|
17
|
+
"name": "mp-jd",
|
|
18
|
+
"title": "京东小程序"
|
|
19
|
+
},
|
|
20
|
+
"gitHead": "dc143acb83df709adba2685e24d17fc385212b4a"
|
|
21
|
+
}
|