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

wip(uts): compiler

上级 5cdfd682
import Log from 'android.util.Log' import Log from 'android.util.Log'
import { IUser } from './interface.uts' import { IUser } from './interface.uts'
import { login } from './login.uts' import { login } from './login.uts'
import logo from '../static/logo.png'
export class User implements IUser { export class User implements IUser {
async login(name: string, pwd: string) { async login(name: string, pwd: string) {
login(name, pwd) login(name, pwd)
Log.info('123') Log.info('123')
Log.info(logo)
}
register(name: string) {
Log.info(logo)
} }
register(name: string) {}
} }
package uts.modules.testUniPlugin; package uts.modules.testUniPlugin;
import kotlinx.coroutines.*; import kotlinx.coroutines.*;
import io.dcloud.uts.runtime.*; import io.dcloud.uts.runtime.*;
import io.dcloud.uts.andriod.getResourcePath;
import android.util.Log; import android.util.Log;
interface IUser { interface IUser {
fun register(name: String): Unit; fun register(name: String): Unit;
...@@ -12,10 +13,14 @@ fun login(name: String, pwd: String): UtsJSONObject { ...@@ -12,10 +13,14 @@ fun login(name: String, pwd: String): UtsJSONObject {
var pwd = pwd var pwd = pwd
}; };
} }
val __default = getResourcePath("static/logo.png");
open class User : IUser { open class User : IUser {
open suspend fun login(name: String, pwd: String) = CoroutineScope(Dispatchers.Default).async { open suspend fun login(name: String, pwd: String) = CoroutineScope(Dispatchers.Default).async {
login(name, pwd); login(name, pwd);
Log.info("123"); Log.info("123");
Log.info(__default);
}
override fun register(name: String) {
Log.info(__default);
} }
override fun register(name: String) {}
} }
...@@ -3,9 +3,8 @@ import fs from 'fs-extra' ...@@ -3,9 +3,8 @@ import fs from 'fs-extra'
import path from 'path' import path from 'path'
import AdmZip from 'adm-zip' import AdmZip from 'adm-zip'
import { sync } from 'fast-glob' import { sync } from 'fast-glob'
import { once } from '@dcloudio/uni-shared'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts' import type { parse, bundle, UtsTarget } from '@dcloudio/uts'
import { normalizePath } from '@dcloudio/uni-cli-shared' import { installHBuilderXPlugin, normalizePath } from '@dcloudio/uni-cli-shared'
import { camelize } from '@vue/shared' import { camelize } from '@vue/shared'
export function getUtsCompiler(): { export function getUtsCompiler(): {
...@@ -69,8 +68,12 @@ export async function compile(filename: string) { ...@@ -69,8 +68,12 @@ export async function compile(filename: string) {
} else if (process.env.NODE_ENV === 'development') { } else if (process.env.NODE_ENV === 'development') {
// 开发模式下,需要生成 dex // 开发模式下,需要生成 dex
if (fs.existsSync(kotlinFile)) { if (fs.existsSync(kotlinFile)) {
const compilerServer = getCompilerServer()
if (!compilerServer) {
return
}
const { getDefaultJar, compile } = compilerServer
time = Date.now() time = Date.now()
const { getDefaultJar, compile } = getCompilerServer()
const jarFile = resolveJarPath(kotlinFile) const jarFile = resolveJarPath(kotlinFile)
const options = { const options = {
kotlinc: resolveKotlincArgs( kotlinc: resolveKotlincArgs(
...@@ -179,19 +182,27 @@ function resolveClassPath(jars: string[]) { ...@@ -179,19 +182,27 @@ function resolveClassPath(jars: string[]) {
return jars.join(os.platform() === 'win32' ? ';' : ':') return jars.join(os.platform() === 'win32' ? ';' : ':')
} }
const getCompilerServer = once(() => { const getCompilerServer = ():
// eslint-disable-next-line no-restricted-globals | {
return require(path.resolve( getDefaultJar(): string[]
process.env.UNI_HBUILDERX_PLUGINS, compile(
'uniAppRun-Extension/out/main.js' options: { kotlinc: string[]; d8: string[] },
)) as { projectPath: string
getDefaultJar(): string[] ): Promise<boolean>
compile( }
options: { kotlinc: string[]; d8: string[] }, | false => {
projectPath: string try {
): Promise<boolean> const compilerServerPath = path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'uniapp-runextension/out/main.js'
)
// eslint-disable-next-line no-restricted-globals
return require(compilerServerPath)
} catch (e) {
installHBuilderXPlugin('uniapp-runextension')
} }
}) return false
}
export function parsePackage(filepath: string) { export function parsePackage(filepath: string) {
const parts = normalizePath(filepath).split('/') const parts = normalizePath(filepath).split('/')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册