Skip to content

Commit

Permalink
Merge pull request #122 from AElfProject/feature/drawer
Browse files Browse the repository at this point in the history
feat: add image-check
  • Loading branch information
aelf-lxy authored Jun 26, 2024
2 parents d3a8a59 + 6f3f167 commit bb8be29
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 793 deletions.
2 changes: 1 addition & 1 deletion .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default defineConfig({
name: 'Aelf Design',
logo: 'https://ipfs.io/ipfs/QmWtjvb47DU1EQ4MpridFY1ow4214aAWCkhGu3ZF4xvRSY/',
socialLinks: {
github: 'https://github.com/AElf-devops/aelf-design',
github: 'https://github.com/AElfProject/aelf-design',
},
},
favicons: ['https://ipfs.io/ipfs/QmWtjvb47DU1EQ4MpridFY1ow4214aAWCkhGu3ZF4xvRSY/'],
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,9 @@ css`

1. ### According to the component design draft, identify the differences with the antd component

![img](https://hoopox.feishu.cn/space/api/box/stream/download/asynccode/?code=OWY0Yjc4MGRlMjY5ZWIzOTFmMWFlMWVlNjE2NmUyNGFfcTM4dWUyTkhLYTBQVG1pSjhjWkVhVzNhaGIxazJoRFpfVG9rZW46Q0x6S2JwTlZRb2pDdVV4TU5mWGNVd2ZEbllnXzE3MTc3MzA0OTE6MTcxNzczNDA5MV9WNA)
2. ### List the new features based on the antd component

1. 5 size types need to be provided, antd has 3
2. Different sizes of height, padding, rounded corners, font size, and minimum width are different

3. ### List the new features based on the antd component

4. Provide optional throttle click function

5. ### Configure token
3. ### Configure token

Component tokens required to configure this component, global tokens (pay attention to whether it will affect other components), and custom tokens.

Expand Down
2 changes: 1 addition & 1 deletion docs/home/components/Banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Banner: React.FC = () => {
{intl.formatMessage({ id: 'app.docs.site.index.banner.button-text' })}
</Link> */}
<Link to={`/components/address`}>开始</Link>
<a href="https://github.com/AElf-devops/aelf-design" target="_blank" rel="noreferrer">
<a href="https://github.com/AElfProject/aelf-design" target="_blank" rel="noreferrer">
GitHub
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/icon.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ group:

## How to use

使用图标组件,你需要安装 [@aelf-design/icons](https://github.com/AElf-devops/aelf-design/tree/main/packages/icons) 图标组件包:
使用图标组件,你需要安装 [@aelf-design/icons](https://github.com/AElfProject/aelf-design/tree/main/packages/icons) 图标组件包:

<InstallDependencies npm='npm install @aelf-design/icons --save' yarn='yarn add @aelf-design/icons' pnpm='pnpm install @aelf-design/icons --save'></InstallDependencies>

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"packages/*"
],
"type": "module",
"packageManager": "[email protected]",
"files": [],
"scripts": {
"start": "./scripts/generate-icon-config.js && dumi dev",
Expand Down Expand Up @@ -107,5 +106,5 @@
"engines": {
"node": ">=18"
},
"repository": "https://github.com/AElf-devops/aelf-design"
"repository": "https://github.com/AElfProject/aelf-design"
}
8 changes: 4 additions & 4 deletions packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
],
"homepage": "https://aelf-design.vercel.app/components/address",
"bugs": {
"url": "https://github.com/AElf-devops/aelf-design/issues"
"url": "https://github.com/AElfProject/aelf-design/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/AElf-devops/aelf-design/tree/main/packages/component"
"url": "https://github.com/AElfProject/aelf-design/tree/main/packages/component"
},
"scripts": {
"dev": "father dev",
Expand Down Expand Up @@ -68,8 +68,8 @@
},
"peerDependencies": {
"antd": ">=5.0.0",
"react": ">=17.0.0",
"react-dom": ">=17.0.0"
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
],
"homepage": "https://aelf-design.vercel.app/icon",
"bugs": {
"url": "https://github.com/AElf-devops/aelf-design/issues"
"url": "https://github.com/AElfProject/aelf-design/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/AElf-devops/aelf-design/tree/main/packages/icons"
"url": "https://github.com/AElfProject/aelf-design/tree/main/packages/icons"
},
"scripts": {
"dev": "father dev",
Expand Down
5 changes: 5 additions & 0 deletions packages/image-check/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'father';

export default defineConfig({
extends: '../../.fatherrc.base.ts',
});
25 changes: 25 additions & 0 deletions packages/image-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Install

```bash
yarn add @aelf-design/image-check
```

# Usage

1. add `image-check` command to your `scripts` in `package.json`

```js
...
"scripts": {
"check": "image-check"
}
...
```

2. run `yarn run check`

```bash
yarn run check
```

3. in the terminal you will see the results ![alt text](https://silver-abstract-unicorn-590.mypinata.cloud/ipfs/QmfAeQpAw88chrHbwH2YzD7g9EA9wvesrMKVH7aVoHcCFV?pinataGatewayToken=J-4VqFJOcNwmARnesBKmHYTpzCmzYA9o5Zx2On1Tp2VOC6W1DYjx45AygAaXHfpV)
42 changes: 42 additions & 0 deletions packages/image-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@aelf-design/image-check",
"version": "1.1.4",
"type": "module",
"main": "src/imageCheck.js",
"bin": {
"image-check": "./src/imageCheck.js"
},
"files": [
"CHANGELOG.md",
"README.md"
],
"keywords": [
"aelf",
"frontend",
"web3"
],
"bugs": {
"url": "https://github.com/AElfProject/aelf-design/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/AElfProject/aelf-design/tree/main/packages/image-check"
},
"scripts": {
"start": "node src/imageCheck.js"
},
"devDependencies": {
"father": "^4.3.8",
"glob": "^10.3.10"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
},
"browserslist": [
"last 2 versions",
"Firefox ESR",
"> 1%",
"ie >= 11"
]
}
103 changes: 103 additions & 0 deletions packages/image-check/src/imageCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';

const IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff'];
const IGNORED_FOLDERS = ['node_modules', '.next'];

function getFileSizeInBytes(filePath) {
const stats = fs.statSync(filePath);
return stats.size;
}

function isCamelCase(fileName) {
return /[a-z][A-Z]/.test(fileName);
}

function findImages(dir, fileList = [], dirSet = new Set()) {
const files = fs.readdirSync(dir);

files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory() && IGNORED_FOLDERS.includes(file)) {
return;
}

if (stat.isDirectory()) {
findImages(filePath, fileList, dirSet);
} else if (IMAGE_EXTENSIONS.includes(path.extname(file).toLowerCase())) {
fileList.push(filePath);
dirSet.add(path.dirname(filePath));
}
});

return { fileList, dirSet };
}

function inspectImages(dir, limitSize) {
const { fileList: images, dirSet: directories } = findImages(dir);
const largeImages = [];
const camelCaseImages = [];

images.forEach((imagePath) => {
const size = getFileSizeInBytes(imagePath);
const imageSizeInKb = size / 1024;
const imageName = path.basename(imagePath);

if (size > limitSize * 1024) {
largeImages.push({
name: imageName,
size: `${imageSizeInKb.toFixed(2)} KB`,
path: imagePath,
});
}

if (isCamelCase(imageName)) {
camelCaseImages.push({
name: imageName,
size: `${imageSizeInKb.toFixed(2)} KB`,
path: imagePath,
});
}
});

if (largeImages.length === 0) {
console.log(`\n${chalk.bold.green('Image size check passed')}`);
} else {
console.log(`\n${chalk.bold.red(`Images larger than ${limitSize}KB:`)}`);
largeImages.forEach((image) =>
console.log(`Name: ${image.name}, Size: ${chalk.red(image.size)}, Path: ${image.path}`),
);
}

if (camelCaseImages.length === 0) {
console.log(`\n${chalk.bold.green('Image naming compliance check passed')}`);
} else {
console.log(`\n${chalk.bold.red('Images with camelCase names:')}`);
// camelCaseImages.forEach((image) => console.log(image));
camelCaseImages.forEach((image) =>
console.log(`Name: ${chalk.red(image.name)}, Size: ${image.size}, Path: ${image.path}`),
);
}

console.log(`\n${chalk.bold.cyan('Directories containing images:')}`);
directories.forEach((directory) => console.log(directory));

if (directories.size > 1) {
console.log(
`\n${chalk.bold.red(
`There are multiple directories (${directories.size}) containing images.`,
)}`,
);
} else {
console.log(`\n${chalk.bold.green('Image storage directory check passed')}`);
}
}

const targetDir = process.argv[2] || '.';
const targetLimitSize = process.argv[3] || 100;

inspectImages(targetDir, targetLimitSize);
3 changes: 3 additions & 0 deletions packages/image-check/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}
4 changes: 2 additions & 2 deletions packages/nextjs-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"web3"
],
"bugs": {
"url": "https://github.com/AElf-devops/aelf-design/issues"
"url": "https://github.com/AElfProject/aelf-design/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/AElf-devops/aelf-design/tree/main/packages/nextjs-registry"
"url": "https://github.com/AElfProject/aelf-design/tree/main/packages/nextjs-registry"
},
"scripts": {
"dev": "father dev",
Expand Down
Loading

0 comments on commit bb8be29

Please sign in to comment.