create-blocklet 0.3.3 → 0.3.6
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.
- package/README.md +14 -0
- package/index.js +38 -28
- package/lib/did.js +1 -1
- package/lib/git.js +21 -5
- package/lib/index.js +8 -3
- package/lib/npm.js +1 -1
- package/lib/server.js +23 -11
- package/package.json +9 -10
- package/{template-static/blocklet-page → templates/blocklet-page-static}/README.md +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/blocklet.md +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/blocklet.yml +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/package.json +1 -1
- package/{template-static/blocklet-page → templates/blocklet-page-static}/site/blocks/CustomBlock.mdx +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/site/composes/MyLayout.mdx +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/site/pages/index.mdx +0 -0
- package/{template-static/blocklet-page → templates/blocklet-page-static}/xmark.yml +0 -0
- package/{template-api/express → templates/express-api}/README.md +0 -0
- package/{template-api/express → templates/express-api}/api/hooks/pre-start.js +0 -0
- package/{template-api/express → templates/express-api}/api/index.js +0 -0
- package/{template-api/express → templates/express-api}/api/libs/auth.js +0 -0
- package/{template-api/express → templates/express-api}/api/libs/env.js +0 -0
- package/{template-api/express → templates/express-api}/api/libs/logger.js +0 -0
- package/{template-api/express → templates/express-api}/blocklet.md +0 -0
- package/{template-api/express → templates/express-api}/blocklet.yml +3 -4
- package/{template-api/express → templates/express-api}/package.json +0 -0
- package/{template-api/express → templates/express-api}/screenshots/.gitkeep +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/.eslintrc.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/README.md +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/hooks/pre-start.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/index.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/libs/auth.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/libs/env.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/libs/logger.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/api/routes/index.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/blocklet.md +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/blocklet.yml +3 -4
- package/{template-dapp/nextjs → templates/nextjs-dapp}/next.config.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/package.json +5 -5
- package/{template-dapp/nextjs → templates/nextjs-dapp}/pages/_app.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/pages/api/hello.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/pages/index.js +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/styles/Home.module.css +0 -0
- package/{template-dapp/nextjs → templates/nextjs-dapp}/styles/globals.css +0 -0
- package/{template-dapp/react → templates/react-dapp}/.env +0 -0
- package/{template-dapp/react → templates/react-dapp}/.env.local +0 -0
- package/{template-dapp/react → templates/react-dapp}/README.md +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/hooks/pre-start.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/index.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/libs/auth.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/libs/env.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/libs/logger.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/api/routes/index.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/blocklet.md +0 -0
- package/{template-dapp/react → templates/react-dapp}/blocklet.yml +3 -4
- package/templates/react-dapp/craco.config.js +17 -0
- package/{template-dapp/react → templates/react-dapp}/package.json +8 -8
- package/{template-dapp/react → templates/react-dapp}/public/index.html +0 -0
- package/{template-static/react → templates/react-dapp}/src/app.css +5 -3
- package/{template-dapp/react → templates/react-dapp}/src/app.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/src/index.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/src/libs/api.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/src/logo.svg +0 -0
- package/{template-dapp/react → templates/react-dapp}/src/pages/about.js +0 -0
- package/{template-dapp/react → templates/react-dapp}/src/pages/home.js +1 -1
- package/templates/react-gun-dapp/.env +3 -0
- package/templates/react-gun-dapp/README.md +153 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/api/hooks/pre-start.js +0 -0
- package/templates/react-gun-dapp/api/index.js +65 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/api/libs/auth.js +0 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/api/libs/env.js +0 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/api/libs/logger.js +0 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/api/routes/index.js +0 -0
- package/{template-static/react → templates/react-gun-dapp}/blocklet.md +0 -0
- package/templates/react-gun-dapp/blocklet.yml +57 -0
- package/templates/react-gun-dapp/craco.config.js +30 -0
- package/templates/react-gun-dapp/package.json +81 -0
- package/{template-static/react → templates/react-gun-dapp}/public/index.html +0 -0
- package/templates/react-gun-dapp/src/app.css +41 -0
- package/{template-static/react → templates/react-gun-dapp}/src/app.js +0 -0
- package/{template-static/react → templates/react-gun-dapp}/src/index.js +0 -0
- package/{template-dapp/vue → templates/react-gun-dapp}/src/libs/api.js +0 -0
- package/templates/react-gun-dapp/src/logo.svg +1 -0
- package/templates/react-gun-dapp/src/pages/about.js +26 -0
- package/templates/react-gun-dapp/src/pages/home.js +61 -0
- package/{template-static/react → templates/react-static}/.env +0 -0
- package/{template-static/react → templates/react-static}/README.md +0 -0
- package/templates/react-static/blocklet.md +3 -0
- package/{template-static/react → templates/react-static}/blocklet.yml +3 -4
- package/templates/react-static/craco.config.js +11 -0
- package/{template-static/react → templates/react-static}/package.json +3 -2
- package/templates/react-static/public/index.html +35 -0
- package/{template-dapp/react → templates/react-static}/src/app.css +5 -3
- package/templates/react-static/src/app.js +32 -0
- package/templates/react-static/src/index.js +5 -0
- package/{template-static/react → templates/react-static}/src/logo.svg +0 -0
- package/{template-static/react → templates/react-static}/src/pages/about.js +0 -0
- package/{template-static/react → templates/react-static}/src/pages/home.js +4 -0
- package/{template-dapp/vue → templates/vue-dapp}/.browserslistrc +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/.env +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/.eslintrc.js +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/README.md +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/api/hooks/pre-start.js +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/api/index.js +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/api/libs/auth.js +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/api/libs/env.js +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/api/libs/logger.js +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/api/routes/index.js +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/blocklet.md +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/blocklet.yml +3 -4
- package/{template-dapp/vue → templates/vue-dapp}/index.html +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/package.json +7 -7
- package/{template-dapp/vue → templates/vue-dapp}/src/App.vue +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/src/assets/logo.png +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/src/components/HelloWorld.vue +0 -0
- package/{template-dapp/vue2 → templates/vue-dapp}/src/libs/api.js +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/src/main.js +0 -0
- package/{template-dapp/vue → templates/vue-dapp}/vite.config.js +0 -0
- package/{template-dapp/vue2 → templates/vue-static}/.browserslistrc +0 -0
- package/{template-dapp/vue2 → templates/vue-static}/.env +0 -0
- package/{template-static/vue → templates/vue-static}/.eslintrc.js +0 -0
- package/{template-static/vue → templates/vue-static}/README.md +0 -0
- package/{template-static/vue → templates/vue-static}/blocklet.md +0 -0
- package/{template-static/vue → templates/vue-static}/blocklet.yml +3 -4
- package/{template-static/vue → templates/vue-static}/index.html +0 -0
- package/{template-static/vue → templates/vue-static}/package.json +1 -1
- package/{template-static/vue → templates/vue-static}/src/App.vue +0 -0
- package/{template-dapp/vue2 → templates/vue-static}/src/assets/logo.png +0 -0
- package/{template-static/vue → templates/vue-static}/src/components/HelloWorld.vue +0 -0
- package/{template-static/vue → templates/vue-static}/src/main.js +0 -0
- package/{template-static/vue → templates/vue-static}/vite.config.js +0 -0
- package/{template-static/vue → templates/vue2-dapp}/.browserslistrc +0 -0
- package/{template-static/vue → templates/vue2-dapp}/.env +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/.eslintrc.js +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/README.md +0 -0
- package/templates/vue2-dapp/api/hooks/pre-start.js +33 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/api/index.js +0 -0
- package/templates/vue2-dapp/api/libs/auth.js +22 -0
- package/templates/vue2-dapp/api/libs/env.js +6 -0
- package/templates/vue2-dapp/api/libs/logger.js +3 -0
- package/templates/vue2-dapp/api/routes/index.js +6 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/babel.config.js +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/blocklet.md +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/blocklet.yml +4 -4
- package/{template-dapp/vue2 → templates/vue2-dapp}/jsconfig.json +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/package.json +6 -6
- package/{template-dapp/vue2 → templates/vue2-dapp}/public/index.html +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/src/App.vue +0 -0
- package/{template-static/vue → templates/vue2-dapp}/src/assets/logo.png +0 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/src/components/HelloWorld.vue +0 -0
- package/templates/vue2-dapp/src/libs/api.js +14 -0
- package/{template-dapp/vue2 → templates/vue2-dapp}/src/main.js +0 -0
- package/templates/vue2-dapp/vue.config.js +18 -0
- package/{template-static/vue2 → templates/vue2-static}/.browserslistrc +0 -0
- package/{template-static/vue2 → templates/vue2-static}/.env +0 -0
- package/{template-static/vue2 → templates/vue2-static}/.eslintrc.js +0 -0
- package/{template-static/vue2 → templates/vue2-static}/README.md +0 -0
- package/{template-static/vue2 → templates/vue2-static}/babel.config.js +0 -0
- package/{template-static/vue2 → templates/vue2-static}/blocklet.md +0 -0
- package/{template-static/vue2 → templates/vue2-static}/blocklet.yml +3 -4
- package/{template-static/vue2 → templates/vue2-static}/jsconfig.json +0 -0
- package/{template-static/vue2 → templates/vue2-static}/package.json +0 -0
- package/{template-static/vue2 → templates/vue2-static}/public/index.html +0 -0
- package/{template-static/vue2 → templates/vue2-static}/src/App.vue +0 -0
- package/{template-static/vue2 → templates/vue2-static}/src/assets/logo.png +0 -0
- package/{template-static/vue2 → templates/vue2-static}/src/components/HelloWorld.vue +0 -0
- package/{template-static/vue2 → templates/vue2-static}/src/main.js +0 -0
- package/templates/vue2-static/vue.config.js +13 -0
- package/template-dapp/react/src/setupProxy.js +0 -12
- package/template-dapp/vue2/vue.config.js +0 -10
- package/template-static/vue2/vue.config.js +0 -3
|
@@ -8,7 +8,7 @@ const Home = () => {
|
|
|
8
8
|
<header className="app-header">
|
|
9
9
|
<img src={logo} className="app-logo" alt="logo" />
|
|
10
10
|
<pre style={{ textAlign: 'left' }}>
|
|
11
|
-
<code>{JSON.stringify(window.blocklet, null, 2)}</code>
|
|
11
|
+
<code>window.blocklet = {JSON.stringify(window.blocklet, null, 2)}</code>
|
|
12
12
|
</pre>
|
|
13
13
|
<Link className="app-link" to="/about">
|
|
14
14
|
About
|
|
@@ -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 `server` and `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 react
|
|
13
|
+
- screenshots/ - Screenshots
|
|
14
|
+
- api/ - Api side code
|
|
15
|
+
- hooks/ - blocklet lifecycle hooks
|
|
16
|
+
- libs/ - Api side libraries
|
|
17
|
+
- middlewares/ - Api side middlewares
|
|
18
|
+
- routes/ - Api side routes
|
|
19
|
+
- index.js - Api side entry point
|
|
20
|
+
- src/ - Client side code (A standard react app structure)
|
|
21
|
+
- .env - Environment variables
|
|
22
|
+
- .env.local - Local environment variables
|
|
23
|
+
- .eslintrc.js - ESLint configuration
|
|
24
|
+
- .gitignore - Git ignore file
|
|
25
|
+
- .prettierrc - Prettier configuration
|
|
26
|
+
- blocklet.md - Blocklet README
|
|
27
|
+
- blocklet.yml - Blocklet configuration
|
|
28
|
+
- LICENSE - License file
|
|
29
|
+
- logo.png - Blocklet logo file
|
|
30
|
+
- Makefile - Makefile
|
|
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.
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require('dotenv-flow').config();
|
|
2
|
+
require('express-async-errors');
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const cors = require('cors');
|
|
6
|
+
const Gun = require('gun');
|
|
7
|
+
const express = require('express');
|
|
8
|
+
const compression = require('compression');
|
|
9
|
+
const cookieParser = require('cookie-parser');
|
|
10
|
+
const fallback = require('express-history-api-fallback');
|
|
11
|
+
|
|
12
|
+
const { name, version } = require('../package.json');
|
|
13
|
+
const logger = require('./libs/logger');
|
|
14
|
+
const env = require('./libs/env');
|
|
15
|
+
|
|
16
|
+
const app = express();
|
|
17
|
+
|
|
18
|
+
app.set('trust proxy', true);
|
|
19
|
+
app.use(cookieParser());
|
|
20
|
+
app.use(express.json({ limit: '1 mb' }));
|
|
21
|
+
app.use(express.urlencoded({ extended: true, limit: '1 mb' }));
|
|
22
|
+
|
|
23
|
+
app.use(Gun.serve);
|
|
24
|
+
|
|
25
|
+
const router = express.Router();
|
|
26
|
+
router.use('/api', require('./routes'));
|
|
27
|
+
|
|
28
|
+
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
29
|
+
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
30
|
+
|
|
31
|
+
if (isDevelopment) {
|
|
32
|
+
process.env.BLOCKLET_PORT = 3030;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isProduction) {
|
|
36
|
+
app.use(cors());
|
|
37
|
+
app.use(compression());
|
|
38
|
+
|
|
39
|
+
const staticDir = path.resolve(__dirname, '../', 'build');
|
|
40
|
+
app.use(express.static(staticDir, { index: 'index.html' }));
|
|
41
|
+
app.use(router);
|
|
42
|
+
app.use(fallback('index.html', { root: staticDir }));
|
|
43
|
+
|
|
44
|
+
app.use((req, res) => {
|
|
45
|
+
res.status(404).send('404 NOT FOUND');
|
|
46
|
+
});
|
|
47
|
+
app.use((err, req, res) => {
|
|
48
|
+
logger.error(err.stack);
|
|
49
|
+
res.status(500).send('Something broke!');
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
app.use(router);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const port = parseInt(process.env.BLOCKLET_PORT, 10) || 3030;
|
|
56
|
+
|
|
57
|
+
const server = app.listen(port, (err) => {
|
|
58
|
+
if (err) throw err;
|
|
59
|
+
logger.info(`> ${name} v${version} ready on ${port}`);
|
|
60
|
+
logger.info('> gun server ready on /gun');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const gun = Gun({ web: server, file: path.join(env.dataDir, 'gun.json') });
|
|
64
|
+
|
|
65
|
+
module.exports = { gun, server, app };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: template-react
|
|
2
|
+
title: Blocklet Template React
|
|
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
|
+
- build
|
|
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
|
+
payment:
|
|
38
|
+
price: []
|
|
39
|
+
share: []
|
|
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,30 @@
|
|
|
1
|
+
const port = process.env.BLOCKLET_PORT || process.env.PORT || 8080;
|
|
2
|
+
const dappPort = process.env.APP_PORT || 3030;
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
devServer: {
|
|
6
|
+
port,
|
|
7
|
+
client: {
|
|
8
|
+
// If you want to development this blocklet without blocklet-server, you can delete next line, otherwise the hot reload will be failed.
|
|
9
|
+
webSocketURL: 'wss://0.0.0.0/ws',
|
|
10
|
+
},
|
|
11
|
+
proxy: [
|
|
12
|
+
{
|
|
13
|
+
context: ['/api'],
|
|
14
|
+
target: `http://127.0.0.1:${dappPort}`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
context: ['/gun'],
|
|
18
|
+
target: `ws://127.0.0.1:${dappPort}`,
|
|
19
|
+
ws: true,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
webpack: {
|
|
24
|
+
configure: {
|
|
25
|
+
module: {
|
|
26
|
+
noParse: /gun\.js$/,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-gun",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"dev": "craco start",
|
|
6
|
+
"build": "craco build",
|
|
7
|
+
"eject": "react-scripts eject",
|
|
8
|
+
"lint": "eslint src api --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
9
|
+
"start": "npm-run-all --parallel start:*",
|
|
10
|
+
"start:client": "npm run dev",
|
|
11
|
+
"start:api": "NODE_ENV=development nodemon api/index.js -w api",
|
|
12
|
+
"clean": "rm -rf .blocklet",
|
|
13
|
+
"bundle": "npm run bundle:client && npm run bundle:api",
|
|
14
|
+
"bundle:client": "PUBLIC_URL='/.blocklet/proxy/<%= did %>' npm run build",
|
|
15
|
+
"bundle:api": "npm run clean && blocklet bundle --zip --create-release",
|
|
16
|
+
"deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
|
|
17
|
+
"upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
|
|
18
|
+
"prepare": "husky install"
|
|
19
|
+
},
|
|
20
|
+
"lint-staged": {
|
|
21
|
+
"*.{mjs,js,jsx,ts,tsx}": [
|
|
22
|
+
"prettier --write",
|
|
23
|
+
"eslint"
|
|
24
|
+
],
|
|
25
|
+
"*.{css,less,scss,json,graphql}": [
|
|
26
|
+
"prettier --write"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"browserslist": {
|
|
30
|
+
"production": [
|
|
31
|
+
">0.2%",
|
|
32
|
+
"not dead",
|
|
33
|
+
"not op_mini all"
|
|
34
|
+
],
|
|
35
|
+
"development": [
|
|
36
|
+
"last 1 chrome version",
|
|
37
|
+
"last 1 firefox version",
|
|
38
|
+
"last 1 safari version"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@arcblock/did-auth": "^1.16.0",
|
|
43
|
+
"@arcblock/did-auth-storage-nedb": "^1.6.3",
|
|
44
|
+
"@blocklet/sdk": "^1.7.6",
|
|
45
|
+
"@craco/craco": "^6.4.3",
|
|
46
|
+
"@ocap/client": "^1.16.0",
|
|
47
|
+
"@ocap/mcrypto": "^1.16.0",
|
|
48
|
+
"@ocap/wallet": "^1.16.0",
|
|
49
|
+
"axios": "^0.26.1",
|
|
50
|
+
"compression": "^1.7.4",
|
|
51
|
+
"cookie-parser": "^1.4.6",
|
|
52
|
+
"cors": "^2.8.5",
|
|
53
|
+
"dotenv-flow": "^3.2.0",
|
|
54
|
+
"express": "^4.17.3",
|
|
55
|
+
"express-async-errors": "^3.1.1",
|
|
56
|
+
"express-history-api-fallback": "^2.2.1",
|
|
57
|
+
"gun": "^0.2020.1236",
|
|
58
|
+
"react": "^17.0.2",
|
|
59
|
+
"react-dom": "^17.0.2",
|
|
60
|
+
"react-router-dom": "^6.2.2",
|
|
61
|
+
"react-scripts": "5.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@arcblock/eslint-config": "^0.1.8",
|
|
65
|
+
"babel-eslint": "^10.1.0",
|
|
66
|
+
"eslint": "^7.32.0",
|
|
67
|
+
"eslint-config-airbnb": "^18.2.1",
|
|
68
|
+
"eslint-config-prettier": "^8.3.0",
|
|
69
|
+
"eslint-plugin-import": "^2.23.4",
|
|
70
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
71
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
72
|
+
"eslint-plugin-react": "^7.24.0",
|
|
73
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
74
|
+
"eslint-plugin-unicorn": "^34.0.1",
|
|
75
|
+
"husky": "^7.0.4",
|
|
76
|
+
"lint-staged": "^12.3.7",
|
|
77
|
+
"nodemon": "^2.0.15",
|
|
78
|
+
"npm-run-all": "^4.1.5",
|
|
79
|
+
"prettier": "^2.6.0"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
html,
|
|
2
|
+
body {
|
|
3
|
+
padding: 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
}
|
|
6
|
+
.app {
|
|
7
|
+
text-align: center;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.app-logo {
|
|
11
|
+
height: 10vmin;
|
|
12
|
+
pointer-events: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.app-header {
|
|
16
|
+
min-height: 100vh;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
font-size: calc(10px + 2vmin);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pre {
|
|
25
|
+
font-size: 0.75em;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.app-link {
|
|
29
|
+
color: #4f6af5;
|
|
30
|
+
margin-right: 32px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.input-wrapper {
|
|
34
|
+
margin: 32px 0;
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.input {
|
|
39
|
+
width: 480px;
|
|
40
|
+
height: 240px;
|
|
41
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="450" height="520" viewBox="0 0 45 52"><g fill="none" fill-rule="evenodd" stroke="#4F6AF5"><path d="M.5 13.077L22.15.577l21.651 12.5v25l-21.65 12.5L.5 38.077zM22.15.577v50M.5 13.077l43.301 25m-43.301 0l43.301-25"></path><path d="M22.15 38.077l10.826-6.25-10.825-18.75-10.825 18.75z"></path></g></svg>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
import logo from '../logo.svg';
|
|
5
|
+
|
|
6
|
+
const About = () => {
|
|
7
|
+
return (
|
|
8
|
+
<header className="app-header">
|
|
9
|
+
<img src={logo} className="app-logo" alt="logo" />
|
|
10
|
+
<pre style={{ textAlign: 'left' }}>
|
|
11
|
+
<code>window.blocklet = {JSON.stringify(window.blocklet, null, 2)}</code>
|
|
12
|
+
</pre>
|
|
13
|
+
<Link className="app-link" to="/home">
|
|
14
|
+
Home
|
|
15
|
+
</Link>
|
|
16
|
+
<a className="app-link" href="https://docs.arcblock.io/abtnode/" target="_blank" rel="noopener noreferrer">
|
|
17
|
+
Learn Blocklet
|
|
18
|
+
</a>
|
|
19
|
+
<a className="app-link" href="https://gun.eco" target="_blank" rel="noopener noreferrer">
|
|
20
|
+
Learn GunJS
|
|
21
|
+
</a>
|
|
22
|
+
</header>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default About;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import Gun from 'gun';
|
|
4
|
+
|
|
5
|
+
import { Link } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
const gun = Gun({
|
|
8
|
+
peers: [`${window.location.origin}/gun`], // Put the relay nodes that you want here
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default function Home() {
|
|
12
|
+
const [txt, setTxt] = useState();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
gun.get('text').once((node) => {
|
|
16
|
+
// Retrieve the text value on startup
|
|
17
|
+
console.log(node);
|
|
18
|
+
if (node === undefined) {
|
|
19
|
+
gun.get('text').put({ text: 'Write the text here' });
|
|
20
|
+
} else {
|
|
21
|
+
console.log('Found Node');
|
|
22
|
+
setTxt(node.text);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
gun.get('text').on((node) => {
|
|
27
|
+
// Is called whenever text is updated
|
|
28
|
+
console.log('Receiving Update');
|
|
29
|
+
console.log(node);
|
|
30
|
+
setTxt(node.text);
|
|
31
|
+
});
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
const updateText = (event) => {
|
|
35
|
+
console.log('Updating Text');
|
|
36
|
+
console.log(event.target.value);
|
|
37
|
+
gun.get('text').put({ text: event.target.value }); // Edit the value in our db
|
|
38
|
+
setTxt(event.target.value);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="App">
|
|
43
|
+
<h1 className="page-title">Sample App build with React & GunJS</h1>
|
|
44
|
+
<div className="input-wrapper">
|
|
45
|
+
<textarea className="input" value={txt} onChange={updateText} />
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div className="link-wrapper">
|
|
49
|
+
<Link className="app-link" to="/home">
|
|
50
|
+
Home
|
|
51
|
+
</Link>
|
|
52
|
+
<a className="app-link" href="https://docs.arcblock.io/abtnode/" target="_blank" rel="noopener noreferrer">
|
|
53
|
+
Learn Blocklet
|
|
54
|
+
</a>
|
|
55
|
+
<a className="app-link" href="https://gun.eco" target="_blank" rel="noopener noreferrer">
|
|
56
|
+
Learn GunJS
|
|
57
|
+
</a>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const port = process.env.BLOCKLET_PORT || process.env.PORT || 8080;
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
devServer: {
|
|
5
|
+
port,
|
|
6
|
+
client: {
|
|
7
|
+
// If you want to development this blocklet without blocklet-server, you can delete next line, otherwise the hot reload will be failed.
|
|
8
|
+
webSocketURL: 'wss://0.0.0.0/ws',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "template-react",
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"dev": "
|
|
6
|
-
"build": "
|
|
5
|
+
"dev": "craco start",
|
|
6
|
+
"build": "craco build",
|
|
7
7
|
"eject": "react-scripts eject",
|
|
8
8
|
"lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
9
9
|
"start": "npm run dev",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
]
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@craco/craco": "^6.4.3",
|
|
38
39
|
"react": "^17.0.2",
|
|
39
40
|
"react-dom": "^17.0.2",
|
|
40
41
|
"react-router-dom": "^6.2.2",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
|
7
|
+
<meta name="theme-color" content="#4F6AF5" />
|
|
8
|
+
<meta name="description" content="Web site created using create-blocklet" />
|
|
9
|
+
<script src="__meta__.js"></script>
|
|
10
|
+
<!--
|
|
11
|
+
Notice the use of %PUBLIC_URL% in the tags above.
|
|
12
|
+
It will be replaced with the URL of the `public` folder during the build.
|
|
13
|
+
Only files inside the `public` folder can be referenced from the HTML.
|
|
14
|
+
|
|
15
|
+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
|
16
|
+
work correctly both with client-side routing and a non-root public URL.
|
|
17
|
+
Learn how to configure a non-root public URL by running `npm run build`.
|
|
18
|
+
-->
|
|
19
|
+
<title>%REACT_APP_TITLE%</title>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
23
|
+
<div id="root"></div>
|
|
24
|
+
<!--
|
|
25
|
+
This HTML file is a template.
|
|
26
|
+
If you open it directly in the browser, you will see an empty page.
|
|
27
|
+
|
|
28
|
+
You can add webfonts, meta tags, or analytics to this file.
|
|
29
|
+
The build step will place the bundled scripts into the <body> tag.
|
|
30
|
+
|
|
31
|
+
To begin the development, run `npm start` or `yarn start`.
|
|
32
|
+
To create a production bundle, use `npm run build` or `yarn build`.
|
|
33
|
+
-->
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|