create-blocklet 0.3.1 → 0.3.4

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 CHANGED
@@ -5,7 +5,7 @@ import boxen from 'boxen';
5
5
  import { fileURLToPath } from 'url';
6
6
  import { execSync } from 'child_process';
7
7
  import { cd, argv, fs, YAML, chalk, path } from 'zx';
8
- import { startSpinner } from 'zx/experimental';
8
+ import ora from 'ora';
9
9
  import prompts from 'prompts';
10
10
  import * as envfile from 'envfile';
11
11
 
@@ -182,12 +182,14 @@ async function init() {
182
182
  name: 'authorName',
183
183
  message: 'Author name:',
184
184
  initial: authorInfo?.name || '',
185
+ validate: (name) => (name ? true : 'Author name is required'),
185
186
  },
186
187
  {
187
188
  type: 'text',
188
189
  name: 'authorEmail',
189
190
  message: 'Author email:',
190
191
  initial: authorInfo?.email || '',
192
+ validate: (email) => (email ? true : 'Author email is required'),
191
193
  },
192
194
  ],
193
195
  {
@@ -204,7 +206,7 @@ async function init() {
204
206
  // user choice associated with prompts
205
207
  const { type, framework, overwrite, packageName, authorName, authorEmail } = result;
206
208
 
207
- const stopSpinner = startSpinner();
209
+ await echoDocument();
208
210
 
209
211
  const root = path.join(cwd, targetDir);
210
212
 
@@ -214,15 +216,18 @@ async function init() {
214
216
  fs.mkdirSync(root);
215
217
  }
216
218
 
217
- await echoDocument();
218
-
219
- console.log('Checking blocklet server runtime environment...', '\n');
219
+ const checkSpinner = ora({
220
+ text: 'Checking blocklet server runtime environment\n',
221
+ }).start();
220
222
 
221
223
  const isServerInstalled = await checkServerInstalled();
222
224
  const isSatisfiedVersion = await checkSatisfiedVersion();
223
225
  const isServerRunning = await checkServerRunning();
226
+ checkSpinner.succeed('Done');
227
+
228
+ console.log(`\nScaffolding project in ${cyan(root)}`);
224
229
 
225
- console.log(`\n\nScaffolding project in ${root}...`);
230
+ const scaffoldSpinner = ora('Creating project...').start();
226
231
 
227
232
  const templateDir = path.join(__dirname, `template-${type}/${framework}`);
228
233
  const name = packageName || targetDir;
@@ -305,9 +310,9 @@ async function init() {
305
310
  // fs.writeFileSync(path.join(root, 'logo.png'), pngIcon);
306
311
  })();
307
312
 
313
+ scaffoldSpinner.succeed('✨ Done. Now run:\n');
314
+
308
315
  const related = path.relative(cwd, root);
309
- console.log('\n\n✨ Done. Now run:\n');
310
- stopSpinner();
311
316
 
312
317
  // const pkgManager =
313
318
  // // eslint-disable-next-line no-nested-ternary
@@ -317,19 +322,20 @@ async function init() {
317
322
  // ? 'yarn'
318
323
  // : 'npm';
319
324
  try {
320
- const { yes } = await prompts(
321
- {
322
- type: 'confirm',
323
- name: 'yes',
324
- initial: 'Y',
325
- message: 'Install and start it now?',
326
- },
327
- {
328
- onCancel: () => {
329
- throw new Error(`${red('✖')} Operation cancelled`);
330
- },
331
- }
332
- );
325
+ // const { yes } = await prompts(
326
+ // {
327
+ // type: 'confirm',
328
+ // name: 'yes',
329
+ // initial: 'Y',
330
+ // message: 'Install and start it now?',
331
+ // },
332
+ // {
333
+ // onCancel: () => {
334
+ // throw new Error(`${red('✖')} Operation cancelled`);
335
+ // },
336
+ // }
337
+ // );
338
+ const yes = false;
333
339
  let hasStart = false;
334
340
 
335
341
  await initGitRepo(root);
@@ -463,9 +469,10 @@ async function init() {
463
469
  const env = envfile.parse(envContent);
464
470
  modifyFn(env);
465
471
  write('.env', envfile.stringify(env));
466
- } else {
467
- console.warn(`\n${yellow('No .env file found, please add one.')}`);
468
472
  }
473
+ // else {
474
+ // console.warn(`\n${yellow('No .env file found, please add one.')}`);
475
+ // }
469
476
  }
470
477
  }
471
478
 
package/lib/arcblock.js CHANGED
@@ -16,7 +16,7 @@ export function echoBrand({ version = '' }) {
16
16
  const indent = (symbolLen - 10) / 2;
17
17
  const msgList = [`\n${' '.repeat(indent)}Powered By`, data];
18
18
  if (version) {
19
- msgList.push(`${' '.repeat((symbolLen - 20) / 2)}Create Blocklet v0.3.0\n`);
19
+ msgList.push(`${' '.repeat((symbolLen - 20) / 2)}Create Blocklet v${version}\n`);
20
20
  }
21
21
  msg = gradient(['cyan', 'rgb(0, 111, 150)', 'rgb(0, 246,136)']).multiline(msgList.join('\n'));
22
22
  console.log(msg);
package/lib/did.js CHANGED
@@ -7,7 +7,7 @@ import { fromPublicKey } from '@arcblock/did';
7
7
  const { types } = Mcrypto;
8
8
 
9
9
  export function toBlockletDid(name) {
10
- const pk = toHex(name);
10
+ const pk = toHex(Buffer.from(typeof name === 'string' ? name.trim() : name));
11
11
  return fromPublicKey(pk, { role: types.RoleType.ROLE_ANY });
12
12
  }
13
13
 
package/lib/git.js CHANGED
@@ -19,7 +19,14 @@ export async function initGitRepo(root) {
19
19
  }
20
20
 
21
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() };
22
+ try {
23
+ const { stdout: name } = await $`git config user.name`;
24
+ const { stdout: email } = await $`git config user.email`;
25
+ return { name: name.trim(), email: email.trim() };
26
+ } catch {
27
+ return {
28
+ name: '',
29
+ email: '',
30
+ };
31
+ }
25
32
  }
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { $ } from 'zx';
2
2
  import { getAuthor } from './npm.js';
