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

wip(uts): automator

上级 2c9e11e5
export function initAutomator() {
console.log('initAutomator')
}
...@@ -156,11 +156,15 @@ function normalizeCode(code: string, isMain = false) { ...@@ -156,11 +156,15 @@ function normalizeCode(code: string, isMain = false) {
if (!isMain) { if (!isMain) {
return code return code
} }
const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT
? 'initAutomator();'
: ''
return ` return `
${code} ${code}
export function main(app: IApp) { export function main(app: IApp) {
defineAppConfig(); defineAppConfig();
definePageRoutes(); definePageRoutes();
${automatorCode}
(createApp()['app'] as VueApp).mount(app); (createApp()['app'] as VueApp).mount(app);
} }
` `
......
...@@ -162,12 +162,12 @@ export async function transformVue( ...@@ -162,12 +162,12 @@ export async function transformVue(
templateCode = templateResult.code templateCode = templateResult.code
} }
// 生成 script 文件 // 生成 script 文件
const utsCode = let utsCode =
genScript(descriptor, { filename: className }) + genScript(descriptor, { filename: className }) +
'\n' + '\n' +
genStyle(descriptor, { filename: fileName, className }) + genStyle(descriptor, { filename: fileName, className }) +
'\n' + '\n'
templateCode utsCode += templateCode
let jsCode = '' let jsCode = ''
const content = descriptor.script?.content const content = descriptor.script?.content
if (content) { if (content) {
......
...@@ -28,6 +28,13 @@ exports.default = [ ...@@ -28,6 +28,13 @@ exports.default = [
} }
if (opts.filter(id)) { if (opts.filter(id)) {
const platform = process.env.UNI_PLATFORM; 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`)); 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 { return {
code: code + `;import '${automatorPath}';`, code: code + `;import '${automatorPath}';`,
......
...@@ -37,6 +37,15 @@ export default [ ...@@ -37,6 +37,15 @@ export default [
} }
if (opts.filter(id)) { if (opts.filter(id)) {
const platform = process.env.UNI_PLATFORM 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( const automatorPath = normalizePath(
resolveBuiltIn( resolveBuiltIn(
`@dcloudio/uni-${ `@dcloudio/uni-${
......
...@@ -27,7 +27,7 @@ export async function runDev(options: CliOptions & ServerOptions) { ...@@ -27,7 +27,7 @@ export async function runDev(options: CliOptions & ServerOptions) {
;(options as BuildOptions).minify = true ;(options as BuildOptions).minify = true
} }
initEnv('dev', options) initEnv('dev', options)
if (process.env.UNI_APP_X === 'true') { if (process.env.UNI_APP_X === 'true' && options.platform === 'app') {
return runUVueDev(options) return runUVueDev(options)
} }
const createLogger = await import('vite').then( const createLogger = await import('vite').then(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册