Skip to content

Commit

Permalink
Merge pull request #373 from blocklet/fix/name-validate
Browse files Browse the repository at this point in the history
fix(create-blocklet): validate project name compliance before creation
  • Loading branch information
zhuzhuyule authored Dec 2, 2024
2 parents 8c3483a + 38e87f3 commit bc58969
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.14 (2024-12-2)

- fix(create-blocklet): validate project name compliance before creation(#372)

## 0.9.13 (2024-11-13)

- chore(deps): update deps
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ TBD
pnpm install

```

## Run the command

```bash
node packages/create-app/index.js test-demo
```

## Change Blocklet Server Command

Change the file `packages/create-app/lib/constant.js`

```
// your command alias
export const BLOCKLET_COMMAND = 'bn';
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-blocklet",
"private": true,
"version": "0.9.13",
"version": "0.9.14",
"description": "",
"keywords": [],
"author": "",
Expand Down
30 changes: 17 additions & 13 deletions packages/create-app/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#!/usr/bin/env node

import ejs from 'ejs';
import { isValid, toTypeInfo, types } from '@arcblock/did';
import boxen from 'boxen';
import { fileURLToPath } from 'url';
import { execSync } from 'child_process';
import { cd, argv, fs, YAML, chalk, path } from 'zx';
import ejs from 'ejs';
import * as envfile from 'envfile';
import ora from 'ora';
import prompts from 'prompts';
import { isValid, toTypeInfo, types } from '@arcblock/did';
import * as envfile from 'envfile';
import { fileURLToPath } from 'url';
import { argv, cd, chalk, fs, path, YAML } from 'zx';

import { echoBrand, echoDocument } from './lib/arcblock.js';
import { getUser } from './lib/index.js';
import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getServerDirectory } from './lib/server.js';
import { getBlockletDidList } from './lib/did.js';
import { initGitRepo } from './lib/git.js';
import { getUser } from './lib/index.js';
import { checkSatisfiedVersion, checkServerInstalled, checkServerRunning, getServerDirectory } from './lib/server.js';
import {
checkLerna,
checkYarn,
copy,
emptyDir,
fuzzyQuery,
isEmpty,
isValidName,
isValidPackageName,
toValidPackageName,
fuzzyQuery,
checkLerna,
checkYarn,
} from './lib/utils.js';

const { yellow, red, green, cyan, blue, bold } = chalk;
Expand Down Expand Up @@ -247,18 +248,21 @@ async function init() {

let result = {};
const authorInfo = await getUser();
const transferName = toValidPackageName(defaultProjectName);

try {
result = await prompts(
[
{
type: targetDir && !['.', './'].includes(targetDir) ? null : 'text',
type: isValidName(defaultProjectName) && targetDir && !['.', './'].includes(targetDir) ? null : 'text',
name: 'projectName',
message: 'Project name:',
initial: defaultProjectName,
initial: transferName,
onState: (state) => {
projectName = state.value.trim() || defaultProjectName;
projectName = state.value.trim() || transferName;
},
validate: (value) =>
isValidName(value) ? true : 'Please enter a valid project name, only a~z, A~Z, 0~9, - and _ are allowed.',
},
{
type: () => (!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm'),
Expand Down
4 changes: 4 additions & 0 deletions packages/create-app/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function copy(src, dest) {
}
}

export function isValidName(name) {
return /^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/.test(name);
}

export function isValidPackageName(projectName) {
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-blocklet",
"version": "0.9.13",
"version": "0.9.14",
"exports": "./index.js",
"type": "module",
"repository": "[email protected]:blocklet/create-blocklet.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/did-wallet-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-node": "^2.1.1",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-require": "^1.2.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-dapp-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-gun-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/solidjs-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-solid": "^2.10.2",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/solidjs-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"simple-git-hooks": "^2.11.1",
"solid-js": "^1.9.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-solid": "^2.10.2",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/svelte-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.19",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"zx": "^8.1.8"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/svelte-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.19",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"zx": "^8.1.8"
},
"lint-staged": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vue": "^3.5.10",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vue": "^3.5.10",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-ts-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"taze": "^0.16.9",
"typescript": "^5.6.2",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vue-tsc": "^2.1.6",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue2-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vue": "^2.7.16",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue2-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^5.4.8",
"vite-plugin-blocklet": "^0.9.13",
"vite-plugin-blocklet": "^0.9.14",
"vue": "^2.7.16",
"zx": "^8.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/vite-plugin-blocklet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-blocklet",
"type": "module",
"version": "0.9.13",
"version": "0.9.14",
"description": "",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion plugins/vite-plugin-wss-hmr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-wss-hmr",
"type": "module",
"version": "0.9.13",
"version": "0.9.14",
"description": "",
"main": "index.js",
"exports": {
Expand Down
20 changes: 17 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.13
0.9.14
2 changes: 1 addition & 1 deletion website/docs/blocklet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository:
type: git
url: git+https://github.com/blocklet/create-blocklet.git
specVersion: 1.2.8
version: 0.9.13
version: 0.9.14
logo: logo.png
files:
- logo.png
Expand Down
2 changes: 1 addition & 1 deletion website/pages/blocklet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository:
type: git
url: git+https://github.com/blocklet/create-blocklet.git
specVersion: 1.2.8
version: 0.9.13
version: 0.9.14
logo: logo.png
files:
- logo.png
Expand Down

0 comments on commit bc58969

Please sign in to comment.