提交 901f51bf 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 45a8193d
import android.util.Log;
fun login(name: String, pwd: String): UtsJSONObject {
return object : UtsJSONObject() {
var name = name
var pwd = pwd
};
}
open class User {
open suspend fun login(name: String, pwd: String) = CoroutineScope(Dispatchers.Default).async {
login(name, pwd);
Log.info("123");
}
}
......@@ -25,6 +25,7 @@ import { compile, parsePackage } from '../utils/compiler'
export function uniUtsV1Plugin(): Plugin {
// 目前仅支持 app-android
process.env.UNI_APP_PLATFORM = 'app-android'
let isFirst = true
return {
name: 'uni:uts-v1',
apply: 'build',
......@@ -59,9 +60,24 @@ const pkg = '${pkg}'
const cls = 'IndexKt'
${genProxyCode(ast)}
`
await compile(id)
const dexFile = await compile(id)
if (!isFirst && dexFile) {
const files = []
if (process.env.UNI_APP_CHANGED_DEX_FILES) {
try {
files.push(...JSON.parse(process.env.UNI_APP_CHANGED_DEX_FILES))
} catch (e) {}
}
files.push(dexFile)
process.env.UNI_APP_CHANGED_DEX_FILES = JSON.stringify([
...new Set(files),
])
}
return code
},
buildEnd() {
isFirst = false
},
}
}
......@@ -216,7 +232,7 @@ function genVariableDeclarationCode(decl: VariableDeclaration) {
return false
})
) {
return `${decl.kind} ${decl.declarations
return `export ${decl.kind} ${decl.declarations
.map((d) => `${(d.id as Identifier).value} = ${genInitCode(d.init!)}`)
.join(', ')}`
}
......
......@@ -80,11 +80,19 @@ export async function compile(filename: string) {
// 短期内先不删除,方便排查问题
// fs.unlinkSync(kotlinFile)
} catch (e) {}
const dexFile = resolveDexFile(jarFile)
if (fs.existsSync(dexFile)) {
return normalizePath(path.relative(outputDir, dexFile))
}
}
}
}
}
function resolveDexFile(jarFile: string) {
return normalizePath(path.resolve(path.dirname(jarFile), 'classes.dex'))
}
function resolveKotlinFile(
filename: string,
inputDir: string,
......
......@@ -45,10 +45,15 @@ export async function runDev(options: CliOptions & ServerOptions) {
}
const files = process.env.UNI_APP_CHANGED_FILES
const pages = process.env.UNI_APP_CHANGED_PAGES
const dex = process.env.UNI_APP_CHANGED_DEX_FILES
const changedFiles = pages || files
process.env.UNI_APP_CHANGED_PAGES = ''
process.env.UNI_APP_CHANGED_FILES = ''
if (changedFiles && !changedFiles.includes(APP_CONFIG_SERVICE)) {
process.env.UNI_APP_CHANGED_DEX_FILES = ''
if (
(changedFiles && !changedFiles.includes(APP_CONFIG_SERVICE)) ||
dex
) {
if (pages) {
return output(
'log',
......@@ -57,7 +62,14 @@ export async function runDev(options: CliOptions & ServerOptions) {
}
return output(
'log',
M['dev.watching.end.files'].replace('{files}', changedFiles)
M['dev.watching.end.files'].replace(
'{files}',
JSON.stringify(
JSON.parse(changedFiles || JSON.stringify([])).concat(
JSON.parse(dex || JSON.stringify([]))
)
)
)
)
}
return output('log', M['dev.watching.end'])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册