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 +30 -23
- package/lib/arcblock.js +1 -1
- package/lib/did.js +1 -1
- package/lib/git.js +10 -3
- package/lib/index.js +4 -4
- package/lib/npm.js +10 -3
- package/lib/server.js +16 -0
- package/package.json +2 -1
- package/template-api/express/blocklet.yml +3 -4
- package/template-dapp/nextjs/blocklet.yml +3 -4
- package/template-dapp/react/blocklet.yml +3 -4
- package/template-dapp/vue/blocklet.yml +3 -4
- package/template-dapp/vue2/blocklet.yml +3 -4
- package/template-static/react/blocklet.yml +3 -4
- package/template-static/vue/blocklet.yml +3 -4
- package/template-static/vue2/blocklet.yml +3 -4
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
|
|
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
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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.
|
|
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",
|