create-blocklet 0.2.4 → 0.2.8

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 (78) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/common/.github/workflows/main.yml +3 -3
  3. package/common/.prettierrc +1 -0
  4. package/common/_gitignore +1 -0
  5. package/index.js +29 -1
  6. package/package.json +1 -1
  7. package/template-dapp/react/README.md +13 -13
  8. package/{common → template-dapp/react}/public/index.html +0 -0
  9. package/template-dapp/vue/.env +1 -0
  10. package/template-dapp/vue/README.md +147 -0
  11. package/template-dapp/vue/blocklet.md +3 -0
  12. package/template-dapp/vue/blocklet.yml +62 -0
  13. package/template-dapp/vue/index.html +18 -0
  14. package/template-dapp/vue/package.json +43 -0
  15. package/template-dapp/vue/server/hooks/pre-start.js +33 -0
  16. package/template-dapp/vue/server/index.js +55 -0
  17. package/template-dapp/vue/server/libs/auth.js +31 -0
  18. package/template-dapp/vue/server/libs/env.js +12 -0
  19. package/template-dapp/vue/server/libs/logger.js +3 -0
  20. package/template-dapp/vue/server/middlewares/user.js +10 -0
  21. package/template-dapp/vue/server/routes/index.js +6 -0
  22. package/template-dapp/vue/src/App.vue +35 -0
  23. package/template-dapp/vue/src/assets/logo.png +0 -0
  24. package/template-dapp/vue/src/components/HelloWorld.vue +38 -0
  25. package/template-dapp/vue/src/libs/api.js +14 -0
  26. package/template-dapp/vue/src/main.js +4 -0
  27. package/template-dapp/vue/vite.config.js +26 -0
  28. package/template-dapp/vue2/.env +1 -0
  29. package/template-dapp/vue2/README.md +147 -0
  30. package/template-dapp/vue2/babel.config.js +3 -0
  31. package/template-dapp/vue2/blocklet.md +3 -0
  32. package/template-dapp/vue2/blocklet.yml +60 -0
  33. package/template-dapp/vue2/package.json +68 -0
  34. package/template-dapp/vue2/public/index.html +24 -0
  35. package/template-dapp/vue2/server/hooks/pre-start.js +33 -0
  36. package/template-dapp/vue2/server/index.js +55 -0
  37. package/template-dapp/vue2/server/libs/auth.js +31 -0
  38. package/template-dapp/vue2/server/libs/env.js +12 -0
  39. package/template-dapp/vue2/server/libs/logger.js +3 -0
  40. package/template-dapp/vue2/server/middlewares/user.js +10 -0
  41. package/template-dapp/vue2/server/routes/index.js +6 -0
  42. package/template-dapp/vue2/src/App.vue +22 -0
  43. package/template-dapp/vue2/src/assets/logo.png +0 -0
  44. package/template-dapp/vue2/src/components/HelloWorld.vue +74 -0
  45. package/template-dapp/vue2/src/libs/api.js +14 -0
  46. package/template-dapp/vue2/src/main.js +10 -0
  47. package/template-dapp/vue2/src/pages/About.vue +13 -0
  48. package/template-dapp/vue2/src/pages/Home.vue +37 -0
  49. package/template-dapp/vue2/src/router.js +24 -0
  50. package/template-dapp/vue2/vue.config.js +11 -0
  51. package/template-static/react/README.md +14 -14
  52. package/template-static/react/public/index.html +37 -0
  53. package/template-static/vue/.env +1 -0
  54. package/template-static/vue/README.md +147 -0
  55. package/template-static/vue/blocklet.md +3 -0
  56. package/template-static/vue/blocklet.yml +50 -0
  57. package/template-static/vue/index.html +18 -0
  58. package/template-static/vue/package.json +23 -0
  59. package/template-static/vue/src/App.vue +21 -0
  60. package/template-static/vue/src/assets/logo.png +0 -0
  61. package/template-static/vue/src/components/HelloWorld.vue +38 -0
  62. package/template-static/vue/src/main.js +4 -0
  63. package/template-static/vue/vite.config.js +23 -0
  64. package/template-static/vue2/.env +1 -0
  65. package/template-static/vue2/README.md +147 -0
  66. package/template-static/vue2/babel.config.js +3 -0
  67. package/template-static/vue2/blocklet.md +3 -0
  68. package/template-static/vue2/blocklet.yml +50 -0
  69. package/template-static/vue2/package.json +48 -0
  70. package/template-static/vue2/public/index.html +24 -0
  71. package/template-static/vue2/src/App.vue +22 -0
  72. package/template-static/vue2/src/assets/logo.png +0 -0
  73. package/template-static/vue2/src/components/HelloWorld.vue +74 -0
  74. package/template-static/vue2/src/main.js +10 -0
  75. package/template-static/vue2/src/pages/About.vue +13 -0
  76. package/template-static/vue2/src/pages/Home.vue +20 -0
  77. package/template-static/vue2/src/router.js +24 -0
  78. package/template-static/vue2/vue.config.js +6 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.2.8 (十一月 26, 2021)
