Skip to content

Commit 3f28c0b

Browse files
committed
optimize structor
1 parent 6574dd7 commit 3f28c0b

File tree

4 files changed

+55
-57
lines changed

4 files changed

+55
-57
lines changed

generate.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,7 @@
1-
const fs = require('fs');
21
const args = require('yargs').argv;
2+
const { copyComponents } = require('./scripts/copyComponents');
33

44
// get project name via args.env
55
const project = args.env || 'milvus';
66

7-
// copy milvus header and footer to components
8-
// new folder path is src/component/commonComponents
97
copyComponents(project);
10-
11-
// copy common component
12-
function copyComponents(project) {
13-
const [baseSrcDir, baseTarDir] = [
14-
'./src/commonComponents',
15-
'./src/components/commonComponents',
16-
];
17-
const copyFile = (sourcePath, targetPath) => {
18-
const isDir = fs.statSync(sourcePath).isDirectory();
19-
20-
if (isDir) {
21-
const paths = fs
22-
.readdirSync(sourcePath)
23-
.map(path => ({
24-
srcPath: `${sourcePath}/${path}`,
25-
tarPath: `${targetPath}/${path}`,
26-
}))
27-
.filter(v => !v.srcPath.includes('.DS_Store'));
28-
29-
fs.mkdirSync(targetPath);
30-
paths.forEach(({ srcPath, tarPath }) => {
31-
copyFile(srcPath, tarPath);
32-
});
33-
} else {
34-
const file = fs.readFileSync(sourcePath);
35-
fs.writeFileSync(targetPath, file);
36-
}
37-
};
38-
39-
const paths = fs
40-
.readdirSync(`${baseSrcDir}/${project}`)
41-
.map(path => ({
42-
srcPath: `${baseSrcDir}/${project}/${path}`,
43-
tarPath: `${baseTarDir}/${path}`,
44-
}))
45-
.filter(v => !v.srcPath.includes('.DS_Store'));
46-
47-
const isExist = fs.existsSync(baseTarDir);
48-
if (!isExist) {
49-
fs.mkdirSync(baseTarDir);
50-
} else {
51-
fs.rmSync(baseTarDir, {
52-
recursive: true,
53-
force: true,
54-
});
55-
fs.mkdirSync(baseTarDir);
56-
}
57-
paths.forEach(({ srcPath, tarPath }) => {
58-
copyFile(srcPath, tarPath);
59-
});
60-
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev-milvus": "node generate.js --env milvus && next dev",
77
"dev-tohi": "node generate.js --env towhee && next dev",
8-
"build": "next build && next export",
8+
"build": "node generate.js --env milvus && next build && next export",
99
"start": "next start",
1010
"lint": "next lint"
1111
},

scripts/copyComponents.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const fs = require('fs');
2+
3+
// copy common component
4+
exports.copyComponents = project => {
5+
const [baseSrcDir, baseTarDir] = [
6+
'./src/commonComponents',
7+
'./src/components/commonComponents',
8+
];
9+
const copyFile = (sourcePath, targetPath) => {
10+
const isDir = fs.statSync(sourcePath).isDirectory();
11+
12+
if (isDir) {
13+
const paths = fs
14+
.readdirSync(sourcePath)
15+
.map(path => ({
16+
srcPath: `${sourcePath}/${path}`,
17+
tarPath: `${targetPath}/${path}`,
18+
}))
19+
.filter(v => !v.srcPath.includes('.DS_Store'));
20+
21+
fs.mkdirSync(targetPath);
22+
paths.forEach(({ srcPath, tarPath }) => {
23+
copyFile(srcPath, tarPath);
24+
});
25+
} else {
26+
const file = fs.readFileSync(sourcePath);
27+
fs.writeFileSync(targetPath, file);
28+
}
29+
};
30+
31+
const paths = fs
32+
.readdirSync(`${baseSrcDir}/${project}`)
33+
.map(path => ({
34+
srcPath: `${baseSrcDir}/${project}/${path}`,
35+
tarPath: `${baseTarDir}/${path}`,
36+
}))
37+
.filter(v => !v.srcPath.includes('.DS_Store'));
38+
39+
const isExist = fs.existsSync(baseTarDir);
40+
if (!isExist) {
41+
fs.mkdirSync(baseTarDir);
42+
} else {
43+
fs.rmSync(baseTarDir, {
44+
recursive: true,
45+
force: true,
46+
});
47+
fs.mkdirSync(baseTarDir);
48+
}
49+
paths.forEach(({ srcPath, tarPath }) => {
50+
copyFile(srcPath, tarPath);
51+
});
52+
};

src/pages/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import TutorialCard from '../components/card';
99
import classes from '../../styles/home.module.less';
1010
import ToolBar from '../components/toolBar';
1111
import { useRouter } from 'next/router';
12-
import axiosInstance from '../http/axios';
1312
import { getCodelabsJson } from '../utils/common';
1413

1514
export default function HomePage({ data = [] }) {
@@ -77,7 +76,7 @@ export default function HomePage({ data = [] }) {
7776
case 'duration':
7877
return tempData.sort((x, y) => x.duration - y.duration);
7978
}
80-
}, [sortWay, pathname, keyWord, categoryVal]);
79+
}, [data, sortWay, pathname, keyWord, categoryVal]);
8180

8281
return (
8382
<Layout>

0 commit comments

Comments
 (0)