create-blocklet 0.3.6 → 0.3.9
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 +5 -0
- package/common/.makefiles/bump_version.sh +2 -1
- package/common/_editorconfig +23 -0
- package/common/_gitignore +9 -16
- package/common/{.prettierrc → _prettierrc} +1 -1
- package/index.js +50 -12
- package/package.json +2 -1
- package/templates/blocklet-page-static/package.json +1 -1
- package/templates/express-api/api/index.js +1 -1
- package/templates/express-api/package.json +4 -4
- package/templates/html-static/app/favicon.ico +0 -0
- package/templates/html-static/app/images/logo.svg +17 -0
- package/templates/html-static/app/index.html +39 -0
- package/templates/html-static/app/styles/style.css +67 -0
- package/templates/html-static/blocklet.md +3 -0
- package/templates/html-static/blocklet.yml +48 -0
- package/templates/html-static/package.json +13 -0
- package/templates/{react-dapp/.env.local → nextjs-dapp/.env} +0 -0
- package/templates/nextjs-dapp/api/index.js +1 -1
- package/templates/nextjs-dapp/package.json +13 -13
- package/templates/react-dapp/.env +0 -1
- package/templates/react-dapp/api/index.js +1 -6
- package/templates/react-dapp/craco.config.js +5 -3
- package/templates/react-dapp/package.json +11 -11
- package/templates/react-gun-dapp/.env +0 -1
- package/templates/react-gun-dapp/api/index.js +1 -6
- package/templates/react-gun-dapp/craco.config.js +6 -4
- package/templates/react-gun-dapp/package.json +13 -13
- package/templates/react-static/craco.config.js +1 -1
- package/templates/react-static/package.json +6 -6
- package/templates/solidjs-dapp/.env +1 -0
- package/templates/solidjs-dapp/.eslintrc.js +17 -0
- package/templates/solidjs-dapp/README.md +147 -0
- package/templates/solidjs-dapp/api/hooks/pre-start.js +33 -0
- package/templates/solidjs-dapp/api/index.js +50 -0
- package/templates/solidjs-dapp/api/libs/auth.js +22 -0
- package/templates/solidjs-dapp/api/libs/env.js +6 -0
- package/templates/solidjs-dapp/api/libs/logger.js +3 -0
- package/templates/solidjs-dapp/api/routes/index.js +6 -0
- package/templates/solidjs-dapp/blocklet.md +3 -0
- package/templates/solidjs-dapp/blocklet.yml +49 -0
- package/templates/solidjs-dapp/index.html +17 -0
- package/templates/solidjs-dapp/package.json +63 -0
- package/templates/solidjs-dapp/src/App.jsx +24 -0
- package/templates/solidjs-dapp/src/App.module.css +33 -0
- package/templates/solidjs-dapp/src/assets/favicon.ico +0 -0
- package/templates/solidjs-dapp/src/index.css +13 -0
- package/templates/solidjs-dapp/src/index.jsx +7 -0
- package/templates/solidjs-dapp/src/logo.svg +1 -0
- package/templates/solidjs-dapp/vite.config.js +36 -0
- package/templates/solidjs-static/.env +1 -0
- package/templates/solidjs-static/.eslintrc.js +9 -0
- package/templates/solidjs-static/README.md +147 -0
- package/templates/solidjs-static/blocklet.md +3 -0
- package/templates/solidjs-static/blocklet.yml +49 -0
- package/templates/solidjs-static/index.html +17 -0
- package/templates/solidjs-static/package.json +43 -0
- package/templates/solidjs-static/src/App.jsx +24 -0
- package/templates/solidjs-static/src/App.module.css +33 -0
- package/templates/solidjs-static/src/assets/favicon.ico +0 -0
- package/templates/solidjs-static/src/index.css +13 -0
- package/templates/solidjs-static/src/index.jsx +7 -0
- package/templates/solidjs-static/src/logo.svg +1 -0
- package/templates/solidjs-static/vite.config.js +32 -0
- package/templates/svelte-dapp/.browserslistrc +4 -0
- package/templates/svelte-dapp/.env +1 -0
- package/templates/svelte-dapp/.eslintrc.js +22 -0
- package/templates/svelte-dapp/.vscode/extensions.json +3 -0
- package/templates/svelte-dapp/README.md +146 -0
- package/templates/svelte-dapp/api/hooks/pre-start.js +33 -0
- package/templates/svelte-dapp/api/index.js +50 -0
- package/templates/svelte-dapp/api/libs/auth.js +22 -0
- package/templates/svelte-dapp/api/libs/env.js +6 -0
- package/templates/svelte-dapp/api/libs/logger.js +3 -0
- package/templates/svelte-dapp/api/routes/index.js +6 -0
- package/templates/svelte-dapp/blocklet.md +3 -0
- package/templates/svelte-dapp/blocklet.yml +49 -0
- package/templates/svelte-dapp/index.html +16 -0
- package/templates/svelte-dapp/jsconfig.json +34 -0
- package/templates/svelte-dapp/package.json +59 -0
- package/templates/svelte-dapp/src/App.svelte +64 -0
- package/templates/svelte-dapp/src/assets/svelte.png +0 -0
- package/templates/svelte-dapp/src/lib/Counter.svelte +34 -0
- package/templates/svelte-dapp/src/main.js +7 -0
- package/templates/svelte-dapp/src/vite-env.d.ts +2 -0
- package/templates/svelte-dapp/vite.config.js +33 -0
- package/templates/svelte-static/.browserslistrc +4 -0
- package/templates/svelte-static/.env +1 -0
- package/templates/svelte-static/.eslintrc.js +22 -0
- package/templates/svelte-static/.vscode/extensions.json +3 -0
- package/templates/svelte-static/README.md +146 -0
- package/templates/svelte-static/blocklet.md +3 -0
- package/templates/svelte-static/blocklet.yml +49 -0
- package/templates/svelte-static/index.html +16 -0
- package/templates/svelte-static/jsconfig.json +34 -0
- package/templates/svelte-static/package.json +40 -0
- package/templates/svelte-static/src/App.svelte +64 -0
- package/templates/svelte-static/src/assets/svelte.png +0 -0
- package/templates/svelte-static/src/lib/Counter.svelte +34 -0
- package/templates/svelte-static/src/main.js +7 -0
- package/templates/svelte-static/src/vite-env.d.ts +2 -0
- package/templates/svelte-static/vite.config.js +29 -0
- package/templates/vue-dapp/api/index.js +1 -6
- package/templates/vue-dapp/index.html +1 -1
- package/templates/vue-dapp/package.json +15 -15
- package/templates/vue-dapp/vite.config.js +8 -4
- package/templates/vue-static/README.md +0 -1
- package/templates/vue-static/package.json +9 -9
- package/templates/vue-static/vite.config.js +5 -3
- package/templates/vue2-dapp/api/index.js +1 -6
- package/templates/vue2-dapp/package.json +16 -16
- package/templates/vue2-dapp/vue.config.js +5 -2
- package/templates/vue2-static/package.json +8 -8
- package/templates/vue2-static/vue.config.js +1 -1
|
@@ -25,13 +25,8 @@ app.use(Gun.serve);
|
|
|
25
25
|
const router = express.Router();
|
|
26
26
|
router.use('/api', require('./routes'));
|
|
27
27
|
|
|
28
|
-
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
29
28
|
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
30
29
|
|
|
31
|
-
if (isDevelopment) {
|
|
32
|
-
process.env.BLOCKLET_PORT = 3030;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
if (isProduction) {
|
|
36
31
|
app.use(cors());
|
|
37
32
|
app.use(compression());
|
|
@@ -52,7 +47,7 @@ if (isProduction) {
|
|
|
52
47
|
app.use(router);
|
|
53
48
|
}
|
|
54
49
|
|
|
55
|
-
const port = parseInt(process.env.
|
|
50
|
+
const port = parseInt(process.env.API_PORT, 10) || 3030;
|
|
56
51
|
|
|
57
52
|
const server = app.listen(port, (err) => {
|
|
58
53
|
if (err) throw err;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require('dotenv-flow').config();
|
|
2
|
+
|
|
3
|
+
const port = process.env.BLOCKLET_PORT || process.env.PORT || 3000;
|
|
4
|
+
const apiPort = process.env.API_PORT || 3030;
|
|
3
5
|
|
|
4
6
|
module.exports = {
|
|
5
7
|
devServer: {
|
|
@@ -11,11 +13,11 @@ module.exports = {
|
|
|
11
13
|
proxy: [
|
|
12
14
|
{
|
|
13
15
|
context: ['/api'],
|
|
14
|
-
target: `http://127.0.0.1:${
|
|
16
|
+
target: `http://127.0.0.1:${apiPort}`,
|
|
15
17
|
},
|
|
16
18
|
{
|
|
17
19
|
context: ['/gun'],
|
|
18
|
-
target: `ws://127.0.0.1:${
|
|
20
|
+
target: `ws://127.0.0.1:${apiPort}`,
|
|
19
21
|
ws: true,
|
|
20
22
|
},
|
|
21
23
|
],
|
|
@@ -39,26 +39,26 @@
|
|
|
39
39
|
]
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@arcblock/did-auth": "^1.16.
|
|
42
|
+
"@arcblock/did-auth": "^1.16.4",
|
|
43
43
|
"@arcblock/did-auth-storage-nedb": "^1.6.3",
|
|
44
|
-
"@blocklet/sdk": "^1.7.
|
|
44
|
+
"@blocklet/sdk": "^1.7.9",
|
|
45
45
|
"@craco/craco": "^6.4.3",
|
|
46
|
-
"@ocap/client": "^1.16.
|
|
47
|
-
"@ocap/mcrypto": "^1.16.
|
|
48
|
-
"@ocap/wallet": "^1.16.
|
|
49
|
-
"axios": "^0.
|
|
46
|
+
"@ocap/client": "^1.16.4",
|
|
47
|
+
"@ocap/mcrypto": "^1.16.4",
|
|
48
|
+
"@ocap/wallet": "^1.16.4",
|
|
49
|
+
"axios": "^0.27.2",
|
|
50
50
|
"compression": "^1.7.4",
|
|
51
51
|
"cookie-parser": "^1.4.6",
|
|
52
52
|
"cors": "^2.8.5",
|
|
53
53
|
"dotenv-flow": "^3.2.0",
|
|
54
|
-
"express": "^4.
|
|
54
|
+
"express": "^4.18.0",
|
|
55
55
|
"express-async-errors": "^3.1.1",
|
|
56
56
|
"express-history-api-fallback": "^2.2.1",
|
|
57
|
-
"gun": "^0.2020.
|
|
57
|
+
"gun": "^0.2020.1237",
|
|
58
58
|
"react": "^17.0.2",
|
|
59
59
|
"react-dom": "^17.0.2",
|
|
60
|
-
"react-router-dom": "^6.
|
|
61
|
-
"react-scripts": "5.0.
|
|
60
|
+
"react-router-dom": "^6.3.0",
|
|
61
|
+
"react-scripts": "5.0.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@arcblock/eslint-config": "^0.1.8",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
74
74
|
"eslint-plugin-unicorn": "^34.0.1",
|
|
75
75
|
"husky": "^7.0.4",
|
|
76
|
-
"lint-staged": "^12.
|
|
77
|
-
"nodemon": "^2.0.
|
|
76
|
+
"lint-staged": "^12.4.1",
|
|
77
|
+
"nodemon": "^2.0.16",
|
|
78
78
|
"npm-run-all": "^4.1.5",
|
|
79
|
-
"prettier": "^2.6.
|
|
79
|
+
"prettier": "^2.6.2"
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@craco/craco": "^6.4.3",
|
|
39
|
-
"react": "^
|
|
40
|
-
"react-dom": "^
|
|
41
|
-
"react-router-dom": "^6.
|
|
42
|
-
"react-scripts": "5.0.
|
|
39
|
+
"react": "^18.1.0",
|
|
40
|
+
"react-dom": "^18.1.0",
|
|
41
|
+
"react-router-dom": "^6.3.0",
|
|
42
|
+
"react-scripts": "5.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@arcblock/eslint-config": "^0.1.8",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
55
55
|
"eslint-plugin-unicorn": "^34.0.1",
|
|
56
56
|
"husky": "^7.0.4",
|
|
57
|
-
"lint-staged": "^12.
|
|
58
|
-
"prettier": "^2.6.
|
|
57
|
+
"lint-staged": "^12.4.1",
|
|
58
|
+
"prettier": "^2.6.2"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
APP_TITLE=''
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
browser: true,
|
|
5
|
+
node: true,
|
|
6
|
+
es6: true,
|
|
7
|
+
},
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 2018,
|
|
10
|
+
},
|
|
11
|
+
plugins: ['solid'],
|
|
12
|
+
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:solid/recommended'],
|
|
13
|
+
rules: {
|
|
14
|
+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
15
|
+
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -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 [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
|
|
32
|
+
|
|
33
|
+
Blocklet needs blocklet server as a dependency. So you need to install it first.
|
|
34
|
+
`npm install -g @blocklet/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 blocklet server & start blocklet server
|
|
38
|
+
|
|
39
|
+
Before starting an blocklet server, you need to init blocklet server.
|
|
40
|
+
`blocklet server init --mode=debug`
|
|
41
|
+
`blocklet server 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 blocklet server, 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 blocklet server, you can use the command below.
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server 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 blocklet server. 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 Blocklet Server & 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,33 @@
|
|
|
1
|
+
require('@blocklet/sdk/lib/error-handler');
|
|
2
|
+
require('dotenv-flow').config();
|
|
3
|
+
|
|
4
|
+
const Client = require('@ocap/client');
|
|
5
|
+
|
|
6
|
+
const env = require('../libs/env');
|
|
7
|
+
const logger = require('../libs/logger');
|
|
8
|
+
const { wallet } = require('../libs/auth');
|
|
9
|
+
const { name } = require('../../package.json');
|
|
10
|
+
|
|
11
|
+
const ensureAccountDeclared = async () => {
|
|
12
|
+
if (env.isComponent) return;
|
|
13
|
+
if (!env.chainHost) return;
|
|
14
|
+
|
|
15
|
+
const client = new Client(env.chainHost);
|
|
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,50 @@
|
|
|
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 isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
24
|
+
|
|
25
|
+
if (isProduction) {
|
|
26
|
+
app.use(cors());
|
|
27
|
+
app.use(compression());
|
|
28
|
+
|
|
29
|
+
const staticDir = path.resolve(__dirname, '../', 'dist');
|
|
30
|
+
app.use(express.static(staticDir, { index: 'index.html' }));
|
|
31
|
+
app.use(router);
|
|
32
|
+
app.use(fallback('index.html', { root: staticDir }));
|
|
33
|
+
|
|
34
|
+
app.use((req, res) => {
|
|
35
|
+
res.status(404).send('404 NOT FOUND');
|
|
36
|
+
});
|
|
37
|
+
app.use((err, req, res) => {
|
|
38
|
+
logger.error(err.stack);
|
|
39
|
+
res.status(500).send('Something broke!');
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
app.use(router);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const port = parseInt(process.env.API_PORT, 10) || 3030;
|
|
46
|
+
|
|
47
|
+
app.listen(port, (err) => {
|
|
48
|
+
if (err) throw err;
|
|
49
|
+
logger.info(`> ${name} v${version} ready on ${port}`);
|
|
50
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const AuthStorage = require('@arcblock/did-auth-storage-nedb');
|
|
3
|
+
const getWallet = require('@blocklet/sdk/lib/wallet');
|
|
4
|
+
const WalletAuthenticator = require('@blocklet/sdk/lib/wallet-authenticator');
|
|
5
|
+
const WalletHandler = require('@blocklet/sdk/lib/wallet-handler');
|
|
6
|
+
|
|
7
|
+
const env = require('./env');
|
|
8
|
+
|
|
9
|
+
const wallet = getWallet();
|
|
10
|
+
const authenticator = new WalletAuthenticator();
|
|
11
|
+
const handlers = new WalletHandler({
|
|
12
|
+
authenticator,
|
|
13
|
+
tokenStorage: new AuthStorage({
|
|
14
|
+
dbPath: path.join(env.dataDir, 'auth.db'),
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
authenticator,
|
|
20
|
+
handlers,
|
|
21
|
+
wallet,
|
|
22
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: template-solidjs
|
|
2
|
+
title: Blocklet Template Solidjs
|
|
3
|
+
description: A Blocklet Server blocklet
|
|
4
|
+
keywords:
|
|
5
|
+
- blocklet
|
|
6
|
+
- solidjs
|
|
7
|
+
group: static
|
|
8
|
+
did: ''
|
|
9
|
+
main: dist
|
|
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
|
+
interfaces:
|
|
25
|
+
- type: web
|
|
26
|
+
name: publicUrl
|
|
27
|
+
path: /
|
|
28
|
+
prefix: '*'
|
|
29
|
+
port: BLOCKLET_PORT
|
|
30
|
+
protocol: http
|
|
31
|
+
community: ''
|
|
32
|
+
documentation: ''
|
|
33
|
+
homepage: ''
|
|
34
|
+
license: ''
|
|
35
|
+
payment:
|
|
36
|
+
price: []
|
|
37
|
+
share: []
|
|
38
|
+
timeout:
|
|
39
|
+
start: 60
|
|
40
|
+
requirements:
|
|
41
|
+
server: '>=1.6.29'
|
|
42
|
+
os: '*'
|
|
43
|
+
cpu: '*'
|
|
44
|
+
scripts:
|
|
45
|
+
dev: npm run start
|
|
46
|
+
environments: []
|
|
47
|
+
capabilities: {}
|
|
48
|
+
screenshots: []
|
|
49
|
+
children: []
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="theme-color" content="#000000" />
|
|
7
|
+
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" />
|
|
8
|
+
<title><%- title %></title>
|
|
9
|
+
<script src="__meta__.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
13
|
+
<div id="root"></div>
|
|
14
|
+
|
|
15
|
+
<script src="/src/index.jsx" type="module"></script>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-template-solid",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"serve": "vite preview",
|
|
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": "vite build --base /.blocklet/proxy/<%= did %>/",
|
|
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
|
+
"lint": "eslint src --ext .mjs,.js,.jsx",
|
|
19
|
+
"prepare": "husky install"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"eslint": "^8.14.0",
|
|
24
|
+
"eslint-config-prettier": "^8.5.0",
|
|
25
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
26
|
+
"eslint-plugin-solid": "0.4.7",
|
|
27
|
+
"husky": "^7.0.4",
|
|
28
|
+
"lint-staged": "^12.4.1",
|
|
29
|
+
"nodemon": "^2.0.16",
|
|
30
|
+
"npm-run-all": "^4.1.5",
|
|
31
|
+
"prettier": "^2.6.2",
|
|
32
|
+
"vite": "^2.9.6",
|
|
33
|
+
"vite-plugin-solid": "^2.2.6",
|
|
34
|
+
"vite-plugin-blocklet": "^0.1.2",
|
|
35
|
+
"vite-plugin-html": "^3.2.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@arcblock/did-auth": "^1.16.4",
|
|
39
|
+
"@arcblock/did-auth-storage-nedb": "^1.6.3",
|
|
40
|
+
"@blocklet/sdk": "^1.7.9",
|
|
41
|
+
"@ocap/client": "^1.16.4",
|
|
42
|
+
"@ocap/mcrypto": "^1.16.4",
|
|
43
|
+
"@ocap/wallet": "^1.16.4",
|
|
44
|
+
"axios": "^0.27.2",
|
|
45
|
+
"compression": "^1.7.4",
|
|
46
|
+
"cookie-parser": "^1.4.6",
|
|
47
|
+
"cors": "^2.8.5",
|
|
48
|
+
"dotenv-flow": "^3.2.0",
|
|
49
|
+
"express": "^4.18.0",
|
|
50
|
+
"express-async-errors": "^3.1.1",
|
|
51
|
+
"express-history-api-fallback": "^2.2.1",
|
|
52
|
+
"solid-js": "^1.3.17"
|
|
53
|
+
},
|
|
54
|
+
"lint-staged": {
|
|
55
|
+
"*.{mjs,js,vue}": [
|
|
56
|
+
"prettier --write",
|
|
57
|
+
"eslint --ext .js,.vue,.mjs"
|
|
58
|
+
],
|
|
59
|
+
"*.{css,less,scss,json,graphql}": [
|
|
60
|
+
"prettier --write"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import logo from './logo.svg';
|
|
2
|
+
import styles from './App.module.css';
|
|
3
|
+
|
|
4
|
+
function App() {
|
|
5
|
+
return (
|
|
6
|
+
<div class={styles.App}>
|
|
7
|
+
<header class={styles.header}>
|
|
8
|
+
<img src={logo} class={styles.logo} alt="logo" />
|
|
9
|
+
<p>
|
|
10
|
+
Edit <code>src/App.jsx</code> and save to reload.
|
|
11
|
+
</p>
|
|
12
|
+
<a
|
|
13
|
+
class={styles.link}
|
|
14
|
+
href="https://docs.arcblock.io/abtnode/en/blocklet"
|
|
15
|
+
target="_blank"
|
|
16
|
+
rel="noopener noreferrer">
|
|
17
|
+
Learn Blocklet
|
|
18
|
+
</a>
|
|
19
|
+
</header>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default App;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.App {
|
|
2
|
+
text-align: center;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.logo {
|
|
6
|
+
animation: logo-spin infinite 20s linear;
|
|
7
|
+
height: 40vmin;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.header {
|
|
12
|
+
background-color: #282c34;
|
|
13
|
+
min-height: 100vh;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
font-size: calc(10px + 2vmin);
|
|
19
|
+
color: white;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.link {
|
|
23
|
+
color: #b318f0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@keyframes logo-spin {
|
|
27
|
+
from {
|
|
28
|
+
transform: rotate(0deg);
|
|
29
|
+
}
|
|
30
|
+
to {
|
|
31
|
+
transform: rotate(360deg);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
|
4
|
+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
|
5
|
+
sans-serif;
|
|
6
|
+
-webkit-font-smoothing: antialiased;
|
|
7
|
+
-moz-osx-font-smoothing: grayscale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
code {
|
|
11
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
|
12
|
+
monospace;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 166 155.3"><path d="M163 35S110-4 69 5l-3 1c-6 2-11 5-14 9l-2 3-15 26 26 5c11 7 25 10 38 7l46 9 18-30z" fill="#76b3e1"/><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="27.5" y1="3" x2="152" y2="63.5"><stop offset=".1" stop-color="#76b3e1"/><stop offset=".3" stop-color="#dcf2fd"/><stop offset="1" stop-color="#76b3e1"/></linearGradient><path d="M163 35S110-4 69 5l-3 1c-6 2-11 5-14 9l-2 3-15 26 26 5c11 7 25 10 38 7l46 9 18-30z" opacity=".3" fill="url(#a)"/><path d="M52 35l-4 1c-17 5-22 21-13 35 10 13 31 20 48 15l62-21S92 26 52 35z" fill="#518ac8"/><linearGradient id="b" gradientUnits="userSpaceOnUse" x1="95.8" y1="32.6" x2="74" y2="105.2"><stop offset="0" stop-color="#76b3e1"/><stop offset=".5" stop-color="#4377bb"/><stop offset="1" stop-color="#1f3b77"/></linearGradient><path d="M52 35l-4 1c-17 5-22 21-13 35 10 13 31 20 48 15l62-21S92 26 52 35z" opacity=".3" fill="url(#b)"/><linearGradient id="c" gradientUnits="userSpaceOnUse" x1="18.4" y1="64.2" x2="144.3" y2="149.8"><stop offset="0" stop-color="#315aa9"/><stop offset=".5" stop-color="#518ac8"/><stop offset="1" stop-color="#315aa9"/></linearGradient><path d="M134 80a45 45 0 00-48-15L24 85 4 120l112 19 20-36c4-7 3-15-2-23z" fill="url(#c)"/><linearGradient id="d" gradientUnits="userSpaceOnUse" x1="75.2" y1="74.5" x2="24.4" y2="260.8"><stop offset="0" stop-color="#4377bb"/><stop offset=".5" stop-color="#1a336b"/><stop offset="1" stop-color="#1a336b"/></linearGradient><path d="M114 115a45 45 0 00-48-15L4 120s53 40 94 30l3-1c17-5 23-21 13-34z" fill="url(#d)"/></svg>
|