@dcloudio/uni-app-uts 3.0.0-3080720230630001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.js +30 -0
  4. package/dist/plugins/css.d.ts +2 -0
  5. package/dist/plugins/css.js +94 -0
  6. package/dist/plugins/index.d.ts +2 -0
  7. package/dist/plugins/index.js +203 -0
  8. package/dist/plugins/mainUTS.d.ts +2 -0
  9. package/dist/plugins/mainUTS.js +24 -0
  10. package/dist/plugins/manifestJson.d.ts +2 -0
  11. package/dist/plugins/manifestJson.js +68 -0
  12. package/dist/plugins/pagesJson.d.ts +2 -0
  13. package/dist/plugins/pagesJson.js +84 -0
  14. package/dist/plugins/pre.d.ts +7 -0
  15. package/dist/plugins/pre.js +52 -0
  16. package/dist/plugins/utils.d.ts +8 -0
  17. package/dist/plugins/utils.js +85 -0
  18. package/dist/plugins/uvue/code/script.d.ts +4 -0
  19. package/dist/plugins/uvue/code/script.js +14 -0
  20. package/dist/plugins/uvue/code/style.d.ts +12 -0
  21. package/dist/plugins/uvue/code/style.js +90 -0
  22. package/dist/plugins/uvue/code/template.d.ts +3 -0
  23. package/dist/plugins/uvue/code/template.js +16 -0
  24. package/dist/plugins/uvue/compiler/codegen.d.ts +22 -0
  25. package/dist/plugins/uvue/compiler/codegen.js +579 -0
  26. package/dist/plugins/uvue/compiler/errors.d.ts +70 -0
  27. package/dist/plugins/uvue/compiler/errors.js +82 -0
  28. package/dist/plugins/uvue/compiler/index.d.ts +9 -0
  29. package/dist/plugins/uvue/compiler/index.js +65 -0
  30. package/dist/plugins/uvue/compiler/options.d.ts +92 -0
  31. package/dist/plugins/uvue/compiler/options.js +2 -0
  32. package/dist/plugins/uvue/compiler/runtimeHelpers.d.ts +10 -0
  33. package/dist/plugins/uvue/compiler/runtimeHelpers.js +25 -0
  34. package/dist/plugins/uvue/compiler/transform.d.ts +53 -0
  35. package/dist/plugins/uvue/compiler/transform.js +294 -0
  36. package/dist/plugins/uvue/compiler/transforms/transformExpression.d.ts +5 -0
  37. package/dist/plugins/uvue/compiler/transforms/transformExpression.js +208 -0
  38. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.d.ts +4 -0
  39. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.js +107 -0
  40. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.d.ts +10 -0
  41. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.js +79 -0
  42. package/dist/plugins/uvue/compiler/transforms/transformText.d.ts +2 -0
  43. package/dist/plugins/uvue/compiler/transforms/transformText.js +99 -0
  44. package/dist/plugins/uvue/compiler/transforms/vBind.d.ts +2 -0
  45. package/dist/plugins/uvue/compiler/transforms/vBind.js +83 -0
  46. package/dist/plugins/uvue/compiler/transforms/vFor.d.ts +12 -0
  47. package/dist/plugins/uvue/compiler/transforms/vFor.js +325 -0
  48. package/dist/plugins/uvue/compiler/transforms/vIf.d.ts +4 -0
  49. package/dist/plugins/uvue/compiler/transforms/vIf.js +212 -0
  50. package/dist/plugins/uvue/compiler/transforms/vModel.d.ts +2 -0
  51. package/dist/plugins/uvue/compiler/transforms/vModel.js +51 -0
  52. package/dist/plugins/uvue/compiler/transforms/vOn.d.ts +8 -0
  53. package/dist/plugins/uvue/compiler/transforms/vOn.js +136 -0
  54. package/dist/plugins/uvue/compiler/transforms/vShow.d.ts +2 -0
  55. package/dist/plugins/uvue/compiler/transforms/vShow.js +11 -0
  56. package/dist/plugins/uvue/compiler/transforms/vText.d.ts +2 -0
  57. package/dist/plugins/uvue/compiler/transforms/vText.js +29 -0
  58. package/dist/plugins/uvue/compiler/utils.d.ts +5 -0
  59. package/dist/plugins/uvue/compiler/utils.js +37 -0
  60. package/dist/plugins/uvue/descriptorCache.d.ts +24 -0
  61. package/dist/plugins/uvue/descriptorCache.js +57 -0
  62. package/dist/plugins/uvue/error.d.ts +3 -0
  63. package/dist/plugins/uvue/error.js +22 -0
  64. package/dist/plugins/uvue/index.d.ts +13 -0
  65. package/dist/plugins/uvue/index.js +188 -0
  66. package/lib/automator/apis/App.uts +144 -0
  67. package/lib/automator/apis/Page.uts +55 -0
  68. package/lib/automator/apis/util.uts +63 -0
  69. package/lib/automator/index.uts +106 -0
  70. package/package.json +42 -0
