create-blocklet 0.2.17 → 0.3.1

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 (107) hide show
  1. package/common/.github/workflows/main.yml +5 -5
  2. package/common/.husky/pre-commit +4 -0
  3. package/common/_eslintignore +10 -0
  4. package/common/_eslintrc.js +1 -0
  5. package/common/_gitignore +15 -9
  6. package/common/logo.png +0 -0
  7. package/common/public/favicon.ico +0 -0
  8. package/index.js +195 -106
  9. package/lib/arcblock.js +11 -7
  10. package/lib/git.js +25 -0
  11. package/lib/index.js +17 -5
  12. package/lib/npm.js +7 -9
  13. package/lib/server.js +26 -20
  14. package/package.json +18 -16
  15. package/template-api/express/README.md +146 -0
  16. package/{template-dapp/react/server → template-api/express/api}/hooks/pre-start.js +0 -0
  17. package/template-api/express/api/index.js +13 -0
  18. package/{template-dapp/react/server → template-api/express/api}/libs/auth.js +0 -0
  19. package/{template-dapp/react/server → template-api/express/api}/libs/env.js +0 -0
  20. package/{template-dapp/react/server → template-api/express/api}/libs/logger.js +0 -0
  21. package/template-api/express/blocklet.md +3 -0
  22. package/template-api/express/blocklet.yml +57 -0
  23. package/template-api/express/package.json +26 -0
  24. package/template-api/express/screenshots/.gitkeep +0 -0
  25. package/template-dapp/nextjs/.eslintrc.js +4 -0
  26. package/template-dapp/nextjs/README.md +153 -0
  27. package/template-dapp/{vue/server → nextjs/api}/hooks/pre-start.js +0 -0
  28. package/template-dapp/nextjs/api/index.js +24 -0
  29. package/template-dapp/{vue/server → nextjs/api}/libs/auth.js +0 -0
  30. package/template-dapp/{vue/server → nextjs/api}/libs/env.js +0 -0
  31. package/template-dapp/{vue/server → nextjs/api}/libs/logger.js +0 -0
  32. package/template-dapp/{vue2/server → nextjs/api}/routes/index.js +1 -1
  33. package/template-dapp/nextjs/blocklet.md +3 -0
  34. package/template-dapp/nextjs/blocklet.yml +58 -0
  35. package/template-dapp/nextjs/next.config.js +6 -0
  36. package/template-dapp/nextjs/package.json +48 -0
  37. package/template-dapp/nextjs/pages/_app.js +21 -0
  38. package/template-dapp/nextjs/pages/api/hello.js +5 -0
  39. package/template-dapp/nextjs/pages/index.js +69 -0
  40. package/template-dapp/nextjs/styles/Home.module.css +116 -0
  41. package/template-dapp/nextjs/styles/globals.css +16 -0
  42. package/template-dapp/react/README.md +5 -5
  43. package/template-dapp/{vue2/server → react/api}/hooks/pre-start.js +0 -0
  44. package/template-dapp/react/{server → api}/index.js +0 -0
  45. package/template-dapp/{vue2/server → react/api}/libs/auth.js +0 -0
  46. package/template-dapp/{vue2/server → react/api}/libs/env.js +0 -0
  47. package/template-dapp/{vue2/server → react/api}/libs/logger.js +0 -0
  48. package/template-dapp/react/{server → api}/routes/index.js +1 -1
  49. package/template-dapp/react/blocklet.yml +7 -7
  50. package/template-dapp/react/package.json +35 -23
  51. package/template-dapp/react/public/index.html +1 -3
  52. package/template-dapp/react/src/app.js +8 -8
  53. package/template-dapp/vue/.browserslistrc +4 -0
  54. package/template-dapp/vue/.eslintrc.js +25 -0
  55. package/template-dapp/vue/api/hooks/pre-start.js +33 -0
  56. package/template-dapp/vue/{server → api}/index.js +0 -0
  57. package/template-dapp/vue/api/libs/auth.js +22 -0
  58. package/template-dapp/vue/api/libs/env.js +6 -0
  59. package/template-dapp/vue/api/libs/logger.js +3 -0
  60. package/template-dapp/vue/{server → api}/routes/index.js +1 -1
  61. package/template-dapp/vue/blocklet.yml +7 -6
  62. package/template-dapp/vue/index.html +2 -3
  63. package/template-dapp/vue/package.json +39 -21
  64. package/template-dapp/vue/src/App.vue +4 -2
  65. package/template-dapp/vue/vite.config.js +10 -6
  66. package/template-dapp/vue2/.browserslistrc +4 -0
  67. package/template-dapp/vue2/.eslintrc.js +14 -0
  68. package/template-dapp/vue2/api/hooks/pre-start.js +33 -0
  69. package/template-dapp/vue2/{server → api}/index.js +0 -0
  70. package/template-dapp/vue2/api/libs/auth.js +22 -0
  71. package/template-dapp/vue2/api/libs/env.js +6 -0
  72. package/template-dapp/vue2/api/libs/logger.js +3 -0
  73. package/template-dapp/vue2/api/routes/index.js +6 -0
  74. package/template-dapp/vue2/blocklet.yml +8 -6
  75. package/template-dapp/vue2/jsconfig.json +19 -0
  76. package/template-dapp/vue2/package.json +38 -43
  77. package/template-dapp/vue2/public/index.html +2 -9
  78. package/template-dapp/vue2/src/App.vue +17 -1
  79. package/template-dapp/vue2/src/main.js +0 -2
  80. package/template-dapp/vue2/vue.config.js +0 -1
  81. package/template-static/blocklet-page/package.json +5 -5
  82. package/template-static/react/blocklet.yml +3 -3
  83. package/template-static/react/package.json +21 -9
  84. package/template-static/react/public/index.html +1 -3
  85. package/template-static/react/src/app.js +8 -8
  86. package/template-static/vue/.browserslistrc +4 -0
  87. package/template-static/vue/.eslintrc.js +25 -0
  88. package/template-static/vue/blocklet.yml +3 -3
  89. package/template-static/vue/index.html +2 -3
  90. package/template-static/vue/package.json +26 -8
  91. package/template-static/vue/vite.config.js +10 -6
  92. package/template-static/vue2/.browserslistrc +4 -0
  93. package/template-static/vue2/.eslintrc.js +14 -0
  94. package/template-static/vue2/blocklet.yml +3 -3
  95. package/template-static/vue2/jsconfig.json +19 -0
  96. package/template-static/vue2/package.json +25 -30
  97. package/template-static/vue2/public/index.html +2 -9
  98. package/template-static/vue2/src/App.vue +7 -1
  99. package/template-static/vue2/src/main.js +0 -2
  100. package/template-static/vue2/vue.config.js +0 -3
  101. package/common/public/favicon.svg +0 -1
  102. package/template-dapp/vue2/src/pages/About.vue +0 -13
  103. package/template-dapp/vue2/src/pages/Home.vue +0 -27
  104. package/template-dapp/vue2/src/router.js +0 -24
  105. package/template-static/vue2/src/pages/About.vue +0 -13
  106. package/template-static/vue2/src/pages/Home.vue +0 -20
  107. package/template-static/vue2/src/router.js +0 -24
