UNPKG

logic-helper

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

75 lines (68 loc) 1.97 kB
const getObjType = (obj) => { var toString = Object.prototype.toString; var map = { "[object Boolean]": "boolean", "[object Number]": "number", "[object String]": "string", "[object Function]": "function", "[object Array]": "array", "[object Date]": "date", "[object RegExp]": "regExp", "[object Undefined]": "undefined", "[object Null]": "null", "[object Object]": "object", "[object Symbol]": "symbol", "[object AsyncFunction]": "function", }; return map[toString.call(obj)]; }; function deepMerge(obj, other) { if (typeof obj !== "object" || typeof other !== "object") { return other; } if (obj === other) { return obj; } for (let k in other) { if (other.hasOwnProperty(k)) { if(Array.isArray(other[k])) { obj[k] = other[k]; }else if (getObjType(other[k]) === "object") { obj[k] = deepMerge(obj[k], other[k]); } else { obj[k] = other[k]; } } } return obj; } function fileExists(path) { var fs = require('fs'); var exists = fs.existsSync(path); return exists; } let config = require('../logic.config.js') const path = require('path') module.exports = () => { if (fileExists(path.resolve(process.cwd(), 'logic.config.js'))) { let customed = require(path.resolve(process.cwd(), 'logic.config.js')); if(!customed.name) { throw new Error('logic.config.js must have a name property'); console.error('logic.config.js 必需有一个name ,用于生成本地缓存'); } config = deepMerge(config, customed); } else { fs.writeFileSync(path.resolve(process.cwd(), 'logic.config.js'), ` const config = { name: '_logic_topo_${Date.now()}', mode: 'development', server: { host: 'localhost', port: 9503, }, }; module.exports = config; `) } return config }