UNPKG

1.07 kBJavaScriptView Raw
1const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
2const path = require('path');
3const fs = require('fs');
4
5// todo: 抽取公共tools
6const appDirectory = fs.realpathSync(process.cwd());
7const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
8
9const checkPagesRequired = (allPagesName) => {
10 let page = '';
11 for (let i = 0, len = allPagesName.length; i < len; i++) {
12 page = allPagesName[i];
13 if (!checkRequiredFiles([
14 resolveApp(`public/${page}.html`),
15 resolveApp(`src/pages/${page}/index.js`)
16 ])
17 ) {
18 return false
19 }
20 }
21 return true
22};
23
24/**
25 * get port from `package.json` proxy
26 * @param proxy
27 */
28const getLocalMockPort = (proxy) => {
29
30 const ip = require('ip').address().replace(/\./g, '\\.');
31
32 const proxyMatch = new RegExp(`https*://(localhost|127\\.0\\.0\\.1|${ip}):(\\d+)`).exec(proxy);
33
34 return proxyMatch ? proxyMatch[2] : ''
35
36};
37
38module.exports = {
39 checkPagesRequired,
40 resolveApp,
41 getLocalMockPort
42};
\No newline at end of file