create-blocklet 0.2.18 → 0.3.0
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/.github/workflows/main.yml +5 -5
- package/common/.husky/pre-commit +4 -0
- package/common/_eslintignore +10 -0
- package/common/_eslintrc.js +1 -0
- package/common/_gitignore +15 -9
- package/common/logo.png +0 -0
- package/common/public/favicon.ico +0 -0
- package/index.js +178 -72
- package/lib/arcblock.js +3 -1
- package/lib/git.js +25 -0
- package/lib/index.js +17 -5
- package/lib/npm.js +7 -9
- package/lib/server.js +26 -20
- package/package.json +18 -16
- package/template-dapp/react/README.md +5 -5
- package/template-dapp/react/{server → api}/hooks/pre-start.js +0 -0
- package/template-dapp/react/{server → api}/index.js +0 -0
- package/template-dapp/react/{server → api}/libs/auth.js +0 -0
- package/template-dapp/react/{server → api}/libs/env.js +0 -0
- package/template-dapp/react/{server → api}/libs/logger.js +0 -0
- package/template-dapp/{vue2/server → react/api}/routes/index.js +1 -1
- package/template-dapp/react/blocklet.yml +5 -5
- package/template-dapp/react/package.json +35 -23
- package/template-dapp/react/public/index.html +1 -3
- package/template-dapp/react/src/app.js +8 -8
- package/template-dapp/vue/.browserslistrc +4 -0
- package/template-dapp/vue/.eslintrc.js +25 -0
- package/template-dapp/vue/{server → api}/hooks/pre-start.js +0 -0
- package/template-dapp/vue/{server → api}/index.js +0 -0
- package/template-dapp/vue/{server → api}/libs/auth.js +0 -0
- package/template-dapp/vue/{server → api}/libs/env.js +0 -0
- package/template-dapp/vue/{server → api}/libs/logger.js +0 -0
- package/template-dapp/{react/server → vue/api}/routes/index.js +1 -1
- package/template-dapp/vue/blocklet.yml +5 -4
- package/template-dapp/vue/index.html +2 -3
- package/template-dapp/vue/package.json +38 -21
- package/template-dapp/vue/src/App.vue +4 -2
- package/template-dapp/vue/vite.config.js +8 -6
- package/template-dapp/vue2/.browserslistrc +4 -0
- package/template-dapp/vue2/.eslintrc.js +14 -0
- package/template-dapp/vue2/{server → api}/hooks/pre-start.js +0 -0
- package/template-dapp/vue2/{server → api}/index.js +0 -0
- package/template-dapp/vue2/{server → api}/libs/auth.js +0 -0
- package/template-dapp/vue2/{server → api}/libs/env.js +0 -0
- package/template-dapp/vue2/{server → api}/libs/logger.js +0 -0
- package/template-dapp/{vue/server → vue2/api}/routes/index.js +1 -1
- package/template-dapp/vue2/blocklet.yml +6 -4
- package/template-dapp/vue2/jsconfig.json +19 -0
- package/template-dapp/vue2/package.json +38 -43
- package/template-dapp/vue2/public/index.html +2 -9
- package/template-dapp/vue2/src/App.vue +17 -1
- package/template-dapp/vue2/src/main.js +0 -2
- package/template-dapp/vue2/vue.config.js +0 -1
- package/template-static/blocklet-page/package.json +5 -5
- package/template-static/react/blocklet.yml +2 -2
- package/template-static/react/package.json +21 -9
- package/template-static/react/public/index.html +1 -3
- package/template-static/react/src/app.js +8 -8
- package/template-static/vue/.browserslistrc +4 -0
- package/template-static/vue/.eslintrc.js +25 -0
- package/template-static/vue/blocklet.yml +2 -2
- package/template-static/vue/index.html +2 -3
- package/template-static/vue/package.json +25 -8
- package/template-static/vue/vite.config.js +8 -6
- package/template-static/vue2/.browserslistrc +4 -0
- package/template-static/vue2/.eslintrc.js +14 -0
- package/template-static/vue2/blocklet.yml +2 -2
- package/template-static/vue2/jsconfig.json +19 -0
- package/template-static/vue2/package.json +25 -30
- package/template-static/vue2/public/index.html +2 -9
- package/template-static/vue2/src/App.vue +7 -1
- package/template-static/vue2/src/main.js +0 -2
- package/template-static/vue2/vue.config.js +0 -3
- package/common/public/favicon.svg +0 -1
- package/template-dapp/vue2/src/pages/About.vue +0 -13
- package/template-dapp/vue2/src/pages/Home.vue +0 -27
- package/template-dapp/vue2/src/router.js +0 -24
- package/template-static/vue2/src/pages/About.vue +0 -13
- package/template-static/vue2/src/pages/Home.vue +0 -20
- package/template-static/vue2/src/router.js +0 -24
|
@@ -27,10 +27,10 @@ jobs:
|
|
|
27
27
|
skip-upload: false
|
|
28
28
|
skip-deploy: false
|
|
29
29
|
bundle-command: yarn bundle
|
|
30
|
-
store-endpoint: ${{ secrets.
|
|
31
|
-
store-access-token: ${{ secrets.
|
|
32
|
-
server-endpoint: ${{ secrets.
|
|
33
|
-
server-access-key: ${{ secrets.
|
|
34
|
-
server-access-secret: ${{ secrets.
|
|
30
|
+
store-endpoint: ${{ secrets.STORE_ENDPOINT }}
|
|
31
|
+
store-access-token: ${{ secrets.STORE_ACCESS_TOKEN }}
|
|
32
|
+
server-endpoint: ${{ secrets.SERVER_ENDPOINT }}
|
|
33
|
+
server-access-key: ${{ secrets.SERVER_ACCESS_KEY }}
|
|
34
|
+
server-access-secret: ${{ secrets.SERVER_ACCESS_SECRET }}
|
|
35
35
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
|
36
36
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package/common/_eslintrc.js
CHANGED
package/common/_gitignore
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
2
|
|
|
3
3
|
# dependencies
|
|
4
|
-
/node_modules
|
|
5
4
|
/.pnp
|
|
6
5
|
.pnp.js
|
|
6
|
+
.DS_Store
|
|
7
|
+
node_modules
|
|
7
8
|
|
|
8
9
|
# testing
|
|
9
10
|
/coverage
|
|
@@ -11,19 +12,24 @@
|
|
|
11
12
|
# production
|
|
12
13
|
/build
|
|
13
14
|
/dist
|
|
15
|
+
.blocklet
|
|
14
16
|
|
|
15
|
-
#
|
|
16
|
-
.DS_Store
|
|
17
|
+
# local env files
|
|
17
18
|
.env.local
|
|
18
|
-
.env
|
|
19
|
-
.env.test.local
|
|
20
|
-
.env.production.local
|
|
19
|
+
.env.*.local
|
|
21
20
|
|
|
21
|
+
# Log files
|
|
22
22
|
npm-debug.log*
|
|
23
23
|
yarn-debug.log*
|
|
24
24
|
yarn-error.log*
|
|
25
|
+
pnpm-debug.log*
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.DS_Store
|
|
27
|
+
# Editor directories and files
|
|
28
|
+
.idea
|
|
29
29
|
.vscode
|
|
30
|
+
*.suo
|
|
31
|
+
*.ntvs*
|
|
32
|
+
*.njsproj
|
|
33
|
+
*.sln
|
|
34
|
+
*.sw?
|
|
35
|
+
|
package/common/logo.png
CHANGED
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from 'fs';
|
|
4
3
|
import ejs from 'ejs';
|
|
5
|
-
import
|
|
6
|
-
import YAML from 'yaml';
|
|
4
|
+
import boxen from 'boxen';
|
|
7
5
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
import { cd, argv, fs, YAML, chalk, path } from 'zx';
|
|
8
|
+
import { startSpinner } from 'zx/experimental';
|
|
9
9
|
import prompts from 'prompts';
|
|
10
|
-
import { yellow, red, green, cyan, blue, lightYellow } from 'kolorist';
|
|
11
10
|
import * as envfile from 'envfile';
|
|
12
11
|
|
|
13
12
|
import { echoBrand, echoDocument } from './lib/arcblock.js';
|
|
14
|
-
import {
|
|
13
|
+
import { getUser } from './lib/index.js';
|
|
15
14
|
import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getServerDirectory } from './lib/server.js';
|
|
16
|
-
import { toBlockletDid
|
|
15
|
+
import { toBlockletDid } from './lib/did.js';
|
|
16
|
+
import { initGitRepo } from './lib/git.js';
|
|
17
|
+
|
|
18
|
+
const { yellow, red, green, cyan, blue, bold, dim } = chalk;
|
|
17
19
|
|
|
18
|
-
const argv = minimist(process.argv.slice(2));
|
|
19
20
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
21
|
|
|
21
22
|
const cwd = process.cwd();
|
|
@@ -73,15 +74,28 @@ const TYPES = [
|
|
|
73
74
|
const renameFiles = {
|
|
74
75
|
_gitignore: '.gitignore',
|
|
75
76
|
'_eslintrc.js': '.eslintrc.js',
|
|
77
|
+
_eslintignore: '.eslintignore',
|
|
76
78
|
_npmrc: '.npmrc',
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
async function init() {
|
|
80
|
-
|
|
82
|
+
const { version } = await fs.readJSONSync(path.resolve(__dirname, 'package.json'));
|
|
83
|
+
|
|
84
|
+
console.log(
|
|
85
|
+
boxen(`${bold('Blocklet') + dim(' Starter')} ${blue(`v${version}`)}`, {
|
|
86
|
+
padding: 1,
|
|
87
|
+
margin: 1,
|
|
88
|
+
float: 'center',
|
|
89
|
+
borderStyle: 'double',
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
let targetDir = argv._[0] ? String(argv._[0]) : undefined;
|
|
81
94
|
|
|
82
95
|
const defaultProjectName = !targetDir ? 'blocklet-project' : targetDir;
|
|
83
96
|
|
|
84
97
|
let result = {};
|
|
98
|
+
const authorInfo = await getUser();
|
|
85
99
|
|
|
86
100
|
try {
|
|
87
101
|
result = await prompts(
|
|
@@ -153,6 +167,18 @@ async function init() {
|
|
|
153
167
|
});
|
|
154
168
|
},
|
|
155
169
|
},
|
|
170
|
+
{
|
|
171
|
+
type: 'text',
|
|
172
|
+
name: 'authorName',
|
|
173
|
+
message: 'Author name:',
|
|
174
|
+
initial: authorInfo?.name || '',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: 'text',
|
|
178
|
+
name: 'authorEmail',
|
|
179
|
+
message: 'Author email:',
|
|
180
|
+
initial: authorInfo?.email || '',
|
|
181
|
+
},
|
|
156
182
|
],
|
|
157
183
|
{
|
|
158
184
|
onCancel: () => {
|
|
@@ -161,12 +187,14 @@ async function init() {
|
|
|
161
187
|
}
|
|
162
188
|
);
|
|
163
189
|
} catch (cancelled) {
|
|
164
|
-
console.
|
|
190
|
+
console.error(cancelled.message);
|
|
165
191
|
return;
|
|
166
192
|
}
|
|
167
193
|
|
|
168
194
|
// user choice associated with prompts
|
|
169
|
-
const { type, framework, overwrite, packageName } = result;
|
|
195
|
+
const { type, framework, overwrite, packageName, authorName, authorEmail } = result;
|
|
196
|
+
|
|
197
|
+
const stopSpinner = startSpinner();
|
|
170
198
|
|
|
171
199
|
const root = path.join(cwd, targetDir);
|
|
172
200
|
|
|
@@ -181,42 +209,9 @@ async function init() {
|
|
|
181
209
|
|
|
182
210
|
console.log('Checking blocklet server runtime environment...', '\n');
|
|
183
211
|
|
|
184
|
-
const isServerInstalled = checkServerInstalled();
|
|
185
|
-
const isSatisfiedVersion = checkSatisfiedVersion();
|
|
186
|
-
const isServerRunning = checkServerRunning();
|
|
187
|
-
|
|
188
|
-
if (!isServerInstalled) {
|
|
189
|
-
// 未安装 blocklet server
|
|
190
|
-
console.log(red('To run the blocklet, you need a running blocklet server instance on local machine.'), '\n');
|
|
191
|
-
console.log(`Checkout ${green('README.md')} for more usage instructions.`);
|
|
192
|
-
console.log('Now you should run:', '\n');
|
|
193
|
-
console.log(cyan('npm install -g @blocklet/cli'));
|
|
194
|
-
console.log(cyan('blocklet server start -a'));
|
|
195
|
-
} else if (!isSatisfiedVersion) {
|
|
196
|
-
// 已安装 blocklet server,但版本不满足
|
|
197
|
-
console.log(red('Your blocklet server version is outdate, please update it to the latest version.'));
|
|
198
|
-
console.log('Now you should run:', '\n');
|
|
199
|
-
if (isServerRunning) {
|
|
200
|
-
// blocklet server 已经启动
|
|
201
|
-
const serverPath = getServerDirectory();
|
|
202
|
-
console.log(cyan(`cd ${serverPath}`));
|
|
203
|
-
console.log(cyan('blocklet server stop'));
|
|
204
|
-
console.log(cyan('npm install -g @blocklet/cli'));
|
|
205
|
-
console.log(cyan('blocklet server start'));
|
|
206
|
-
console.log(cyan(`cd ${cwd}`));
|
|
207
|
-
} else {
|
|
208
|
-
// blocklet server 未启动
|
|
209
|
-
// TODO: 如何获取未启动的 blocklet server 实例目录?
|
|
210
|
-
console.log(cyan('npm install -g @blocklet/cli'));
|
|
211
|
-
console.log(cyan('blocklet server start -a'));
|
|
212
|
-
}
|
|
213
|
-
} else if (!isServerRunning) {
|
|
214
|
-
// 已经安装 blocklet server,且版本满足,并且 blocklet server 未启动
|
|
215
|
-
console.log(red('You need to start your blocklet server before develop this blocklet.'));
|
|
216
|
-
console.log('Now you should run:', '\n');
|
|
217
|
-
// TODO: 如何获取未启动的 blocklet server 实例目录?
|
|
218
|
-
console.log(cyan('blocklet server start -a'));
|
|
219
|
-
}
|
|
212
|
+
const isServerInstalled = await checkServerInstalled();
|
|
213
|
+
const isSatisfiedVersion = await checkSatisfiedVersion();
|
|
214
|
+
const isServerRunning = await checkServerRunning();
|
|
220
215
|
|
|
221
216
|
console.log(`\n\nScaffolding project in ${root}...`);
|
|
222
217
|
|
|
@@ -232,6 +227,10 @@ async function init() {
|
|
|
232
227
|
// eslint-disable-next-line no-continue
|
|
233
228
|
continue;
|
|
234
229
|
}
|
|
230
|
+
if (framework === 'blocklet-page' && ['_eslintignore', '.husky'].includes(file)) {
|
|
231
|
+
// eslint-disable-next-line no-continue
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
235
234
|
const targetPath = renameFiles[file] ? path.join(root, renameFiles[file]) : path.join(root, file);
|
|
236
235
|
copy(path.join(commonDir, file), targetPath);
|
|
237
236
|
}
|
|
@@ -256,21 +255,23 @@ async function init() {
|
|
|
256
255
|
modifyBlockletMd((md) => {
|
|
257
256
|
return md.replace(/# template-react/g, `# ${name}`);
|
|
258
257
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
258
|
+
if (!['blocklet-page'].includes(framework)) {
|
|
259
|
+
modifyEnv((env) => {
|
|
260
|
+
if (['react'].includes(framework)) {
|
|
261
|
+
env.REACT_APP_TITLE = name;
|
|
262
|
+
} else if (['vue', 'blocklet-page'].includes(framework)) {
|
|
263
|
+
env.VITE_APP_TITLE = name;
|
|
264
|
+
} else {
|
|
265
|
+
env.APP_TITLE = name;
|
|
266
|
+
}
|
|
267
|
+
return env;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
267
270
|
|
|
268
271
|
// patch blocklet author
|
|
269
|
-
modifyBlockletYaml((yamlConfig) => {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (name) yamlConfig.author.name = name;
|
|
273
|
-
if (email) yamlConfig.author.email = email;
|
|
272
|
+
modifyBlockletYaml(async (yamlConfig) => {
|
|
273
|
+
yamlConfig.author.name = authorName;
|
|
274
|
+
yamlConfig.author.email = authorEmail;
|
|
274
275
|
});
|
|
275
276
|
|
|
276
277
|
// patch did
|
|
@@ -286,23 +287,128 @@ async function init() {
|
|
|
286
287
|
pkg.scripts.bundle = ejs.render(pkg.scripts.bundle, { did });
|
|
287
288
|
}
|
|
288
289
|
});
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
// disabled random logo
|
|
291
|
+
// const pngIcon = toDidIcon(did, undefined, true);
|
|
292
|
+
// fs.writeFileSync(path.join(root, 'logo.png'), pngIcon);
|
|
291
293
|
})();
|
|
292
294
|
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
+
const related = path.relative(cwd, root);
|
|
295
296
|
console.log('\n\n✨ Done. Now run:\n');
|
|
297
|
+
stopSpinner();
|
|
298
|
+
|
|
299
|
+
// const pkgManager =
|
|
300
|
+
// // eslint-disable-next-line no-nested-ternary
|
|
301
|
+
// /pnpm/.test(process.env.npm_execpath) || /pnpm/.test(process.env.npm_config_user_agent)
|
|
302
|
+
// ? 'pnpm'
|
|
303
|
+
// : /yarn/.test(process.env.npm_execpath)
|
|
304
|
+
// ? 'yarn'
|
|
305
|
+
// : 'npm';
|
|
306
|
+
try {
|
|
307
|
+
const { yes } = await prompts(
|
|
308
|
+
{
|
|
309
|
+
type: 'confirm',
|
|
310
|
+
name: 'yes',
|
|
311
|
+
initial: 'Y',
|
|
312
|
+
message: 'Install and start it now?',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
onCancel: () => {
|
|
316
|
+
throw new Error(`${red('✖')} Operation cancelled`);
|
|
317
|
+
},
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
let hasStart = false;
|
|
321
|
+
|
|
322
|
+
await initGitRepo(root);
|
|
323
|
+
|
|
324
|
+
let defaultAgent = 'npm';
|
|
325
|
+
let agentList = ['npm', 'yarn', 'pnpm'];
|
|
326
|
+
switch (framework) {
|
|
327
|
+
case 'react':
|
|
328
|
+
case 'blocklet-page':
|
|
329
|
+
agentList = ['npm', 'yarn'];
|
|
330
|
+
break;
|
|
331
|
+
default:
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
if (yes) {
|
|
335
|
+
const { agent } = await prompts({
|
|
336
|
+
name: 'agent',
|
|
337
|
+
type: 'select',
|
|
338
|
+
message: 'Choose the agent',
|
|
339
|
+
choices: agentList.map((i) => ({ value: i, title: i })),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
if (!agent) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
defaultAgent = agent;
|
|
346
|
+
|
|
347
|
+
await cd(root);
|
|
348
|
+
execSync(`${agent} install`, { stdio: 'inherit' });
|
|
349
|
+
if (isServerInstalled && isServerRunning && isSatisfiedVersion) {
|
|
350
|
+
console.log(
|
|
351
|
+
boxen(bold('blocklet dev'), {
|
|
352
|
+
padding: 1,
|
|
353
|
+
margin: 1,
|
|
354
|
+
float: 'center',
|
|
355
|
+
})
|
|
356
|
+
);
|
|
357
|
+
hasStart = true;
|
|
358
|
+
execSync('blocklet dev', { stdio: 'inherit' });
|
|
359
|
+
} else {
|
|
360
|
+
console.log();
|
|
361
|
+
console.log();
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
console.log();
|
|
365
|
+
console.log();
|
|
366
|
+
}
|
|
296
367
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
368
|
+
if (!isServerInstalled) {
|
|
369
|
+
// 未安装 blocklet server
|
|
370
|
+
console.log(red('To run the blocklet, you need a running blocklet server instance on local machine.'), '\n');
|
|
371
|
+
console.log(`Checkout ${green('README.md')} for more usage instructions.`);
|
|
372
|
+
console.log('Now you should run:', '\n');
|
|
373
|
+
console.log(cyan(`${defaultAgent} install -g @blocklet/cli`));
|
|
374
|
+
console.log(cyan('blocklet server start -a'));
|
|
375
|
+
} else if (!isSatisfiedVersion) {
|
|
376
|
+
// 已安装 blocklet server,但版本不满足
|
|
377
|
+
console.log(red('Your blocklet server version is outdate, please update it to the latest version.'));
|
|
378
|
+
console.log('Now you should run:', '\n');
|
|
379
|
+
if (isServerRunning) {
|
|
380
|
+
// blocklet server 已经启动
|
|
381
|
+
const serverPath = await getServerDirectory();
|
|
382
|
+
console.log(cyan(`cd ${serverPath}`));
|
|
383
|
+
console.log(cyan('blocklet server stop'));
|
|
384
|
+
console.log(cyan(`${defaultAgent} install -g @blocklet/cli`));
|
|
385
|
+
console.log(cyan('blocklet server start'));
|
|
386
|
+
} else {
|
|
387
|
+
// blocklet server 未启动
|
|
388
|
+
// TODO: 如何获取未启动的 blocklet server 实例目录?
|
|
389
|
+
console.log(cyan(`${defaultAgent} install -g @blocklet/cli`));
|
|
390
|
+
console.log(cyan('blocklet server start -a'));
|
|
391
|
+
}
|
|
392
|
+
} else if (!isServerRunning) {
|
|
393
|
+
// 已经安装 blocklet server,且版本满足,并且 blocklet server 未启动
|
|
394
|
+
console.log(red('You need to start your blocklet server before develop this blocklet.'));
|
|
395
|
+
console.log('Now you should run:', '\n');
|
|
396
|
+
// TODO: 如何获取未启动的 blocklet server 实例目录?
|
|
397
|
+
console.log(cyan('blocklet server start -a'));
|
|
398
|
+
}
|
|
300
399
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
400
|
+
if (!hasStart) {
|
|
401
|
+
console.log(dim('\n start it later by:\n'));
|
|
402
|
+
if (root !== cwd) console.log(blue(` cd ${bold(related)}`));
|
|
304
403
|
|
|
305
|
-
|
|
404
|
+
console.log(blue(` ${defaultAgent === 'yarn' ? 'yarn' : `${defaultAgent} install`}`));
|
|
405
|
+
console.log(blue(` ${defaultAgent === 'yarn' ? 'yarn dev' : `${defaultAgent} run dev`}`));
|
|
406
|
+
console.log(cyan('blocklet dev'));
|
|
407
|
+
console.log('\n', `Find more usage in ${green('README.md')}`, '\n');
|
|
408
|
+
}
|
|
409
|
+
} catch (cancelled) {
|
|
410
|
+
console.error(cancelled.message);
|
|
411
|
+
}
|
|
306
412
|
|
|
307
413
|
// inside functions
|
|
308
414
|
function write(file, content) {
|
|
@@ -341,7 +447,7 @@ async function init() {
|
|
|
341
447
|
modifyFn(env);
|
|
342
448
|
write('.env', envfile.stringify(env));
|
|
343
449
|
} catch {
|
|
344
|
-
console.warn(`\n${
|
|
450
|
+
console.warn(`\n${yellow('No .env file found, please add one.')}`);
|
|
345
451
|
}
|
|
346
452
|
}
|
|
347
453
|
}
|
package/lib/arcblock.js
CHANGED
package/lib/git.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { $, which, cd } from 'zx';
|
|
2
|
+
|
|
3
|
+
$.verbose = false;
|
|
4
|
+
|
|
5
|
+
export async function isGitInstalled() {
|
|
6
|
+
try {
|
|
7
|
+
await which('git');
|
|
8
|
+
return true;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function initGitRepo(root) {
|
|
15
|
+
await cd(root);
|
|
16
|
+
await $`git init`;
|
|
17
|
+
await $`git add .`;
|
|
18
|
+
await $`git commit -m 'init'`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function getUserInfo() {
|
|
22
|
+
const { stdout: name } = await $`git config user.name`;
|
|
23
|
+
const { stdout: email } = await $`git config user.email`;
|
|
24
|
+
return { name: name.trim(), email: email.trim() };
|
|
25
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { $ } from 'zx';
|
|
2
|
+
import { getAuthor } from './npm.js';
|
|
3
|
+
import { getUserInfo } from './git.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
$.verbose = false;
|
|
6
|
+
|
|
7
|
+
export async function getOutput(cmd) {
|
|
8
|
+
const { stdout: output } = await $`${cmd}`;
|
|
9
|
+
return output.trim();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function getUser() {
|
|
13
|
+
const npmAuthor = await getAuthor();
|
|
14
|
+
const gitUser = await getUserInfo();
|
|
15
|
+
return {
|
|
16
|
+
name: npmAuthor.name || gitUser.name,
|
|
17
|
+
email: npmAuthor.email || gitUser.email,
|
|
18
|
+
};
|
|
7
19
|
}
|
package/lib/npm.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import { $ } from 'zx';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const conf = rc('npm');
|
|
5
|
-
return conf?.[key] || '';
|
|
6
|
-
}
|
|
4
|
+
$.verbose = false;
|
|
7
5
|
|
|
8
|
-
export function getAuthor() {
|
|
9
|
-
const name =
|
|
10
|
-
const email =
|
|
6
|
+
export async function getAuthor() {
|
|
7
|
+
const { stdout: name } = await $`npm config get init.author.name`;
|
|
8
|
+
const { stdout: email } = await $`npm config get init.author.email`;
|
|
11
9
|
|
|
12
|
-
return { name, email };
|
|
10
|
+
return { name: name.trim(), email: email.trim() };
|
|
13
11
|
}
|
package/lib/server.js
CHANGED
|
@@ -1,38 +1,44 @@
|
|
|
1
|
+
import { $, which } from 'zx';
|
|
1
2
|
import semver from 'semver';
|
|
2
|
-
import { getOutput } from './index.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
$.verbose = false;
|
|
5
|
+
|
|
6
|
+
export async function checkServerInstalled() {
|
|
7
|
+
try {
|
|
8
|
+
await which('blocklet');
|
|
9
|
+
return true;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
7
13
|
}
|
|
8
14
|
|
|
9
|
-
export function getServerVersion() {
|
|
10
|
-
const output =
|
|
15
|
+
export async function getServerVersion() {
|
|
16
|
+
const { stdout: output } = await $`blocklet --version`;
|
|
11
17
|
return output.trim();
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
export function getServerStatus() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
export async function getServerStatus() {
|
|
21
|
+
try {
|
|
22
|
+
const { stdout: output } = await $`blocklet server status`;
|
|
23
|
+
const [matchStr] = output.match(/Blocklet Server status:[\s\S]*?\n/g) || [];
|
|
24
|
+
const status = matchStr.replace(/Blocklet Server status:\s*(\S+)\s*\S*\n*[\s\S]*/gm, '$1');
|
|
25
|
+
return status.toLowerCase();
|
|
26
|
+
} catch (e) {
|
|
18
27
|
return 'stop';
|
|
19
28
|
}
|
|
20
|
-
const status = matchStr.replace(/Blocklet Server status:\s*(\S+)\s*\S*\n*[\s\S]*/gm, '$1');
|
|
21
|
-
return status.toLowerCase();
|
|
22
29
|
}
|
|
23
|
-
export function checkServerRunning() {
|
|
24
|
-
const status = getServerStatus();
|
|
30
|
+
export async function checkServerRunning() {
|
|
31
|
+
const status = await getServerStatus();
|
|
25
32
|
return status === 'running';
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
export function checkSatisfiedVersion() {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
return semver.satisfies(version, '>= 1.6.1');
|
|
35
|
+
export async function checkSatisfiedVersion() {
|
|
36
|
+
const version = await getServerVersion();
|
|
37
|
+
return semver.satisfies(version, '>= 1.7.0');
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
export function getServerDirectory() {
|
|
35
|
-
const output =
|
|
40
|
+
export async function getServerDirectory() {
|
|
41
|
+
const { stdout: output } = await $`blocklet server status`;
|
|
36
42
|
const [matchStr] = output.match(/Blocklet Server Data Directory:[\s\S]*?\n/gm) || [];
|
|
37
43
|
if (!matchStr) return null;
|
|
38
44
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-blocklet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"exports": "./index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "git@github.com:blocklet/create-blocklet.git",
|
|
@@ -13,36 +13,37 @@
|
|
|
13
13
|
"index.js",
|
|
14
14
|
"common",
|
|
15
15
|
"lib",
|
|
16
|
+
"template-api",
|
|
16
17
|
"template-dapp",
|
|
17
18
|
"template-static"
|
|
18
19
|
],
|
|
19
20
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
21
|
+
"node": ">=16.0.0"
|
|
21
22
|
},
|
|
22
23
|
"bugs": {
|
|
23
24
|
"url": "https://github.com/blocklet/create-blocklet/issues"
|
|
24
25
|
},
|
|
25
26
|
"homepage": "https://github.com/blocklet/create-blocklet/tree/main#readme",
|
|
26
27
|
"scripts": {
|
|
27
|
-
"lint": "eslint ."
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"test:ui": "vitest --ui",
|
|
31
|
+
"test:run": "vitest run"
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@arcblock/did": "^1.
|
|
31
|
-
"@ocap/mcrypto": "^1.
|
|
32
|
-
"@ocap/util": "^1.
|
|
34
|
+
"@arcblock/did": "^1.14.25",
|
|
35
|
+
"@ocap/mcrypto": "^1.14.25",
|
|
36
|
+
"@ocap/util": "^1.14.25",
|
|
37
|
+
"boxen": "^6.2.1",
|
|
33
38
|
"ejs": "^3.1.6",
|
|
34
|
-
"envfile": "^6.
|
|
35
|
-
"figlet": "^1.5.
|
|
36
|
-
"gradient-string": "^
|
|
39
|
+
"envfile": "^6.17.0",
|
|
40
|
+
"figlet": "^1.5.2",
|
|
41
|
+
"gradient-string": "^2.0.0",
|
|
37
42
|
"jdenticon": "^3.1.1",
|
|
38
|
-
"
|
|
39
|
-
"minimist": "^1.2.5",
|
|
40
|
-
"prompts": "^2.4.1",
|
|
41
|
-
"rc": "^1.2.8",
|
|
43
|
+
"prompts": "^2.4.2",
|
|
42
44
|
"semver": "^7.3.5",
|
|
43
|
-
"shelljs": "^0.8.5",
|
|
44
45
|
"terminal-link": "^3.0.0",
|
|
45
|
-
"
|
|
46
|
+
"zx": "^6.0.6"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@arcblock/eslint-config": "0.1.8",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"eslint-plugin-react": "^7.24.0",
|
|
57
58
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
58
59
|
"eslint-plugin-unicorn": "^34.0.1",
|
|
59
|
-
"prettier": "^2.3.2"
|
|
60
|
+
"prettier": "^2.3.2",
|
|
61
|
+
"vitest": "^0.7.6"
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -11,12 +11,12 @@ This blocklet is a dapp project, which means this is a full-stack application. I
|
|
|
11
11
|
- favicon.svg - favicon
|
|
12
12
|
- index.html - main html file, template for react
|
|
13
13
|
- screenshots/ - Screenshots
|
|
14
|
-
-
|
|
14
|
+
- api/ - Api side code
|
|
15
15
|
- hooks/ - blocklet lifecycle hooks
|
|
16
|
-
- libs/ -
|
|
17
|
-
- middlewares/ -
|
|
18
|
-
- routes/ -
|
|
19
|
-
- index.js -
|
|
16
|
+
- libs/ - Api side libraries
|
|
17
|
+
- middlewares/ - Api side middlewares
|
|
18
|
+
- routes/ - Api side routes
|
|
19
|
+
- index.js - Api side entry point
|
|
20
20
|
- src/ - Client side code (A standard react app structure)
|
|
21
21
|
- .env - Environment variables
|
|
22
22
|
- .env.local - Local environment variables
|
|
File without changes
|
|
File without changes
|
|
File without changes
|