From 96614d35af362726297633d4f683e4c4e30c80ec Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 23 May 2023 15:27:17 +0800 Subject: [PATCH] wip(uts): automator --- packages/uni-app-uts/lib/automator/index.uts | 3 +++ packages/uni-app-uts/src/plugins/index.ts | 4 ++++ packages/uni-app-uts/src/plugins/uvue/index.ts | 6 +++--- packages/uni-automator/lib/uni.plugin.js | 7 +++++++ packages/uni-automator/src/uni.plugin.ts | 9 +++++++++ packages/vite-plugin-uni/src/cli/action.ts | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 packages/uni-app-uts/lib/automator/index.uts diff --git a/packages/uni-app-uts/lib/automator/index.uts b/packages/uni-app-uts/lib/automator/index.uts new file mode 100644 index 0000000000..3cfb4a1af2 --- /dev/null +++ b/packages/uni-app-uts/lib/automator/index.uts @@ -0,0 +1,3 @@ +export function initAutomator() { + console.log('initAutomator') +} diff --git a/packages/uni-app-uts/src/plugins/index.ts b/packages/uni-app-uts/src/plugins/index.ts index 170d6e20a5..a7b863e4f6 100644 --- a/packages/uni-app-uts/src/plugins/index.ts +++ b/packages/uni-app-uts/src/plugins/index.ts @@ -156,11 +156,15 @@ function normalizeCode(code: string, isMain = false) { if (!isMain) { return code } + const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT + ? 'initAutomator();' + : '' return ` ${code} export function main(app: IApp) { defineAppConfig(); definePageRoutes(); + ${automatorCode} (createApp()['app'] as VueApp).mount(app); } ` diff --git a/packages/uni-app-uts/src/plugins/uvue/index.ts b/packages/uni-app-uts/src/plugins/uvue/index.ts index f871524a61..cc9e680b51 100644 --- a/packages/uni-app-uts/src/plugins/uvue/index.ts +++ b/packages/uni-app-uts/src/plugins/uvue/index.ts @@ -162,12 +162,12 @@ export async function transformVue( templateCode = templateResult.code } // ็”Ÿๆˆ script ๆ–‡ไปถ - const utsCode = + let utsCode = genScript(descriptor, { filename: className }) + '\n' + genStyle(descriptor, { filename: fileName, className }) + - '\n' + - templateCode + '\n' + utsCode += templateCode let jsCode = '' const content = descriptor.script?.content if (content) { diff --git a/packages/uni-automator/lib/uni.plugin.js b/packages/uni-automator/lib/uni.plugin.js index 1ce43d17df..647b162876 100644 --- a/packages/uni-automator/lib/uni.plugin.js +++ b/packages/uni-automator/lib/uni.plugin.js @@ -28,6 +28,13 @@ exports.default = [ } if (opts.filter(id)) { const platform = process.env.UNI_PLATFORM; + if (platform === 'app' && process.env.UNI_APP_X === 'true') { + const automatorPath = (0, uni_cli_shared_1.normalizePath)((0, uni_cli_shared_1.resolveBuiltIn)(`@dcloudio/uni-app-uts/lib/automator/index.uts`)); + return { + code: code + `;import { initAutomator } = '${automatorPath}';`, + map: null, + }; + } const automatorPath = (0, uni_cli_shared_1.normalizePath)((0, uni_cli_shared_1.resolveBuiltIn)(`@dcloudio/uni-${platform === 'app' ? 'app-plus' : platform}/lib/automator.js`)); return { code: code + `;import '${automatorPath}';`, diff --git a/packages/uni-automator/src/uni.plugin.ts b/packages/uni-automator/src/uni.plugin.ts index 419513e086..48c796a1b7 100644 --- a/packages/uni-automator/src/uni.plugin.ts +++ b/packages/uni-automator/src/uni.plugin.ts @@ -37,6 +37,15 @@ export default [ } if (opts.filter(id)) { const platform = process.env.UNI_PLATFORM + if (platform === 'app' && process.env.UNI_APP_X === 'true') { + const automatorPath = normalizePath( + resolveBuiltIn(`@dcloudio/uni-app-uts/lib/automator/index.uts`) + ) + return { + code: code + `;import { initAutomator } = '${automatorPath}';`, + map: null, + } + } const automatorPath = normalizePath( resolveBuiltIn( `@dcloudio/uni-${ diff --git a/packages/vite-plugin-uni/src/cli/action.ts b/packages/vite-plugin-uni/src/cli/action.ts index e497c4a636..9aaf6c6db9 100644 --- a/packages/vite-plugin-uni/src/cli/action.ts +++ b/packages/vite-plugin-uni/src/cli/action.ts @@ -27,7 +27,7 @@ export async function runDev(options: CliOptions & ServerOptions) { ;(options as BuildOptions).minify = true } initEnv('dev', options) - if (process.env.UNI_APP_X === 'true') { + if (process.env.UNI_APP_X === 'true' && options.platform === 'app') { return runUVueDev(options) } const createLogger = await import('vite').then( -- GitLab