Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
283c8429
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
283c8429
编写于
5月 27, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore(automator): uts ios 优化 program.swipe
上级
2f65226b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
packages/uni-app-plus/lib/uni.automator.js
packages/uni-app-plus/lib/uni.automator.js
+1
-1
未找到文件。
packages/uni-app-plus/lib/uni.automator.js
浏览文件 @
283c8429
"
use strict
"
;
var
e
=
require
(
"
fs
"
),
t
=
require
(
"
path
"
),
s
=
require
(
"
debug
"
),
a
=
require
(
"
jsonc-parser
"
),
r
=
require
(
"
fs-extra
"
),
i
=
require
(
"
postcss-selector-parser
"
),
o
=
require
(
"
licia/dateFormat
"
),
n
=
require
(
"
util
"
),
l
=
require
(
"
jimp
"
),
c
=
require
(
"
child_process
"
),
d
=
require
(
"
dns
"
);
function
u
(
e
){
return
e
&&
"
object
"
==
typeof
e
&&
"
default
"
in
e
?
e
:{
default
:
e
}}
var
p
=
u
(
e
),
h
=
u
(
t
),
m
=
u
(
s
),
f
=
u
(
r
),
y
=
u
(
i
),
v
=
u
(
o
),
_
=
u
(
l
),
I
=
u
(
d
);
function
P
(
e
){
e
.
walk
((
e
=>
{
if
(
"
tag
"
===
e
.
type
){
const
t
=
e
.
value
;
e
.
value
=
"
page
"
===
t
?
"
body
"
:
"
uni-
"
+
t
}}))}
m
.
default
(
"
automator:devtool
"
);
const
N
=
[
"
Page.getElement
"
,
"
Page.getElements
"
,
"
Element.getElement
"
,
"
Element.getElements
"
];
const
E
=
/^win/
.
test
(
process
.
platform
);
function
w
(
e
){
try
{
return
require
(
e
)}
catch
(
t
){
return
require
(
require
.
resolve
(
e
,{
paths
:[
process
.
cwd
()]}))}}
const
S
=
m
.
default
(
"
automator:launcher
"
),
g
=
n
.
promisify
(
p
.
default
.
readdir
),
$
=
n
.
promisify
(
p
.
default
.
stat
);
async
function
D
(
e
){
const
s
=
await
g
(
e
);
return
(
await
Promise
.
all
(
s
.
map
((
async
s
=>
{
const
a
=
t
.
resolve
(
e
,
s
);
return
(
await
$
(
a
)).
isDirectory
()?
D
(
a
):
a
})))).
reduce
(((
e
,
t
)
=>
e
.
concat
(
t
)),[])}
class
U
{
constructor
(
e
){
this
.
isX
=!
1
,
"
true
"
===
process
.
env
.
UNI_APP_X
&&
(
this
.
isX
=!
0
),
this
.
id
=
e
.
id
,
this
.
app
=
e
.
executablePath
,
this
.
appid
=
e
.
appid
||
process
.
env
.
UNI_APP_ID
||
(
this
.
isX
?
"
__UNI__uniappx
"
:
"
HBuilder
"
),
this
.
package
=
e
.
package
||
(
this
.
isX
?
"
io.dcloud.uniappx
"
:
"
io.dcloud.HBuilder
"
),
this
.
activity
=
e
.
activity
||
(
this
.
isX
?
"
io.dcloud.uniapp.UniAppActivity
"
:
"
io.dcloud.PandoraEntry
"
)}
shouldPush
(){
return
this
.
exists
(
this
.
FILE_APP_SERVICE
).
then
((()
=>
(
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
exists`
),
!
1
))).
catch
((()
=>
(
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
not exists`
),
!
0
)))}
push
(
e
){
return
D
(
e
).
then
((
s
=>
{
const
a
=
s
.
map
((
s
=>
{
const
a
=
(
e
=>
E
?
e
.
replace
(
/
\\
/g
,
"
/
"
):
e
)(
t
.
join
(
this
.
DIR_WWW
,
t
.
relative
(
e
,
s
)));
return
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
push
${
s
}
${
a
}
`
),
this
.
pushFile
(
s
,
a
)}));
return
Promise
.
all
(
a
)})).
then
((
e
=>!
0
))}
get
FILE_APP_SERVICE
(){
return
`
${
this
.
DIR_WWW
}
/app-service.js`
}}
const
A
=
m
.
default
(
"
automator:simctl
"
),
M
=
n
.
promisify
(
c
.
exec
);
function
R
(
e
){
const
t
=
parseInt
(
e
);
return
t
>
9
?
String
(
t
):
"
0
"
+
t
}
class
b
extends
U
{
constructor
(){
super
(...
arguments
),
this
.
bundleVersion
=
""
}
async
init
(){
const
e
=
w
(
"
node-simctl
"
).
Simctl
;
this
.
tool
=
new
e
({
udid
:
this
.
id
});
try
{
await
this
.
tool
.
bootDevice
()}
catch
(
e
){}
await
this
.
initSDCard
(),
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
`
)}
async
initSDCard
(){
const
e
=
await
this
.
tool
.
appInfo
(
this
.
package
);
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
appInfo
${
e
}
`
);
const
t
=
e
.
match
(
/DataContainer
\s
+=
\s
+"
(
.*
)
"/
);
if
(
!
t
)
return
Promise
.
resolve
(
""
);
const
s
=
e
.
match
(
/CFBundleVersion
\s
+=
\s
+
(
.*
)
;/
);
if
(
!
s
)
return
Promise
.
resolve
(
""
);
this
.
sdcard
=
t
[
1
].
replace
(
"
file:
"
,
""
),
this
.
bundleVersion
=
s
[
1
],
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
sdcard
}
`
)}
async
version
(){
return
Promise
.
resolve
(
this
.
bundleVersion
)}
formatVersion
(
e
){
const
t
=
e
.
split
(
"
.
"
);
return
3
!==
t
.
length
?
e
:
t
[
0
]
+
R
(
t
[
1
])
+
R
(
t
[
2
])}
async
install
(){
return
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
`
),
await
this
.
tool
.
installApp
(
this
.
app
),
await
this
.
tool
.
grantPermission
(
this
.
package
,
"
all
"
),
await
this
.
initSDCard
(),
Promise
.
resolve
(
!
0
)}
async
start
(){
A
(
"
ios simulator start
"
);
try
{
await
this
.
tool
.
terminateApp
(
this
.
package
)}
catch
(
e
){
console
.
error
(
"
ios simulator start terminateApp fail
"
,
e
)}
try
{
await
this
.
tool
.
launchApp
(
this
.
package
)}
catch
(
e
){
console
.
error
(
"
ios simulator start launchApp fail
"
,
e
),
console
.
error
(
e
)}
return
Promise
.
resolve
(
!
0
)}
async
exit
(){
return
await
this
.
tool
.
terminateApp
(
this
.
package
),
await
this
.
tool
.
shutdownDevice
(),
Promise
.
resolve
(
!
0
)}
async
captureScreenshot
(
e
){
const
t
=
await
Promise
.
resolve
(
await
this
.
tool
.
getScreenshot
());
return
new
Promise
(((
s
,
a
)
=>
{
var
r
,
i
;
void
0
!==
(
null
===
(
r
=
null
==
e
?
void
0
:
e
.
area
)
||
void
0
===
r
?
void
0
:
r
.
x
)
&&
void
0
!==
(
null
===
(
i
=
null
==
e
?
void
0
:
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
y
)?
_
.
default
.
read
(
Buffer
.
from
(
t
,
"
base64
"
)).
then
((
t
=>
{
const
r
=
e
.
area
.
x
,
i
=
e
.
area
.
y
;
let
o
=
t
.
bitmap
.
width
-
r
;
e
.
area
.
width
&&
(
o
=
Math
.
min
(
o
,
e
.
area
.
width
));
let
n
=
t
.
bitmap
.
height
-
i
;
e
.
area
.
height
&&
(
n
=
Math
.
min
(
n
,
e
.
area
.
height
)),
t
.
crop
(
r
,
i
,
o
,
n
).
getBase64Async
(
_
.
default
.
MIME_PNG
).
then
((
e
=>
{
s
(
e
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
e
=>
{
a
(
e
)}))})).
catch
((
e
=>
{
a
(
e
)})):
s
(
t
)}))}
exists
(
e
){
return
f
.
default
.
existsSync
(
e
)?
Promise
.
resolve
(
!
0
):
Promise
.
reject
(
Error
(
`
${
e
}
not exists`
))}
pushFile
(
e
,
t
){
return
Promise
.
resolve
(
f
.
default
.
copySync
(
e
,
t
))}
adbCommand
(
e
){
return
new
Promise
((
e
=>
{
e
(
"
adbCommand only for App Android!
"
)}))}
swipe
(
e
){
return
new
Promise
((
async
t
=>
{
var
s
,
a
;
const
{
startPoint
:
r
,
endPoint
:
i
,
duration
:
o
}
=
e
;
try
{
const
{
stdout
:
e
}
=
await
M
(
"
idb list-targets
"
),
n
=
e
.
split
(
"
\n
"
);
for
(
let
e
=
0
;
e
<
n
.
length
;
e
++
){
const
t
=
n
[
e
].
split
(
"
|
"
),
r
=
null
===
(
s
=
t
[
1
])
||
void
0
===
s
?
void
0
:
s
.
trim
();
r
&&
r
!==
this
.
id
&&
"
No Companion Connected
"
!==
(
null
===
(
a
=
t
[
t
.
length
-
1
])
||
void
0
===
a
?
void
0
:
a
.
trim
())
&&
await
M
(
`idb disconnect
${
r
}
`
)}
await
M
(
`idb connect
${
this
.
id
}
&& idb ui swipe
${
r
.
x
}
${
r
.
y
}
${
i
.
x
}
${
i
.
y
}
--duration
${
o
?
o
/
1
e3
:.
1
}
`
),
t
(
"
swipe success
"
)}
catch
(
e
){
const
s
=
`idb list-targets error:
${
e
}
`
;
console
.
error
(
s
),
t
(
s
)}}))}
get
DIR_WWW
(){
return
"
true
"
===
process
.
env
.
UNI_APP_X
?
`
${
this
.
sdcard
}
/Documents/uni-app-x/apps/__UNI__uniappx/www/`
:
`
${
this
.
sdcard
}
/Documents/Pandora/apps/
${
this
.
appid
}
/www/`
}}
const
H
=
w
(
"
adbkit
"
),
x
=
m
.
default
(
"
automator:adb
"
);
class
T
extends
U
{
constructor
(){
super
(...
arguments
),
this
.
needStart
=!
0
}
async
init
(){
if
(
void
0
!==
I
.
default
.
setDefaultResultOrder
&&
I
.
default
.
setDefaultResultOrder
(
"
ipv4first
"
),
this
.
tool
=
H
.
createClient
(),
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
await
this
.
tool
.
version
()}
`
),
!
this
.
id
){
const
e
=
await
this
.
tool
.
listDevices
();
if
(
!
e
.
length
)
throw
Error
(
"
Device not found
"
);
this
.
id
=
e
[
0
].
id
}
console
.
log
(
"
before echo ${$EXTERNAL_STORAGE}
"
),
this
.
sdcard
=
(
await
this
.
shell
(
this
.
COMMAND_EXTERNAL
)).
trim
(),
console
.
log
(
"
after echo ${$EXTERNAL_STORAGE}
"
,
this
.
sdcard
),
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
${
this
.
sdcard
}
`
)}
root
(){
return
this
.
tool
.
root
(
this
.
id
).
then
((()
=>
{
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
this
.
sdcard
}
`
)})).
catch
((
e
=>
{
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
e
}
`
)}))}
version
(){
return
this
.
shell
(
this
.
COMMAND_VERSION
).
then
((
e
=>
{
const
t
=
e
.
match
(
/versionName=
(
.*
)
/
);
return
t
&&
t
.
length
>
1
?
t
[
1
]:
""
}))}
formatVersion
(
e
){
return
e
}
async
install
(){
let
e
=!
0
;
try
{
const
t
=
(
await
this
.
tool
.
getProperties
(
this
.
id
))[
"
ro.build.version.release
"
].
split
(
"
.
"
)[
0
];
parseInt
(
t
)
<
6
&&
(
e
=!
1
)}
catch
(
e
){}
if
(
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
permission=
${
e
}
`
),
e
){
const
e
=
w
(
"
adbkit/lib/adb/command.js
"
),
t
=
e
.
prototype
.
_send
;
e
.
prototype
.
_send
=
function
(
e
){
return
0
===
e
.
indexOf
(
"
shell:pm install -r
"
)
&&
(
e
=
e
.
replace
(
"
shell:pm install -r
"
,
"
shell:pm install -r -g
"
),
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
e
}
`
)),
t
.
call
(
this
,
e
)}}
return
this
.
tool
.
install
(
this
.
id
,
this
.
app
).
then
((()
=>
{
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
installed`
),
this
.
init
()}))}
start
(){
return
this
.
needStart
?
this
.
exit
().
then
((()
=>
this
.
shell
(
this
.
COMMAND_START
))):
Promise
.
resolve
()}
exit
(){
return
this
.
shell
(
this
.
COMMAND_STOP
)}
captureScreenshot
(
e
){
return
this
.
tool
.
screencap
(
this
.
id
).
then
((
t
=>
new
Promise
(((
s
,
a
)
=>
{
const
r
=
[];
t
.
on
(
"
data
"
,(
function
(
e
){
r
.
push
(
e
)})),
t
.
on
(
"
end
"
,(
function
(){
var
t
,
i
;
void
0
!==
(
null
===
(
t
=
e
.
area
)
||
void
0
===
t
?
void
0
:
t
.
x
)
&&
void
0
!==
(
null
===
(
i
=
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
y
)?
_
.
default
.
read
(
Buffer
.
concat
(
r
)).
then
((
t
=>
{
var
r
,
i
,
o
,
n
;
const
l
=
e
.
area
.
x
,
c
=
e
.
area
.
y
;
let
d
=
t
.
bitmap
.
width
-
l
;(
null
===
(
r
=
e
.
area
)
||
void
0
===
r
?
void
0
:
r
.
width
)
&&
(
d
=
Math
.
min
(
d
,
null
===
(
i
=
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
width
));
let
u
=
t
.
bitmap
.
height
-
c
;(
null
===
(
o
=
e
.
area
)
||
void
0
===
o
?
void
0
:
o
.
height
)
&&
(
u
=
Math
.
min
(
u
,
null
===
(
n
=
e
.
area
)
||
void
0
===
n
?
void
0
:
n
.
height
)),
t
.
crop
(
l
,
c
,
d
,
u
).
getBase64Async
(
_
.
default
.
MIME_PNG
).
then
((
e
=>
{
s
(
e
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
e
=>
{
a
(
e
)}))})).
catch
((
e
=>
{
a
(
e
)})):
s
(
Buffer
.
concat
(
r
).
toString
(
"
base64
"
))}))}))))}
adbCommand
(
e
){
return
new
Promise
((
t
=>
{
this
.
tool
.
shell
(
this
.
id
,
e
).
then
((
e
=>
{
let
s
,
a
=
""
;
e
.
on
(
"
data
"
,(
e
=>
{
a
+=
e
.
toString
(),
s
&&
clearTimeout
(
s
),
s
=
setTimeout
((()
=>
{
t
(
a
)}),
50
)})),
setTimeout
((()
=>
{
t
(
a
)}),
1500
)}))}))}
swipe
(
e
){
return
new
Promise
((
t
=>
{
this
.
tool
.
shell
(
this
.
id
,
`input swipe
${
e
.
startPoint
.
x
}
${
e
.
startPoint
.
y
}
${
e
.
endPoint
.
x
}
${
e
.
endPoint
.
y
}
${
e
.
duration
||
100
}
`
).
then
((
e
=>
{
let
s
,
a
=
""
;
e
.
on
(
"
data
"
,(
e
=>
{
a
+=
e
.
toString
(),
s
&&
clearTimeout
(
s
),
s
=
setTimeout
((()
=>
{
t
(
a
)}),
50
)})),
setTimeout
((()
=>
{
t
(
a
)}),
1500
)}))}))}
exists
(
e
){
return
this
.
tool
.
stat
(
this
.
id
,
e
)}
pushFile
(
e
,
t
){
return
this
.
tool
.
push
(
this
.
id
,
e
,
t
)}
async
push
(
e
){
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
return
super
.
push
(
e
);
const
t
=
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
launcher
"
,
"
out
"
,
"
export
"
,
"
pushResources.js
"
),
s
=
process
.
env
.
HX_CONFIG_ADB_PATH
||
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
launcher-tools
"
,
"
tools
"
,
"
adbs
"
,
"
adb
"
),
a
=
[
t
,
s
].
map
((
e
=>
p
.
default
.
promises
.
access
(
e
,
p
.
default
.
constants
.
F_OK
).
then
((()
=>
`
${
e
}
exists`
)).
catch
((()
=>
`
${
e
}
not exists`
))));
return
Promise
.
all
(
a
).
then
((()
=>
{
const
{
PushResources
:
a
}
=
require
(
t
);
return
new
a
({
adbPath
:
s
,
appid
:
this
.
appid
,
uuid
:
this
.
id
,
packageName
:
this
.
package
,
sourcePath
:
e
}).
start
(),
this
.
needStart
=!
1
,
!
0
})).
catch
((
async
t
=>
(
console
.
log
(
"
pushResources or adb not exists:
"
,
t
),
await
super
.
push
(
e
))))}
shell
(
e
){
return
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
SEND ►
${
e
}
`
),
this
.
tool
.
shell
(
this
.
id
,
e
).
then
(
H
.
util
.
readAll
).
then
((
e
=>
{
const
t
=
e
.
toString
();
return
x
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
◀ RECV
${
t
}
`
),
t
}))}
get
DIR_WWW
(){
return
`/storage/emulated/0/Android/data/
${
this
.
package
}
/apps/
${
this
.
appid
}
/www`
}
get
COMMAND_EXTERNAL
(){
return
"
echo $EXTERNAL_STORAGE
"
}
get
COMMAND_VERSION
(){
return
`dumpsys package
${
this
.
package
}
`
}
get
COMMAND_STOP
(){
return
`am force-stop
${
this
.
package
}
`
}
get
COMMAND_START
(){
return
`am start -n
${
this
.
package
}
/
${
this
.
activity
}
--es appid
${
this
.
appid
}
--ez needUpdateApp false --ez reload true --ez externalStorage true`
}}
const
C
=
m
.
default
(
"
automator:devtool
"
);
let
O
,
X
=!
1
;
const
k
=
{
android
:
/android_version=
(
.*
)
/
,
ios
:
/iphone_version=
(
.*
)
/
};
const
j
=
{
"
Tool.close
"
:{
reflect
:
async
()
=>
{}},
"
App.exit
"
:{
reflect
:
async
()
=>
O
.
exit
()},
"
App.enableLog
"
:{
reflect
:()
=>
Promise
.
resolve
()},
"
App.captureScreenshotWithDevice
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
O
.
captureScreenshot
(
t
);
return
C
(
`App.captureScreenshot
${
s
.
length
}
`
),{
data
:
s
}}},
"
App.adbCommand
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
O
.
adbCommand
(
t
);
return
C
(
`App.adbCommand
${
s
.
length
}
`
),{
data
:
s
}}},
"
App.swipe
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
O
.
swipe
(
t
);
return
C
(
`App.swipe
${
s
.
length
}
`
),{
data
:
s
}}}};
!
function
(
e
){
N
.
forEach
((
t
=>
{
e
[
t
]
=
function
(
e
){
return
{
reflect
:
async
(
t
,
s
)
=>
t
(
e
,
s
,
!
1
),
params
:
e
=>
(
e
.
selector
&&
(
e
.
selector
=
y
.
default
(
P
).
processSync
(
e
.
selector
)),
e
)}}(
t
)}))}(
j
);
const
L
=
{
devtools
:{
name
:
"
App
"
,
paths
:[],
required
:[
"
manifest.json
"
,
"
app-service.js
"
],
validate
:
async
function
(
e
,
t
){
e
.
platform
=
(
e
.
platform
||
process
.
env
.
UNI_OS_NAME
).
toLocaleLowerCase
(),
Object
.
assign
(
e
,
e
[
e
.
platform
]),
O
=
function
(
e
,
t
){
return
"
ios
"
===
e
?
new
b
(
t
):
new
T
(
t
)}(
e
.
platform
,
e
),
await
O
.
init
();
const
s
=
await
O
.
version
();
if
(
s
){
if
(
e
.
version
){
const
t
=
O
.
formatVersion
(
function
(
e
,
t
){
if
(
e
.
endsWith
(
"
.txt
"
))
try
{
const
s
=
p
.
default
.
readFileSync
(
e
).
toString
().
match
(
k
[
t
]);
if
(
s
)
return
s
[
1
]}
catch
(
e
){
console
.
error
(
e
)}
return
e
}(
e
.
version
,
e
.
platform
));
C
(
`version:
${
s
}
`
),
C
(
`newVersion:
${
t
}
`
),
t
!==
s
&&
(
X
=!
0
)}}
else
X
=!
0
;
if
(
X
){
if
(
!
e
.
executablePath
)
throw
Error
(
`app-plus->
${
e
.
platform
}
->executablePath is not provided`
);
if
(
!
p
.
default
.
existsSync
(
e
.
executablePath
))
throw
Error
(
`
${
e
.
executablePath
}
not exists`
)}
return
e
},
create
:
async
function
(
e
,
t
,
s
){
X
&&
await
O
.
install
(),(
X
||
s
.
compiled
||
await
O
.
shouldPush
())
&&
await
O
.
push
(
e
),
await
O
.
start
()}},
adapter
:
j
,
beforeCompile
(
e
){
if
(
process
.
env
.
UNI_INPUT_DIR
&&
"
true
"
===
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
){
const
t
=
a
.
parse
(
r
.
readFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
"
utf8
"
)),
s
=
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
unpackage
"
,
"
.automator
"
,
"
app-webview
"
);
process
.
env
.
UNI_INPUT_DIR
=
h
.
default
.
resolve
(
s
,
"
src
"
),
process
.
env
.
UNI_OUTPUT_DIR
=
h
.
default
.
resolve
(
s
,
"
unpackage
"
,
"
dist
"
,
"
dev
"
),
r
.
existsSync
(
process
.
env
.
UNI_INPUT_DIR
)
&&
r
.
emptyDirSync
(
process
.
env
.
UNI_INPUT_DIR
),
r
.
copySync
(
h
.
default
.
resolve
(
e
,
"
lib
"
,
"
app-webview
"
,
"
project
"
),
process
.
env
.
UNI_INPUT_DIR
);
const
i
=
a
.
parse
(
r
.
readFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
"
utf8
"
));
r
.
writeFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
JSON
.
stringify
(
Object
.
assign
(
Object
.
assign
({},
i
),{
name
:
t
.
name
||
""
,
appid
:
t
.
appid
||
""
}),
null
,
2
))}
else
if
(
process
.
env
.
UNI_INPUT_DIR
&&
"
ios
"
===
process
.
env
.
UNI_OS_NAME
&&
O
.
app
&&
O
.
app
.
endsWith
(
"
.app
"
)){
const
e
=
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
uni_modules
"
);
if
(
!
p
.
default
.
existsSync
(
e
))
return
;
if
(
!
r
.
readdirSync
(
e
).
some
((
t
=>
r
.
existsSync
(
h
.
default
.
resolve
(
e
,
t
,
"
utssdk
"
)))))
return
;
process
.
env
.
UNI_APP_X
=
"
true
"
===
process
.
env
.
UNI_APP_X
?
"
1
"
:
"
0
"
,
process
.
env
.
HX_DEPENDENCIES_DIR
=
h
.
default
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
"
../../../cache/.automator/uts_standard_simulator
"
),
process
.
env
.
HX_RUN_DEVICE_TYPE
=
"
ios_simulator
"
,
O
.
app
&&
(
process
.
env
.
UTS_BASE_INFO
=
p
.
default
.
readFileSync
(
h
.
default
.
resolve
(
O
.
app
,
"
Frameworks/DCloudUTSFoundation.framework/uts-info.json
"
),
"
utf8
"
)),
!
process
.
env
.
HX_Version
&&
process
.
env
.
UNI_HBUILDERX_PLUGINS
&&
(
process
.
env
.
HX_Version
=
require
(
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
about
"
,
"
package.json
"
)).
version
),
C
(
"
HX_DEPENDENCIES_DIR
"
,
process
.
env
.
HX_DEPENDENCIES_DIR
),
C
(
"
UTS_BASE_INFO
"
,
process
.
env
.
UTS_BASE_INFO
)}},
afterCompile
(){
if
(
"
ios_simulator
"
===
process
.
env
.
HX_RUN_DEVICE_TYPE
&&
O
.
app
){
process
.
env
.
UNI_APP_X
=
"
1
"
===
process
.
env
.
UNI_APP_X
?
"
true
"
:
"
false
"
;
const
t
=
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
Resources
"
),
s
=
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
modules
"
),
a
=
p
.
default
.
existsSync
(
t
),
i
=
p
.
default
.
existsSync
(
s
),
o
=
(
e
=
h
.
default
.
basename
(
O
.
app
),
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
.automator/
"
+
e
));
if
(
!
a
&&!
i
)
return
;
if
(
r
.
existsSync
(
o
)
&&
r
.
emptyDirSync
(
o
),
r
.
copySync
(
O
.
app
,
o
),
O
.
app
=
o
,
a
&&
r
.
copySync
(
t
,
h
.
default
.
resolve
(
O
.
app
,
"
Resources
"
)),
i
){
const
e
=
[];
r
.
readdirSync
(
s
).
forEach
((
t
=>
{
t
.
endsWith
(
"
.framework
"
)
&&
(
e
.
push
(
t
),
r
.
copySync
(
h
.
default
.
join
(
s
,
t
),
h
.
default
.
resolve
(
O
.
app
,
"
Frameworks
"
,
t
)))})),
e
.
forEach
((
e
=>
{
const
t
=
`'
${
process
.
env
.
UNI_HBUILDERX_PLUGINS
}
/launcher-tools/tools/uts/optool' 'install' '-c' 'weak' '-p' '@rpath/
${
e
}
/
${
e
.
replace
(
"
.framework
"
,
""
)}
' '-t' '
${
O
.
app
}
'`
,
s
=
c
.
execSync
(
t
);
C
(
t
,
s
.
toString
())}))}
if
(
a
||
i
){
const
e
=
c
.
execSync
(
`codesign -fs "-" "
${
O
.
app
}
"`
);
C
(
"
codesign success
"
,
e
.
toString
())}}
var
e
}};
module
.
exports
=
L
;
"
use strict
"
;
var
e
=
require
(
"
fs
"
),
t
=
require
(
"
path
"
),
s
=
require
(
"
debug
"
),
r
=
require
(
"
jsonc-parser
"
),
a
=
require
(
"
fs-extra
"
),
i
=
require
(
"
postcss-selector-parser
"
),
o
=
require
(
"
licia/dateFormat
"
),
n
=
require
(
"
util
"
),
l
=
require
(
"
jimp
"
),
c
=
require
(
"
child_process
"
),
d
=
require
(
"
dns
"
);
function
u
(
e
){
return
e
&&
"
object
"
==
typeof
e
&&
"
default
"
in
e
?
e
:{
default
:
e
}}
var
p
=
u
(
e
),
h
=
u
(
t
),
m
=
u
(
s
),
f
=
u
(
a
),
y
=
u
(
i
),
v
=
u
(
o
),
_
=
u
(
l
),
I
=
u
(
d
);
function
P
(
e
){
e
.
walk
((
e
=>
{
if
(
"
tag
"
===
e
.
type
){
const
t
=
e
.
value
;
e
.
value
=
"
page
"
===
t
?
"
body
"
:
"
uni-
"
+
t
}}))}
m
.
default
(
"
automator:devtool
"
);
const
N
=
[
"
Page.getElement
"
,
"
Page.getElements
"
,
"
Element.getElement
"
,
"
Element.getElements
"
];
const
E
=
/^win/
.
test
(
process
.
platform
);
function
w
(
e
){
try
{
return
require
(
e
)}
catch
(
t
){
return
require
(
require
.
resolve
(
e
,{
paths
:[
process
.
cwd
()]}))}}
const
S
=
m
.
default
(
"
automator:launcher
"
),
$
=
n
.
promisify
(
p
.
default
.
readdir
),
g
=
n
.
promisify
(
p
.
default
.
stat
);
async
function
D
(
e
){
const
s
=
await
$
(
e
);
return
(
await
Promise
.
all
(
s
.
map
((
async
s
=>
{
const
r
=
t
.
resolve
(
e
,
s
);
return
(
await
g
(
r
)).
isDirectory
()?
D
(
r
):
r
})))).
reduce
(((
e
,
t
)
=>
e
.
concat
(
t
)),[])}
class
U
{
constructor
(
e
){
this
.
isX
=!
1
,
"
true
"
===
process
.
env
.
UNI_APP_X
&&
(
this
.
isX
=!
0
),
this
.
id
=
e
.
id
,
this
.
app
=
e
.
executablePath
,
this
.
appid
=
e
.
appid
||
process
.
env
.
UNI_APP_ID
||
(
this
.
isX
?
"
__UNI__uniappx
"
:
"
HBuilder
"
),
this
.
package
=
e
.
package
||
(
this
.
isX
?
"
io.dcloud.uniappx
"
:
"
io.dcloud.HBuilder
"
),
this
.
activity
=
e
.
activity
||
(
this
.
isX
?
"
io.dcloud.uniapp.UniAppActivity
"
:
"
io.dcloud.PandoraEntry
"
)}
shouldPush
(){
return
this
.
exists
(
this
.
FILE_APP_SERVICE
).
then
((()
=>
(
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
exists`
),
!
1
))).
catch
((()
=>
(
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
not exists`
),
!
0
)))}
push
(
e
){
return
D
(
e
).
then
((
s
=>
{
const
r
=
s
.
map
((
s
=>
{
const
r
=
(
e
=>
E
?
e
.
replace
(
/
\\
/g
,
"
/
"
):
e
)(
t
.
join
(
this
.
DIR_WWW
,
t
.
relative
(
e
,
s
)));
return
S
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
push
${
s
}
${
r
}
`
),
this
.
pushFile
(
s
,
r
)}));
return
Promise
.
all
(
r
)})).
then
((
e
=>!
0
))}
get
FILE_APP_SERVICE
(){
return
`
${
this
.
DIR_WWW
}
/app-service.js`
}}
const
A
=
m
.
default
(
"
automator:simctl
"
);
function
M
(
e
){
const
t
=
parseInt
(
e
);
return
t
>
9
?
String
(
t
):
"
0
"
+
t
}
class
R
extends
U
{
constructor
(){
super
(...
arguments
),
this
.
bundleVersion
=
""
}
async
init
(){
const
e
=
w
(
"
node-simctl
"
).
Simctl
;
this
.
tool
=
new
e
({
udid
:
this
.
id
});
try
{
await
this
.
tool
.
bootDevice
()}
catch
(
e
){}
await
this
.
initSDCard
(),
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
`
)}
async
initSDCard
(){
const
e
=
await
this
.
tool
.
appInfo
(
this
.
package
);
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
appInfo
${
e
}
`
);
const
t
=
e
.
match
(
/DataContainer
\s
+=
\s
+"
(
.*
)
"/
);
if
(
!
t
)
return
Promise
.
resolve
(
""
);
const
s
=
e
.
match
(
/CFBundleVersion
\s
+=
\s
+
(
.*
)
;/
);
if
(
!
s
)
return
Promise
.
resolve
(
""
);
this
.
sdcard
=
t
[
1
].
replace
(
"
file:
"
,
""
),
this
.
bundleVersion
=
s
[
1
],
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
sdcard
}
`
)}
async
version
(){
return
Promise
.
resolve
(
this
.
bundleVersion
)}
formatVersion
(
e
){
const
t
=
e
.
split
(
"
.
"
);
return
3
!==
t
.
length
?
e
:
t
[
0
]
+
M
(
t
[
1
])
+
M
(
t
[
2
])}
async
install
(){
return
A
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
`
),
await
this
.
tool
.
installApp
(
this
.
app
),
await
this
.
tool
.
grantPermission
(
this
.
package
,
"
all
"
),
await
this
.
initSDCard
(),
Promise
.
resolve
(
!
0
)}
async
start
(){
A
(
"
ios simulator start
"
);
try
{
await
this
.
tool
.
terminateApp
(
this
.
package
)}
catch
(
e
){
console
.
error
(
"
ios simulator start terminateApp fail
"
,
e
)}
try
{
await
this
.
tool
.
launchApp
(
this
.
package
)}
catch
(
e
){
console
.
error
(
"
ios simulator start launchApp fail
"
,
e
),
console
.
error
(
e
)}
return
Promise
.
resolve
(
!
0
)}
async
exit
(){
return
await
this
.
tool
.
terminateApp
(
this
.
package
),
await
this
.
tool
.
shutdownDevice
(),
Promise
.
resolve
(
!
0
)}
async
captureScreenshot
(
e
){
const
t
=
await
Promise
.
resolve
(
await
this
.
tool
.
getScreenshot
());
return
new
Promise
(((
s
,
r
)
=>
{
var
a
,
i
;
void
0
!==
(
null
===
(
a
=
null
==
e
?
void
0
:
e
.
area
)
||
void
0
===
a
?
void
0
:
a
.
x
)
&&
void
0
!==
(
null
===
(
i
=
null
==
e
?
void
0
:
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
y
)?
_
.
default
.
read
(
Buffer
.
from
(
t
,
"
base64
"
)).
then
((
t
=>
{
const
a
=
e
.
area
.
x
,
i
=
e
.
area
.
y
;
let
o
=
t
.
bitmap
.
width
-
a
;
e
.
area
.
width
&&
(
o
=
Math
.
min
(
o
,
e
.
area
.
width
));
let
n
=
t
.
bitmap
.
height
-
i
;
e
.
area
.
height
&&
(
n
=
Math
.
min
(
n
,
e
.
area
.
height
)),
t
.
crop
(
a
,
i
,
o
,
n
).
getBase64Async
(
_
.
default
.
MIME_PNG
).
then
((
e
=>
{
s
(
e
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
e
=>
{
r
(
e
)}))})).
catch
((
e
=>
{
r
(
e
)})):
s
(
t
)}))}
exists
(
e
){
return
f
.
default
.
existsSync
(
e
)?
Promise
.
resolve
(
!
0
):
Promise
.
reject
(
Error
(
`
${
e
}
not exists`
))}
pushFile
(
e
,
t
){
return
Promise
.
resolve
(
f
.
default
.
copySync
(
e
,
t
))}
adbCommand
(
e
){
return
new
Promise
((
e
=>
{
e
(
"
adbCommand only for App Android!
"
)}))}
swipe
(
e
){
return
new
Promise
((
t
=>
{
const
{
startPoint
:
s
,
endPoint
:
r
,
duration
:
a
}
=
e
;
c
.
exec
(
`idb connect
${
this
.
id
}
&& idb ui swipe
${
s
.
x
}
${
s
.
y
}
${
r
.
x
}
${
r
.
y
}
--duration
${
a
?
a
/
1
e3
:.
1
}
--udid
${
this
.
id
}
`
,(
e
=>
{
if
(
e
)
return
console
.
error
(
`exec error:
${
e
}
`
),
void
t
(
`swipe fail:
${
e
}
`
);
t
(
"
swipe success
"
)}))}))}
get
DIR_WWW
(){
return
"
true
"
===
process
.
env
.
UNI_APP_X
?
`
${
this
.
sdcard
}
/Documents/uni-app-x/apps/__UNI__uniappx/www/`
:
`
${
this
.
sdcard
}
/Documents/Pandora/apps/
${
this
.
appid
}
/www/`
}}
const
x
=
w
(
"
adbkit
"
),
H
=
m
.
default
(
"
automator:adb
"
);
class
b
extends
U
{
constructor
(){
super
(...
arguments
),
this
.
needStart
=!
0
}
async
init
(){
if
(
void
0
!==
I
.
default
.
setDefaultResultOrder
&&
I
.
default
.
setDefaultResultOrder
(
"
ipv4first
"
),
this
.
tool
=
x
.
createClient
(),
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
await
this
.
tool
.
version
()}
`
),
!
this
.
id
){
const
e
=
await
this
.
tool
.
listDevices
();
if
(
!
e
.
length
)
throw
Error
(
"
Device not found
"
);
this
.
id
=
e
[
0
].
id
}
console
.
log
(
"
before echo ${$EXTERNAL_STORAGE}
"
),
this
.
sdcard
=
(
await
this
.
shell
(
this
.
COMMAND_EXTERNAL
)).
trim
(),
console
.
log
(
"
after echo ${$EXTERNAL_STORAGE}
"
,
this
.
sdcard
),
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
${
this
.
sdcard
}
`
)}
root
(){
return
this
.
tool
.
root
(
this
.
id
).
then
((()
=>
{
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
this
.
sdcard
}
`
)})).
catch
((
e
=>
{
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
e
}
`
)}))}
version
(){
return
this
.
shell
(
this
.
COMMAND_VERSION
).
then
((
e
=>
{
const
t
=
e
.
match
(
/versionName=
(
.*
)
/
);
return
t
&&
t
.
length
>
1
?
t
[
1
]:
""
}))}
formatVersion
(
e
){
return
e
}
async
install
(){
let
e
=!
0
;
try
{
const
t
=
(
await
this
.
tool
.
getProperties
(
this
.
id
))[
"
ro.build.version.release
"
].
split
(
"
.
"
)[
0
];
parseInt
(
t
)
<
6
&&
(
e
=!
1
)}
catch
(
e
){}
if
(
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
permission=
${
e
}
`
),
e
){
const
e
=
w
(
"
adbkit/lib/adb/command.js
"
),
t
=
e
.
prototype
.
_send
;
e
.
prototype
.
_send
=
function
(
e
){
return
0
===
e
.
indexOf
(
"
shell:pm install -r
"
)
&&
(
e
=
e
.
replace
(
"
shell:pm install -r
"
,
"
shell:pm install -r -g
"
),
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
e
}
`
)),
t
.
call
(
this
,
e
)}}
return
this
.
tool
.
install
(
this
.
id
,
this
.
app
).
then
((()
=>
{
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
installed`
),
this
.
init
()}))}
start
(){
return
this
.
needStart
?
this
.
exit
().
then
((()
=>
this
.
shell
(
this
.
COMMAND_START
))):
Promise
.
resolve
()}
exit
(){
return
this
.
shell
(
this
.
COMMAND_STOP
)}
captureScreenshot
(
e
){
return
this
.
tool
.
screencap
(
this
.
id
).
then
((
t
=>
new
Promise
(((
s
,
r
)
=>
{
const
a
=
[];
t
.
on
(
"
data
"
,(
function
(
e
){
a
.
push
(
e
)})),
t
.
on
(
"
end
"
,(
function
(){
var
t
,
i
;
void
0
!==
(
null
===
(
t
=
e
.
area
)
||
void
0
===
t
?
void
0
:
t
.
x
)
&&
void
0
!==
(
null
===
(
i
=
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
y
)?
_
.
default
.
read
(
Buffer
.
concat
(
a
)).
then
((
t
=>
{
var
a
,
i
,
o
,
n
;
const
l
=
e
.
area
.
x
,
c
=
e
.
area
.
y
;
let
d
=
t
.
bitmap
.
width
-
l
;(
null
===
(
a
=
e
.
area
)
||
void
0
===
a
?
void
0
:
a
.
width
)
&&
(
d
=
Math
.
min
(
d
,
null
===
(
i
=
e
.
area
)
||
void
0
===
i
?
void
0
:
i
.
width
));
let
u
=
t
.
bitmap
.
height
-
c
;(
null
===
(
o
=
e
.
area
)
||
void
0
===
o
?
void
0
:
o
.
height
)
&&
(
u
=
Math
.
min
(
u
,
null
===
(
n
=
e
.
area
)
||
void
0
===
n
?
void
0
:
n
.
height
)),
t
.
crop
(
l
,
c
,
d
,
u
).
getBase64Async
(
_
.
default
.
MIME_PNG
).
then
((
e
=>
{
s
(
e
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
e
=>
{
r
(
e
)}))})).
catch
((
e
=>
{
r
(
e
)})):
s
(
Buffer
.
concat
(
a
).
toString
(
"
base64
"
))}))}))))}
adbCommand
(
e
){
return
new
Promise
((
t
=>
{
this
.
tool
.
shell
(
this
.
id
,
e
).
then
((
e
=>
{
let
s
,
r
=
""
;
e
.
on
(
"
data
"
,(
e
=>
{
r
+=
e
.
toString
(),
s
&&
clearTimeout
(
s
),
s
=
setTimeout
((()
=>
{
t
(
r
)}),
50
)})),
setTimeout
((()
=>
{
t
(
r
)}),
1500
)}))}))}
swipe
(
e
){
return
new
Promise
((
t
=>
{
this
.
tool
.
shell
(
this
.
id
,
`input swipe
${
e
.
startPoint
.
x
}
${
e
.
startPoint
.
y
}
${
e
.
endPoint
.
x
}
${
e
.
endPoint
.
y
}
${
e
.
duration
||
100
}
`
).
then
((
e
=>
{
let
s
,
r
=
""
;
e
.
on
(
"
data
"
,(
e
=>
{
r
+=
e
.
toString
(),
s
&&
clearTimeout
(
s
),
s
=
setTimeout
((()
=>
{
t
(
r
)}),
50
)})),
setTimeout
((()
=>
{
t
(
r
)}),
1500
)}))}))}
exists
(
e
){
return
this
.
tool
.
stat
(
this
.
id
,
e
)}
pushFile
(
e
,
t
){
return
this
.
tool
.
push
(
this
.
id
,
e
,
t
)}
async
push
(
e
){
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
return
super
.
push
(
e
);
const
t
=
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
launcher
"
,
"
out
"
,
"
export
"
,
"
pushResources.js
"
),
s
=
process
.
env
.
HX_CONFIG_ADB_PATH
||
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
launcher-tools
"
,
"
tools
"
,
"
adbs
"
,
"
adb
"
),
r
=
[
t
,
s
].
map
((
e
=>
p
.
default
.
promises
.
access
(
e
,
p
.
default
.
constants
.
F_OK
).
then
((()
=>
`
${
e
}
exists`
)).
catch
((()
=>
`
${
e
}
not exists`
))));
return
Promise
.
all
(
r
).
then
((()
=>
{
const
{
PushResources
:
r
}
=
require
(
t
);
return
new
r
({
adbPath
:
s
,
appid
:
this
.
appid
,
uuid
:
this
.
id
,
packageName
:
this
.
package
,
sourcePath
:
e
}).
start
(),
this
.
needStart
=!
1
,
!
0
})).
catch
((
async
t
=>
(
console
.
log
(
"
pushResources or adb not exists:
"
,
t
),
await
super
.
push
(
e
))))}
shell
(
e
){
return
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
SEND ►
${
e
}
`
),
this
.
tool
.
shell
(
this
.
id
,
e
).
then
(
x
.
util
.
readAll
).
then
((
e
=>
{
const
t
=
e
.
toString
();
return
H
(
`
${
v
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
◀ RECV
${
t
}
`
),
t
}))}
get
DIR_WWW
(){
return
`/storage/emulated/0/Android/data/
${
this
.
package
}
/apps/
${
this
.
appid
}
/www`
}
get
COMMAND_EXTERNAL
(){
return
"
echo $EXTERNAL_STORAGE
"
}
get
COMMAND_VERSION
(){
return
`dumpsys package
${
this
.
package
}
`
}
get
COMMAND_STOP
(){
return
`am force-stop
${
this
.
package
}
`
}
get
COMMAND_START
(){
return
`am start -n
${
this
.
package
}
/
${
this
.
activity
}
--es appid
${
this
.
appid
}
--ez needUpdateApp false --ez reload true --ez externalStorage true`
}}
const
T
=
m
.
default
(
"
automator:devtool
"
);
let
C
,
O
=!
1
;
const
X
=
{
android
:
/android_version=
(
.*
)
/
,
ios
:
/iphone_version=
(
.*
)
/
};
const
k
=
{
"
Tool.close
"
:{
reflect
:
async
()
=>
{}},
"
App.exit
"
:{
reflect
:
async
()
=>
C
.
exit
()},
"
App.enableLog
"
:{
reflect
:()
=>
Promise
.
resolve
()},
"
App.captureScreenshotWithDevice
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
C
.
captureScreenshot
(
t
);
return
T
(
`App.captureScreenshot
${
s
.
length
}
`
),{
data
:
s
}}},
"
App.adbCommand
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
C
.
adbCommand
(
t
);
return
T
(
`App.adbCommand
${
s
.
length
}
`
),{
data
:
s
}}},
"
App.swipe
"
:{
reflect
:
async
(
e
,
t
)
=>
{
const
s
=
await
C
.
swipe
(
t
);
return
T
(
`App.swipe
${
s
.
length
}
`
),{
data
:
s
}}}};
!
function
(
e
){
N
.
forEach
((
t
=>
{
e
[
t
]
=
function
(
e
){
return
{
reflect
:
async
(
t
,
s
)
=>
t
(
e
,
s
,
!
1
),
params
:
e
=>
(
e
.
selector
&&
(
e
.
selector
=
y
.
default
(
P
).
processSync
(
e
.
selector
)),
e
)}}(
t
)}))}(
k
);
const
j
=
{
devtools
:{
name
:
"
App
"
,
paths
:[],
required
:[
"
manifest.json
"
,
"
app-service.js
"
],
validate
:
async
function
(
e
,
t
){
e
.
platform
=
(
e
.
platform
||
process
.
env
.
UNI_OS_NAME
).
toLocaleLowerCase
(),
Object
.
assign
(
e
,
e
[
e
.
platform
]),
C
=
function
(
e
,
t
){
return
"
ios
"
===
e
?
new
R
(
t
):
new
b
(
t
)}(
e
.
platform
,
e
),
await
C
.
init
();
const
s
=
await
C
.
version
();
if
(
s
){
if
(
e
.
version
){
const
t
=
C
.
formatVersion
(
function
(
e
,
t
){
if
(
e
.
endsWith
(
"
.txt
"
))
try
{
const
s
=
p
.
default
.
readFileSync
(
e
).
toString
().
match
(
X
[
t
]);
if
(
s
)
return
s
[
1
]}
catch
(
e
){
console
.
error
(
e
)}
return
e
}(
e
.
version
,
e
.
platform
));
T
(
`version:
${
s
}
`
),
T
(
`newVersion:
${
t
}
`
),
t
!==
s
&&
(
O
=!
0
)}}
else
O
=!
0
;
if
(
O
){
if
(
!
e
.
executablePath
)
throw
Error
(
`app-plus->
${
e
.
platform
}
->executablePath is not provided`
);
if
(
!
p
.
default
.
existsSync
(
e
.
executablePath
))
throw
Error
(
`
${
e
.
executablePath
}
not exists`
)}
return
e
},
create
:
async
function
(
e
,
t
,
s
){
O
&&
await
C
.
install
(),(
O
||
s
.
compiled
||
await
C
.
shouldPush
())
&&
await
C
.
push
(
e
),
await
C
.
start
()}},
adapter
:
k
,
beforeCompile
(
e
){
if
(
process
.
env
.
UNI_INPUT_DIR
&&
"
true
"
===
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
){
const
t
=
r
.
parse
(
a
.
readFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
"
utf8
"
)),
s
=
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
unpackage
"
,
"
.automator
"
,
"
app-webview
"
);
process
.
env
.
UNI_INPUT_DIR
=
h
.
default
.
resolve
(
s
,
"
src
"
),
process
.
env
.
UNI_OUTPUT_DIR
=
h
.
default
.
resolve
(
s
,
"
unpackage
"
,
"
dist
"
,
"
dev
"
),
a
.
existsSync
(
process
.
env
.
UNI_INPUT_DIR
)
&&
a
.
emptyDirSync
(
process
.
env
.
UNI_INPUT_DIR
),
a
.
copySync
(
h
.
default
.
resolve
(
e
,
"
lib
"
,
"
app-webview
"
,
"
project
"
),
process
.
env
.
UNI_INPUT_DIR
);
const
i
=
r
.
parse
(
a
.
readFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
"
utf8
"
));
a
.
writeFileSync
(
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
manifest.json
"
),
JSON
.
stringify
(
Object
.
assign
(
Object
.
assign
({},
i
),{
name
:
t
.
name
||
""
,
appid
:
t
.
appid
||
""
}),
null
,
2
))}
else
if
(
process
.
env
.
UNI_INPUT_DIR
&&
"
ios
"
===
process
.
env
.
UNI_OS_NAME
&&
C
.
app
&&
C
.
app
.
endsWith
(
"
.app
"
)){
const
e
=
h
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
"
uni_modules
"
);
if
(
!
p
.
default
.
existsSync
(
e
))
return
;
if
(
!
a
.
readdirSync
(
e
).
some
((
t
=>
a
.
existsSync
(
h
.
default
.
resolve
(
e
,
t
,
"
utssdk
"
)))))
return
;
process
.
env
.
UNI_APP_X
=
"
true
"
===
process
.
env
.
UNI_APP_X
?
"
1
"
:
"
0
"
,
process
.
env
.
HX_DEPENDENCIES_DIR
=
h
.
default
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
"
../../../cache/.automator/uts_standard_simulator
"
),
process
.
env
.
HX_RUN_DEVICE_TYPE
=
"
ios_simulator
"
,
C
.
app
&&
(
process
.
env
.
UTS_BASE_INFO
=
p
.
default
.
readFileSync
(
h
.
default
.
resolve
(
C
.
app
,
"
Frameworks/DCloudUTSFoundation.framework/uts-info.json
"
),
"
utf8
"
)),
!
process
.
env
.
HX_Version
&&
process
.
env
.
UNI_HBUILDERX_PLUGINS
&&
(
process
.
env
.
HX_Version
=
require
(
h
.
default
.
join
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
"
about
"
,
"
package.json
"
)).
version
),
T
(
"
HX_DEPENDENCIES_DIR
"
,
process
.
env
.
HX_DEPENDENCIES_DIR
),
T
(
"
UTS_BASE_INFO
"
,
process
.
env
.
UTS_BASE_INFO
)}},
afterCompile
(){
if
(
"
ios_simulator
"
===
process
.
env
.
HX_RUN_DEVICE_TYPE
&&
C
.
app
){
process
.
env
.
UNI_APP_X
=
"
1
"
===
process
.
env
.
UNI_APP_X
?
"
true
"
:
"
false
"
;
const
t
=
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
Resources
"
),
s
=
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
modules
"
),
r
=
p
.
default
.
existsSync
(
t
),
i
=
p
.
default
.
existsSync
(
s
),
o
=
(
e
=
h
.
default
.
basename
(
C
.
app
),
h
.
default
.
resolve
(
process
.
env
.
HX_DEPENDENCIES_DIR
,
"
.automator/
"
+
e
));
if
(
!
r
&&!
i
)
return
;
if
(
a
.
existsSync
(
o
)
&&
a
.
emptyDirSync
(
o
),
a
.
copySync
(
C
.
app
,
o
),
C
.
app
=
o
,
r
&&
a
.
copySync
(
t
,
h
.
default
.
resolve
(
C
.
app
,
"
Resources
"
)),
i
){
const
e
=
[];
a
.
readdirSync
(
s
).
forEach
((
t
=>
{
t
.
endsWith
(
"
.framework
"
)
&&
(
e
.
push
(
t
),
a
.
copySync
(
h
.
default
.
join
(
s
,
t
),
h
.
default
.
resolve
(
C
.
app
,
"
Frameworks
"
,
t
)))})),
e
.
forEach
((
e
=>
{
const
t
=
`'
${
process
.
env
.
UNI_HBUILDERX_PLUGINS
}
/launcher-tools/tools/uts/optool' 'install' '-c' 'weak' '-p' '@rpath/
${
e
}
/
${
e
.
replace
(
"
.framework
"
,
""
)}
' '-t' '
${
C
.
app
}
'`
,
s
=
c
.
execSync
(
t
);
T
(
t
,
s
.
toString
())}))}
if
(
r
||
i
){
const
e
=
c
.
execSync
(
`codesign -fs "-" "
${
C
.
app
}
"`
);
T
(
"
codesign success
"
,
e
.
toString
())}}
var
e
}};
module
.
exports
=
j
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录