@hap-toolkit/dsl-xvm 1.9.11 → 1.9.12

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 (30) hide show
  1. package/LICENSE +51 -0
  2. package/lib/loaders/common/utils.js +1 -1
  3. package/lib/loaders/ux-fragment-utils.js +1 -1
  4. package/package.json +5 -5
  5. package/templates/app/demo/.gitignore +26 -0
  6. package/templates/app/demo/.npmrc +1 -0
  7. package/templates/app/demo/.prettierignore +6 -0
  8. package/templates/app/demo/README.md +2 -4
  9. package/templates/app/demo/package-lock.json +2720 -0
  10. package/templates/app/demo/package.json +50 -13
  11. package/templates/app/demo/scripts/gen/index.js +92 -0
  12. package/templates/app/demo/scripts/gen/template.ux +32 -0
  13. package/templates/app/demo/scripts/selfCloseInputTag.js +41 -0
  14. package/templates/app/demo/src/CardDemo/index.ux +14 -8
  15. package/templates/app/demo/src/Demo/index.ux +7 -0
  16. package/templates/app/demo/src/DemoDetail/index.ux +7 -0
  17. package/templates/app/demo/src/app.ux +15 -7
  18. package/templates/app/demo/src/assets/images/logo.png +0 -0
  19. package/templates/app/demo/src/assets/styles/mixins.scss +5 -0
  20. package/templates/app/demo/src/assets/styles/style.scss +2 -0
  21. package/templates/app/demo/src/assets/styles/variables.scss +9 -0
  22. package/templates/app/demo/src/global.js +4 -0
  23. package/templates/app/demo/src/helper/ajax.js +67 -0
  24. package/templates/app/demo/src/helper/apis/example.js +25 -0
  25. package/templates/app/demo/src/helper/apis/index.js +16 -0
  26. package/templates/app/demo/src/helper/utils.js +31 -0
  27. package/templates/app/demo/src/manifest.json +64 -54
  28. package/templates/app/demo/src/pages/Demo/index.ux +72 -0
  29. package/templates/app/demo/src/pages/DemoDetail/index.ux +62 -0
  30. package/templates/app/demo/src/sitemap.json +0 -1