2
+
3
+ - feat: rebrand blocklet registry -> blocklet store
4
+
5
+ ## 0.2.7 (十一月 21, 2021)
6
+
7
+ - chore: prettier default useTabs: false
8
+
9
+ ## 0.2.6 (十一月 20, 2021)
10
+
11
+ - feat: add vue2 + @vue/cli template
12
+
13
+ ## 0.2.5 (十一月 20, 2021)
14
+
15
+ - feat: add vite + vue3 template
16
+
1
17
  ## 0.2.4 (October 28, 2021)
2
18
 
3
19
  - chore: bump deps to latest
@@ -22,13 +22,13 @@ jobs:
22
22
  run: yarn
23
23
 
24
24
  - name: Blocklet workflow
25
- uses: blocklet/action-workflow@v1
25
+ uses: blocklet/action-workflow@v1.1
26
26
  with:
27
27
  skip-upload: false
28
28
  skip-deploy: false
29
29
  bundle-command: yarn bundle
30
- registry-endpoint: ${{ secrets.STAGING_REGISTRY }}
31
- developer-sk: ${{ secrets.ABTNODE_DEV_STAGING_SK }}
30
+ store-endpoint: ${{ secrets.STORE_ENDPOINT_STAGING }}
31
+ store-access-token: ${{ secrets.STORE_ACCESS_TOKEN_STAGING }}
32
32
  abtnode-endpoint: ${{ secrets.STAGING_NODE_ENDPOINT }}
33
33
  access-key: ${{ secrets.STAGING_NODE_ACCESS_KEY }}
34
34
  access-secret: ${{ secrets.STAGING_NODE_ACCESS_SECRET }}
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "printWidth": 120,
3
+ "useTabs": false,
3
4
  "tabWidth": 2,
4
5
  "trailingComma": "es5",
5
6
  "jsxBracketSameLine": true,
package/common/_gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  # production
12
12
  /build
13
+ /dist
13
14
 
14
15
  # misc
15
16
  .DS_Store
package/index.js CHANGED
@@ -35,6 +35,16 @@ const TYPES = [
35
35
  display: 'react',
36
36
  color: yellow,
37
37
  },
38
+ {
39
+ name: 'vue',
40
+ display: 'vue3 + vite',
41
+ color: green,
42
+ },
43
+ {
44
+ name: 'vue2',
45
+ display: 'vue2 + @vue/cli',
46
+ color: green,
47
+ },
38
48
  ],
39
49
  },
40
50
  {
@@ -46,6 +56,16 @@ const TYPES = [
46
56
  display: 'react',
47
57
  color: yellow,
48
58
  },
59
+ {
60
+ name: 'vue',
61
+ display: 'vue3 + vite',
62
+ color: green,
63
+ },
64
+ {
65
+ name: 'vue2',
66
+ display: 'vue2 + @vue/cli',
67
+ color: green,
68
+ },
49
69
  ],
50
70
  },
51
71
  ];