@@ -0,0 +1,144 @@
1
+
2
+ import { JSONArray, JSONObject } from 'com.alibaba.fastjson'
3
+ import {
4
+ ViewToTempFilePathSuccess,
5
+ ViewToTempFilePathFail
6
+ } from 'io.dcloud.uniapp.runtime'
7
+ import { getCurrentPages } from 'io.dcloud.uts.framework'
8
+ import { parsePage } from './util.uts'
9
+
10
+ export type GetPageStackParams = {
11
+ callback: (res: any) => void
12
+ }
13
+ export const getPageStack = (params: GetPageStackParams): void => {
14
+ params.callback({
15
+ pageStack: getCurrentPages().map((page: BasePage): UTSJSONObject => {
16
+ return parsePage(page)
17
+ })
18
+ })
19
+ }
20
+ export type GetCurrentPageParams = {
21
+ callback: (res: any) => void
22
+ }
23
+
24
+ function _getCurrentPage(): BasePage | null {
25
+ const pages = getCurrentPages()
26
+ return pages.length > 0 ? pages[pages.length - 1] : null
27
+ }
28
+
29
+ export const getCurrentPage = (params: GetCurrentPageParams): void => {
30
+ const page = _getCurrentPage()
31
+ params.callback({ page: page !== null ? parsePage(page) : null })
32
+ }
33
+
34
+ export type CallUniMethodParams = {
35
+ method: string
36
+ args: JSONArray
37
+ callback: (res: any) => void
38
+ }
39
+
40
+
41
+ export const callUniMethod = (params: CallUniMethodParams): void => {
42
+ const method = params.method
43
+ const args = params.args
44
+ const callback = params.callback
45
+ let animationType: string = 'pop-in'
46
+ let animationDuration: number = 300
47
+ let arg = {} as JSONObject
48
+ if (args.size > 0) {
49
+ arg = args[0] as JSONObject
50
+ }
51
+ const success = (result: any) => {
52
+ const timeout = method == 'pageScrollTo' ? 350 : 0
53
+ setTimeout(() => {
54
+ callback(result)
55
+ }, timeout)
56
+ }
57
+ const fail = (err: any) => {
58
+ callback(err)
59
+ }
60
+ switch (method) {
61
+ case 'navigateTo':
62
+ if (arg['animationType'] !== null) {
63
+ animationType = arg['animationType'] as string
64
+ }
65
+ if (arg['animationDuration'] !== null) {
66
+ animationDuration = arg['animationDuration'] as number
67
+ }
68
+ uni.navigateTo({
69
+ url: arg['url'] as string,
70
+ animationType,
71
+ animationDuration,
72
+ success,
73
+ fail
74
+ })
75
+ break
76
+
77
+ case 'redirectTo':
78
+ uni.redirectTo({
79
+ url: arg['url'] as string,
80
+ success,
81
+ fail
82
+ })
83
+ break
84
+
85
+ case 'reLaunch':
86
+ uni.reLaunch({
87
+ url: arg['url'] as string,
88
+ success,
89
+ fail
90
+ })
91
+ break
92
+
93
+ case 'navigateBack':
94
+ animationType = 'pop-out'
95
+ if (arg['animationType'] !== null) {
96
+ animationType = arg['animationType'] as string
97
+ }
98
+ if (arg['animationDuration'] !== null) {
99
+ animationDuration = arg['animationDuration'] as number
100
+ }
101
+ uni.navigateBack({
102
+ animationType,
103
+ animationDuration,
104
+ success,
105
+ fail
106
+ })
107
+ break
108
+ default:
109
+ callback({ errMsg: 'uni.' + method + ' not exists' })
110
+ break
111
+ }
112
+ }
113
+
114
+ export type CaptureScreenshotParams = {
115
+ id?: string | null,
116
+ fullPage: boolean,
117
+ path: string
118
+ callback: (res: any) => void
119
+ }
120
+ export const captureScreenshot = (params: CaptureScreenshotParams): void => {
121
+ const callback = params.callback
122
+ const currentPage = _getCurrentPage()
123
+ if (currentPage !== null) {
124
+ currentPage.$viewToTempFilePath({
125
+ id: params.fullPage ? null : params.id,
126
+ wholeContent: params.fullPage,
127
+ path: params.path,
128
+ success: (res: ViewToTempFilePathSuccess) => {
129
+ callback({
130
+ errMsg: 'screenshot:ok',
131
+ tempFilePath: res.tempFilePath,
132
+ data: UTSAndroid.dcloud_private_getFileBase64(res.tempFilePath)
133
+ })
134
+ },
135
+ fail: (err: ViewToTempFilePathFail) => {
136
+ callback(err)
137
+ }
138
+ })
139
+ } else {
140
+ callback({
141
+ errMsg: `captureScreenshot:fail, currentPage is not found.`
142
+ })
143
+ }
144
+ }
@@ -0,0 +1,55 @@
1
+ // @ts-ignore
2
+ import { JSONObject } from 'com.alibaba.fastjson'
3
+ import { getData, setData, getPageVm } from './util.uts'
4
+ import { hasVueMethod, callVueMethod } from 'io.dcloud.uts.vue.shared'
5
+
6
+ export type GetDataParams = {
7
+ pageId: number
8
+ path: string
9
+ callback: (res: any) => void
10
+ }
11
+ export const pageGetData = (params: GetDataParams): void => {
12
+ const callback = params.callback
13
+ const result = getData(getPageVm(params.pageId)!, params.path)
14
+ callback(result)
15
+ }
16
+
17
+ export type SetDataParams = {
18
+ pageId: number
19
+ data: JSONObject
20
+ callback: (res?: any | null) => void
21
+ }
22
+ export const pageSetData = (params: SetDataParams): void => {
23
+ const pageId = params.pageId
24
+ const callback = params.callback
25
+ const page = getPageVm(pageId)
26
+ if (page !== null) {
27
+ setData(page, params.data)
28
+ callback(null)
29
+ } else {
30
+ callback({ errMsg: `setData:fail, Page:${pageId} is not found.` })
31
+ }
32
+ }
33
+
34
+ export type CallMethodWithCallbackParams = {
35
+ pageId: number
36
+ methodName: string
37
+ args: Array<any | null>
38
+ }
39
+ export const callMethodWithCallback = (params: CallMethodWithCallbackParams): void => {
40
+ const page = getPageVm(params.pageId)
41
+ const callback = params.args[params.args.length - 1] as (data: any) => void
42
+ if (page === null) {
43
+ callback({ errMsg: `callMethodWithCallback:fail, Page[${params.pageId}] not exists` })
44
+ return
45
+ }
46
+ if (!hasVueMethod(page, params.methodName)) {
47
+ callback({ errMsg: `callMethodWithCallback:fail, Page.${params.methodName} not exists` })
48
+ return
49
+ }
50
+ callVueMethod(
51
+ page,
52
+ params.methodName,
53
+ params.args
54
+ )
55
+ }
@@ -0,0 +1,63 @@
1
+ import { JSONObject } from 'com.alibaba.fastjson'
2
+ import { getCurrentPages } from 'io.dcloud.uts.framework'
3
+
4
+ function getPageId(page: BasePage): number {
5
+ return page.$.uid
6
+ }
7
+
8
+ function getPagePath(page: BasePage): string {
9
+ return page.route
10
+ }
11
+
12
+ function getPageQuery(page: BasePage): VueComponentOptions {
13
+ return page.$options
14
+ }
15
+
16
+ function getPageById(id: number): BasePage | null {
17
+ const pages = getCurrentPages()
18
+ let result: BasePage | null = null
19
+ pages.forEach((page: BasePage) => {
20
+ if (getPageId(page) === id) {
21
+ result = page
22
+ }
23
+ })
24
+ return result
25
+ }
26
+
27
+ export function getPageVm(id: number): BasePage | null {
28
+ return getPageById(id)
29
+ }
30
+
31
+ export function getData(
32
+ vm: BasePage | null,
33
+ path?: string
34
+ ): Map<string, any | null> {
35
+ let data = new Map<string, any | null>()
36
+ if (vm !== null) {
37
+ // TODO: path
38
+ if(path !== null){
39
+ data.set("errMsg", `getData:fail, path:${path} is not supported.`)
40
+ }else{
41
+ data = vm.$data
42
+ }
43
+ }
44
+ return data
45
+ }
46
+
47
+ export function setData(vm: BasePage, data: JSONObject): void {
48
+ for (const key in data) {
49
+ // @ts-ignore
50
+ const _key = key.key
51
+ // @ts-ignore
52
+ const value = key.value
53
+ vm.$data.set(_key, value)
54
+ }
55
+ }
56
+
57
+ export function parsePage(page: BasePage): UTSJSONObject {
58
+ return {
59
+ id: getPageId(page),
60
+ path: getPagePath(page),
61
+ query: getPageQuery(page),
62
+ } as UTSJSONObject
63
+ }
@@ -0,0 +1,106 @@
1
+ import { JSONArray, JSONObject } from 'com.alibaba.fastjson'
2
+ import { SocketTask, SendSocketMessageOptions } from 'uts.sdk.modules.DCloudUniWebsocket'
3
+ import {
4
+ callUniMethod,
5
+ CallUniMethodParams,
6
+ captureScreenshot,
7
+ CaptureScreenshotParams,
8
+ getPageStack,
9
+ GetPageStackParams,
10
+ getCurrentPage,
11
+ GetCurrentPageParams
12
+ } from './apis/App.uts'
13
+ import {
14
+ pageGetData,
15
+ GetDataParams,
16
+ pageSetData,
17
+ SetDataParams,
18
+ CallMethodWithCallbackParams,
19
+ callMethodWithCallback
20
+ } from './apis/Page.uts'
21
+
22
+ let socketTask: SocketTask | null = null
23
+ const wsEndpoint = process.env.UNI_AUTOMATOR_WS_ENDPOINT
24
+
25
+ function send(data: any) {
26
+ socketTask?.send({ data: JSON.stringify(data) } as SendSocketMessageOptions)
27
+ }
28
+
29
+ function onMessage(msg: string) {
30
+ const json = JSON.parse(msg)!
31
+ const method = json['method'] as string
32
+ const params = json['params'] as UTSJSONObject
33
+ const path = params['path'] !== null ? (params['path'] as string) : ''
34
+ const res = new Map<string, any | null>([['id', json['id'] as string]])
35
+ try {
36
+ const callback = (result?: any | null) => {
37
+ if (result !== null) {
38
+ res.set('result', result)
39
+ }
40
+ send(res)
41
+ }
42
+ if (method.startsWith('App.')) {
43
+ switch (method) {
44
+ case 'App.callUniMethod':
45
+ const method = params['method'] as string
46
+ const args = (params['args'] as UTSJSONObject).toJSONObject() as JSONArray
47
+ callUniMethod({
48
+ method,
49
+ args,
50
+ callback
51
+ } as CallUniMethodParams)
52
+ break
53
+ case 'App.captureScreenshot':
54
+ const id = params['id'] !== null ? (params['id'] as string) : null
55
+ const fullPage = params['fullPage'] !== null ? (params['fullPage'] as boolean) : false
56
+ captureScreenshot({ id, fullPage, path, callback } as CaptureScreenshotParams)
57
+ break
58
+ case 'App.getPageStack':
59
+ getPageStack({ callback } as GetPageStackParams)
60
+ break
61
+ case 'App.getCurrentPage':
62
+ getCurrentPage({ callback } as GetCurrentPageParams)
63
+ break
64
+ }
65
+ } else if (method.startsWith('Page.')) {
66
+ const pageId = params['pageId'] as number
67
+ const data =
68
+ params['data'] !== null
69
+ ? (params['data'] as JSONObject)
70
+ : ({} as JSONObject)
71
+ switch (method) {
72
+ case 'Page.getData':
73
+ pageGetData({ pageId, path, callback } as GetDataParams)
74
+ break
75
+ case 'Page.setData':
76
+ pageSetData({ pageId, data, callback } as SetDataParams)
77
+ break
78
+ case 'Page.callMethodWithCallback':
79
+ const methodName = params['method'] as string
80
+ const args = params['args'] !== null ? params['args'] as Array<any | null> : [] as Array<any | null>
81
+ args.push(callback)
82
+ callMethodWithCallback({ pageId, methodName, args } as CallMethodWithCallbackParams)
83
+ break;
84
+ }
85
+ }
86
+ } catch (error) {
87
+ res.set('error', error)
88
+ send(res)
89
+ }
90
+ }
91
+
92
+ export function initAutomator() {
93
+ socketTask = uni.connectSocket({
94
+ url: wsEndpoint
95
+ });
96
+ socketTask!.onMessage((res) => { onMessage(res.data as string) })
97
+ socketTask!.onOpen((_) => {
98
+ console.warn("automator.onOpen")
99
+ })
100
+ socketTask!.onError((err) => {
101
+ console.warn(`automator.onError: ${JSON.stringify(err)}`);
102
+ })
103
+ socketTask!.onClose((_) => {
104
+ console.warn("automator.onClose");
105
+ })
106
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@dcloudio/uni-app-uts",
3
+ "version": "3.0.0-3080720230630001",
4
+ "description": "uni-app-uts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "bin",
9
+ "dist",
10
+ "lib"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/dcloudio/uni-app.git",
15
+ "directory": "packages/uni-app-uts"
16
+ },
17
+ "scripts": {
18
+ "test": "echo \"Error: no test specified\" && exit 1"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "dependencies": {
22
+ "@babel/parser": "^7.16.4",
23
+ "@babel/types": "^7.20.7",
24
+ "@dcloudio/uni-cli-shared": "3.0.0-3080720230630001",
25
+ "@dcloudio/uni-i18n": "3.0.0-3080720230630001",
26
+ "@dcloudio/uni-nvue-styler": "3.0.0-3080720230630001",
27
+ "@dcloudio/uni-shared": "3.0.0-3080720230630001",
28
+ "@rollup/pluginutils": "^4.2.0",
29
+ "@vue/compiler-core": "3.2.47",
30
+ "@vue/compiler-sfc": "3.2.47",
31
+ "@vue/shared": "3.2.47",
32
+ "debug": "^4.3.3",
33
+ "es-module-lexer": "^1.2.1",
34
+ "fs-extra": "^10.0.0",
35
+ "picocolors": "^1.0.0",
36
+ "source-map": "^0.6.1"
37
+ },
38
+ "devDependencies": {
39
+ "@types/debug": "^4.1.7",
40
+ "@types/fs-extra": "^9.0.13"
41
+ }
42
+ }