Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | 2x 2x 2x 2x 2x 2x 1x 1x 1x 3x 2x 2x 1x 4x 4x 9x 9x 21x 6x 3x 27x 27x 1x 1x 2x 2x 2x 6x 6x 6x 6x 4x 2x 2x 8x 4x 2x 2x 2x 2x 1x 1x 2x 2x 2x | const fs = require('fs'); const path = require('path'); const http = require('http'); const got = require('got'); const packageConfig = require('../package.json'); const semver = require('semver'); /** * * @param jsonArray * @returns {Array} */ function jsonArrayUnique(jsonArray) { const n = {}, r = []; for (let i = 0; i < jsonArray.length; i++) { if (!n[jsonArray[i].path]) { n[jsonArray[i].path] = true; r.push(jsonArray[i]); } } return r; } /** * * @param errorInfo */ function errorHandler(errorInfo) { console.log(errorInfo); process.exit(); } /** * 判断是否为整数 * @param x * @returns {boolean} */ function isInt(x) { const y = parseInt(x, 10); return !isNaN(y) && x == y && x.toString() === y.toString(); } /** * * @param arr * @param search * @returns {boolean} */ function isInArray(arr, search) { Eif (typeof arr === 'object' && typeof arr.length === 'number') { for (let i = 0; i < arr.length; i++) { if (arr[i] === search) { return true; } } } return false; } /** * * @param path * @returns {string} */ function normalizePath(path) { Eif (typeof path === 'string') { return path.replace(/[\\|\\\\|//|////]/gi, '/'); } return path; } /** * 获取本地调试下的静态资源前缀 * @returns {RegExp} */ function getRegexpStaticFilesPrefix() { global.localStaticResourcesPrefix.lastIndex = 0; return global.localStaticResourcesPrefix; } /** * * @param dir * @param extension * @returns {*} */ function getAllFilesByDir(dir, extension) { let list = []; const fileList = fs.readdirSync(dir); for (let i = fileList.length - 1; i >= 0; i--) { const filePath = path.join(dir, fileList[i]); const stat = fs.statSync(filePath); Iif (stat.isDirectory()) { list = list.concat(getAllFilesByDir(filePath, extension)); } else { if (isInArray(extension, path.extname(filePath))) { list.push(normalizePath(filePath)); } } } return list; } /** * * @param dir */ function mkdirRecursive(dir) { if (fs.existsSync(dir)) { return; } if (!fs.existsSync(path.dirname(dir))) { mkdirRecursive(path.dirname(dir)); } fs.mkdirSync(dir); } /** * * @param argv * @param search * @returns {boolean} */ function hasArgument(argv, search) { let ret = false; for (let i = 0; i < argv.length; i++) { if (argv[i] === search) { ret = true; break; } } return ret; } /** * 启动WebSocket服务, 用于监听文件修改信号 */ function startWebSocketServer() { const app = http.createServer(); const io = require('socket.io')(app, { cors: { origin: '*', methods: ['GET', 'POST'], allowedHeaders: [] } }); app.listen(global.livereloadPort); io.on('connection', function (socket) { global.socket = socket; }); console.log('WebSocketServer running... port: ' + global.livereloadPort); } /** * 获取script标签正则 * @returns {RegExp} */ function getRegexpScriptElements() { return /<script([\s\S\w\W]*?)>{1}?[\s\S\w\W]*?(<\/script>){1}?/gi; } /** * 获取script标签src属性匹配正则 * @returns {RegExp} */ function getRegexpScriptElementSrcAttrValue() { return /<script[\s\S\w\W]+?src="([\s\S\w\W]+?)"[\s\S\w\W]*?>[\s\S\w\W]*?<\/script>/gi; } /** * 获取link标签正则 * @returns {RegExp} */ function getRegexpCSSLinkElements() { return /<link((?![>])[\s\S\w\W])+?rel="stylesheet"((?![>])[\s\S\w\W])*?>{1}?/gi; } /** * 获取link标签的href匹配正则 * @returns {RegExp} */ function getRegexpCSSHrefValue() { return /<link([\s\S\w\W]+?)href="(.+?)"([\s\S\w\W]*?)>{1}?/gi; } /** * 获取img标签正则 * @returns {RegExp} */ function getRegexpImgElements() { return /<img[\S\s\W\w]+?src="(.+?)"[\S\s\W\w]+?/gi; } /** * 获取内联style属性里的backgroundImage匹配正则 * @returns {RegExp} */ function getRegexpBackgroundImage() { return /:[\s]?url\(['|"]??(\$!?(\{)?.+?\(\)(})?[\w\W]+?)['|"]??\)/gi; } /** * 生成唯一值 */ function uniqueVal() { return `webpackJsonp${Date.now()}${Math.random()}`.replace('.', ''); } async function verifyVersion() { const check1 = nodeVersionCheck(); const check2 = await wenkeDevVersionCheck(); return check1 && check2; } //检测本地版本与最新版本是否一致 async function wenkeDevVersionCheck() { let latestVersion; try { const jsonRes = await got('https://registry.npmjs.org/wenke-dev', { timeout: { request: 10000 } }).json(); latestVersion = jsonRes['dist-tags'].latest; } catch { console.log( "latest version of 'https://registry.npmjs.org/wenke-dev' fetch failed, please check your network or try again" ); return false; } const localVersion = packageConfig.version; if (semver.lt(localVersion, latestVersion)) { console.log(` ************************************************************** * * * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. * * | ______ | * * | .-" "-. | * * | / \\ | * * | _ | | _ | * * | ( \\ |, .-. .-. ,| / ) | * * | > "=._ | )(__/ \\__)( | _.=" < | * * | (_/"=._"=._ |/ /\\ \\| _.="_.="\\_) | * * | "=._"(_ ^^ _)"_.=" | * * | "=\\__|IIIIII|__/=" | * * | _.="| \\IIIIII/ |"=._ | * * | _ _.="_.="\\ /"=._"=._ _ | * * | ( \\_.="_.=" \`--------\` "=._"=._/ ) | * * | > _.=" "=._ < | * * | (_/ \\_) | * * | | * * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' * * * * wenke-dev工具当前版本(${localVersion})不是最新版本, * * 请升级到最新版本(${latestVersion})。 * ************************************************************** `); return false; } return true; } // 增加Node版本检查 function nodeVersionCheck() { const nodeVersion = process.versions.node; const rightVersionReg = /16\.\d+\.\d+/; if (!rightVersionReg.test(nodeVersion)) { console.error( '[ERROR] Node.js的版本必须是16.*,当前运行版本:', nodeVersion ); return false; } else { console.log('[INFO] 当前Node.js运行版本:', nodeVersion); } return true; } function triggerRefresh() { if (global.socket) { global.socket.emit('refresh', { refresh: 1 }); console.log('some files changed: trigger refresh...'); } else { console.log('socket not connected'); } } function isKeyIncludesArrayItem(key, array = []) { if (!key?.length || !array.length) { return; } for (let i = 0; i < array.length; i++) { const item = array[i]; if (key.indexOf(item) > -1) { return true; } } return; } const ssrTemplateExtensionList = ['.js', '.jsx', '.ts', '.tsx']; const isomorphicCSSHashReplaceLoader = { test: /\.(js|jsx|ts|tsx)$/, loader: 'string-replace-loader', options: { search: 'ISOMORPHICCSSHASH', replace(match) { return require('crypto') .createHash('md5') .update(match) .digest('hex'); }, flags: 'ig' } }; module.exports = { jsonArrayUnique, errorHandler, isInt, isInArray, normalizePath, getRegexpStaticFilesPrefix, getAllFilesByDir, mkdirRecursive, hasArgument, startWebSocketServer, getRegexpScriptElements, getRegexpScriptElementSrcAttrValue, getRegexpCSSLinkElements, getRegexpCSSHrefValue, getRegexpImgElements, getRegexpBackgroundImage, uniqueVal, verifyVersion, triggerRefresh, isKeyIncludesArrayItem, ssrTemplateExtensionList, isomorphicCSSHashReplaceLoader: isomorphicCSSHashReplaceLoader }; |