3
3
  import { getUserInfo } from './git.js';
4
+ import { getUserInfo as getServerUserInfo } from './server.js';
4
5
 
5
6
  $.verbose = false;
6
7
 
@@ -10,10 +11,9 @@ export async function getOutput(cmd) {
10
11
  }
11
12
 
12
13
  export async function getUser() {
13
- const npmAuthor = await getAuthor();
14
- const gitUser = await getUserInfo();
14
+ const [npmAuthor, gitUser, serverUser] = await Promise.all([getAuthor(), getUserInfo(), getServerUserInfo()]);
15
15
  return {
16
- name: npmAuthor.name || gitUser.name,
17
- email: npmAuthor.email || gitUser.email,
16
+ name: serverUser.name || npmAuthor.name || gitUser.name || '',
17
+ email: serverUser.email || npmAuthor.email || gitUser.email || '',
18
18
  };
19
19
  }
package/lib/npm.js CHANGED
@@ -4,8 +4,15 @@ import { $ } from 'zx';
4
4
  $.verbose = false;
5
5
 
6
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`;
7
+ try {
8
+ const { stdout: name } = await $`npm config get init.author.name`;
9
+ const { stdout: email } = await $`npm config get init.author.email`;
9
10
 
10
- return { name: name.trim(), email: email.trim() };
11
+ return { name: name.trim(), email: email.trim() };
12
+ } catch {
13
+ return {
14
+ name: '',
15
+ email: '',
16
+ };
17
+ }
11
18
  }
package/lib/server.js CHANGED
@@ -45,3 +45,19 @@ export async function getServerDirectory() {
45
45
  const directory = matchStr.replace(/Blocklet Server Data Directory:[\s]*([\S]+)\/\.abtnode\n/gm, '$1');
46
46
  return directory;
47
47
  }
48
+
49
+ export async function getUserInfo() {
50
+ try {
51
+ const { stdout: user } = await $`blocklet config get user`;
52
+ const { stdout: email } = await $`blocklet config get email`;
53
+ return {
54
+ user: user?.trim(),
55
+ email: email?.trim(),
56
+ };
57
+ } catch {
58
+ return {
59
+ user: '',
60
+ email: '',
61
+ };
62
+ }
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.3.1",
3
+ "version": "0.3.4",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -40,6 +40,7 @@
40
40
  "figlet": "^1.5.2",
41
41
  "gradient-string": "^2.0.0",
42
42
  "jdenticon": "^3.1.1",
43
+ "ora": "^6.1.0",
43
44
  "prompts": "^2.4.2",
44
45
  "semver": "^7.3.5",
45
46
  "terminal-link": "^3.0.0",
@@ -33,10 +33,9 @@ community: ''
33
33
  documentation: ''
34
34
  homepage: ''
35
35
  license: ''
36
- charging:
37
- price: 0
38
- tokens: []
39
- shares: []
36
+ payment:
37
+ price: []
38
+ share: []
40
39
  timeout:
41
40
  start: 60
42
41
  requirements:
@@ -34,10 +34,9 @@ community: ''
34
34
  documentation: ''
35
35
  homepage: ''
36
36
  license: ''
37
- charging:
38
- price: 0
39
- tokens: []
40
- shares: []
37
+ payment:
38
+ price: []
39
+ share: []
41
40
  timeout:
42
41
  start: 60
43
42
  requirements:
@@ -34,10 +34,9 @@ community: ''
34
34
  documentation: ''
35
35
  homepage: ''
36
36
  license: ''
37
- charging:
38
- price: 0
39
- tokens: []
40
- shares: []
37
+ payment:
38
+ price: []
39
+ share: []
41
40
  timeout:
42
41
  start: 60
43
42
  requirements:
@@ -34,10 +34,9 @@ community: ''
34
34
  documentation: ''
35
35
  homepage: ''
36
36
  license: ''
37
- charging:
38
- price: 0
39
- tokens: []
40
- shares: []
37
+ payment:
38
+ price: []
39
+ share: []
41
40
  timeout:
42
41
  start: 60
43
42
  requirements:
@@ -33,10 +33,9 @@ community: ''
33
33
  documentation: ''
34
34
  homepage: ''
35
35
  license: ''
36
- charging:
37
- price: 0
38
- tokens: []
39
- shares: []
36
+ payment:
37
+ price: []
38
+ share: []
40
39
  timeout:
41
40
  start: 60
42
41
  requirements:
@@ -32,10 +32,9 @@ community: ''
32
32
  documentation: ''
33
33
  homepage: ''
34
34
  license: ''
35
- charging:
36
- price: 0
37
- tokens: []
38
- shares: []
35
+ payment:
36
+ price: []
37
+ share: []
39
38
  timeout:
40
39
  start: 60
41
40
  requirements:
@@ -32,10 +32,9 @@ community: ''
32
32
  documentation: ''
33
33
  homepage: ''
34
34
  license: ''
35
- charging:
36
- price: 0
37
- tokens: []
38
- shares: []
35
+ payment:
36
+ price: []
37
+ share: []
39
38
  timeout:
40
39
  start: 60
41
40
  requirements:
@@ -32,10 +32,9 @@ community: ''
32
32
  documentation: ''
33
33
  homepage: ''
34
34
  license: ''
35
- charging:
36
- price: 0
37
- tokens: []
38
- shares: []
35
+ payment:
36
+ price: []
37
+ share: []
39
38
  timeout:
40
39
  start: 60
41
40
  requirements: