Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
4b67163d
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b67163d
编写于
6月 27, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): swift
上级
1ee9bfad
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
162 addition
and
101 deletion
+162
-101
packages/playground/uts/nativeplugins/test-uniplugin/ios/src/TestModuleImpl.uts
...s/nativeplugins/test-uniplugin/ios/src/TestModuleImpl.uts
+27
-0
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/ios/src/TestModuleImpl.swift
...nativeplugins/test-uniplugin/ios/src/TestModuleImpl.swift
+11
-0
packages/uts-darwin-arm64/uts.darwin-arm64.node
packages/uts-darwin-arm64/uts.darwin-arm64.node
+0
-0
packages/uts-darwin-x64/uts.darwin-x64.node
packages/uts-darwin-x64/uts.darwin-x64.node
+0
-0
packages/uts/src/api.ts
packages/uts/src/api.ts
+5
-4
packages/uts/src/cli.ts
packages/uts/src/cli.ts
+8
-1
packages/uts/src/index.ts
packages/uts/src/index.ts
+93
-79
packages/uts/src/types.ts
packages/uts/src/types.ts
+6
-17
scripts/test.js
scripts/test.js
+12
-0
未找到文件。
packages/playground/uts/nativeplugins/test-uniplugin/ios/src/TestModuleImpl.uts
0 → 100644
浏览文件 @
4b67163d
//
// TestModuleImpl.swift
// libWeex
//
// Created by dcloud on 2022/6/1.
// Copyright © 2022 DCloud. All rights reserved.
//
@objcMembers
class TestModuleImpl extends NSObject {
testAsyncFunc(option: NSDictionary, callback: UniModuleKeepAliveCallback) {
// options 为 js 端调用此方法时传递的参数
console.log(option)
// // 可以在该方法中实现原生能力,然后通过 callback 回调到 js
//
// // 回调方法,传递参数给 js 端 注:只支持返回 String 或 NSDictionary (map) 类型
// 第一个参数为回传给js端的数据,第二个参数为标识,表示该回调方法是否支持多次调用,如果原生端需要多次回调js端则第二个参数传 YES;
callback('success', false)
}
/// 同步方法(注:同步方法会在 js 线程执行)
/// @param options js 端调用方法时传递的参数
testSyncFunc(option: NSDictionary): string {
console.log(option)
return ''
}
}
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/ios/src/TestModuleImpl.swift
0 → 100644
浏览文件 @
4b67163d
@objcMembers
class
TestModuleImpl
:
NSObject
{
func
testAsyncFunc
(
option
:
NSDictionary
,
callback
:
UniModuleKeepAliveCallback
)
{
console
.
log
(
option
);
callback
(
"success"
,
false
);
}
func
testSyncFunc
(
option
:
NSDictionary
)
->
String
{
console
.
log
(
option
);
return
""
;
}
}
packages/uts-darwin-arm64/uts.darwin-arm64.node
浏览文件 @
4b67163d
无法预览此类型文件
packages/uts-darwin-x64/uts.darwin-x64.node
浏览文件 @
4b67163d
无法预览此类型文件
packages/uts/src/api.ts
浏览文件 @
4b67163d
import
{
resolve
}
from
'
path
'
import
type
{
Uts
KotlinOptions
,
UtsResult
,
UtsSwiftOptions
}
from
'
./types
'
import
type
{
Uts
Options
,
UtsResult
}
from
'
./types
'
import
{
normalizePath
}
from
'
./utils
'
const
bindingsOverride
=
process
.
env
[
'
UTS_BINARY_PATH
'
]
...
...
@@ -7,7 +7,7 @@ const bindings = !!bindingsOverride
?
require
(
resolve
(
bindingsOverride
))
:
require
(
'
./binding
'
).
default
function
resolveOptions
(
options
:
Uts
KotlinOptions
|
UtsSwift
Options
)
{
function
resolveOptions
(
options
:
UtsOptions
)
{
const
{
input
,
output
}
=
options
if
(
!
input
?.
root
)
{
return
...
...
@@ -32,10 +32,11 @@ function resolveOptions(options: UtsKotlinOptions | UtsSwiftOptions) {
input
.
filename
=
normalizePath
(
input
.
filename
)
output
.
outDir
=
normalizePath
(
output
.
outDir
)
output
.
sourceMap
=
normalizePath
(
output
.
sourceMap
)
return
options
}
export
function
toKotlin
(
options
:
Uts
Kotlin
Options
):
Promise
<
UtsResult
>
{
export
function
toKotlin
(
options
:
UtsOptions
):
Promise
<
UtsResult
>
{
const
kotlinOptions
=
resolveOptions
(
options
)
if
(
!
kotlinOptions
)
{
return
Promise
.
resolve
({})
...
...
@@ -45,7 +46,7 @@ export function toKotlin(options: UtsKotlinOptions): Promise<UtsResult> {
.
then
((
res
:
string
)
=>
JSON
.
parse
(
res
))
}
export
function
toSwift
(
options
:
Uts
Swift
Options
):
Promise
<
UtsResult
>
{
export
function
toSwift
(
options
:
UtsOptions
):
Promise
<
UtsResult
>
{
const
swiftOptions
=
resolveOptions
(
options
)
if
(
!
swiftOptions
)
{
return
Promise
.
resolve
({})
...
...
packages/uts/src/cli.ts
浏览文件 @
4b67163d
import
{
cac
}
from
'
cac
'
import
{
runBuild
,
runDev
,
ToOptions
,
UtsTarget
}
from
'
./index
'
import
{
runBuild
,
runDev
,
ToOptions
,
UtsTarget
,
UtsTargetExtNames
,
}
from
'
./index
'
const
cli
=
cac
(
'
uts
'
)
...
...
@@ -47,6 +53,7 @@ cli
dir
:
output
,
sourceMap
:
opts
.
sourceMap
,
inlineSourcesContent
:
opts
.
inlineSourcesContent
,
extname
:
UtsTargetExtNames
[
opts
.
target
],
},
}
return
opts
.
watch
...
...
packages/uts/src/index.ts
浏览文件 @
4b67163d
...
...
@@ -2,13 +2,13 @@ import path from 'path'
import
fs
from
'
fs-extra
'
import
glob
from
'
fast-glob
'
import
{
watch
}
from
'
chokidar
'
import
chokidar
from
'
chokidar
'
import
{
toKotlin
}
from
'
./api
'
import
{
toKotlin
,
toSwift
}
from
'
./api
'
import
type
{
InputKotlin
Options
,
OutputKotlin
Options
,
Uts
Kotlin
Options
,
UtsInput
Options
,
Uts
Options
,
Uts
Output
Options
,
UtsResult
,
}
from
'
./types
'
import
{
printStartup
,
printUtsResult
,
printUtsResults
,
timeEnd
}
from
'
./utils
'
...
...
@@ -20,10 +20,15 @@ export enum UtsTarget {
export
type
UtsMode
=
'
dev
'
|
'
build
'
const
t
argetDirs
=
{
const
UtsT
argetDirs
=
{
[
UtsTarget
.
KOTLIN
]:
'
android
'
,
[
UtsTarget
.
SWIFT
]:
'
ios
'
,
}
as
const
export
const
UtsTargetExtNames
=
{
[
UtsTarget
.
KOTLIN
]:
'
kt
'
,
[
UtsTarget
.
SWIFT
]:
'
swift
'
,
}
as
const
export
interface
ToOptions
{
/**
* 为 true 时,禁用日志输出,默认为 false
...
...
@@ -52,20 +57,18 @@ export interface ToOptions {
* sourceMap 中是否包含源码
*/
inlineSourcesContent
?:
boolean
extname
:
string
}
}
interface
ToKotlinOptions
extends
ToOptions
{}
interface
ToSwiftOptions
extends
ToOptions
{}
function
resolveDefaultOutputDir
(
mode
:
UtsMode
,
inputDir
:
string
)
{
return
path
.
resolve
(
inputDir
,
'
../dist/
'
+
mode
)
}
function
parseOptions
(
mode
:
UtsMode
,
target
:
UtsTarget
,
opts
:
Partial
<
To
Kotlin
Options
>
)
{
opts
:
Partial
<
ToOptions
>
)
:
ToOptions
{
const
{
input
}
=
opts
if
(
!
input
?.
dir
)
{
throw
new
Error
(
`input.dir is required.`
)
...
...
@@ -73,12 +76,8 @@ function parseOptions(
if
(
!
fs
.
existsSync
(
input
.
dir
))
{
throw
new
Error
(
`
${
input
}
is not found.`
)
}
let
inputSrcDir
:
string
=
''
if
(
target
===
UtsTarget
.
KOTLIN
)
{
inputSrcDir
=
resolveKotlinSrcDir
(
input
.
dir
)
}
else
{
throw
new
Error
(
`
${
target
}
is unsupported.`
)
}
const
inputSrcDir
:
string
=
resolveSrcDir
(
target
,
input
.
dir
)
if
(
!
fs
.
existsSync
(
inputSrcDir
))
{
throw
new
Error
(
`
${
inputSrcDir
}
is not found.`
)
...
...
@@ -88,77 +87,90 @@ function parseOptions(
opts
.
output
=
{
dir
:
''
,
sourceMap
:
''
,
extname
:
UtsTargetExtNames
[
target
],
}
}
if
(
!
opts
.
output
.
dir
)
{
opts
.
output
.
dir
=
resolveDefaultOutputDir
(
mode
,
input
.
dir
)
}
opts
.
silent
=
opts
.
silent
===
true
return
opts
as
To
Kotlin
Options
return
opts
as
ToOptions
}
const
EXTNAME
=
'
.uts
'
function
resolve
KotlinSrcDir
(
dir
:
string
)
{
return
path
.
join
(
dir
,
targetDirs
[
UtsTarget
.
KOTLIN
]
+
'
/src
'
)
function
resolve
SrcDir
(
target
:
UtsTarget
,
dir
:
string
)
{
return
path
.
join
(
dir
,
UtsTargetDirs
[
target
]
+
'
/src
'
)
}
function
initInput
KotlinOptions
(
root
:
string
):
InputKotlin
Options
{
function
initInput
Options
(
root
:
string
):
UtsInput
Options
{
return
{
root
,
filename
:
''
,
}
}
function
initOutputKotlinOptions
(
function
initOutputOptions
(
target
:
UtsTarget
,
outDir
:
string
,
sourceMap
:
string
|
boolean
,
inlineSourcesContent
:
boolean
):
OutputKotlin
Options
{
):
UtsOutput
Options
{
return
{
outDir
,
sourceMap
,
inlineSourcesContent
,
extname
:
UtsTargetExtNames
[
target
],
}
}
function
watchSwift
(
_
:
ToSwiftOptions
)
{}
function
buildSwift
(
_
:
ToSwiftOptions
)
{}
function
watchKotlin
({
silent
,
input
:
{
dir
:
inputDir
,
extname
},
output
:
{
dir
:
outputDir
,
sourceMap
,
inlineSourcesContent
},
}:
ToKotlinOptions
)
{
function
watch
(
target
:
UtsTarget
,
{
silent
,
input
:
{
dir
:
inputDir
,
extname
},
output
:
{
dir
:
outputDir
,
sourceMap
,
inlineSourcesContent
},
}:
ToOptions
)
{
fs
.
emptyDirSync
(
outputDir
)
extname
=
extname
||
EXTNAME
const
inputSrcDir
=
resolve
KotlinSrcDir
(
inputDir
)
const
outputSrcDir
=
resolve
KotlinSrcDir
(
outputDir
)
const
inputSrcDir
=
resolve
SrcDir
(
UtsTarget
.
KOTLIN
,
inputDir
)
const
outputSrcDir
=
resolve
SrcDir
(
UtsTarget
.
KOTLIN
,
outputDir
)
const
input
=
initInputKotlinOptions
(
inputSrcDir
)
const
output
=
initOutputKotlinOptions
(
const
input
=
initInputOptions
(
inputSrcDir
)
const
output
=
initOutputOptions
(
target
,
outputSrcDir
,
sourceMap
,
!!
inlineSourcesContent
)
watch
(
'
**/*
'
+
extname
,
{
cwd
:
inputSrcDir
,
ignored
:
[
'
**/*.d
'
+
extname
],
})
chokidar
.
watch
(
'
**/*
'
+
extname
,
{
cwd
:
inputSrcDir
,
ignored
:
[
'
**/*.d
'
+
extname
],
})
.
on
(
'
add
'
,
(
filename
)
=>
{
buildKotlinFile
(
path
.
resolve
(
inputSrcDir
,
filename
),
input
,
output
).
then
(
(
res
)
=>
{
!
silent
&&
printUtsResult
(
res
)
}
)
buildFile
(
target
,
path
.
resolve
(
inputSrcDir
,
filename
),
input
,
output
).
then
((
res
)
=>
{
!
silent
&&
printUtsResult
(
res
)
})
})
.
on
(
'
change
'
,
(
filename
)
=>
{
buildKotlinFile
(
path
.
resolve
(
inputSrcDir
,
filename
),
input
,
output
).
then
(
(
res
)
=>
{
!
silent
&&
printUtsResult
(
res
)
}
)
buildFile
(
target
,
path
.
resolve
(
inputSrcDir
,
filename
),
input
,
output
).
then
((
res
)
=>
{
!
silent
&&
printUtsResult
(
res
)
})
})
.
on
(
'
unlink
'
,
(
filename
)
=>
{
try
{
...
...
@@ -169,20 +181,23 @@ function watchKotlin({
copyAssets
(
UtsTarget
.
KOTLIN
,
inputDir
,
outputDir
,
extname
!
)
})
}
function
buildKotlin
({
silent
,
input
:
{
dir
:
inputDir
,
extname
},
output
:
{
dir
:
outputDir
,
sourceMap
,
inlineSourcesContent
},
}:
ToKotlinOptions
)
{
fs
.
emptyDirSync
(
outputDir
)
function
build
(
target
:
UtsTarget
,
{
silent
,
input
:
{
dir
:
inputDir
,
extname
},
output
:
{
dir
:
outputDir
,
sourceMap
,
inlineSourcesContent
},
}:
ToOptions
)
{
extname
=
extname
||
EXTNAME
const
inputSrcDir
=
resolveKotlinSrcDir
(
inputDir
)
const
outputSrcDir
=
resolveKotlinSrcDir
(
outputDir
)
const
input
=
initInputKotlinOptions
(
inputSrcDir
)
const
output
=
initOutputKotlinOptions
(
const
inputSrcDir
=
resolveSrcDir
(
target
,
inputDir
)
const
outputSrcDir
=
resolveSrcDir
(
target
,
outputDir
)
// fs.emptyDirSync(outputSrcDir)
const
input
=
initInputOptions
(
inputSrcDir
)
const
output
=
initOutputOptions
(
target
,
outputSrcDir
,
sourceMap
,
!!
inlineSourcesContent
...
...
@@ -196,7 +211,7 @@ function buildKotlin({
return
Promise
.
all
(
files
.
map
((
filename
)
=>
build
KotlinFile
(
filename
,
input
,
output
).
catch
((
error
)
=>
{
build
File
(
target
,
filename
,
input
,
output
).
catch
((
error
)
=>
{
return
{
error
,
}
as
UtsResult
...
...
@@ -222,8 +237,8 @@ function copyAssets(
)
{
inputDir
=
path
.
resolve
(
inputDir
)
outputDir
=
path
.
resolve
(
outputDir
)
const
kotlinRootDir
=
path
.
join
(
inputDir
,
t
argetDirs
[
UtsTarget
.
KOTLIN
])
const
swiftRootDir
=
path
.
join
(
inputDir
,
t
argetDirs
[
UtsTarget
.
SWIFT
])
const
kotlinRootDir
=
path
.
join
(
inputDir
,
UtsT
argetDirs
[
UtsTarget
.
KOTLIN
])
const
swiftRootDir
=
path
.
join
(
inputDir
,
UtsT
argetDirs
[
UtsTarget
.
SWIFT
])
return
fs
.
copy
(
inputDir
,
outputDir
,
{
filter
(
src
)
{
if
(
target
===
UtsTarget
.
KOTLIN
)
{
...
...
@@ -235,17 +250,24 @@ function copyAssets(
return
false
}
}
if
(
path
.
basename
(
src
).
startsWith
(
'
.
'
))
{
return
false
}
if
(
fs
.
lstatSync
(
src
).
isDirectory
())
{
return
false
}
return
!
[
extname
,
'
.ts
'
].
includes
(
path
.
extname
(
src
))
},
})
}
function
buildKotlinFile
(
function
buildFile
(
target
:
UtsTarget
,
filename
:
string
,
input
:
InputKotlin
Options
,
output
:
OutputKotlin
Options
input
:
UtsInput
Options
,
output
:
UtsOutput
Options
)
{
const
to
KotlinOptions
:
UtsKotlin
Options
=
{
const
to
Options
:
Uts
Options
=
{
input
:
{
...
input
,
filename
,
...
...
@@ -256,7 +278,9 @@ function buildKotlinFile(
},
}
const
start
=
process
.
hrtime
()
return
toKotlin
(
toKotlinOptions
).
then
((
res
)
=>
{
return
(
target
===
UtsTarget
.
KOTLIN
?
toKotlin
(
toOptions
)
:
toSwift
(
toOptions
)
).
then
((
res
)
=>
{
res
.
time
=
timeEnd
(
start
)
return
res
})
...
...
@@ -265,21 +289,11 @@ function buildKotlinFile(
export
function
runDev
(
target
:
UtsTarget
,
opts
:
ToOptions
)
{
opts
=
parseOptions
(
'
dev
'
,
target
,
opts
)
!
opts
.
silent
&&
printStartup
(
target
,
'
development
'
)
switch
(
target
)
{
case
UtsTarget
.
KOTLIN
:
return
watchKotlin
(
opts
)
case
UtsTarget
.
SWIFT
:
return
watchSwift
(
opts
)
}
watch
(
target
,
opts
)
}
export
function
runBuild
(
target
:
UtsTarget
,
opts
:
ToOptions
)
{
opts
=
parseOptions
(
'
build
'
,
target
,
opts
)
!
opts
.
silent
&&
printStartup
(
target
,
'
production
'
)
switch
(
target
)
{
case
UtsTarget
.
KOTLIN
:
return
buildKotlin
(
opts
)
case
UtsTarget
.
SWIFT
:
return
buildSwift
(
opts
)
}
build
(
target
,
opts
)
}
packages/uts/src/types.ts
浏览文件 @
4b67163d
...
...
@@ -18,33 +18,22 @@ export type UtsParseOptions = UtsParserConfig & {
comments
?:
boolean
}
export
type
InputKotlin
Options
=
UtsParseOptions
&
{
export
type
UtsInput
Options
=
UtsParseOptions
&
{
root
:
string
filename
:
string
namespace
?:
string
}
export
type
OutputKotlin
Options
=
{
export
type
UtsOutput
Options
=
{
outDir
:
string
imports
?:
string
[]
sourceMap
:
boolean
|
string
inlineSourcesContent
?:
boolean
extname
:
string
}
export
interface
UtsKotlinOptions
{
input
:
InputKotlinOptions
output
:
OutputKotlinOptions
}
export
type
InputSwiftOptions
=
UtsParseOptions
&
{
root
:
string
filename
:
string
}
export
type
OutputSwiftOptions
=
OutputKotlinOptions
export
interface
UtsSwiftOptions
{
input
:
InputSwiftOptions
output
:
OutputSwiftOptions
export
interface
UtsOptions
{
input
:
UtsInputOptions
output
:
UtsOutputOptions
}
export
interface
UtsResult
{
...
...
scripts/test.js
浏览文件 @
4b67163d
...
...
@@ -14,3 +14,15 @@ runBuild(UtsTarget.KOTLIN, {
inlineSourcesContent
:
false
,
},
})
runBuild
(
UtsTarget
.
SWIFT
,
{
silent
:
false
,
input
:
{
dir
:
path
.
resolve
(
projectDir
,
'
nativeplugins/test-uniplugin
'
),
extname
:
'
.uts
'
,
},
output
:
{
dir
:
path
.
resolve
(
projectDir
,
'
unpackage/nativeplugins/test-uniplugin
'
),
sourceMap
:
false
,
inlineSourcesContent
:
false
,
},
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录