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

test serve

parent 6c519bb2
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
"lint:style": "stylelint --fix 'src/**/*.less' --syntax less", "lint:style": "stylelint --fix 'src/**/*.less' --syntax less",
"lint:ts": "tslint -p . -c tslint.yml", "lint:ts": "tslint -p . -c tslint.yml",
"prettier": " check-prettier write", "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": "umi dev",
"start:no-mock": "cross-env MOCK=none umi dev", "start:no-mock": "cross-env MOCK=none umi dev",
"test": "umi test", "test": "umi test",
...@@ -61,11 +61,13 @@ ...@@ -61,11 +61,13 @@
"bizcharts-plugin-slider": "^2.1.1-beta.1", "bizcharts-plugin-slider": "^2.1.1-beta.1",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"dva": "^2.4.0", "dva": "^2.4.0",
"gg-editor": "^2.0.4",
"hash.js": "^1.1.7", "hash.js": "^1.1.7",
"lodash": "^4.17.10", "lodash": "^4.17.10",
"lodash-decorators": "^6.0.0", "lodash-decorators": "^6.0.0",
"memoize-one": "^5.0.0", "memoize-one": "^5.0.0",
"moment": "^2.22.2", "moment": "^2.22.2",
"node-fetch": "^2.6.0",
"numeral": "^2.0.6", "numeral": "^2.0.6",
"nzh": "^1.0.4", "nzh": "^1.0.4",
"omit.js": "^1.0.0", "omit.js": "^1.0.0",
...@@ -151,4 +153,4 @@ ...@@ -151,4 +153,4 @@
"config/**/*.js*", "config/**/*.js*",
"scripts/**/*.js" "scripts/**/*.js"
] ]
} }
\ No newline at end of file
...@@ -4,25 +4,35 @@ const fetch = require('node-fetch'); ...@@ -4,25 +4,35 @@ const fetch = require('node-fetch');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const getNewRouteCode = require('./repalceRouter'); const getNewRouteCode = require('./repalceRouter');
const router = require('./router.config'); 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 relativePath = path.join(__dirname, '../config/config.ts');
const findAllInstallRouter = router => { const findAllInstallRouter = router => {
let routers = []; let routers = [];
router.forEach(item => { router.forEach(item => {
if (item.routes) {
routers = routers.concat(findAllInstallRouter(item.routes));
}
if (item.component && item.path) { if (item.component && item.path) {
if (item.path === '/user' || item.path === '/') { if (item.path !== '/user' || item.path !== '/') {
return; routers.push({
...item,
routes: '',
});
} }
routers.push({
...item,
routes: '',
});
} }
return null; if (item.routes) {
routers = routers.concat(findAllInstallRouter(item.routes));
}
}); });
return routers; return routers;
}; };
...@@ -65,24 +75,47 @@ const { routesPath, code } = getNewRouteCode(relativePath, parentRouter); ...@@ -65,24 +75,47 @@ const { routesPath, code } = getNewRouteCode(relativePath, parentRouter);
// write ParentRouter // write ParentRouter
fs.writeFileSync(routesPath, code); fs.writeFileSync(routesPath, code);
const installBlock = () => { const installBlock = async () => {
let gitFiles = await fetchGithubFiles();
const installRouters = findAllInstallRouter(router); const installRouters = findAllInstallRouter(router);
const installBlockIteration = async i => { const installBlockIteration = async i => {
const item = installRouters[i]; const item = installRouters[i];
if (!item || !item.path) { if (!item || !item.path) {
return; return Promise.resolve();
} }
console.log('install ' + item.name + ' to: ' + item.component); const gitPath = firstUpperCase(item.path);
const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${firstUpperCase( // 如果这个区块在 git 上存在
item.path, if (gitFiles.find(file => file.path === gitPath)) {
)} --npm-client=cnpm --path=${item.path}`; console.log('install ' + chalk.green(item.name) + ' to: ' + chalk.yellow(item.path));
const data = await fetch( gitFiles = gitFiles.filter(file => file.path !== gitPath);
` https://github.com/ant-design/pro-blocks/tree/master/${firstUpperCase(item.path)}`, const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${
); item.path
}`;
try {
await execCmd(cmd);
console.log(`install ${chalk.hex('#1890ff')(item.name)} success`);
} catch (error) {
console.error(error);
}
}
return installBlockIteration(i + 1);
};
// 安装路由中设置的区块
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); await execCmd(cmd);
installBlockIteration(i + 1); return installBlockIteration(1);
}; };
installBlockIteration(0);
// 安装 router 中没有的剩余区块.
installGitFile(0);
}; };
installBlock(); 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