package/lib/server.js CHANGED
@@ -1,38 +1,44 @@
1
+ import { $, which } from 'zx';
1
2
  import semver from 'semver';
2
- import { getOutput } from './index.js';
3
3
 
4
- export function checkServerInstalled() {
5
- const output = getOutput('which blocklet');
6
- return !!output;
4
+ $.verbose = false;
5
+
6
+ export async function checkServerInstalled() {
7
+ try {
8
+ await which('blocklet');
9
+ return true;
10
+ } catch (e) {
11
+ return false;
12
+ }
7
13
  }
8
14
 
9
- export function getServerVersion() {
10
- const output = getOutput('blocklet --version');
15
+ export async function getServerVersion() {
16
+ const { stdout: output } = await $`blocklet --version`;
11
17
  return output.trim();
12
18
  }
13
19
 
14
- export function getServerStatus() {
15
- const output = getOutput('blocklet server status');
16
- const [matchStr] = output.match(/Blocklet Server status:[\s\S]*?\n/g) || [];
17
- if (!matchStr) {
20
+ export async function getServerStatus() {
21
+ try {
22
+ const { stdout: output } = await $`blocklet server status`;
23
+ const [matchStr] = output.match(/Blocklet Server status:[\s\S]*?\n/g) || [];
24
+ const status = matchStr.replace(/Blocklet Server status:\s*(\S+)\s*\S*\n*[\s\S]*/gm, '$1');
25
+ return status.toLowerCase();
26
+ } catch (e) {
18
27
  return 'stop';
19
28
  }
20
- const status = matchStr.replace(/Blocklet Server status:\s*(\S+)\s*\S*\n*[\s\S]*/gm, '$1');
21
- return status.toLowerCase();
22
29
  }
23
- export function checkServerRunning() {
24
- const status = getServerStatus();
30
+ export async function checkServerRunning() {
31
+ const status = await getServerStatus();
25
32
  return status === 'running';
26
33
  }
27
34
 
28
- export function checkSatisfiedVersion() {
29
- const output = getOutput('blocklet --version');
30
- const version = output.trim();
31
- return semver.satisfies(version, '>= 1.6.1');
35
+ export async function checkSatisfiedVersion() {
36
+ const version = await getServerVersion();
37
+ return semver.satisfies(version, '>= 1.7.0');
32
38
  }
33
39
 
34
- export function getServerDirectory() {
35
- const output = getOutput('blocklet server status');
40
+ export async function getServerDirectory() {
41
+ const { stdout: output } = await $`blocklet server status`;
36
42
  const [matchStr] = output.match(/Blocklet Server Data Directory:[\s\S]*?\n/gm) || [];
37
43
  if (!matchStr) return null;
38
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.2.17",
3
+ "version": "0.3.1",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -13,36 +13,37 @@
13
13
  "index.js",
14
14
  "common",
15
15
  "lib",
16
+ "template-api",
16
17
  "template-dapp",
17
18
  "template-static"
18
19
  ],
19
20
  "engines": {
20
- "node": ">=14.0.0"
21
+ "node": ">=16.0.0"
21
22
  },
22
23
  "bugs": {
23
24
  "url": "https://github.com/blocklet/create-blocklet/issues"
24
25
  },
25
26
  "homepage": "https://github.com/blocklet/create-blocklet/tree/main#readme",
26
27
  "scripts": {
27
- "lint": "eslint ."
28
+ "lint": "eslint .",
29
+ "test": "vitest",
30
+ "test:ui": "vitest --ui",
31
+ "test:run": "vitest run"
28
32
  },
29
33
  "dependencies": {
30
- "@arcblock/did": "^1.13.55",
31
- "@ocap/mcrypto": "^1.13.55",
32
- "@ocap/util": "^1.13.55",
34
+ "@arcblock/did": "^1.14.25",
35
+ "@ocap/mcrypto": "^1.14.25",
36
+ "@ocap/util": "^1.14.25",
37
+ "boxen": "^6.2.1",
33
38
  "ejs": "^3.1.6",
34
- "envfile": "^6.15.0",
35
- "figlet": "^1.5.0",
36
- "gradient-string": "^1.2.0",
39
+ "envfile": "^6.17.0",
40
+ "figlet": "^1.5.2",
41
+ "gradient-string": "^2.0.0",
37
42
  "jdenticon": "^3.1.1",
38
- "kolorist": "^1.5.0",
39
- "minimist": "^1.2.5",
40
- "prompts": "^2.4.1",
41
- "rc": "^1.2.8",
43
+ "prompts": "^2.4.2",
42
44
  "semver": "^7.3.5",
43
- "shelljs": "^0.8.5",
44
45
  "terminal-link": "^3.0.0",
45
- "yaml": "^1.10.2"
46
+ "zx": "^6.0.6"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@arcblock/eslint-config": "0.1.8",
@@ -56,6 +57,7 @@
56
57
  "eslint-plugin-react": "^7.24.0",
57
58
  "eslint-plugin-react-hooks": "^4.2.0",
58
59
  "eslint-plugin-unicorn": "^34.0.1",
59
- "prettier": "^2.3.2"
60
+ "prettier": "^2.3.2",
61
+ "vitest": "^0.7.6"
60
62
  }
61
63
  }
@@ -0,0 +1,146 @@
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 dapp project, which means this is a full-stack application. It's contained both `server` and `client` code.
6
+
7
+ ## File Structure
8
+
9
+ - screenshots/ - Screenshots
10
+ - api/ - Api side code
11
+ - hooks/ - blocklet lifecycle hooks
12
+ - libs/ - Api side libraries
13
+ - middlewares/ - Api side middlewares
14
+ - routes/ - Api side routes
15
+ - index.js - Api side entry point
16
+ - .env - Environment variables
17
+ - .env.local - Local environment variables
18
+ - .prettierrc - Prettier configuration
19
+ - blocklet.md - Blocklet README
20
+ - blocklet.yml - Blocklet configuration
21
+ - LICENSE - License file
22
+ - logo.png - Blocklet logo file
23
+ - Makefile - Makefile
24
+ - package.json - Npm package file
25
+ - README.md - A guide for this blocklet
26
+ - version - Version file
27
+
28
+ ## Development
29
+
30
+ 1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
31
+
32
+ Blocklet needs blocklet server as a dependency. So you need to install it first.
33
+ `npm install -g @blocklet/cli`
34
+ 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)
35
+
36
+ 2. Init blocklet server & start blocklet server
37
+
38
+ Before starting an blocklet server, you need to init blocklet server.
39
+ `blocklet server init --mode=debug`
40
+ `blocklet server start`
41
+ 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)
42
+
43
+ 3. Go to the project directory `cd [name]`
44
+ 4. Install dependencies: `npm install` or `yarn`
45
+ 5. Start development server: `blocklet dev`
46
+
47
+ ## Bundle
48
+
49
+ After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
50
+
51
+ ## Deploy
52
+
53
+ - If you want to deploy this blocklet to local blocklet server, you can use `blocklet deploy .blocklet/bundle` command(Make sure the blocklet is bundled before deployment).
54
+ > Or you can simply use `npm run deploy` command.
55
+ - If you want to deploy this blocklet to remote blocklet server, you can use the command below.
56
+
57
+ ```shell
58
+ blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
59
+ ```
60
+
61
+ > Make sure the blocklet is bundled before deployment.
62
+
63
+ ## Upload to blocklet store
64
+
65
+ - If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
66
+
67
+ Bump version at first.
68
+
69
+ ```shell
70
+ make bump-version
71
+ ```
72
+
73
+ Then config blocklet store url.
74
+ You can use those store url in below.
75
+
76
+ 1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
77
+ 2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
78
+ 3. A blocklet store started by yourself.
79
+ > Make sure you have installed a `blocklet store` on your own blocklet server. Check it on here: [https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)
80
+
81
+ ```shell
82
+ blocklet config set store {store url}
83
+ ```
84
+
85
+ Get a `accessToken` by using this command.
86
+
87
+ > Why we need a `accessToken`?
88
+ > A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
89
+
90
+ Set `accessToken` to blocklet config
91
+
92
+ ```shell
93
+ blocklet config set accessToken {accessToken}
94
+ ```
95
+
96
+ Upload a new version to a store.
97
+
98
+ > Make sure the blocklet is bundled before upload.
99
+
100
+ ```shell
101
+ blocklet upload
102
+ ```
103
+
104
+ Or you can simply use `npm run upload` command.
105
+
106
+ - You also can upload a new version to a store by Github CI.
107
+ Bump version at first.
108
+
109
+ ```shell
110
+ make bump-version
111
+ ```
112
+
113
+ Push your code to Github main/master branch, or make a pull request to the main/master branch.
114
+ The CI workflow will automatically upload a new version to a store.
115
+
116
+ ## Q & A
117
+
118
+ 1. Q: How to change a blocklet's name?
119
+
120
+ A: Change the `name` field in the `package.json` file, change the `name` field in the `blocklet.yml` file.
121
+
122
+ You can also change the `title` field and `description` field in the `blocklet.yml` file.
123
+
124
+ Run `blocklet meta` command, you will get a `did` config, copy the `did` value.
125
+
126
+ Replace this command `"bundle:client": "PUBLIC_URL='/.blocklet/proxy/{did}' npm run build",` in `package.json`
127
+
128
+ Replace `did` field in the `blocklet.yml`
129
+
130
+ 2. Q: How to change a blocklet's logo?
131
+
132
+ Change the `logo.png` file root folder.
133
+
134
+ Or you can change the `logo` field in the `blocklet.yml` file.
135
+
136
+ > Make sure you have added the logo path to the `blocklet.yml` file `files` field.
137
+
138
+ ## Learn More
139
+
140
+ - 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)
141
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
142
+
143
+ ## License
144
+
145
+ The code is licensed under the Apache 2.0 license found in the
146
+ [LICENSE](LICENSE) file.
@@ -0,0 +1,13 @@
1
+ const express = require('express');
2
+
3
+ const app = express();
4
+
5
+ const port = process.env.BLOCKLET_PORT || 3030;
6
+
7
+ app.get('/', (req, res) => {
8
+ res.send('Hello World, Blocklet!');
9
+ });
10
+
11
+ app.listen(port, () => {
12
+ console.log(`Blocklet app listening on port ${port}`);
13
+ });
@@ -0,0 +1,3 @@
1
+ # template-react
2
+
3
+ A react template for creating a new blocklet project.
@@ -0,0 +1,57 @@
1
+ name: template-express
2
+ title: Blocklet Template Express
3
+ description: A Blocklet Api blocklet
4
+ keywords:
5
+ - blocklet
6
+ - react
7
+ group: dapp
8
+ did: ''
9
+ main: api/index.js
10
+ author:
11
+ name: Blocklet
12
+ email: blocklet@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
+ - logo.png
21
+ - README.md
22
+ - blocklet.md
23
+ - screenshots
24
+ - api/hooks/pre-start.js
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
+ server: '>=1.6.29'
44
+ os: '*'
45
+ cpu: '*'
46
+ scripts:
47
+ preStart: node api/hooks/pre-start.js
48
+ dev: npm run start
49
+ environments:
50
+ - name: CHAIN_HOST
51
+ description: What's endpoint of the chain?
52
+ required: true
53
+ default: 'https://beta.abtnetwork.io/api/'
54
+ secure: false
55
+ capabilities: {}
56
+ screenshots: []
57
+ children: []
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "express",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "api/index.js",
6
+ "scripts": {
7
+ "start": "NODE_ENV=development nodemon api/index.js -w api",
8
+ "clean": "rm -rf .blocklet",
9
+ "bundle": "npm run clean && blocklet bundle --zip --create-release",
10
+ "deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
11
+ "upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "@arcblock/did-auth-storage-nedb": "^1.6.3",
18
+ "@blocklet/sdk": "^1.7.0",
19
+ "@ocap/client": "^1.15.2",
20
+ "dotenv-flow": "^3.2.0",
21
+ "express": "^4.17.3"
22
+ },
23
+ "devDependencies": {
24
+ "nodemon": "^2.0.15"
25
+ }
26
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: 'next/core-web-vitals',
4
+ };
@@ -0,0 +1,153 @@
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 dapp project, which means this is a full-stack application. It's contained both `api` and `client` code.
6
+
7
+ ## File Structure
8
+
9
+ - public/ - static files
10
+ - favicon.ico - favicon
11
+ - screenshots/ - Screenshots
12
+ - api/ - Api side code
13
+ - hooks/ - blocklet lifecycle hooks
14
+ - libs/ - Api side libraries
15
+ - middlewares/ - Api side middlewares
16
+ - routes/ - Api side routes
17
+ - index.js - Api side entry point
18
+ - pages/ - next.js pages folder
19
+ - styles/ - next.js styles folder
20
+ - .env - Environment variables
21
+ - .env.local - Local environment variables
22
+ - .eslintrc.js - ESLint configuration
23
+ - .gitignore - Git ignore file
24
+ - .prettierrc - Prettier configuration
25
+ - blocklet.md - Blocklet README
26
+ - blocklet.yml - Blocklet configuration
27
+ - LICENSE - License file
28
+ - logo.png - Blocklet logo file
29
+ - Makefile - Makefile
30
+ - next.config.js - next.js config file
31
+ - package.json - Npm package file
32
+ - README.md - A guide for this blocklet
33
+ - version - Version file
34
+
35
+ ## Development
36
+
37
+ 1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
38
+
39
+ Blocklet needs blocklet server as a dependency. So you need to install it first.
40
+ `npm install -g @blocklet/cli`
41
+ 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)
42
+
43
+ 2. Init blocklet server & start blocklet server
44
+
45
+ Before starting an blocklet server, you need to init blocklet server.
46
+ `blocklet server init --mode=debug`
47
+ `blocklet server start`
48
+ 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)
49
+
50
+ 3. Go to the project directory `cd [name]`
51
+ 4. Install dependencies: `npm install` or `yarn`
52
+ 5. Start development server: `blocklet dev`
53
+
54
+ ## Bundle
55
+
56
+ After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
57
+
58
+ ## Deploy
59
+
60
+ - If you want to deploy this blocklet to local blocklet server, you can use `blocklet deploy .blocklet/bundle` command(Make sure the blocklet is bundled before deployment).
61
+ > Or you can simply use `npm run deploy` command.
62
+ - If you want to deploy this blocklet to remote blocklet server, you can use the command below.
63
+
64
+ ```shell
65
+ blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
66
+ ```
67
+
68
+ > Make sure the blocklet is bundled before deployment.
69
+
70
+ ## Upload to blocklet store
71
+
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
+
74
+ Bump version at first.
75
+
76
+ ```shell
77
+ make bump-version
78
+ ```
79
+
80
+ Then config blocklet store url.
81
+ You can use those store url in below.
82
+
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 blocklet server. Check it on here: [https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)
87
+
88
+ ```shell
89
+ blocklet config set store {store url}
90
+ ```
91
+
92
+ Get a `accessToken` by using this command.
93
+
94
+ > Why we need a `accessToken`?
95
+ > A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
96
+
97
+ Set `accessToken` to blocklet config
98
+
99
+ ```shell
100
+ blocklet config set accessToken {accessToken}
101
+ ```
102
+
103
+ Upload a new version to a store.
104
+
105
+ > Make sure the blocklet is bundled before upload.
106
+
107
+ ```shell
108
+ blocklet upload
109
+ ```
110
+
111
+ Or you can simply use `npm run upload` command.
112
+
113
+ - You also can upload a new version to a store by Github CI.
114
+ Bump version at first.
115
+
116
+ ```shell
117
+ make bump-version
118
+ ```
119
+
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 store.
122
+
123
+ ## Q & A
124
+
125
+ 1. Q: How to change a blocklet's name?
126
+
127
+ A: Change the `name` field in the `package.json` file, change the `name` field in the `blocklet.yml` file.
128
+
129
+ You can also change the `title` field and `description` field in the `blocklet.yml` file.
130
+
131
+ Run `blocklet meta` command, you will get a `did` config, copy the `did` value.
132
+
133
+ Replace this command `"bundle:client": "PUBLIC_URL='/.blocklet/proxy/{did}' npm run build",` in `package.json`
134
+
135
+ Replace `did` field in the `blocklet.yml`
136
+
137
+ 2. Q: How to change a blocklet's logo?
138
+
139
+ Change the `logo.png` file root folder.
140
+
141
+ Or you can change the `logo` field in the `blocklet.yml` file.
142
+
143
+ > Make sure you have added the logo path to the `blocklet.yml` file `files` field.
144
+
145
+ ## Learn More
146
+
147
+ - 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)
148
+ - Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
149
+
150
+ ## License
151
+
152
+ The code is licensed under the Apache 2.0 license found in the
153
+ [LICENSE](LICENSE) file.
@@ -0,0 +1,24 @@
1
+ const express = require('express');
2
+ const next = require('next');
3
+
4
+ const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3000;
5
+ const dev = process.env.NODE_ENV !== 'production';
6
+ const app = next({ dev });
7
+ const handle = app.getRequestHandler();
8
+
9
+ app.prepare().then(() => {
10
+ const server = express();
11
+
12
+ const router = express.Router();
13
+ router.use('/api', require('./routes'));
14
+ server.use(router);
15
+
16
+ server.all('*', (req, res) => {
17
+ return handle(req, res);
18
+ });
19
+
20
+ server.listen(port, (err) => {
21
+ if (err) throw err;
22
+ console.log(`> Ready on http://localhost:${port}`);
23
+ });
24
+ });
@@ -1,6 +1,6 @@
1
1
  const middleware = require('@blocklet/sdk/lib/middlewares');
