create-blocklet 0.5.12 → 0.5.13
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/index.js +5 -0
- package/package.json +1 -1
- package/templates/react-dapp/package.json +1 -1
- package/templates/react-dapp-ts/.eslintrc.js +7 -0
- package/templates/react-dapp-ts/README.md +157 -0
- package/templates/react-dapp-ts/api/dev.ts +6 -0
- package/templates/react-dapp-ts/api/hooks/pre-start.js +12 -0
- package/templates/react-dapp-ts/api/src/hooks/pre-start.ts +37 -0
- package/templates/react-dapp-ts/api/src/index.ts +50 -0
- package/templates/react-dapp-ts/api/src/libs/auth.ts +17 -0
- package/templates/react-dapp-ts/api/src/libs/env.ts +6 -0
- package/templates/react-dapp-ts/api/src/libs/logger.ts +3 -0
- package/templates/react-dapp-ts/api/src/routes/index.ts +8 -0
- package/templates/react-dapp-ts/api/third.d.ts +15 -0
- package/templates/react-dapp-ts/blocklet.md +3 -0
- package/templates/react-dapp-ts/blocklet.yml +50 -0
- package/templates/react-dapp-ts/index.html +14 -0
- package/templates/react-dapp-ts/package.json +95 -0
- package/templates/react-dapp-ts/src/app.css +30 -0
- package/templates/react-dapp-ts/src/app.tsx +28 -0
- package/templates/react-dapp-ts/src/env.d.ts +3 -0
- package/templates/react-dapp-ts/src/index.tsx +5 -0
- package/templates/react-dapp-ts/src/libs/api.ts +14 -0
- package/templates/react-dapp-ts/src/logo.svg +1 -0
- package/templates/react-dapp-ts/src/pages/about.tsx +16 -0
- package/templates/react-dapp-ts/src/pages/home.tsx +22 -0
- package/templates/react-dapp-ts/template-info.json +12 -0
- package/templates/react-dapp-ts/tsconfig.api.json +9 -0
- package/templates/react-dapp-ts/tsconfig.json +99 -0
- package/templates/react-dapp-ts/vite.config.ts +20 -0
- package/templates/react-gun-dapp/package.json +1 -1
- package/templates/react-static/package.json +1 -1
- package/templates/solidjs-dapp/package.json +1 -1
- package/templates/solidjs-static/package.json +1 -1
- package/templates/svelte-dapp/package.json +1 -1
- package/templates/svelte-static/package.json +1 -1
- package/templates/vue-dapp/package.json +1 -1
- package/templates/vue-static/package.json +1 -1
- package/templates/vue2-dapp/package.json +1 -1
- package/templates/vue2-static/package.json +1 -1
package/index.js
CHANGED
|
@@ -37,6 +37,11 @@ const templates = [
|
|
|
37
37
|
display: '[dapp] react + express.js',
|
|
38
38
|
color: yellow,
|
|
39
39
|
},
|
|
40
|
+
{
|
|
41
|
+
name: 'react-dapp-ts',
|
|
42
|
+
display: '[dapp] react + express + typescript',
|
|
43
|
+
color: yellow,
|
|
44
|
+
},
|
|
40
45
|
{
|
|
41
46
|
name: 'solidjs-dapp',
|
|
42
47
|
display: '[dapp] solid + express.js',
|
package/package.json
CHANGED
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
## Launch on Blocklet Server
|
|
8
|
+
|
|
9
|
+
[](https://install.arcblock.io/launch?action=blocklet-install&meta_url=https%3A%2F%2Fgithub.com%2Fblocklet%2Fpages-kit%2Freleases%2Fdownload%2Fv0.1.33%2Fblocklet.json)
|
|
10
|
+
|
|
11
|
+
## File Structure
|
|
12
|
+
|
|
13
|
+
- public/ - static files
|
|
14
|
+
- favicon.ico - favicon
|
|
15
|
+
- favicon.svg - favicon
|
|
16
|
+
- index.html - main html file, template for react
|
|
17
|
+
- screenshots/ - Screenshots
|
|
18
|
+
- api/
|
|
19
|
+
- src/ - Api side code
|
|
20
|
+
- hooks/ - blocklet lifecycle hooks
|
|
21
|
+
- libs/ - Api side libraries
|
|
22
|
+
- middlewares/ - Api side middlewares
|
|
23
|
+
- routes/ - Api side routes
|
|
24
|
+
- index.ts - Api side entry point
|
|
25
|
+
- src/ - Client side code (A standard react app structure)
|
|
26
|
+
- .env - Environment variables
|
|
27
|
+
- .env.local - Local environment variables
|
|
28
|
+
- .eslintrc.js - ESLint configuration
|
|
29
|
+
- .gitignore - Git ignore file
|
|
30
|
+
- .prettierrc - Prettier configuration
|
|
31
|
+
- blocklet.md - Blocklet README
|
|
32
|
+
- blocklet.yml - Blocklet configuration
|
|
33
|
+
- LICENSE - License file
|
|
34
|
+
- logo.png - Blocklet logo file
|
|
35
|
+
- package.json - Npm package file
|
|
36
|
+
- README.md - A guide for this blocklet
|
|
37
|
+
- version - Version file
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
|
|
42
|
+
|
|
43
|
+
Blocklet needs blocklet server as a dependency. So you need to install it first.
|
|
44
|
+
`npm install -g @blocklet/cli`
|
|
45
|
+
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)
|
|
46
|
+
|
|
47
|
+
2. Init blocklet server & start blocklet server
|
|
48
|
+
|
|
49
|
+
Before starting an blocklet server, you need to init blocklet server.
|
|
50
|
+
`blocklet server init --mode=debug`
|
|
51
|
+
`blocklet server start`
|
|
52
|
+
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)
|
|
53
|
+
|
|
54
|
+
3. Go to the project directory `cd [name]`
|
|
55
|
+
4. Install dependencies: `npm install` or `yarn`
|
|
56
|
+
5. Start development server: `blocklet dev`
|
|
57
|
+
|
|
58
|
+
## Bundle
|
|
59
|
+
|
|
60
|
+
After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
|
|
61
|
+
|
|
62
|
+
## Deploy
|
|
63
|
+
|
|
64
|
+
- 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).
|
|
65
|
+
> Or you can simply use `npm run deploy` command.
|
|
66
|
+
- If you want to deploy this blocklet to remote blocklet server, you can use the command below.
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> Make sure the blocklet is bundled before deployment.
|
|
73
|
+
|
|
74
|
+
## Upload to blocklet store
|
|
75
|
+
|
|
76
|
+
- If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
|
|
77
|
+
|
|
78
|
+
Bump version at first.
|
|
79
|
+
|
|
80
|
+
```shell
|
|
81
|
+
npm run bump-version
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then config blocklet store url.
|
|
85
|
+
You can use those store url in below.
|
|
86
|
+
|
|
87
|
+
1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
|
|
88
|
+
2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
|
|
89
|
+
3. A blocklet store started by yourself.
|
|
90
|
+
> 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)
|
|
91
|
+
|
|
92
|
+
```shell
|
|
93
|
+
blocklet config set store {store url}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Get a `accessToken` by using this command.
|
|
97
|
+
|
|
98
|
+
> Why we need a `accessToken`?
|
|
99
|
+
> A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
|
|
100
|
+
|
|
101
|
+
Set `accessToken` to blocklet config
|
|
102
|
+
|
|
103
|
+
```shell
|
|
104
|
+
blocklet config set accessToken {accessToken}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Upload a new version to a store.
|
|
108
|
+
|
|
109
|
+
> Make sure the blocklet is bundled before upload.
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
blocklet upload
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or you can simply use `npm run upload` command.
|
|
116
|
+
|
|
117
|
+
- You also can upload a new version to a store by Github CI.
|
|
118
|
+
Bump version at first.
|
|
119
|
+
|
|
120
|
+
```shell
|
|
121
|
+
npm run bump-version
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Push your code to Github main/master branch, or make a pull request to the main/master branch.
|
|
125
|
+
The CI workflow will automatically upload a new version to a store.
|
|
126
|
+
|
|
127
|
+
## Q & A
|
|
128
|
+
|
|
129
|
+
1. Q: How to change a blocklet's name?
|
|
130
|
+
|
|
131
|
+
A: Change the `name` field in the `package.json` file, change the `name` field in the `blocklet.yml` file.
|
|
132
|
+
|
|
133
|
+
You can also change the `title` field and `description` field in the `blocklet.yml` file.
|
|
134
|
+
|
|
135
|
+
Run `blocklet meta` command, you will get a `did` config, copy the `did` value.
|
|
136
|
+
|
|
137
|
+
Replace this command `"bundle:client": "PUBLIC_URL='/.blocklet/proxy/{did}' npm run build",` in `package.json`
|
|
138
|
+
|
|
139
|
+
Replace `did` field in the `blocklet.yml`
|
|
140
|
+
|
|
141
|
+
2. Q: How to change a blocklet's logo?
|
|
142
|
+
|
|
143
|
+
Change the `logo.png` file root folder.
|
|
144
|
+
|
|
145
|
+
Or you can change the `logo` field in the `blocklet.yml` file.
|
|
146
|
+
|
|
147
|
+
> Make sure you have added the logo path to the `blocklet.yml` file `files` field.
|
|
148
|
+
|
|
149
|
+
## Learn More
|
|
150
|
+
|
|
151
|
+
- 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)
|
|
152
|
+
- Full document of Blocklet Server & blocklet development: [https://docs.arcblock.io/abtnode/en/introduction](https://docs.arcblock.io/abtnode/en/introduction)
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
The code is licensed under the Apache 2.0 license found in the
|
|
157
|
+
[LICENSE](LICENSE) file.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
|
|
3
|
+
const isDevelopment = process.env.BLOCKLET_MODE === 'development';
|
|
4
|
+
|
|
5
|
+
if (isDevelopment) {
|
|
6
|
+
// rename `require` to skip deps resolve when bundling
|
|
7
|
+
const r = require;
|
|
8
|
+
r('ts-node').register();
|
|
9
|
+
r('../src/hooks/pre-start');
|
|
10
|
+
} else {
|
|
11
|
+
require('../dist/hooks/pre-start');
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import '@blocklet/sdk/lib/error-handler';
|
|
2
|
+
|
|
3
|
+
import Client from '@ocap/client';
|
|
4
|
+
import dotenv from 'dotenv-flow';
|
|
5
|
+
|
|
6
|
+
import { wallet } from '../libs/auth';
|
|
7
|
+
import env from '../libs/env';
|
|
8
|
+
import logger from '../libs/logger';
|
|
9
|
+
|
|
10
|
+
dotenv.config();
|
|
11
|
+
|
|
12
|
+
const { name } = require('../../../package.json');
|
|
13
|
+
|
|
14
|
+
const ensureAccountDeclared = async () => {
|
|
15
|
+
if (env.isComponent) return;
|
|
16
|
+
if (!env.chainHost) return;
|
|
17
|
+
|
|
18
|
+
const client = new Client(env.chainHost);
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const { state } = await client.getAccountState({ address: wallet.toAddress() }, { ignoreFields: ['context'] });
|
|
21
|
+
if (!state) {
|
|
22
|
+
const hash = await client.declare({ moniker: name, wallet });
|
|
23
|
+
logger.log(`app account declared on chain ${env.chainHost}`, hash);
|
|
24
|
+
} else {
|
|
25
|
+
logger.log(`app account already declared on chain ${env.chainHost}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
(async () => {
|
|
30
|
+
try {
|
|
31
|
+
await ensureAccountDeclared();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
logger.error(`${name} pre-start error`, err.message);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import 'express-async-errors';
|
|
2
|
+
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
import compression from 'compression';
|
|
6
|
+
import cookieParser from 'cookie-parser';
|
|
7
|
+
import cors from 'cors';
|
|
8
|
+
import dotenv from 'dotenv-flow';
|
|
9
|
+
import express, { ErrorRequestHandler } from 'express';
|
|
10
|
+
import fallback from 'express-history-api-fallback';
|
|
11
|
+
|
|
12
|
+
import logger from './libs/logger';
|
|
13
|
+
import routes from './routes';
|
|
14
|
+
|
|
15
|
+
dotenv.config();
|
|
16
|
+
|
|
17
|
+
const { name, version } = require('../../package.json');
|
|
18
|
+
|
|
19
|
+
export const app = express();
|
|
20
|
+
|
|
21
|
+
app.set('trust proxy', true);
|
|
22
|
+
app.use(cookieParser());
|
|
23
|
+
app.use(express.json({ limit: '1 mb' }));
|
|
24
|
+
app.use(express.urlencoded({ extended: true, limit: '1 mb' }));
|
|
25
|
+
app.use(cors());
|
|
26
|
+
|
|
27
|
+
const router = express.Router();
|
|
28
|
+
router.use('/api', routes);
|
|
29
|
+
app.use(router);
|
|
30
|
+
|
|
31
|
+
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
32
|
+
|
|
33
|
+
if (isProduction) {
|
|
34
|
+
const staticDir = path.resolve(process.env.BLOCKLET_APP_DIR!, 'dist');
|
|
35
|
+
app.use(compression());
|
|
36
|
+
app.use(express.static(staticDir, { maxAge: '30d', index: false }));
|
|
37
|
+
app.use(fallback('index.html', { root: staticDir }));
|
|
38
|
+
|
|
39
|
+
app.use(<ErrorRequestHandler>((err, _, res) => {
|
|
40
|
+
logger.error(err.stack);
|
|
41
|
+
res.status(500).send('Something broke!');
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const port = parseInt(process.env.BLOCKLET_PORT!, 10);
|
|
46
|
+
|
|
47
|
+
export const server = app.listen(port, (err?: any) => {
|
|
48
|
+
if (err) throw err;
|
|
49
|
+
logger.info(`> ${name} v${version} ready on ${port}`);
|
|
50
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import AuthStorage from '@arcblock/did-auth-storage-nedb';
|
|
4
|
+
import getWallet from '@blocklet/sdk/lib/wallet';
|
|
5
|
+
import WalletAuthenticator from '@blocklet/sdk/lib/wallet-authenticator';
|
|
6
|
+
import WalletHandler from '@blocklet/sdk/lib/wallet-handler';
|
|
7
|
+
|
|
8
|
+
import env from './env';
|
|
9
|
+
|
|
10
|
+
export const wallet = getWallet();
|
|
11
|
+
export const authenticator = new WalletAuthenticator();
|
|
12
|
+
export const handlers = new WalletHandler({
|
|
13
|
+
authenticator,
|
|
14
|
+
tokenStorage: new AuthStorage({
|
|
15
|
+
dbPath: path.join(env.dataDir, 'auth.db'),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare module 'vite-plugin-blocklet';
|
|
2
|
+
|
|
3
|
+
declare module 'express-history-api-fallback';
|
|
4
|
+
|
|
5
|
+
declare module 'express-async-errors';
|
|
6
|
+
|
|
7
|
+
namespace Express {
|
|
8
|
+
interface Request {
|
|
9
|
+
user?: {
|
|
10
|
+
did: string;
|
|
11
|
+
role: string;
|
|
12
|
+
fullName: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: template-react-dapp-ts
|
|
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/dist/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
|
+
- dist
|
|
21
|
+
- logo.png
|
|
22
|
+
- screenshots
|
|
23
|
+
- api/hooks/pre-start.js
|
|
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
|
+
preStart: node api/hooks/pre-start.js
|
|
46
|
+
dev: npm run start
|
|
47
|
+
environments: []
|
|
48
|
+
capabilities: {}
|
|
49
|
+
screenshots: []
|
|
50
|
+
components: []
|
|
@@ -0,0 +1,14 @@
|
|
|
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.0, maximum-scale=1.0, user-scalable=0" />
|
|
6
|
+
<meta name="theme-color" content="#4F6AF5" />
|
|
7
|
+
<meta name="description" content="Web site created using create-blocklet" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<noscript> You need to enable JavaScript to run this app. </noscript>
|
|
11
|
+
<div id="app"></div>
|
|
12
|
+
<script type="module" src="/src/index.tsx"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "template-react-ts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"dev": "blocklet dev",
|
|
6
|
+
"eject": "vite eject",
|
|
7
|
+
"lint": "tsc --noEmit && eslint src api/src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
8
|
+
"lint:fix": "npm run lint -- --fix",
|
|
9
|
+
"start": "cross-env NODE_ENV=development nodemon api/dev.ts -w api",
|
|
10
|
+
"clean": "node scripts/build-clean.js",
|
|
11
|
+
"bundle": "tsc --noEmit && npm run bundle:client && npm run bundle:api",
|
|
12
|
+
"bundle:client": "vite build",
|
|
13
|
+
"bundle:api": "npm run clean && tsc -p tsconfig.api.json && blocklet bundle --zip --create-release",
|
|
14
|
+
"deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
|
|
15
|
+
"upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
|
|
16
|
+
"prepare": "husky install",
|
|
17
|
+
"bump-version": "zx --quiet scripts/bump-version.mjs"
|
|
18
|
+
},
|
|
19
|
+
"lint-staged": {
|
|
20
|
+
"*.{mjs,js,jsx,ts,tsx}": [
|
|
21
|
+
"prettier --write",
|
|
22
|
+
"eslint"
|
|
23
|
+
],
|
|
24
|
+
"*.{css,less,scss,json,graphql}": [
|
|
25
|
+
"prettier --write"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"browserslist": {
|
|
29
|
+
"production": [
|
|
30
|
+
">0.2%",
|
|
31
|
+
"not dead",
|
|
32
|
+
"not op_mini all"
|
|
33
|
+
],
|
|
34
|
+
"development": [
|
|
35
|
+
"last 1 chrome version",
|
|
36
|
+
"last 1 firefox version",
|
|
37
|
+
"last 1 safari version"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@arcblock/did-auth": "^1.18.36",
|
|
42
|
+
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
43
|
+
"@blocklet/sdk": "^1.8.63",
|
|
44
|
+
"@ocap/client": "^1.18.36",
|
|
45
|
+
"@ocap/mcrypto": "^1.18.36",
|
|
46
|
+
"@ocap/wallet": "^1.18.36",
|
|
47
|
+
"axios": "^0.27.2",
|
|
48
|
+
"compression": "^1.7.4",
|
|
49
|
+
"cookie-parser": "^1.4.6",
|
|
50
|
+
"cors": "^2.8.5",
|
|
51
|
+
"dotenv-flow": "^3.2.0",
|
|
52
|
+
"express": "^4.18.2",
|
|
53
|
+
"express-async-errors": "^3.1.1",
|
|
54
|
+
"express-history-api-fallback": "^2.2.1",
|
|
55
|
+
"react": "^18.2.0",
|
|
56
|
+
"react-dom": "^18.2.0",
|
|
57
|
+
"react-router-dom": "^6.8.0",
|
|
58
|
+
"rimraf": "^3.0.2"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@arcblock/eslint-config": "^0.2.3",
|
|
62
|
+
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
63
|
+
"@types/compression": "^1.7.2",
|
|
64
|
+
"@types/cookie-parser": "^1.4.3",
|
|
65
|
+
"@types/cors": "^2.8.13",
|
|
66
|
+
"@types/dotenv-flow": "^3.2.0",
|
|
67
|
+
"@types/express": "^4.17.15",
|
|
68
|
+
"@types/node": "^18.11.18",
|
|
69
|
+
"@types/react": "^18.0.26",
|
|
70
|
+
"@types/react-dom": "^18.0.10",
|
|
71
|
+
"@vitejs/plugin-react": "^2.2.0",
|
|
72
|
+
"bumpp": "^8.2.1",
|
|
73
|
+
"cross-env": "^7.0.3",
|
|
74
|
+
"eslint": "^8.30.0",
|
|
75
|
+
"husky": "^8.0.2",
|
|
76
|
+
"import-sort-style-module": "^6.0.0",
|
|
77
|
+
"lint-staged": "^12.5.0",
|
|
78
|
+
"nodemon": "^2.0.20",
|
|
79
|
+
"npm-run-all": "^4.1.5",
|
|
80
|
+
"prettier": "^2.8.1",
|
|
81
|
+
"prettier-plugin-import-sort": "^0.0.7",
|
|
82
|
+
"ts-node": "^10.9.1",
|
|
83
|
+
"typescript": "^4.9.4",
|
|
84
|
+
"vite": "^3.2.5",
|
|
85
|
+
"vite-plugin-blocklet": "^0.5.13",
|
|
86
|
+
"vite-plugin-svgr": "^2.4.0",
|
|
87
|
+
"zx": "^7.1.1"
|
|
88
|
+
},
|
|
89
|
+
"importSort": {
|
|
90
|
+
".ts, .tsx": {
|
|
91
|
+
"style": "module",
|
|
92
|
+
"parser": "typescript"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router-dom';
|
|
2
|
+
import './app.css';
|
|
3
|
+
import About from './pages/about';
|
|
4
|
+
import Home from './pages/home';
|
|
5
|
+
|
|
6
|
+
function App() {
|
|
7
|
+
return (
|
|
8
|
+
<div className="app">
|
|
9
|
+
<Routes>
|
|
10
|
+
<Route path="/" element={<Home />} />
|
|
11
|
+
<Route path="/about" element={<About />} />
|
|
12
|
+
<Route path="/home" element={<Home />} />
|
|
13
|
+
<Route path="*" element={<Navigate to="/" />} />
|
|
14
|
+
</Routes>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function WrappedApp() {
|
|
20
|
+
// While the blocklet is deploy to a sub path, this will be work properly.
|
|
21
|
+
const basename = window?.blocklet?.prefix || '/';
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Router basename={basename}>
|
|
25
|
+
<App />
|
|
26
|
+
</Router>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
axios.interceptors.request.use(
|
|
4
|
+
(config) => {
|
|
5
|
+
const prefix = window.blocklet ? window.blocklet.prefix : '/';
|
|
6
|
+
config.baseURL = prefix || '';
|
|
7
|
+
config.timeout = 200000;
|
|
8
|
+
|
|
9
|
+
return config;
|
|
10
|
+
},
|
|
11
|
+
(error) => Promise.reject(error)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default axios;
|
|
@@ -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,22 @@
|
|
|
1
|
+
import { Link } from 'react-router-dom';
|
|
2
|
+
|
|
3
|
+
import logo from '../logo.svg';
|
|
4
|
+
|
|
5
|
+
function Home() {
|
|
6
|
+
return (
|
|
7
|
+
<header className="app-header">
|
|
8
|
+
<img src={logo} className="app-logo" alt="logo" />
|
|
9
|
+
<pre style={{ textAlign: 'left' }}>
|
|
10
|
+
<code>window.blocklet = {JSON.stringify(window.blocklet, null, 2)}</code>
|
|
11
|
+
</pre>
|
|
12
|
+
<Link className="app-link" to="/about">
|
|
13
|
+
About
|
|
14
|
+
</Link>
|
|
15
|
+
<a className="app-link" href="https://docs.arcblock.io/abtnode/" target="_blank" rel="noopener noreferrer">
|
|
16
|
+
Learn Blocklet
|
|
17
|
+
</a>
|
|
18
|
+
</header>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default Home;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-dapp-ts",
|
|
3
|
+
"desc": {
|
|
4
|
+
"en": "A Dapp Blocklet skeleton built with React and Express and Typescript",
|
|
5
|
+
"zh": "一个基于 React 构建的 Dapp Blocklet 应用骨架"
|
|
6
|
+
},
|
|
7
|
+
"blockletType": "dapp",
|
|
8
|
+
"composable": true,
|
|
9
|
+
"languages": "Typescript",
|
|
10
|
+
"useCase": "Starter",
|
|
11
|
+
"author": "Yechao Li"
|
|
12
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ts-node": {
|
|
3
|
+
"files": true
|
|
4
|
+
},
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
7
|
+
/* Projects */
|
|
8
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
9
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
10
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
11
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
12
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
13
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
14
|
+
/* Language and Environment */
|
|
15
|
+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
16
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
+
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
39
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
40
|
+
/* JavaScript Support */
|
|
41
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
42
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
43
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
44
|
+
/* Emit */
|
|
45
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
46
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
47
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
48
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
49
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
50
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
51
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
52
|
+
"noEmit": true /* Disable emitting files from a compilation. */,
|
|
53
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
54
|
+
"importsNotUsedAsValues": "error",
|
|
55
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
56
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
57
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
58
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
59
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
60
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
61
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
62
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
63
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
64
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
65
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
66
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
67
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
68
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
69
|
+
/* Interop Constraints */
|
|
70
|
+
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
|
|
71
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
72
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
73
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
74
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
75
|
+
/* Type Checking */
|
|
76
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
77
|
+
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
|
|
78
|
+
"strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
|
|
79
|
+
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
|
|
80
|
+
"strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
|
|
81
|
+
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
|
|
82
|
+
"noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
|
|
83
|
+
"useUnknownInCatchVariables": false /* Default catch clause variables as 'unknown' instead of 'any'. */,
|
|
84
|
+
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
|
|
85
|
+
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
|
|
86
|
+
"noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
|
|
87
|
+
// "exactOptionalPropertyTypes": false /* Interpret optional property types as written, rather than adding 'undefined'. */,
|
|
88
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
89
|
+
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
|
|
90
|
+
"noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
|
|
91
|
+
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
|
|
92
|
+
// "noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type. */,
|
|
93
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
94
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
95
|
+
/* Completeness */
|
|
96
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
97
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
import { createBlockletPlugin } from 'vite-plugin-blocklet';
|
|
5
|
+
import svgr from 'vite-plugin-svgr';
|
|
6
|
+
|
|
7
|
+
// https://vitejs.dev/config/
|
|
8
|
+
export default defineConfig(() => {
|
|
9
|
+
return {
|
|
10
|
+
plugins: [react(), createBlockletPlugin(), svgr()],
|
|
11
|
+
build: {
|
|
12
|
+
// 禁止 preload 可以解决 js 的请求没有 refferer 的问题
|
|
13
|
+
modulePreload: false,
|
|
14
|
+
cssCodeSplit: false,
|
|
15
|
+
commonjsOptions: {
|
|
16
|
+
transformMixedEsModules: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
});
|