@@ -1,22 +1,59 @@
1
1
  {
2
- "name": "{{ appName }}",
3
- "version": "1.0.0",
4
- "description": "",
5
- "engines": {
6
- "node": ">=8.10"
7
- },
2
+ "name": "quickapp-sample-template",
3
+ "version": "2.0.0",
4
+ "description": "Quickapp Sample Template",
8
5
  "scripts": {
9
6
  "start": "hap server --watch",
7
+ "server": "hap server",
10
8
  "build": "hap build",
11
9
  "release": "hap release",
12
- "server": "hap server",
13
10
  "watch": "hap watch",
14
- "lint": "eslint --format codeframe --fix --ext .ux,.js src/"
11
+ "debug": "hap debug",
12
+ "gen": "node ./scripts/gen/index.js",
13
+ "precommit-msg": "echo '🚧 start pre-commit checks ...' && exit 0",
14
+ "prettier": "node ./scripts/selfCloseInputTag.js && prettier --write \"src/**/*.{js,ux,less,scss,css}\"",
15
+ "prettier-watcher": "onchange '**/*.md' \"src/**/**/*.{js,ux,less,scss,css}\" -- prettier --write {{changed}}"
16
+ },
17
+ "dependencies": {
18
+ "apex-ui": "^1.9.2"
15
19
  },
16
20
  "devDependencies": {
17
- "babel-eslint": "^10.0.1",
18
- "eslint": "^6.8.0",
19
- "eslint-plugin-ux": "^0.0.4",
20
- "hap-toolkit":"^{{ toolkitVersion }}"
21
- }
21
+ "@babel/runtime": "^7.12.5",
22
+ "@types/quickapp": "git+https://github.com/vivoquickapp/quickapp-types.git",
23
+ "husky": "^4.3.0",
24
+ "lint-staged": "^10.5.1",
25
+ "onchange": "^5.2.0",
26
+ "prettier": "^1.15.3",
27
+ "prettier-plugin-ux": "^0.3.0",
28
+ "sass": "^1.32.6",
29
+ "sass-loader": "^10.1.1",
30
+ "colors": "^1.4.0",
31
+ "hap-toolkit": "^{{ toolkitVersion }}"
32
+ },
33
+ "prettier": {
34
+ "singleQuote": true,
35
+ "semi": false,
36
+ "printWidth": 80,
37
+ "proseWrap": "never",
38
+ "tabWidth": 2
39
+ },
40
+ "husky": {
41
+ "hooks": {
42
+ "pre-commit": "yarn run precommit-msg && lint-staged"
43
+ }
44
+ },
45
+ "lint-staged": {
46
+ "**/**.{ux,js,json,pcss,md}": [
47
+ "prettier --write",
48
+ "git add"
49
+ ]
50
+ },
51
+ "keywords": [
52
+ "快应用",
53
+ "快应用示例",
54
+ "快应用模版"
55
+ ],
56
+ "browserslist": [
57
+ "chrome 65"
58
+ ]
22
59
  }
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * @desc: gen script command,make a new page generated by one click.
8
+ * @author: nicejade
9
+ */
10
+
11
+ const fs = require('fs')
12
+ const path = require('path')
13
+ const colors = require('colors')
14
+
15
+ const newFolderName = process.argv[2]
16
+
17
+ String.prototype.firstUpperCase = function () {
18
+ return this.replace(/\b(\w)/g, ($1) => {
19
+ return $1.toLowerCase()
20
+ })
21
+ }
22
+ const resolve = (dir) => {
23
+ return path.join(__dirname, '../..', dir)
24
+ }
25
+
26
+ const successExecPrint = (msg) => {
27
+ console.log(
28
+ colors.green(`✓ `) +
29
+ colors.cyan(`${msg} `) +
30
+ colors.green('task has been successfully executed.')
31
+ )
32
+ }
33
+
34
+ function createNewPage(newFolderPath) {
35
+ const mReg = new RegExp('@PAGE_CLASS_NAME', 'g')
36
+ const pageContent = fs.readFileSync(`${__dirname}/template.ux`, 'UTF-8')
37
+ const rootClassName = newFolderName
38
+ .firstUpperCase()
39
+ .replace(/([A-Z])/g, '-$1')
40
+ .toLowerCase()
41
+ const newContent = pageContent.replace(mReg, rootClassName)
42
+
43
+ fs.mkdirSync(newFolderPath, 0777)
44
+ fs.writeFile(`${newFolderPath}/index.ux`, newContent, (error) => {
45
+ if (error) throw `Something went wrong: ${error}`
46
+ })
47
+ successExecPrint('Create New Page')
48
+ }
49
+
50
+ function saveRouter2Manifest() {
51
+ const manifestPath = resolve('/src/manifest.json')
52
+ let manifestConf = fs.readFileSync(manifestPath, 'UTF-8')
53
+ manifestConf = JSON.parse(manifestConf)
54
+ const routerPages = manifestConf.router.pages
55
+ routerPages[`pages/${newFolderName}`] = {
56
+ component: 'index',
57
+ }
58
+ manifestConf = JSON.stringify(manifestConf, null, 2)
59
+ fs.writeFile(manifestPath, manifestConf, (error) => {
60
+ if (error) throw `Something went wrong[@saveRouter2Manifest]: ${error}`
61
+ })
62
+ successExecPrint('Save Router Into Manifest')
63
+ }
64
+
65
+ function main() {
66
+ if (!newFolderName) {
67
+ return console.warn(
68
+ `⚠️ Please enter the name of the page you want to create.`.underline.red
69
+ )
70
+ }
71
+
72
+ const folderNameReg = /^[A-Z][[A-Za-z0-9]+$/
73
+ if (!folderNameReg.test(newFolderName)) {
74
+ return console.warn(
75
+ `⚠️ Please enter the standard Folder name. Eg: XyzAbcde.`.underline.red
76
+ )
77
+ }
78
+
79
+ const newFolderPath = path.join(__dirname, `../../src/pages/${newFolderName}`)
80
+ const isExist = fs.existsSync(newFolderPath)
81
+
82
+ if (isExist) {
83
+ return console.warn(
84
+ `⚠️ ${newFolderName} already exists in the /src/pages/ directory.`
85
+ .underline.red
86
+ )
87
+ }
88
+ createNewPage(newFolderPath)
89
+ saveRouter2Manifest()
90
+ }
91
+
92
+ main()
@@ -0,0 +1,32 @@
1
+ <!--
2
+ Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+ <template>
7
+ <div class="wrapper">
8
+ <text class="title">{{ title }}</text>
9
+ </div>
10
+ </template>
11
+
12
+ <script>
13
+ export default {
14
+ private: {
15
+ title: '欢迎体验快应用开发'
16
+ },
17
+
18
+ onInit() {}
19
+ }
20
+ </script>
21
+
22
+ <style lang="scss">
23
+ @import './../../assets/styles/style.scss';
24
+ .wrapper {
25
+ @include flex-box-mixins(column, center, center);
26
+ .title {
27
+ font-size: 8 * $size-factor;
28
+ text-align: center;
29
+ color: $black;
30
+ }
31
+ }
32
+ </style>
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * @file: selfCloseInputTag.js
8
+ * @desc: 遍历指定目录下 .ux 文件,将其中 input 标签由 <input **></input> 转换为 <input ** />
9
+ * @date: 2019-01-23
10
+ */
11
+
12
+ const fs = require('fs')
13
+ const path = require('path')
14
+
15
+ const quickappCodePath = './src/'
16
+
17
+ const main = (codePath) => {
18
+ const traversing = (cpath) => {
19
+ const files = fs.readdirSync(cpath)
20
+ files.forEach((fileName) => {
21
+ const fPath = path.join(cpath, fileName)
22
+ const stats = fs.statSync(fPath)
23
+ stats.isDirectory() && traversing(fPath)
24
+ stats.isFile() && fPath.endsWith('.ux') && matchAndReplace(fPath)
25
+ })
26
+ }
27
+ traversing(codePath)
28
+ }
29
+
30
+ const matchAndReplace = (path) => {
31
+ const pageContent = fs.readFileSync(path, 'UTF-8')
32
+ const newContent = pageContent.replace(
33
+ /(<)([\s]*?)(input\b[^\/]*?)>[\s\S]*?<\/input>/gm,
34
+ '$1$3 />'
35
+ )
36
+ fs.writeFile(path, newContent, (error) => {
37
+ if (error) throw `Something went wrong: ${error}`
38
+ })
39
+ }
40
+
41
+ main(quickappCodePath)
@@ -1,8 +1,13 @@
1
+ <!--
2
+ Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
1
6
  <template>
2
7
  <!-- template里只能有一个根节点 -->
3
8
  <div class="demo-page">
4
- <text>{{text}}</text>
5
- <text>{{des}}</text>
9
+ <text>{{ text }}</text>
10
+ <text>{{ des }}</text>
6
11
  </div>
7
12
  </template>
8
13
 
@@ -10,15 +15,16 @@
10
15
  export default {
11
16
  private: {
12
17
  text: '欢迎使用快应用卡片',
13
- des: '卡片是一种轻量级的快应用,快应用卡片使快应用能够在其他app和系统里提供可扩展的app功能'
18
+ des:
19
+ '卡片是一种轻量级的快应用,快应用卡片使快应用能够在其他app和系统里提供可扩展的app功能'
14
20
  }
15
21
  }
16
22
  </script>
17
23
 
18
24
  <style>
19
- .demo-page {
20
- flex: 1;
21
- flex-direction: column;
22
- align-items: center;
23
- }
25
+ .demo-page {
26
+ flex: 1;
27
+ flex-direction: column;
28
+ align-items: center;
29
+ }
24
30
  </style>
@@ -1,3 +1,10 @@
1
+ <!--
2
+ Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+
7
+
1
8
  <template>
2
9
  <!-- template里只能有一个根节点 -->
3
10
  <div class="demo-page">
@@ -1,3 +1,10 @@
1
+ <!--
2
+ Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+
7
+
1
8
  <template>
2
9
  <!-- template里只能有一个根节点 -->
3
10
  <div class="demo-page">
@@ -1,14 +1,22 @@
1
+ <!--
2
+ Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
1
6
  <script>
2
7
  /**
3
- * @file 应用级别的配置,供所有页面公用
4
- * 可在app.ux导出公用变量
5
- * 其他src目录下的ux文件使用this.$app.$def.<paramName>即可调用此处导出的变量
6
- * 文档地址: https://doc.quickapp.cn/framework/source-file.html#appux
8
+ * 应用级别的配置,供所有页面公用
7
9
  */
8
10
 
9
- // 引入全局函数定义文件global.js
10
- import './global'
11
+ const $utils = require('./helper/utils').default
12
+ const $apis = require('./helper/apis').default
11
13
 
12
- export default {}
14
+ /* @desc: 注入方法至全局 global,以便页面调用 */
15
+ const hook2global = global.__proto__ || global
16
+ hook2global.$utils = $utils
17
+ hook2global.$apis = $apis
13
18
 
19
+ export default {
20
+ onCreate() {}
21
+ }
14
22
  </script>
@@ -0,0 +1,5 @@
1
+ @mixin flex-box-mixins($direction: row, $justify: center, $align-items: center) {
2
+ flex-direction: $direction;
3
+ justify-content: $justify;
4
+ align-items: $align-items;
5
+ }
@@ -0,0 +1,2 @@
1
+ @import './variables.scss';
2
+ @import './mixins.scss';
@@ -0,0 +1,9 @@
1
+ $brand: #09ba07;
2
+
3
+ $white: #ffffff;
4
+ $black: #000000;
5
+ $grey: #9393aa;
6
+ $red: #fa0101;
7
+ $green: #ffff00;
8
+
9
+ $size-factor: 5px;
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
1
5
  /**
2
6
  * @file 全局能力的配置与获取
3
7
  * 文档地址:https://doc.quickapp.cn/tutorial/framework/optimization-skills.html#%E4%BD%BF%E7%94%A8-globaljs
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import $fetch from '@system.fetch'
7
+ import $utils from './utils'
8
+
9
+ Promise.prototype.finally = function (callback) {
10
+ const P = this.constructor
11
+ return this.then(
12
+ (value) => P.resolve(callback()).then(() => value),
13
+ (reason) =>
14
+ P.resolve(callback()).then(() => {
15
+ throw reason
16
+ })
17
+ )
18
+ }
19
+
20
+ function requestHandle(params) {
21
+ return new Promise((resolve, reject) => {
22
+ $fetch
23
+ .fetch({
24
+ url: params.url,
25
+ method: params.method,
26
+ data: params.data,
27
+ })
28
+ .then((response) => {
29
+ const result = response.data
30
+ const content = JSON.parse(result.data)
31
+ /* @desc: 可跟具体不同业务接口数据,返回你所需要的部分,使得使用尽可能便捷 */
32
+ content.success ? resolve(content.value) : resolve(content.message)
33
+ })
34
+ .catch((error, code) => {
35
+ console.log(`🐛 request fail, code = ${code}`)
36
+ reject(error)
37
+ })
38
+ .finally(() => {
39
+ console.log(`✔️ request @${params.url} has been completed.`)
40
+ resolve()
41
+ })
42
+ })
43
+ }
44
+
45
+ export default {
46
+ post: function (url, params) {
47
+ return requestHandle({
48
+ method: 'post',
49
+ url: url,
50
+ data: params,
51
+ })
52
+ },
53
+ get: function (url, params) {
54
+ return requestHandle({
55
+ method: 'get',
56
+ url: $utils.queryString(url, params),
57
+ })
58
+ },
59
+ put: function (url, params) {
60
+ return requestHandle({
61
+ method: 'put',
62
+ url: url,
63
+ data: params,
64
+ })
65
+ },
66
+ // 如果,method 您需要更多类型,可自行添加更多方法;
67
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import $ajax from '../ajax'
7
+
8
+ /**
9
+ * @desc 在实际开发中,您可以将 baseUrl 替换为您的请求地址前缀;
10
+ *
11
+ * 已将 $apis 挂载在 global,您可以通过如下方式,进行调用:
12
+ * $apis.example.getSomeApi().then().catch().finally()
13
+ *
14
+ * 备注:如果您不需要发起请求,删除 apis 目录,以及 app.ux 中引用即可;
15
+ */
16
+ const baseUrl = 'https://api.exampel.com/'
17
+
18
+ export default {
19
+ getSomeApi(data) {
20
+ return $ajax.get(`${baseUrl}your-project-api`, data)
21
+ },
22
+ postOtherApi(data) {
23
+ return $ajax.post(`${baseUrl}your-project-api`, data)
24
+ },
25
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ const files = require.context('.', true, /\.js/)
7
+ const modules = {}
8
+
9
+ files.keys().forEach((key) => {
10
+ if (key === './index.js') {
11
+ return
12
+ }
13
+ modules[key.replace(/(^\.\/|\.js$)/g, '')] = files(key).default
14
+ })
15
+
16
+ export default modules
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) 2021-present, the hapjs-platform Project Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * 您可以将常用的方法、或系统 API,统一封装,暴露全局,以便各页面、组件调用,而无需 require / import.
8
+ */
9
+ const prompt = require('@system.prompt')
10
+
11
+ function queryString(url, query) {
12
+ let str = []
13
+ for (let key in query) {
14
+ str.push(key + '=' + query[key])
15
+ }
16
+ let paramStr = str.join('&')
17
+ return paramStr ? `${url}?${paramStr}` : url
18
+ }
19
+
20
+ function showToast(message = '', duration = 0) {
21
+ if (!message) return
22
+ prompt.showToast({
23
+ message: message,
24
+ duration,
25
+ })
26
+ }
27
+
28
+ export default {
29
+ showToast,
30
+ queryString,
31
+ }
@@ -1,56 +1,66 @@
1
1
  {
2
- "package": "com.application.demo",
3
- "name": "{{appName}}",
4
- "versionName": "1.0.0",
5
- "versionCode": 1,
6
- "minPlatformVersion": 1070,
7
- "icon": "/Common/logo.png",
8
- "deviceTypeList": ["phone"],
9
- "features": [
10
- { "name": "system.prompt" },
11
- { "name": "system.router" },
12
- { "name": "system.shortcut" }
13
- ],
14
- "permissions": [
15
- { "origin": "*" }
16
- ],
17
- "config": {
18
- "logLevel": "log"
19
- },
20
- "router": {
21
- "entry": "Demo",
22
- "pages": {
23
- "Demo": {
24
- "component": "index"
25
- },
26
- "DemoDetail": {
27
- "component": "index"
28
- }
29
- },
30
- "widgets": {
31
- "CardDemo": {
32
- "name": "CardDemo",
33
- "description": "快应用卡片展示",
34
- "component": "index",
35
- "path": "/CardDemo",
36
- "features": []
37
- }
38
- }
39
- },
40
- "display": {
41
- "titleBarBackgroundColor": "#f2f2f2",
42
- "titleBarTextColor": "#414141",
43
- "menu": false,
44
- "menuBarData": {
45
- "menuBar": true
46
- },
47
- "pages": {
48
- "Demo": {
49
- "titleBarText": "示例页"
50
- },
51
- "DemoDetail": {
52
- "titleBarText": "详情页"
53
- }
54
- }
55
- }
2
+ "package": "com.example.demo",
3
+ "name": "快应用示例模版",
4
+ "versionName": "1.0.0",
5
+ "versionCode": 1,
6
+ "minPlatformVersion": 1070,
7
+ "icon": "/assets/images/logo.png",
8
+ "features": [{
9
+ "name": "system.prompt"
10
+ },
11
+ {
12
+ "name": "system.router"
13
+ },
14
+ {
15
+ "name": "system.shortcut"
16
+ },
17
+ {
18
+ "name": "system.fetch"
19
+ }
20
+ ],
21
+ "permissions": [{
22
+ "origin": "*"
23
+ }],
24
+ "template/official": "demo-template",
25
+ "config": {
26
+ "logLevel": "debug"
27
+ },
28
+ "router": {
29
+ "entry": "pages/Demo",
30
+ "pages": {
31
+ "pages/Demo": {
32
+ "component": "index"
33
+ },
34
+ "pages/DemoDetail": {
35
+ "component": "index"
36
+ }
37
+ },
38
+ "widgets": {
39
+ "CardDemo": {
40
+ "name": "CardDemo",
41
+ "description": "快应用卡片展示",
42
+ "component": "index",
43
+ "path": "/CardDemo",
44
+ "minPlatformVersion": 1032,
45
+ "targetManufactorys": [
46
+ "vivo"
47
+ ],
48
+ "features": []
49
+ }
50
+ }
51
+ },
52
+ "display": {
53
+ "titleBarBackgroundColor": "#f2f2f2",
54
+ "titleBarTextColor": "#414141",
55
+ "menu": true,
56
+ "pages": {
57
+ "pages/Demo": {
58
+ "titleBarText": "快应用示例模版",
59
+ "menu": false
60
+ },
61
+ "pages/DemoDetail": {
62
+ "titleBarText": "详情页"
63
+ }
64
+ }
65
+ }
56
66
  }