create-blocklet 0.9.13 → 0.9.14
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 +17 -13
- package/lib/utils.js +4 -0
- package/package.json +1 -1
- package/templates/did-connect-dapp/package.json +1 -1
- package/templates/did-wallet-dapp/package.json +1 -1
- package/templates/react-dapp/package.json +1 -1
- package/templates/react-dapp-ts/package.json +1 -1
- 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/todo-list-example/package.json +1 -1
- package/templates/vue-dapp/package.json +1 -1
- package/templates/vue-static/package.json +1 -1
- package/templates/vue-ts-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
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { isValid, toTypeInfo, types } from '@arcblock/did';
|
|
4
4
|
import boxen from 'boxen';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
5
|
import { execSync } from 'child_process';
|
|
7
|
-
import
|
|
6
|
+
import ejs from 'ejs';
|
|
7
|
+
import * as envfile from 'envfile';
|
|
8
8
|
import ora from 'ora';
|
|
9
9
|
import prompts from 'prompts';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import { argv, cd, chalk, fs, path, YAML } from 'zx';
|
|
12
12
|
|
|
13
13
|
import { echoBrand, echoDocument } from './lib/arcblock.js';
|
|
14
|
-
import { getUser } from './lib/index.js';
|
|
15
|
-
import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getServerDirectory } from './lib/server.js';
|
|
16
14
|
import { getBlockletDidList } from './lib/did.js';
|
|
17
15
|
import { initGitRepo } from './lib/git.js';
|
|
16
|
+
import { getUser } from './lib/index.js';
|
|
17
|
+
import { checkSatisfiedVersion, checkServerInstalled, checkServerRunning, getServerDirectory } from './lib/server.js';
|
|
18
18
|
import {
|
|
19
|
+
checkLerna,
|
|
20
|
+
checkYarn,
|
|
19
21
|
copy,
|
|
20
22
|
emptyDir,
|
|
23
|
+
fuzzyQuery,
|
|
21
24
|
isEmpty,
|
|
25
|
+
isValidName,
|
|
22
26
|
isValidPackageName,
|
|
23
27
|
toValidPackageName,
|
|
24
|
-
fuzzyQuery,
|
|
25
|
-
checkLerna,
|
|
26
|
-
checkYarn,
|
|
27
28
|
} from './lib/utils.js';
|
|
28
29
|
|
|
29
30
|
const { yellow, red, green, cyan, blue, bold } = chalk;
|
|
@@ -247,18 +248,21 @@ async function init() {
|
|
|
247
248
|
|
|
248
249
|
let result = {};
|
|
249
250
|
const authorInfo = await getUser();
|
|
251
|
+
const transferName = toValidPackageName(defaultProjectName);
|
|
250
252
|
|
|
251
253
|
try {
|
|
252
254
|
result = await prompts(
|
|
253
255
|
[
|
|
254
256
|
{
|
|
255
|
-
type: targetDir && !['.', './'].includes(targetDir) ? null : 'text',
|
|
257
|
+
type: isValidName(defaultProjectName) && targetDir && !['.', './'].includes(targetDir) ? null : 'text',
|
|
256
258
|
name: 'projectName',
|
|
257
259
|
message: 'Project name:',
|
|
258
|
-
initial:
|
|
260
|
+
initial: transferName,
|
|
259
261
|
onState: (state) => {
|
|
260
|
-
projectName = state.value.trim() ||
|
|
262
|
+
projectName = state.value.trim() || transferName;
|
|
261
263
|
},
|
|
264
|
+
validate: (value) =>
|
|
265
|
+
isValidName(value) ? true : 'Please enter a valid project name, only a~z, A~Z, 0~9, - and _ are allowed.',
|
|
262
266
|
},
|
|
263
267
|
{
|
|
264
268
|
type: () => (!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm'),
|
package/lib/utils.js
CHANGED
|
@@ -11,6 +11,10 @@ export function copy(src, dest) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export function isValidName(name) {
|
|
15
|
+
return /^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/.test(name);
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export function isValidPackageName(projectName) {
|
|
15
19
|
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
|
|
16
20
|
}
|
package/package.json
CHANGED