2
2
  const router = require('express').Router();
3
3
 
4
- router.use('/user', middleware.user(), (req, res) => res.json(req.user));
4
+ router.use('/user', middleware.user(), (req, res) => res.json(req.user || {}));
5
5
 
6
6
  module.exports = router;
@@ -0,0 +1,3 @@
1
+ # template-react
2
+
3
+ A react template for creating a new blocklet project.
@@ -0,0 +1,58 @@
1
+ name: template-nextjs
2
+ title: Blocklet Template Next.js
3
+ description: A Blocklet DAPP blocklet
4
+ keywords:
5
+ - blocklet
6
+ - react
7
+ group: dapp
8
+ did: ''
9
+ main: api/index.js
10
+ author:
11
+ name: Blocklet
12
+ email: blocklet@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
+ - .next
21
+ - logo.png
22
+ - README.md
23
+ - blocklet.md
24
+ - screenshots
25
+ - api/hooks/pre-start.js
26
+ interfaces:
27
+ - type: web
28
+ name: publicUrl
29
+ path: /
30
+ prefix: '*'
31
+ port: BLOCKLET_PORT
32
+ protocol: http
33
+ community: ''
34
+ documentation: ''
35
+ homepage: ''
36
+ license: ''
37
+ charging:
38
+ price: 0
39
+ tokens: []
40
+ shares: []
41
+ timeout:
42
+ start: 60
43
+ requirements:
44
+ server: '>=1.6.29'
45
+ os: '*'
46
+ cpu: '*'
47
+ scripts:
48
+ preStart: node api/hooks/pre-start.js
49
+ dev: npm run dev
50
+ environments:
51
+ - name: CHAIN_HOST
52
+ description: What's endpoint of the chain?
53
+ required: true
54
+ default: 'https://beta.abtnetwork.io/api/'
55
+ secure: false
56
+ capabilities: {}
57
+ screenshots: []
58
+ children: []
@@ -0,0 +1,6 @@
1
+ /** @type {import('next').NextConfig} */
2
+ const nextConfig = {
3
+ reactStrictMode: true,
4
+ };
5
+
6
+ module.exports = nextConfig;