@@ -228,6 +248,10 @@ async function init() {
228
248
  const commonDir = path.join(__dirname, 'common');
229
249
  const commonFiles = fs.readdirSync(commonDir);
230
250
  for (const file of commonFiles) {
251
+ if (framework !== 'react' && file === '_eslintrc.js') {
252
+ // eslint-disable-next-line no-continue
253
+ continue;
254
+ }
231
255
  const targetPath = renameFiles[file] ? path.join(root, renameFiles[file]) : path.join(root, file);
232
256
  copy(path.join(commonDir, file), targetPath);
233
257
  }
@@ -253,7 +277,11 @@ async function init() {
253
277
  return md.replace(/# template-react/g, `# ${name}`);
254
278
  });
255
279
  modifyEnv((env) => {
256
- env.REACT_APP_TITLE = name;
280
+ if (framework === 'react') {
281
+ env.REACT_APP_TITLE = name;
282
+ } else {
283
+ env.APP_TITLE = name;
284
+ }
257
285
  return env;
258
286
  });
259
287
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.2.4",
3
+ "version": "0.2.8",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -67,9 +67,9 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
67
67
 
68
68
  > Make sure the blocklet is bundled before deployment.
69
69
 
70
- ## Upload to blocklet registry
70
+ ## Upload to blocklet store
71
71
 
72
- - If you want to upload the blocklet to any registry for other users to download and use, you can following the following instructions.
72
+ - If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
73
73
 
74
74
  Bump version at first.
75
75
 
@@ -77,22 +77,22 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
77
77
  make bump-version
78
78
  ```
79
79
 
80
- Then config blocklet registry url.
81
- You can use those registry url in below.
80
+ Then config blocklet store url.
81
+ You can use those store url in below.
82
82
 
83
- 1. [https://registry.arcblock.io/](https://registry.arcblock.io/)
84
- 2. [https://dev.registry.arcblock.io/](https://dev.registry.arcblock.io/)
85
- 3. A blocklet registry started by yourself.
86
- > Make sure you have installed a `blocklet registry` on your own abtnode. Check it on here: [https://registry.arcblock.io/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://registry.arcblock.io/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)
83
+ 1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
84
+ 2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
85
+ 3. A blocklet store started by yourself.
86
+ > Make sure you have installed a `blocklet store` on your own abtnode. Check it on here: [https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)
87
87
 
88
88
  ```shell
89
- blocklet config set registry {registry url}
89
+ blocklet config set store {store url}
90
90
  ```
91
91
 
92
92
  Get a `accessToken` by using this command.
93
93
 
94
94
  > Why we need a `accessToken`?
95
- > A `accessToken` is genrate by blocklet registry, which help us upload our blocklet to any registry.
95
+ > A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
96
96
 
97
97
  Set `accessToken` to blocklet config
98
98
 
@@ -100,7 +100,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
100
100
  blocklet config set accessToken {accessToken}
101
101
  ```
102
102
 
103
- Upload a new version to a registry.
103
+ Upload a new version to a store.
104
104
 
105
105
  > Make sure the blocklet is bundled before upload.
106
106
 
@@ -110,7 +110,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
110
110
 
111
111
  Or you can simply use `npm run upload` command.
112
112
 
113
- - You also can upload a new version to a registry by Github CI.
113
+ - You also can upload a new version to a store by Github CI.
114
114
  Bump version at first.
115
115
 
116
116
  ```shell
@@ -118,7 +118,7 @@ After developing a blocklet, you may need to bundle it. Use `npm run bundle` com
118
118
  ```
119
119
 
120
120
  Push your code to Github main/master branch, or make a pull request to the main/master branch.
121
- The CI workflow will automatically upload a new version to a registry.
121
+ The CI workflow will automatically upload a new version to a store.
122
122
 
123
123
  ## Q & A
124
124
 
@@ -0,0 +1 @@
1
+ APP_TITLE=''
@@ -0,0 +1,147 @@
1
+ # Getting Started with Create Blocklet
2
+
3
+ This project was bootstrapped with [Create Blocklet](https://github.com/blocklet/create-blocklet).
4
+
5
+ This blocklet is a static project, which means this is a frontend application. It's contained `client` code.
6
+
7
+ ## File Structure
8
+
9
+ - public/ - static files
10
+ - favicon.ico - favicon
11
+ - favicon.svg - favicon
12
+ - index.html - main html file, template for vite vue
13
+ - screenshots/ - Screenshots
14
+ - src/ - Client side code (A standard vue app structure)
15
+ - .env - Environment variables
16
+ - .env.local - Local environment variables
17
+ - .eslintrc.js - ESLint configuration
18
+ - .gitignore - Git ignore file
19
+ - .prettierrc - Prettier configuration
20
+ - blocklet.md - Blocklet README
21
+ - blocklet.yml - Blocklet configuration
22
+ - LICENSE - License file
23
+ - logo.png - Blocklet logo file
24
+ - Makefile - Makefile
25
+ - package.json - Npm package file
26
+ - README.md - A guide for this blocklet
27
+ - version - Version file
28
+
29
+ ## Development
30
+
31
+ 1. Make sure you have [@abtnode/cli](https://www.npmjs.com/package/@abtnode/cli) installed
32
+
33
+ Blocklet needs abtnode as a dependency. So you need to install it first.
34
+ `npm install -g @abtnode/cli`
35
+ See details in [https://docs.arcblock.io/abtnode/en/introduction/abtnode-setup#use-the-binary-distribution](https://docs.arcblock.io/abtnode/en/introduction/abtnode-setup#use-the-binary-distribution)
36
+
37
+ 2. Init abtnode & start abtnode
38
+
39
+ Before starting an abtnode, you need to init abtnode.
40
+ `abtnode init --mode=debug`
41
+ `abtnode start`
42
+ See details in [https://docs.arcblock.io/abtnode/en/introduction/abtnode-setup#configure-abt-node](https://docs.arcblock.io/abtnode/en/introduction/abtnode-setup#configure-abt-node)
43
+
44
+ 3. Go to the project directory `cd [name]`
45
+ 4. Install dependencies: `npm install` or `yarn`
46
+ 5. Start development server: `blocklet dev`
47
+
48
+ ## Bundle
49
+
50
+ After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
51
+
52
+ ## Deploy
53
+
54
+ - If you want to deploy this blocklet to local abtnode, you can use `blocklet deploy .blocklet/bundle` command(Make sure the blocklet is bundled before deployment.)
55
+ > Or you can simply use `npm run deploy` command.
56
+ - If you want to deploy this blocklet to remote abtnode, you can use the command below.
57
+
58
+ ```shell
59
+ blocklet deploy .blocklet/bundle --endpoint {your abtnode url} --access-key {abtnode access key} --access-secret {abtnode access secret}
60
+ ```
61
+
62
+ > Make sure the blocklet is bundled before deployment.
63
+
64
+ ## Upload to blocklet store
65
+
66
+ - If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
67
+
68
+ Bump version at first.
69
+
70
+ ```shell
71
+ make bump-version
72
+ ```
73
+
74
+ Then config blocklet store url.
75
+ You can use those store url in below.
76
+
77
+ 1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
78
+ 2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
79
+ 3. A blocklet store started by yourself.
80
+ > Make sure you have installed a `blocklet store` on your own abtnode. Check it on here: [https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)
81
+
82
+ ```shell
83
+ blocklet config set store {store url}
84
+ ```
85
+
86
+ Get a `accessToken` from blocklet store.
87
+
88
+ > Why we need a `accessToken`?
89
+ > A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
90
+
91
+ Set `accessToken` to blocklet config
92
+
93
+ ```shell
94
+ blocklet config set accessToken {accessToken}
95
+ ```
96
+
97
+ Upload a new version to a store.
98
+
99
+ > Make sure the blocklet is bundled before upload.
100
+
101
+ ```shell
102
+ blocklet upload
103
+ ```
104
+
105
+ Or you can simply use `npm run upload` command.
106
+
107
+ - You also can upload a new version to blocklet store by Github CI.
108
+ Bump version at first.
109
+
110
+ ```shell
111
+ make bump-version
112
+ ```
113
+
114
+ Push your code to Github main/master branch, or make a pull request to the main/master branch.
115
+ The CI workflow will automatically upload a new version to a store.
116
+
117
+ ## Q & A
118
+
119
+ 1. Q: How to change a blocklet's name?
120
+
121
+ A: Change the `name` field in the `package.json` file, change the `name` field in the `blocklet.yml` file.
122
+
123
+ You can also change the `title` field and `description` field in the `blocklet.yml` file.
124
+
125
+ Run `blocklet meta` command, you will get a `did` config, copy the `did` value.
126
+
127
+ Replace this command `"bundle": "vite build --base /.blocklet/proxy/<%= did %>",` in `package.json`
128
+
129
+ Replace `did` field in the `blocklet.yml`
130
+
131
+ 2. Q: How to change a blocklet's logo?
132
+
133
+ Change the `logo.png` file root folder.
134
+
135
+ Or you can change the `logo` field in the `blocklet.yml` file.
136
+
137
+ > Make sure you have added the logo path to the `blocklet.yml` file `files` field.
138
+
139
+ ## Learn More
140
+
141
+ - Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
142
+ - Full document of AbtNode & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
143
+
144
+ ## License
145
+
146
+ The code is licensed under the Apache 2.0 license found in the
147
+ [LICENSE](LICENSE) file.
@@ -0,0 +1,3 @@
1
+ # template-vue
2
+
3
+ A vue template for creating a new blocklet project.
@@ -0,0 +1,62 @@
1
+ name: template-vue
2
+ title: Blocklet Template Vue
3
+ description: ABT Node blocklet project
4
+ keywords:
5
+ - blocklet
6
+ - vue
7
+ group: dapp
8
+ did: ''
9
+ main: server/index.js
10
+ author:
11
+ name: zhanghan
12
+ email: zhanghan@arcblock.io
13
+ repository:
14
+ type: git
15
+ url: 'git+https://github.com/blocklet/create-blocklet.git'
16
+ specVersion: 1.1.1
17
+ version: 0.1.0
18
+ logo: logo.png
19
+ files:
20
+ - dist
21
+ - logo.png
22
+ - README.md
23
+ - blocklet.md
24
+ - screenshots
25
+ interfaces:
26
+ - type: web
27
+ name: publicUrl
28
+ path: /
29
+ prefix: '*'
30
+ port: BLOCKLET_PORT
31
+ protocol: http
32
+ community: ''
33
+ documentation: ''
34
+ homepage: ''
35
+ license: ''
36
+ charging:
37
+ price: 0
38
+ tokens: []
39
+ shares: []
40
+ timeout:
41
+ start: 60
42
+ requirements:
43
+ abtnode: '>=1.4.0'
44
+ os: '*'
45
+ cpu: '*'
46
+ scripts:
47
+ preStart: node server/hooks/pre-start.js
48
+ dev: npm run start
49
+ environments:
50
+ - name: CHAIN_ID
51
+ description: What's endpoint of the chain id?
52
+ required: true
53
+ default: 'beta'
54
+ secure: false
55
+ - name: CHAIN_HOST
56
+ description: What's endpoint of the chain?
57
+ required: true
58
+ default: 'https://beta.abtnetwork.io/api/'
59
+ secure: false
60
+ capabilities: {}
61
+ screenshots: []
62
+ children: []
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="<%- base %>/favicon.svg" />
6
+ <link rel="alternate icon" href="<%- base %>/favicon.ico" />
7
+ <link rel="mask-icon" href="<%- base %>/favicon.svg" color="#4F6AF5" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
9
+ <meta name="theme-color" content="#4F6AF5" />
10
+ <meta name="description" content="Web site created using create-blocklet" />
11
+ <title><%- title %></title>
12
+ <script src="__meta__.js"></script>
13
+ </head>
14
+ <body>
15
+ <div id="app"></div>
16
+ <script type="module" src="/src/main.js"></script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "template-vue",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "dev": "vite",
6
+ "build": "vite build",
7
+ "serve": "vite preview",
8
+ "start": "npm-run-all --parallel start:*",
9
+ "start:client": "vite --host",
10
+ "start:server": "NODE_ENV=development nodemon server/index.js -w server",
11
+ "clean": "rm -rf .blocklet",
12
+ "bundle": "npm run bundle:client && npm run bundle:server",
13
+ "bundle:client": "vite build --base /.blocklet/proxy/<%= did %>",
14
+ "bundle:server": "npm run clean && blocklet bundle --zip --create-release",
15
+ "deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
16
+ "upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json"
17
+ },
18
+ "dependencies": {
19
+ "@arcblock/did-auth": "latest",
20
+ "@arcblock/did-auth-storage-nedb": "latest",
21
+ "@blocklet/sdk": "latest",
22
+ "@ocap/client": "latest",
23
+ "@ocap/mcrypto": "latest",
24
+ "@ocap/wallet": "latest",
25
+ "axios": "^0.21.1",
26
+ "compression": "^1.7.4",
27
+ "cookie-parser": "^1.4.5",
28
+ "cors": "^2.8.5",
29
+ "dotenv-flow": "^3.2.0",
30
+ "express": "^4.17.1",
31
+ "express-async-errors": "^3.1.1",
32
+ "express-history-api-fallback": "^2.2.1",
33
+ "vite-plugin-html": "^2.1.1",
34
+ "vue": "^3.2.16"
35
+ },
36
+ "devDependencies": {
37
+ "@vitejs/plugin-vue": "^1.9.3",
38
+ "nodemon": "^2.0.12",
39
+ "npm-run-all": "^4.1.5",
40
+ "vite": "^2.6.4",
41
+ "prettier": "^2.3.2"
42
+ }
43
+ }
@@ -0,0 +1,33 @@
1
+ require('dotenv-flow').config();
2
+
3
+ const Client = require('@ocap/client');
4
+
5
+ const env = require('../libs/env');
6
+ const { wallet } = require('../libs/auth');
7
+ const logger = require('../libs/logger');
8
+ const { name } = require('../../package.json');
9
+
10
+ const client = new Client(env.chainHost);
11
+
12
+ const ensureAccountDeclared = async () => {
13
+ // Check for application account, skip this if we are running as a child component
14
+ if (env.isComponent) return;
15
+
16
+ const { state } = await client.getAccountState({ address: wallet.toAddress() }, { ignoreFields: ['context'] });
17
+ if (!state) {
18
+ const hash = await client.declare({ moniker: name, wallet });
19
+ logger.log(`app account declared on chain ${env.chainHost}`, hash);
20
+ } else {
21
+ logger.log(`app account already declared on chain ${env.chainHost}`);
22
+ }
23
+ };
24
+
25
+ (async () => {
26
+ try {
27
+ await ensureAccountDeclared();
28
+ process.exit(0);
29
+ } catch (err) {
30
+ logger.error(`${name} pre-start error`, err.message);
31
+ process.exit(1);
32
+ }
33
+ })();
@@ -0,0 +1,55 @@
1
+ require('dotenv-flow').config();
2
+ require('express-async-errors');
3
+ const path = require('path');
4
+ const cors = require('cors');
5
+ const express = require('express');
6
+ const compression = require('compression');
7
+ const cookieParser = require('cookie-parser');
8
+ const fallback = require('express-history-api-fallback');
9
+
10
+ const { name, version } = require('../package.json');
11
+ const logger = require('./libs/logger');
12
+
13
+ const app = express();
14
+
15
+ app.set('trust proxy', true);
16
+ app.use(cookieParser());
17
+ app.use(express.json({ limit: '1 mb' }));
18
+ app.use(express.urlencoded({ extended: true, limit: '1 mb' }));
19
+
20
+ const router = express.Router();
21
+ router.use('/api', require('./routes'));
22
+
23
+ const isDevelopment = process.env.NODE_ENV === 'development';
24
+ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
25
+
26
+ if (isDevelopment) {
27
+ process.env.BLOCKLET_PORT = 3030;
28
+ }
29
+
30
+ if (isProduction) {
31
+ app.use(cors());
32
+ app.use(compression());
33
+
34
+ const staticDir = path.resolve(__dirname, '../', 'dist');
35
+ app.use(express.static(staticDir, { index: 'index.html' }));
36
+ app.use(router);
37
+ app.use(fallback('index.html', { root: staticDir }));
38
+
39
+ app.use((req, res) => {
40
+ res.status(404).send('404 NOT FOUND');
41
+ });
42
+ app.use((err, req, res) => {
43
+ logger.error(err.stack);
44
+ res.status(500).send('Something broke!');
45
+ });
46
+ } else {
47
+ app.use(router);
48
+ }
49
+
50
+ const port = parseInt(process.env.BLOCKLET_PORT || process.env.APP_PORT, 10) || 3030;
51
+
52
+ app.listen(port, (err) => {
53
+ if (err) throw err;
54
+ logger.info(`> ${name} v${version} ready on ${port}`);
55
+ });
@@ -0,0 +1,31 @@
1
+ const path = require('path');
2
+ const AuthStorage = require('@arcblock/did-auth-storage-nedb');
3
+ const WalletAuthenticator = require('@blocklet/sdk/lib/wallet-authenticator');
4
+ const WalletHandlers = require('@blocklet/sdk/lib/wallet-handler');
5
+ const { types } = require('@ocap/mcrypto');
6
+ const { fromSecretKey, WalletType } = require('@ocap/wallet');
7
+ const logger = require('./logger');
8
+
9
+ const appSk = process.env.APP_SK || process.env.BLOCKLET_APP_SK;
10
+ const wallet = fromSecretKey(appSk, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
11
+
12
+ const authenticator = new WalletAuthenticator();
13
+
14
+ const handlers = new WalletHandlers({
15
+ authenticator,
16
+ tokenGenerator: () => Date.now().toString(),
17
+ tokenStorage: new AuthStorage({
18
+ dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
19
+ onload: (err) => {
20
+ if (err) {
21
+ logger.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
22
+ }
23
+ },
24
+ }),
25
+ });
26
+
27
+ module.exports = {
28
+ authenticator,
29
+ handlers,
30
+ wallet,
31
+ };
@@ -0,0 +1,12 @@
1
+ const blockletRealDid = process.env.BLOCKLET_REAL_DID || '';
2
+ const blockletDid = process.env.BLOCKLET_DID || '';
3
+ const isComponent = blockletRealDid && blockletDid && blockletRealDid !== blockletDid;
4
+
5
+ module.exports = {
6
+ chainId: process.env.CHAIN_ID || '',
7
+ chainHost: process.env.CHAIN_HOST || '',
8
+ appId: process.env.BLOCKLET_APP_ID || '',
9
+ appName: process.env.APP_NAME || process.env.BLOCKLET_APP_NAME || '',
10
+ appDescription: process.env.APP_DESCRIPTION || process.env.BLOCKLET_APP_DESCRIPTION || '',
11
+ isComponent,
12
+ };
@@ -0,0 +1,3 @@
1
+ const logger = console;
2
+
3
+ module.exports = logger;
@@ -0,0 +1,10 @@
1
+ module.exports = (req, res, next) => {
2
+ if (req.headers['x-user-did']) {
3
+ req.user = {
4
+ did: req.headers['x-user-did'],
5
+ role: req.headers['x-user-role'],
6
+ fullName: decodeURIComponent(req.headers['x-user-fullname']),
7
+ };
8
+ }
9
+ next();
10
+ };
@@ -0,0 +1,6 @@
1
+ const router = require('express').Router();
2
+ const env = require('../libs/env');
3
+
4
+ router.use('/env', (req, res) => res.json(env));
5
+
6
+ module.exports = router;
@@ -0,0 +1,35 @@
1
+ <script setup>
2
+ import { ref } from 'vue';
3
+ // This starter template is using Vue 3 <script setup> SFCs
4
+ // Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
5
+ import HelloWorld from './components/HelloWorld.vue';
6
+ import api from './libs/api';
7
+
8
+ const envData = ref({});
9
+
10
+ (async () => {
11
+ const { data } = await api.get('/api/env');
12
+ envData.value = data;
13
+ })();
14
+ </script>
15
+
16
+ <template>
17
+ <img alt="Vue logo" src="./assets/logo.png" />
18
+ <HelloWorld msg="Hello Vue 3 + Vite" />
19
+ <div :style="{ display: 'flex', justifyContent: 'center' }">
20
+ <pre :style="{ textAlign: 'left' }">
21
+ <code>{{ JSON.stringify(envData, null, 2) }}</code>
22
+ </pre>
23
+ </div>
24
+ </template>
25
+
26
+ <style>
27
+ #app {
28
+ font-family: Avenir, Helvetica, Arial, sans-serif;
29
+ -webkit-font-smoothing: antialiased;
30
+ -moz-osx-font-smoothing: grayscale;
31
+ text-align: center;
32
+ color: #2c3e50;
33
+ margin-top: 60px;
34
+ }
35
+ </style>