Commit 3138d8d2 authored by 陈帅's avatar 陈帅

test serve

parent 6c519bb2
......@@ -26,7 +26,7 @@
"lint:style": "stylelint --fix 'src/**/*.less' --syntax less",
"lint:ts": "tslint -p . -c tslint.yml",
"prettier": " check-prettier write",
"site": "umi build && npm run functions:build",
"site": "node ./script/fetch-block.js && umi build && npm run functions:build",
"start": "umi dev",
"start:no-mock": "cross-env MOCK=none umi dev",
"test": "umi test",
......@@ -61,11 +61,13 @@
"bizcharts-plugin-slider": "^2.1.1-beta.1",
"classnames": "^2.2.6",
"dva": "^2.4.0",
"gg-editor": "^2.0.4",
"hash.js": "^1.1.7",
"lodash": "^4.17.10",
"lodash-decorators": "^6.0.0",
"memoize-one": "^5.0.0",
"moment": "^2.22.2",
"node-fetch": "^2.6.0",
"numeral": "^2.0.6",
"nzh": "^1.0.4",
"omit.js": "^1.0.0",
......
......@@ -4,25 +4,35 @@ const fetch = require('node-fetch');
const exec = require('child_process').exec;
const getNewRouteCode = require('./repalceRouter');
const router = require('./router.config');
const chalk = require('chalk');
const fetchGithubFiles = async () => {
const ignoreFile = ['_scripts'];
const data = await fetch(`https://api.github.com/repos/ant-design/pro-blocks/git/trees/master`);
if (data.status !== 200) {
return;
}
const { tree } = await data.json();
const files = tree.filter(file => file.type === 'tree' && !ignoreFile.includes(file.path));
return Promise.resolve(files);
};
const relativePath = path.join(__dirname, '../config/config.ts');
const findAllInstallRouter = router => {
let routers = [];
router.forEach(item => {
if (item.routes) {
routers = routers.concat(findAllInstallRouter(item.routes));
}
if (item.component && item.path) {
if (item.path === '/user' || item.path === '/') {
return;
}
if (item.path !== '/user' || item.path !== '/') {
routers.push({
...item,
routes: '',
});
}
return null;
}
if (item.routes) {
routers = routers.concat(findAllInstallRouter(item.routes));
}
});
return routers;
};
......@@ -65,24 +75,47 @@ const { routesPath, code } = getNewRouteCode(relativePath, parentRouter);
// write ParentRouter
fs.writeFileSync(routesPath, code);
const installBlock = () => {
const installBlock = async () => {
let gitFiles = await fetchGithubFiles();
const installRouters = findAllInstallRouter(router);
const installBlockIteration = async i => {
const item = installRouters[i];
if (!item || !item.path) {
return;
return Promise.resolve();
}
console.log('install ' + item.name + ' to: ' + item.component);
const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${firstUpperCase(
item.path,
)} --npm-client=cnpm --path=${item.path}`;
const data = await fetch(
` https://github.com/ant-design/pro-blocks/tree/master/${firstUpperCase(item.path)}`,
);
const gitPath = firstUpperCase(item.path);
// 如果这个区块在 git 上存在
if (gitFiles.find(file => file.path === gitPath)) {
console.log('install ' + chalk.green(item.name) + ' to: ' + chalk.yellow(item.path));
gitFiles = gitFiles.filter(file => file.path !== gitPath);
const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${
item.path
}`;
try {
await execCmd(cmd);
installBlockIteration(i + 1);
console.log(`install ${chalk.hex('#1890ff')(item.name)} success`);
} catch (error) {
console.error(error);
}
}
return installBlockIteration(i + 1);
};
installBlockIteration(0);
// 安装路由中设置的区块
await installBlockIteration(0);
const installGitFile = async i => {
const item = gitFiles[i];
if (!item || !item.path) {
return Promise.resolve();
}
console.log('install ' + chalk.green(item.path));
const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${item.path}`;
await execCmd(cmd);
return installBlockIteration(1);
};
// 安装 router 中没有的剩余区块.
installGitFile(0);
};
installBlock();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment