create-blocklet 0.9.5 → 0.9.7
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/common/.prettierrc +11 -1
- package/common/scripts/build-clean.mjs +0 -1
- package/common/scripts/bump-version.mjs +33 -29
- package/index.js +86 -10
- package/package.json +1 -1
- package/templates/base-readme.md +103 -0
- package/templates/did-connect-dapp/.eslintrc.js +4 -0
- package/templates/did-connect-dapp/README.md +143 -0
- package/templates/did-connect-dapp/api/dev.js +5 -0
- package/templates/did-connect-dapp/api/hooks/pre-start.js +33 -0
- package/templates/did-connect-dapp/api/index.js +48 -0
- package/templates/did-connect-dapp/api/libs/auth.js +25 -0
- package/templates/did-connect-dapp/api/libs/env.js +9 -0
- package/templates/did-connect-dapp/api/libs/logger.js +3 -0
- package/templates/did-connect-dapp/api/libs/utils.js +70 -0
- package/templates/did-connect-dapp/api/routes/auth/index.js +15 -0
- package/templates/did-connect-dapp/api/routes/auth/request-digest-signature.js +51 -0
- package/templates/did-connect-dapp/api/routes/auth/request-multiple-claims.js +52 -0
- package/templates/did-connect-dapp/api/routes/auth/request-multiple-steps.js +57 -0
- package/templates/did-connect-dapp/api/routes/auth/request-nft.js +82 -0
- package/templates/did-connect-dapp/api/routes/auth/request-payment.js +72 -0
- package/templates/did-connect-dapp/api/routes/auth/request-profile.js +25 -0
- package/templates/did-connect-dapp/api/routes/auth/request-text-signature.js +44 -0
- package/templates/did-connect-dapp/api/routes/auth/request-transaction-signature.js +62 -0
- package/templates/did-connect-dapp/blocklet.md +5 -0
- package/templates/did-connect-dapp/blocklet.yml +57 -0
- package/templates/did-connect-dapp/index.html +17 -0
- package/templates/did-connect-dapp/package.json +86 -0
- package/templates/did-connect-dapp/src/app.jsx +20 -0
- package/templates/did-connect-dapp/src/assets/get_wallet_en.png +0 -0
- package/templates/did-connect-dapp/src/assets/get_wallet_zh.png +0 -0
- package/templates/did-connect-dapp/src/components/connect-item.jsx +39 -0
- package/templates/did-connect-dapp/src/components/connects/request-digest-signature.jsx +45 -0
- package/templates/did-connect-dapp/src/components/connects/request-multiple-claims.jsx +55 -0
- package/templates/did-connect-dapp/src/components/connects/request-multiple-steps.jsx +54 -0
- package/templates/did-connect-dapp/src/components/connects/request-nft.jsx +75 -0
- package/templates/did-connect-dapp/src/components/connects/request-payment.jsx +82 -0
- package/templates/did-connect-dapp/src/components/connects/request-profile.jsx +72 -0
- package/templates/did-connect-dapp/src/components/connects/request-text-signature.jsx +44 -0
- package/templates/did-connect-dapp/src/components/connects/request-transaction-signature.jsx +44 -0
- package/templates/did-connect-dapp/src/components/info-row.jsx +39 -0
- package/templates/did-connect-dapp/src/components/layout.jsx +26 -0
- package/templates/did-connect-dapp/src/index.jsx +6 -0
- package/templates/did-connect-dapp/src/libs/session.js +11 -0
- package/templates/did-connect-dapp/src/libs/utils.js +4 -0
- package/templates/did-connect-dapp/src/locales/en.js +115 -0
- package/templates/did-connect-dapp/src/locales/index.js +5 -0
- package/templates/did-connect-dapp/src/locales/zh.js +115 -0
- package/templates/did-connect-dapp/src/pages/main.jsx +95 -0
- package/templates/did-connect-dapp/template-info.json +12 -0
- package/templates/did-connect-dapp/vite.config.mjs +11 -0
- package/templates/did-wallet-dapp/.eslintrc.js +7 -0
- package/templates/did-wallet-dapp/README.md +32 -0
- package/templates/did-wallet-dapp/api/dev.js +8 -0
- package/templates/did-wallet-dapp/api/functions/app.js +65 -0
- package/templates/did-wallet-dapp/api/index.js +13 -0
- package/templates/did-wallet-dapp/api/libs/constant.js +1 -0
- package/templates/did-wallet-dapp/api/routes/user.js +30 -0
- package/templates/did-wallet-dapp/blocklet.md +3 -0
- package/templates/did-wallet-dapp/blocklet.yml +58 -0
- package/templates/did-wallet-dapp/index.html +16 -0
- package/templates/did-wallet-dapp/package.json +84 -0
- package/templates/did-wallet-dapp/src/app.jsx +38 -0
- package/templates/did-wallet-dapp/src/assets/blocklet.svg +16 -0
- package/templates/did-wallet-dapp/src/assets/react.svg +1 -0
- package/templates/did-wallet-dapp/src/assets/vite.svg +1 -0
- package/templates/did-wallet-dapp/src/assets/wallet.png +0 -0
- package/templates/did-wallet-dapp/src/components/layout.jsx +28 -0
- package/templates/did-wallet-dapp/src/global.css +79 -0
- package/templates/did-wallet-dapp/src/index.jsx +6 -0
- package/templates/did-wallet-dapp/src/libs/api.js +7 -0
- package/templates/did-wallet-dapp/src/libs/session.js +13 -0
- package/templates/did-wallet-dapp/src/locales/en.js +13 -0
- package/templates/did-wallet-dapp/src/locales/index.js +4 -0
- package/templates/did-wallet-dapp/src/locales/zh.js +13 -0
- package/templates/did-wallet-dapp/src/pages/home/index.css +39 -0
- package/templates/did-wallet-dapp/src/pages/home/index.jsx +57 -0
- package/templates/did-wallet-dapp/src/pages/profile.jsx +136 -0
- package/templates/did-wallet-dapp/template-info.json +12 -0
- package/templates/did-wallet-dapp/vite.config.js +14 -0
- package/templates/did-wallet-dapp/vite.config.server.js +9 -0
- package/templates/express-api/README.md +2 -124
- package/templates/express-api/blocklet.yml +0 -1
- package/templates/express-api/package.json +9 -8
- package/templates/html-static/README.md +3 -125
- package/templates/html-static/blocklet.yml +0 -1
- package/templates/html-static/package.json +4 -3
- package/templates/monorepo/README.md +8 -8
- package/templates/monorepo/package.json +4 -3
- package/templates/monorepo/scripts/bump-version.mjs +36 -32
- package/templates/nestjs-api/README.md +2 -123
- package/templates/nestjs-api/blocklet.yml +0 -1
- package/templates/nestjs-api/package.json +16 -15
- package/templates/nextjs-dapp/README.md +2 -125
- package/templates/nextjs-dapp/blocklet.yml +0 -1
- package/templates/nextjs-dapp/package.json +7 -7
- package/templates/react-dapp/README.md +2 -124
- package/templates/react-dapp/blocklet.yml +0 -1
- package/templates/react-dapp/package.json +16 -15
- package/templates/react-dapp-ts/README.md +2 -125
- package/templates/react-dapp-ts/blocklet.yml +0 -1
- package/templates/react-dapp-ts/package.json +19 -18
- package/templates/react-gun-dapp/README.md +2 -125
- package/templates/react-gun-dapp/blocklet.yml +0 -1
- package/templates/react-gun-dapp/package.json +15 -14
- package/templates/react-static/README.md +2 -125
- package/templates/react-static/blocklet.yml +0 -1
- package/templates/react-static/package.json +11 -10
- package/templates/solidjs-dapp/README.md +2 -125
- package/templates/solidjs-dapp/blocklet.yml +0 -1
- package/templates/solidjs-dapp/package.json +14 -13
- package/templates/solidjs-static/README.md +2 -123
- package/templates/solidjs-static/blocklet.yml +0 -1
- package/templates/solidjs-static/package.json +9 -8
- package/templates/svelte-dapp/README.md +2 -124
- package/templates/svelte-dapp/blocklet.yml +0 -1
- package/templates/svelte-dapp/package.json +12 -11
- package/templates/svelte-static/README.md +2 -125
- package/templates/svelte-static/blocklet.yml +0 -1
- package/templates/svelte-static/package.json +8 -7
- package/templates/todo-list-example/blocklet.yml +0 -1
- package/templates/todo-list-example/package.json +11 -10
- package/templates/vue-dapp/README.md +2 -125
- package/templates/vue-dapp/blocklet.yml +0 -1
- package/templates/vue-dapp/package.json +16 -15
- package/templates/vue-static/README.md +2 -125
- package/templates/vue-static/blocklet.yml +0 -1
- package/templates/vue-static/package.json +11 -10
- package/templates/vue-ts-static/README.md +2 -124
- package/templates/vue-ts-static/blocklet.yml +1 -2
- package/templates/vue-ts-static/package.json +12 -12
- package/templates/vue2-dapp/README.md +2 -125
- package/templates/vue2-dapp/blocklet.yml +0 -1
- package/templates/vue2-dapp/package.json +13 -12
- package/templates/vue2-static/README.md +2 -125
- package/templates/vue2-static/blocklet.yml +0 -1
- package/templates/vue2-static/package.json +9 -8
package/common/.prettierrc
CHANGED
|
@@ -6,5 +6,15 @@
|
|
|
6
6
|
"bracketSameLine": true,
|
|
7
7
|
"semi": true,
|
|
8
8
|
"singleQuote": true,
|
|
9
|
-
"
|
|
9
|
+
"importOrder": [
|
|
10
|
+
"^@core/(.*)$",
|
|
11
|
+
"^@server/(.*)$",
|
|
12
|
+
"^@ui/(.*)$",
|
|
13
|
+
"^[./]"
|
|
14
|
+
],
|
|
15
|
+
"importOrderSeparation": true,
|
|
16
|
+
"importOrderSortSpecifiers": true,
|
|
17
|
+
"plugins": [
|
|
18
|
+
"@trivago/prettier-plugin-sort-imports"
|
|
19
|
+
]
|
|
10
20
|
}
|
|
@@ -2,34 +2,38 @@
|
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
3
|
import { $, chalk, fs } from 'zx';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
await fs.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
async function main() {
|
|
6
|
+
execSync('bumpp --no-tag --no-commit --no-push package.json', { stdio: 'inherit' });
|
|
7
|
+
|
|
8
|
+
const { version } = await fs.readJSON('package.json');
|
|
9
|
+
await fs.writeFileSync('version', version);
|
|
10
|
+
|
|
11
|
+
console.log(chalk.greenBright(`[info]: start to modify blocklet version to ${version}`));
|
|
12
|
+
await $`blocklet version ${version}`;
|
|
13
|
+
console.log(chalk.greenBright('[info]: blocklet version modified.'));
|
|
14
|
+
|
|
15
|
+
let newChangelog = '';
|
|
16
|
+
try {
|
|
17
|
+
const gitRes = await $`git log --pretty=format:"- %s" "main"...HEAD`;
|
|
18
|
+
newChangelog = gitRes.stdout.trim();
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(chalk.redBright('Could not get git log, please write changelog manually.'));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const now = new Date();
|
|
24
|
+
const currentDate = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
|
|
25
|
+
const title = `## ${version} (${currentDate})`;
|
|
26
|
+
|
|
27
|
+
await fs.ensureFile('CHANGELOG.md');
|
|
28
|
+
const oldChangelog = await fs.readFile('CHANGELOG.md', 'utf8');
|
|
29
|
+
const changelog = [title, newChangelog, oldChangelog].filter((item) => !!item).join('\n\n');
|
|
30
|
+
await fs.writeFile('CHANGELOG.md', changelog);
|
|
31
|
+
|
|
32
|
+
console.log(`\nNow you can make adjustments to ${chalk.cyan('CHANGELOG.md')} . Then press enter to continue.`);
|
|
33
|
+
|
|
34
|
+
process.stdin.setRawMode(true);
|
|
35
|
+
process.stdin.resume();
|
|
36
|
+
process.stdin.on('data', process.exit.bind(process, 0));
|
|
20
37
|
}
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
const currentDate = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
|
|
24
|
-
const title = `## ${version} (${currentDate})`;
|
|
25
|
-
|
|
26
|
-
await fs.ensureFile('CHANGELOG.md');
|
|
27
|
-
const oldChangelog = await fs.readFile('CHANGELOG.md', 'utf8');
|
|
28
|
-
const changelog = [title, newChangelog, oldChangelog].filter((item) => !!item).join('\n\n');
|
|
29
|
-
await fs.writeFile('CHANGELOG.md', changelog);
|
|
30
|
-
|
|
31
|
-
console.log(`\nNow you can make adjustments to ${chalk.cyan('CHANGELOG.md')} . Then press enter to continue.`);
|
|
32
|
-
|
|
33
|
-
process.stdin.setRawMode(true);
|
|
34
|
-
process.stdin.resume();
|
|
35
|
-
process.stdin.on('data', process.exit.bind(process, 0));
|
|
39
|
+
main();
|
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
checkYarn,
|
|
27
27
|
} from './lib/utils.js';
|
|
28
28
|
|
|
29
|
-
const { yellow, red, green, cyan, blue, bold
|
|
29
|
+
const { yellow, red, green, cyan, blue, bold } = chalk;
|
|
30
30
|
|
|
31
31
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
32
32
|
|
|
@@ -44,11 +44,21 @@ const templates = [
|
|
|
44
44
|
display: '[dapp] react + express + typescript',
|
|
45
45
|
color: yellow,
|
|
46
46
|
},
|
|
47
|
+
{
|
|
48
|
+
name: 'did-wallet-dapp',
|
|
49
|
+
display: '[dapp: did-wallet] Full stack app (react.js + express.js) with DID Wallet integration',
|
|
50
|
+
color: yellow,
|
|
51
|
+
},
|
|
47
52
|
{
|
|
48
53
|
name: 'todo-list-example',
|
|
49
54
|
display: '[dapp: todo-list] react + express + typescript + DID Spaces',
|
|
50
55
|
color: yellow,
|
|
51
56
|
},
|
|
57
|
+
{
|
|
58
|
+
name: 'did-connect-dapp',
|
|
59
|
+
display: '[dapp: did-connect] Full stack app (react.js + express.js) with DID Connect integration',
|
|
60
|
+
color: yellow,
|
|
61
|
+
},
|
|
52
62
|
{
|
|
53
63
|
name: 'solidjs-dapp',
|
|
54
64
|
display: '[dapp] solid + express.js',
|
|
@@ -57,7 +67,7 @@ const templates = [
|
|
|
57
67
|
{
|
|
58
68
|
name: 'vue-dapp',
|
|
59
69
|
display: '[dapp] vue3 + express.js',
|
|
60
|
-
color:
|
|
70
|
+
color: yellow,
|
|
61
71
|
},
|
|
62
72
|
// {
|
|
63
73
|
// name: 'vue2-dapp',
|
|
@@ -67,7 +77,7 @@ const templates = [
|
|
|
67
77
|
{
|
|
68
78
|
name: 'svelte-dapp',
|
|
69
79
|
display: '[dapp] svelte + express.js',
|
|
70
|
-
color:
|
|
80
|
+
color: yellow,
|
|
71
81
|
},
|
|
72
82
|
// FIXME: @zhanghan add this template in the future
|
|
73
83
|
// {
|
|
@@ -84,12 +94,12 @@ const templates = [
|
|
|
84
94
|
{
|
|
85
95
|
name: 'react-static',
|
|
86
96
|
display: '[static] react',
|
|
87
|
-
color:
|
|
97
|
+
color: green,
|
|
88
98
|
},
|
|
89
99
|
{
|
|
90
100
|
name: 'solidjs-static',
|
|
91
101
|
display: '[static] solidjs',
|
|
92
|
-
color:
|
|
102
|
+
color: green,
|
|
93
103
|
},
|
|
94
104
|
{
|
|
95
105
|
name: 'vue-static',
|
|
@@ -109,23 +119,23 @@ const templates = [
|
|
|
109
119
|
{
|
|
110
120
|
name: 'svelte-static',
|
|
111
121
|
display: '[static] svelte',
|
|
112
|
-
color:
|
|
122
|
+
color: green,
|
|
113
123
|
},
|
|
114
124
|
{
|
|
115
125
|
name: 'html-static',
|
|
116
126
|
display: '[static] html',
|
|
117
|
-
color:
|
|
127
|
+
color: green,
|
|
118
128
|
},
|
|
119
129
|
// api
|
|
120
130
|
{
|
|
121
131
|
name: 'express-api',
|
|
122
132
|
display: '[api] express.js',
|
|
123
|
-
color:
|
|
133
|
+
color: blue,
|
|
124
134
|
},
|
|
125
135
|
{
|
|
126
136
|
name: 'nestjs-api',
|
|
127
137
|
display: '[api] nestjs',
|
|
128
|
-
color:
|
|
138
|
+
color: blue,
|
|
129
139
|
},
|
|
130
140
|
];
|
|
131
141
|
|
|
@@ -148,6 +158,68 @@ function checkDid(did = '') {
|
|
|
148
158
|
return true;
|
|
149
159
|
}
|
|
150
160
|
|
|
161
|
+
function extractContent(content, section) {
|
|
162
|
+
const regex = new RegExp(`## ${section}\\s*([\\s\\S]*?)(?=\\n## |$)`, 'i');
|
|
163
|
+
const match = content.match(regex);
|
|
164
|
+
return match ? match[1].trim() : '';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function mergeReadme(templateName, targetDir, isMonorepo = false) {
|
|
168
|
+
const ignoreTemplates = ['todo-list-example'];
|
|
169
|
+
if (ignoreTemplates.includes(templateName)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const commonReadmePath = path.join(__dirname, 'templates', 'base-readme.md');
|
|
173
|
+
const templateReadmePath = path.join(__dirname, 'templates', templateName, 'README.md');
|
|
174
|
+
const targetReadmePath = isMonorepo
|
|
175
|
+
? path.join(targetDir, 'blocklets', templateName, 'README.md')
|
|
176
|
+
: path.join(targetDir, 'README.md');
|
|
177
|
+
|
|
178
|
+
let commonContent = fs.readFileSync(commonReadmePath, 'utf8');
|
|
179
|
+
const templateContent = fs.existsSync(templateReadmePath) ? fs.readFileSync(templateReadmePath, 'utf8') : '';
|
|
180
|
+
|
|
181
|
+
const templateSections = templateContent.match(/^## .+$/gm) || [];
|
|
182
|
+
|
|
183
|
+
templateSections.forEach((section) => {
|
|
184
|
+
const sectionName = section.replace('## ', '');
|
|
185
|
+
const templateSection = extractContent(templateContent, sectionName);
|
|
186
|
+
|
|
187
|
+
if (commonContent.includes(`## ${sectionName}`)) {
|
|
188
|
+
// If the section exists in the base readme
|
|
189
|
+
if (templateSection.trim()) {
|
|
190
|
+
// If the template section is not empty, replace the entire section
|
|
191
|
+
const sectionRegex = new RegExp(`## ${sectionName}[\\s\\S]*?(?=\\n## |$)`, 'g');
|
|
192
|
+
commonContent = commonContent.replace(sectionRegex, `\n\n## ${sectionName}\n\n${templateSection}`);
|
|
193
|
+
} else {
|
|
194
|
+
// If the template section is empty, remove the entire section including the title
|
|
195
|
+
const sectionRegex = new RegExp(`\n*## ${sectionName}[\\s\\S]*?(?=\n## |$)`, 'g');
|
|
196
|
+
commonContent = commonContent.replace(sectionRegex, '');
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
// If the section doesn't exist in the base readme, replace the corresponding variable
|
|
200
|
+
const variableRegex = new RegExp(`\\{${sectionName}\\}`, 'g');
|
|
201
|
+
commonContent = commonContent.replace(variableRegex, templateSection);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Remove remaining unreplaced variables
|
|
206
|
+
commonContent = commonContent.replace(/\{[A-Z_]+\}\n*/g, '');
|
|
207
|
+
|
|
208
|
+
// Remove empty sections (sections with only title and no content)
|
|
209
|
+
commonContent = commonContent.replace(/\n*## [^\n]+\n+(?=## |$)/g, '');
|
|
210
|
+
|
|
211
|
+
// Ensure two newlines before each section
|
|
212
|
+
commonContent = commonContent.replace(/\n*(## [^\n]+)/g, '\n\n$1');
|
|
213
|
+
|
|
214
|
+
// Remove leading newlines
|
|
215
|
+
commonContent = commonContent.replace(/^\n+/, '');
|
|
216
|
+
|
|
217
|
+
// Remove multiple consecutive newlines, keeping at most two
|
|
218
|
+
commonContent = commonContent.replace(/\n{3,}/g, '\n\n');
|
|
219
|
+
|
|
220
|
+
// Write the merged README file
|
|
221
|
+
fs.writeFileSync(targetReadmePath, commonContent.trim());
|
|
222
|
+
}
|
|
151
223
|
async function init() {
|
|
152
224
|
const { version } = await fs.readJSONSync(path.resolve(__dirname, 'package.json'));
|
|
153
225
|
await echoBrand({ version });
|
|
@@ -382,6 +454,9 @@ async function init() {
|
|
|
382
454
|
}
|
|
383
455
|
})();
|
|
384
456
|
|
|
457
|
+
// merge readme
|
|
458
|
+
mergeReadme(templateName, root, !!mainBlocklet);
|
|
459
|
+
|
|
385
460
|
modifyPackage(
|
|
386
461
|
(pkg) => {
|
|
387
462
|
pkg.name = mainBlocklet ? finalTemplateName : name;
|
|
@@ -391,7 +466,8 @@ async function init() {
|
|
|
391
466
|
);
|
|
392
467
|
modifyBlockletYaml(
|
|
393
468
|
(yamlConfig) => {
|
|
394
|
-
|
|
469
|
+
// NOTICE: don't need set name anymore
|
|
470
|
+
// yamlConfig.name = mainBlocklet ? finalTemplateName : name;
|
|
395
471
|
yamlConfig.title = mainBlocklet ? templateName : name;
|
|
396
472
|
},
|
|
397
473
|
templateDir,
|
package/package.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Getting Started with Create Blocklet
|
|
2
|
+
|
|
3
|
+
This project was bootstrapped with [Create Blocklet](https://github.com/blocklet/create-blocklet).
|
|
4
|
+
|
|
5
|
+
{PROJECT_DESCRIPTION}
|
|
6
|
+
|
|
7
|
+
## File Structure
|
|
8
|
+
|
|
9
|
+
{FILE_STRUCTURE}
|
|
10
|
+
|
|
11
|
+
## Development
|
|
12
|
+
|
|
13
|
+
1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
|
|
14
|
+
|
|
15
|
+
Blocklet needs blocklet server as a dependency. So you need to install it first.
|
|
16
|
+
`npm install -g @blocklet/cli`
|
|
17
|
+
See details in [ https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli#start-blocklet-server]( https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli#start-blocklet-server)
|
|
18
|
+
|
|
19
|
+
2. Init blocklet server & start blocklet server
|
|
20
|
+
|
|
21
|
+
Before starting an blocklet server, you need to init blocklet server.
|
|
22
|
+
`blocklet server init`
|
|
23
|
+
`blocklet server start`
|
|
24
|
+
See details in [https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli#start-blocklet-server](https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli#start-blocklet-server)
|
|
25
|
+
|
|
26
|
+
3. Go to the project directory `cd [name]`
|
|
27
|
+
4. Install dependencies: `npm install` or `yarn`
|
|
28
|
+
5. Start development server: `blocklet dev`
|
|
29
|
+
|
|
30
|
+
## Bundle
|
|
31
|
+
|
|
32
|
+
After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
|
|
33
|
+
|
|
34
|
+
## Deploy
|
|
35
|
+
|
|
36
|
+
- If you want to deploy this blocklet to local blocklet server, you can use `blocklet deploy .blocklet/bundle --app-id {appId}` command(Make sure the blocklet is bundled before deployment).
|
|
37
|
+
- appId is the id of the container you want to run on your server, you can see it in your server's dashboard
|
|
38
|
+
- If you want to deploy this blocklet to remote blocklet server, you can use the command below.
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Upload to blocklet store
|
|
45
|
+
|
|
46
|
+
- If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
|
|
47
|
+
|
|
48
|
+
Bump version at first.
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
npm run bump-version
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Connect to a store, You may need some testnet tokens to deploy your blocklet, you can get some from https://faucet.abtnetwork.io/
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
blocklet connect https://test.store.blocklet.dev/
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Upload a new version to a store.
|
|
61
|
+
|
|
62
|
+
> Make sure the blocklet is bundled before upload.
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
blocklet upload
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or you can simply use `npm run upload` command.
|
|
69
|
+
|
|
70
|
+
- You also can upload a new version to a store by Github CI.
|
|
71
|
+
Bump version at first.
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
npm run bump-version
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Push your code to Github main/master branch, or make a pull request to the main/master branch.
|
|
78
|
+
The CI workflow will automatically upload a new version to a store.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Q & A
|
|
82
|
+
|
|
83
|
+
1. Q: How to change a blocklet's logo?
|
|
84
|
+
|
|
85
|
+
Change the `logo.png` file root folder.
|
|
86
|
+
|
|
87
|
+
Or you can change the `logo` field in the `blocklet.yml` file.
|
|
88
|
+
|
|
89
|
+
> Make sure you have added the logo path to the `blocklet.yml` file `files` field.
|
|
90
|
+
|
|
91
|
+
{QA_SECTION}
|
|
92
|
+
|
|
93
|
+
## Learn More
|
|
94
|
+
|
|
95
|
+
- 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)
|
|
96
|
+
- Full document of Blocklet Server & blocklet development: [https://www.arcblock.io/docs/blocklet-developer](https://www.arcblock.io/docs/blocklet-developer)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
The code is licensed under the Apache 2.0 license found in the
|
|
103
|
+
[LICENSE](LICENSE) file.
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
- routes/auth - DID Connect backend registration
|
|
20
|
+
- dev.js - Api side dev mode entry point
|
|
21
|
+
- index.js - Api side entry point
|
|
22
|
+
- src/ - Client side code (A standard react app structure)
|
|
23
|
+
- .env - Environment variables
|
|
24
|
+
- .env.development.local - Local development environment variables
|
|
25
|
+
- .eslintrc.js - ESLint configuration
|
|
26
|
+
- .gitignore - Git ignore file
|
|
27
|
+
- .prettierrc - Prettier configuration
|
|
28
|
+
- blocklet.md - Blocklet README
|
|
29
|
+
- blocklet.yml - Blocklet configuration
|
|
30
|
+
- LICENSE - License file
|
|
31
|
+
- logo.png - Blocklet logo file
|
|
32
|
+
- Makefile - Makefile
|
|
33
|
+
- package.json - Npm package file
|
|
34
|
+
- README.md - A guide for this blocklet
|
|
35
|
+
- version - Version file
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed
|
|
40
|
+
|
|
41
|
+
Blocklet needs blocklet server as a dependency. So you need to install it first.
|
|
42
|
+
`npm install -g @blocklet/cli`
|
|
43
|
+
See details in [https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli](https://www.arcblock.io/docs/blocklet-developer/install-blocklet-cli)
|
|
44
|
+
|
|
45
|
+
2. Init blocklet server & start blocklet server
|
|
46
|
+
|
|
47
|
+
Before starting an blocklet server, you need to init blocklet server.
|
|
48
|
+
`blocklet server init --mode=debug`
|
|
49
|
+
`blocklet server start`
|
|
50
|
+
See details in [https://www.arcblock.io/docs/blocklet-developer/getting-started](https://www.arcblock.io/docs/blocklet-developer/getting-started)
|
|
51
|
+
|
|
52
|
+
3. Go to the project directory `cd [name]`
|
|
53
|
+
4. Install dependencies: `npm install` or `yarn` or `pnpm install`
|
|
54
|
+
5. Start development server: `blocklet dev`
|
|
55
|
+
|
|
56
|
+
## Bundle
|
|
57
|
+
|
|
58
|
+
After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.
|
|
59
|
+
|
|
60
|
+
## Deploy
|
|
61
|
+
|
|
62
|
+
- 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).
|
|
63
|
+
> Or you can simply use `npm run deploy` command.
|
|
64
|
+
- If you want to deploy this blocklet to remote blocklet server, you can use the command below.
|
|
65
|
+
|
|
66
|
+
```shell
|
|
67
|
+
blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> Make sure the blocklet is bundled before deployment.
|
|
71
|
+
|
|
72
|
+
## Upload to blocklet store
|
|
73
|
+
|
|
74
|
+
- If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.
|
|
75
|
+
|
|
76
|
+
Bump version at first.
|
|
77
|
+
|
|
78
|
+
```shell
|
|
79
|
+
npm run bump-version
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Then config blocklet store url.
|
|
83
|
+
You can use those store url in below.
|
|
84
|
+
|
|
85
|
+
1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
|
|
86
|
+
2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
|
|
87
|
+
3. A blocklet store started by yourself.
|
|
88
|
+
> 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)
|
|
89
|
+
|
|
90
|
+
```shell
|
|
91
|
+
blocklet config set store {store url}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Get a `accessToken` by using this command.
|
|
95
|
+
|
|
96
|
+
> Why we need a `accessToken`?
|
|
97
|
+
> A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.
|
|
98
|
+
|
|
99
|
+
Set `accessToken` to blocklet config
|
|
100
|
+
|
|
101
|
+
```shell
|
|
102
|
+
blocklet config set accessToken {accessToken}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Upload a new version to a store.
|
|
106
|
+
|
|
107
|
+
> Make sure the blocklet is bundled before upload.
|
|
108
|
+
|
|
109
|
+
```shell
|
|
110
|
+
blocklet upload
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or you can simply use `npm run upload` command.
|
|
114
|
+
|
|
115
|
+
- You also can upload a new version to a store by Github CI.
|
|
116
|
+
Bump version at first.
|
|
117
|
+
|
|
118
|
+
```shell
|
|
119
|
+
npm run bump-version
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Push your code to Github main/master branch, or make a pull request to the main/master branch.
|
|
123
|
+
The CI workflow will automatically upload a new version to a store.
|
|
124
|
+
|
|
125
|
+
## Q & A
|
|
126
|
+
|
|
127
|
+
1. Q: How to change a blocklet's logo?
|
|
128
|
+
|
|
129
|
+
Change the `logo.png` file root folder.
|
|
130
|
+
|
|
131
|
+
Or you can change the `logo` field in the `blocklet.yml` file.
|
|
132
|
+
|
|
133
|
+
> Make sure you have added the logo path to the `blocklet.yml` file `files` field.
|
|
134
|
+
|
|
135
|
+
## Learn More
|
|
136
|
+
|
|
137
|
+
- 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)
|
|
138
|
+
- Full document of Blocklet Server & blocklet development: [https://www.arcblock.io/docs/blocklet-developer](https://www.arcblock.io/docs/blocklet-developer)
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
The code is licensed under the Apache 2.0 license found in the
|
|
143
|
+
[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,48 @@
|
|
|
1
|
+
require('dotenv-flow').config();
|
|
2
|
+
require('express-async-errors');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const express = require('express');
|
|
5
|
+
const cookieParser = require('cookie-parser');
|
|
6
|
+
const fallback = require('@blocklet/sdk/lib/middlewares/fallback');
|
|
7
|
+
|
|
8
|
+
const authRoutes = require('./routes/auth');
|
|
9
|
+
const { name, version } = require('../package.json');
|
|
10
|
+
const logger = require('./libs/logger');
|
|
11
|
+
|
|
12
|
+
const app = express();
|
|
13
|
+
|
|
14
|
+
app.set('trust proxy', true);
|
|
15
|
+
app.use(cookieParser());
|
|
16
|
+
app.use(express.json({ limit: '1 mb' }));
|
|
17
|
+
app.use(express.urlencoded({ extended: true, limit: '1 mb' }));
|
|
18
|
+
|
|
19
|
+
const router = express.Router();
|
|
20
|
+
|
|
21
|
+
authRoutes.init(router);
|
|
22
|
+
app.use(router);
|
|
23
|
+
|
|
24
|
+
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
25
|
+
|
|
26
|
+
if (isProduction) {
|
|
27
|
+
const staticDir = path.resolve(__dirname, '../dist');
|
|
28
|
+
app.use(express.static(staticDir, { maxAge: '30d', index: false }));
|
|
29
|
+
app.use(fallback('index.html', { root: staticDir }));
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line no-unused-vars
|
|
32
|
+
app.use((err, req, res, next) => {
|
|
33
|
+
logger.error(err.stack);
|
|
34
|
+
res.status(500).send('Something broke!');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const port = parseInt(process.env.BLOCKLET_PORT, 10);
|
|
39
|
+
|
|
40
|
+
const server = app.listen(port, (err) => {
|
|
41
|
+
if (err) throw err;
|
|
42
|
+
logger.info(`> ${name} v${version} ready on ${port}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
app,
|
|
47
|
+
server,
|
|
48
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const Client = require('@ocap/client');
|
|
7
|
+
|
|
8
|
+
const env = require('./env');
|
|
9
|
+
|
|
10
|
+
const client = new Client(env.chainHost);
|
|
11
|
+
const wallet = getWallet();
|
|
12
|
+
const authenticator = new WalletAuthenticator();
|
|
13
|
+
const handlers = new WalletHandler({
|
|
14
|
+
authenticator,
|
|
15
|
+
tokenStorage: new AuthStorage({
|
|
16
|
+
dbPath: path.join(env.dataDir, 'auth.db'),
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
authenticator,
|
|
22
|
+
handlers,
|
|
23
|
+
wallet,
|
|
24
|
+
client,
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const env = require('@blocklet/sdk/lib/env');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
...env,
|
|
5
|
+
chainHost: process.env.CHAIN_HOST || '',
|
|
6
|
+
chainId: 'playground',
|
|
7
|
+
localTokenId: process.env.LOCAL_TOKEN_ID || 'z35n6UoHSi9MED4uaQy6ozFgKPaZj2UKrurBG',
|
|
8
|
+
apiPrefix: process.env.API_PREFIX || '',
|
|
9
|
+
};
|