Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
bd821544
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
730
Star
38706
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bd821544
编写于
7月 29, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor api manfiest.json
上级
158000c8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
173 addition
and
31 deletion
+173
-31
build/build.js
build/build.js
+4
-1
build/manifest.js
build/manifest.js
+89
-5
lib/babel-plugin-uni-api/index.js
lib/babel-plugin-uni-api/index.js
+77
-24
src/core/helpers/apis.js
src/core/helpers/apis.js
+3
-1
未找到文件。
build/build.js
浏览文件 @
bd821544
...
...
@@ -26,7 +26,10 @@ service.run('build', {
formats
:
process
.
env
.
UNI_WATCH
===
'
true
'
?
'
umd
'
:
'
umd-min
'
,
entry
:
'
./lib/
'
+
process
.
env
.
UNI_PLATFORM
+
'
/main.js
'
}).
then
(
function
()
{
generateApiManifest
(
process
.
UNI_SERVICE_API_MANIFEST
)
generateApiManifest
(
JSON
.
parse
(
JSON
.
stringify
(
process
.
UNI_SERVICE_API_MANIFEST
)),
JSON
.
parse
(
JSON
.
stringify
(
process
.
UNI_SERVICE_API_PROTOCOL
))
)
}).
catch
(
err
=>
{
error
(
err
)
process
.
exit
(
1
)
...
...
build/manifest.js
浏览文件 @
bd821544
...
...
@@ -3,10 +3,68 @@ const path = require('path')
const
apis
=
require
(
'
../src/core/helpers/apis
'
)
function
parseApiManifestDeps
(
manifest
)
{
const
AUTO_LOADS
=
[
'
upx2px
'
,
'
canIUse
'
,
'
getSystemInfo
'
,
'
getSystemInfoSync
'
,
'
navigateTo
'
,
'
redirectTo
'
,
'
switchTab
'
,
'
reLaunch
'
,
'
navigateBack
'
]
const
TOAST_DEPS
=
[
[
'
/platforms/h5/components/app/popup/toast.vue
'
,
'
Toast
'
],
[
'
/platforms/h5/components/app/popup/mixins/toast.js
'
,
'
ToastMixin
'
]
]
// TODO 暂不考虑 head,tabBar 的动态拆分
const
DEPS
=
{
'
chooseLocation
'
:
[
[
'
/platforms/h5/components/system-routes/choose-location/index.vue
'
,
'
ChooseLocation
'
]
],
'
openLocation
'
:
[
[
'
/platforms/h5/components/system-routes/open-location/index.vue
'
,
'
OpenLocation
'
]
],
'
previewImage
'
:
[
[
'
/platforms/h5/components/system-routes/preview-image/index.vue
'
,
'
PreviewImage
'
]
],
'
showToast
'
:
TOAST_DEPS
,
'
hideToast
'
:
TOAST_DEPS
,
'
showLoading
'
:
TOAST_DEPS
,
'
hideLoading
'
:
TOAST_DEPS
,
'
showModal
'
:
[
[
'
/platforms/h5/components/app/popup/modal.vue
'
,
'
Modal
'
],
[
'
/platforms/h5/components/app/popup/mixins/modal.js
'
,
'
ModalMixin
'
]
],
'
showActionSheet
'
:
[
[
'
/platforms/h5/components/app/popup/actionSheet.vue
'
,
'
Modal
'
],
[
'
/platforms/h5/components/app/popup/mixins/action-sheet.js
'
,
'
ActionSheetMixin
'
]
]
}
// 检查依赖文件是否存在
Object
.
keys
(
DEPS
).
reduce
(
function
(
depFiles
,
name
)
{
DEPS
[
name
].
forEach
(
function
(
dep
)
{
depFiles
.
add
(
dep
[
0
])
})
return
depFiles
},
new
Set
()).
forEach
(
file
=>
{
if
(
!
fs
.
existsSync
(
path
.
join
(
__dirname
,
'
../src
'
,
file
)))
{
console
.
warn
(
file
+
'
不存在
'
)
process
.
exit
(
0
)
}
})
function
parseApiManifestDeps
(
manifest
,
protocol
)
{
// 解析 platform 依赖
Object
.
keys
(
manifest
).
forEach
(
name
=>
{
const
deps
=
manifest
[
name
][
1
]
if
(
deps
&&
deps
.
length
)
{
if
(
deps
.
length
)
{
deps
.
forEach
(
dep
=>
{
if
(
manifest
[
dep
[
1
]])
{
dep
[
0
]
=
manifest
[
dep
[
1
]][
0
]
...
...
@@ -16,11 +74,36 @@ function parseApiManifestDeps (manifest) {
})
}
})
// 解析 protocol 依赖
Object
.
keys
(
manifest
).
forEach
(
name
=>
{
const
deps
=
manifest
[
name
][
1
]
if
(
protocol
[
name
])
{
deps
.
push
([
protocol
[
name
],
name
])
}
else
{
console
.
warn
(
`
${
name
}
缺少 protocol`
)
}
})
// 追加默认依赖
Object
.
keys
(
DEPS
).
forEach
(
name
=>
{
if
(
manifest
[
name
])
{
manifest
[
name
][
1
].
push
(...
DEPS
[
name
])
}
else
{
console
.
warn
(
`缺少
${
name
}
`
)
}
})
// 设置自动加载标记
AUTO_LOADS
.
forEach
(
name
=>
{
if
(
manifest
[
name
])
{
manifest
[
name
][
2
]
=
true
}
else
{
console
.
warn
(
`缺少
${
name
}
`
)
}
})
}
module
.
exports
=
{
generateApiManifest
(
manifest
)
{
parseApiManifestDeps
(
manifest
)
generateApiManifest
(
manifest
,
protocol
)
{
parseApiManifestDeps
(
manifest
,
protocol
)
const
manifestJson
=
Object
.
create
(
null
)
const
todoApis
=
[]
...
...
@@ -33,13 +116,14 @@ module.exports = {
})
if
(
todoApis
.
length
)
{
console
.
log
(
'
\n
'
)
console
.
warn
(
`
${
process
.
env
.
UNI_PLATFORM
}
平台缺少以下 API 实现`
)
todoApis
.
forEach
(
name
=>
{
console
.
warn
(
name
)
})
}
fs
.
writeFileSync
(
path
.
resolve
(
__dirname
,
'
../packages/uni-
h5
/manifest.json
'
),
fs
.
writeFileSync
(
path
.
resolve
(
__dirname
,
'
../packages/uni-
'
+
process
.
env
.
UNI_PLATFORM
+
'
/manifest.json
'
),
JSON
.
stringify
(
manifestJson
,
null
,
4
)
)
}
...
...
lib/babel-plugin-uni-api/index.js
浏览文件 @
bd821544
...
...
@@ -9,12 +9,75 @@ function resolve(...args) {
}
const
srcPath
=
resolve
(
'
../../src/
'
)
const
protocolPath
=
resolve
(
'
../../src/core/helpers/protocol
'
)
const
coreApiPath
=
resolve
(
'
../../src/core/service/api
'
)
const
platformApiPath
=
resolve
(
'
../../src/platforms/
'
+
process
.
env
.
UNI_PLATFORM
+
'
/service/api
'
)
const
apis
=
require
(
'
../../src/core/helpers/apis
'
)
process
.
UNI_SERVICE_API_MANIFEST
=
Object
.
create
(
null
)
process
.
UNI_SERVICE_API_PROTOCOL
=
Object
.
create
(
null
)
function
parseProtocolExport
({
file
,
exports
})
{
const
filepath
=
file
.
replace
(
srcPath
,
''
)
exports
.
forEach
(
exportName
=>
{
if
(
process
.
UNI_SERVICE_API_PROTOCOL
[
exportName
])
{
console
.
warn
(
`API[
${
exportName
}
] 冲突:`
)
console
.
warn
(
process
.
UNI_SERVICE_API_PROTOCOL
[
exportName
])
console
.
warn
(
filepath
)
}
else
{
process
.
UNI_SERVICE_API_PROTOCOL
[
exportName
]
=
filepath
}
})
}
function
parseApiExport
({
file
,
methods
,
exports
,
isPlatform
})
{
const
deps
=
[]
methods
&&
methods
.
forEach
(
method
=>
{
deps
.
push
([
''
,
method
])
})
const
filepath
=
file
.
replace
(
srcPath
,
''
)
exports
.
forEach
(
exportName
=>
{
if
(
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
])
{
console
.
warn
(
'
\n
'
)
console
.
warn
(
`API[
${
exportName
}
] 冲突:`
)
console
.
warn
(
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
][
0
])
console
.
warn
(
filepath
)
if
(
isPlatform
)
{
// 优先使用 platform
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
]
=
[
filepath
,
deps
]
console
.
warn
(
`优先使用`
+
filepath
)
}
}
else
{
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
]
=
[
filepath
,
deps
]
}
})
}
function
parseExports
(
node
,
t
,
file
)
{
if
(
t
.
isFunctionDeclaration
(
node
))
{
return
[
node
.
id
.
name
]
}
else
if
(
t
.
isVariableDeclaration
(
node
)
&&
node
.
declarations
.
length
===
1
)
{
return
[
node
.
declarations
[
0
].
id
.
name
]
}
else
if
(
Array
.
isArray
(
node
)
&&
node
.
length
)
{
return
node
.
map
(
specifier
=>
{
return
specifier
.
exported
.
name
})
}
else
{
console
.
warn
(
'
\n
'
)
console
.
warn
(
`
${
file
}
解析 export 失败`
,
node
)
}
}
module
.
exports
=
function
({
types
:
t
...
...
@@ -26,33 +89,19 @@ module.exports = function({
state
.
file
.
opts
.
file
=
normalizePath
(
state
.
file
.
opts
.
filename
)
state
.
file
.
opts
.
isCore
=
state
.
file
.
opts
.
file
.
indexOf
(
coreApiPath
)
===
0
state
.
file
.
opts
.
isPlatform
=
state
.
file
.
opts
.
file
.
indexOf
(
platformApiPath
)
===
0
state
.
file
.
opts
.
isProtocol
=
state
.
file
.
opts
.
file
.
indexOf
(
protocolPath
)
===
0
},
exit
(
path
,
state
)
{
const
{
file
,
methods
,
exports
,
isP
latform
isP
rotocol
}
=
state
.
file
.
opts
if
(
exports
&&
exports
.
length
)
{
const
deps
=
[]
methods
&&
methods
.
forEach
(
method
=>
{
deps
.
push
([
''
,
method
])
})
const
filepath
=
file
.
replace
(
srcPath
,
''
)
exports
.
forEach
(
exportName
=>
{
if
(
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
])
{
console
.
warn
(
`API[
${
exportName
}
] 冲突:`
)
console
.
warn
(
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
][
0
])
console
.
warn
(
filepath
)
if
(
isPlatform
)
{
// 优先使用 platform
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
]
=
[
filepath
,
deps
]
console
.
warn
(
`优先使用`
+
filepath
)
}
}
else
{
process
.
UNI_SERVICE_API_MANIFEST
[
exportName
]
=
[
filepath
,
deps
]
}
})
if
(
isProtocol
)
{
parseProtocolExport
(
state
.
file
.
opts
)
}
else
{
parseApiExport
(
state
.
file
.
opts
)
}
}
}
},
...
...
@@ -60,10 +109,14 @@ module.exports = function({
const
{
file
,
isCore
,
isPlatform
isPlatform
,
isProtocol
}
=
state
.
file
.
opts
if
((
isCore
||
isPlatform
)
&&
t
.
isFunctionDeclaration
(
path
.
node
.
declaration
))
{
(
state
.
file
.
opts
.
exports
||
(
state
.
file
.
opts
.
exports
=
[])).
push
(
path
.
node
.
declaration
.
id
.
name
)
if
(
isCore
||
isPlatform
||
isProtocol
)
{
const
exports
=
parseExports
(
path
.
node
.
declaration
||
path
.
node
.
specifiers
,
t
,
file
)
if
(
Array
.
isArray
(
exports
))
{
(
state
.
file
.
opts
.
exports
||
(
state
.
file
.
opts
.
exports
=
[])).
push
(...
exports
)
}
}
},
CallExpression
(
path
,
state
)
{
...
...
src/core/helpers/apis.js
浏览文件 @
bd821544
const
base
=
[
'
base64ToArrayBuffer
'
,
'
arrayBufferToBase64
'
'
arrayBufferToBase64
'
,
'
addInterceptor
'
,
'
removeInterceptor
'
]
const
network
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录