You've already forked dev-sidecar
mirror of
https://github.com/docmirror/dev-sidecar.git
synced 2025-11-26 14:10:40 +08:00
refactor: dns设置
This commit is contained in:
58
packages/core/package-lock.json
generated
58
packages/core/package-lock.json
generated
@@ -1795,7 +1795,6 @@
|
||||
"thread-loader": "^2.1.3",
|
||||
"url-loader": "^2.2.0",
|
||||
"vue-loader": "^15.9.2",
|
||||
"vue-loader-v16": "npm:vue-loader@^16.0.0-beta.7",
|
||||
"vue-style-loader": "^4.1.2",
|
||||
"webpack": "^4.0.0",
|
||||
"webpack-bundle-analyzer": "^3.8.0",
|
||||
@@ -12415,63 +12414,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"vue-loader-v16": {
|
||||
"version": "npm:vue-loader@16.0.0-beta.9",
|
||||
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.0.0-beta.9.tgz",
|
||||
"integrity": "sha512-mu9pg6554GbXDSO8LlxkQM6qUJzUkb/A0FJc9LgRqnU9MCnhzEXwCt1Zx5NObvFpzs2mH2dH/uUCDwL8Qaz9sA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"chalk": "^4.1.0",
|
||||
"hash-sum": "^2.0.0",
|
||||
"loader-utils": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"color-convert": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
|
||||
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-styles": "^4.1.0",
|
||||
"supports-color": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"color-name": "~1.1.4"
|
||||
}
|
||||
},
|
||||
"loader-utils": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
|
||||
"integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"big.js": "^5.2.2",
|
||||
"emojis-list": "^3.0.0",
|
||||
"json5": "^2.1.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"vue-style-loader": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz",
|
||||
|
||||
@@ -34,31 +34,29 @@ const configApi = {
|
||||
resetDefault () {
|
||||
configTarget = lodash.cloneDeep(defConfig)
|
||||
},
|
||||
async getMirrorEnv () {
|
||||
const envMap = await Shell.getEnv()
|
||||
async getVariables (type) {
|
||||
const method = type === 'npm' ? Shell.getNpmEnv : Shell.getSystemEnv
|
||||
const currentMap = await method()
|
||||
const list = []
|
||||
const mirrors = configTarget.mirrors
|
||||
console.log('envMap', envMap)
|
||||
for (const key in mirrors) {
|
||||
console.log('equale', key, envMap[key])
|
||||
const exists = envMap[key] != null
|
||||
const map = configTarget.variables[type]
|
||||
for (const key in map) {
|
||||
const exists = currentMap[key] != null
|
||||
list.push({
|
||||
key,
|
||||
value: mirrors[key],
|
||||
value: map[key],
|
||||
exists
|
||||
})
|
||||
}
|
||||
console.log('mirrors:', list)
|
||||
return list
|
||||
},
|
||||
async setupMirrors () {
|
||||
const list = await configApi.getMirrorEnv()
|
||||
async setVariables (type) {
|
||||
const list = await configApi.getVariables(type)
|
||||
const noSetList = list.filter(item => {
|
||||
return !item.exists
|
||||
})
|
||||
console.log('mirrors will set:', noSetList)
|
||||
if (list.length > 0) {
|
||||
return Shell.setEnv({ list: noSetList })
|
||||
const method = type === 'npm' ? Shell.setNpmEnv : Shell.setSystemEnv
|
||||
return method({ list: noSetList })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,13 @@ module.exports = {
|
||||
{
|
||||
abort: true
|
||||
}
|
||||
],
|
||||
// https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.0/napi-v3-win32-x64.tar.gz
|
||||
'*.s3.amazonaws.com': [
|
||||
{
|
||||
regexp: '/sqlite3/.*',
|
||||
redirect: 'http://npm.taobao.org/mirrors'
|
||||
}
|
||||
]
|
||||
},
|
||||
dns: {
|
||||
@@ -104,11 +111,18 @@ module.exports = {
|
||||
// "avatars*.githubusercontent.com": "usa"
|
||||
}
|
||||
},
|
||||
mirrors: {
|
||||
SASS_BINARY_SITE: 'https://npm.taobao.org/mirrors/node-sass/',
|
||||
PHANTOMJS_CDNURL: 'https://npm.taobao.org/mirrors/phantomjs/',
|
||||
ELECTRON_MIRROR: 'https://npm.taobao.org/mirrors/electron/',
|
||||
CYPRESS_DOWNLOAD_MIRROR: 'https://cdn.cypress.io'
|
||||
variables: {
|
||||
npm: {
|
||||
SASS_BINARY_SITE: 'https://npm.taobao.org/mirrors/node-sass/',
|
||||
PHANTOMJS_CDNURL: 'https://npm.taobao.org/mirrors/phantomjs/',
|
||||
ELECTRON_MIRROR: 'https://npm.taobao.org/mirrors/electron/',
|
||||
CYPRESS_DOWNLOAD_MIRROR: 'https://cdn.cypress.io',
|
||||
NVM_NODEJS_ORG_MIRROR: 'http://npm.taobao.org/mirrors/node',
|
||||
CHROMEDRIVER_CDNURL: 'http://npm.taobao.org/mirrors/chromedriver',
|
||||
OPERADRIVER: 'http://npm.taobao.org/mirrors/operadriver',
|
||||
ELECTRON_BUILDER_BINARIES_MIRROR: 'http://npm.taobao.org/mirrors/electron-builder-binaries/',
|
||||
PYTHON_MIRROR: 'http://npm.taobao.org/mirrors/python'
|
||||
}
|
||||
},
|
||||
setting: {
|
||||
startup: { // 开机启动
|
||||
@@ -118,8 +132,8 @@ module.exports = {
|
||||
npm: true,
|
||||
yarn: true
|
||||
},
|
||||
mirrors: {
|
||||
set: true
|
||||
variables: {
|
||||
npm: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ module.exports = {
|
||||
}
|
||||
await proxyStartup({ ip: '127.0.0.1', port: config.get().server.port })
|
||||
|
||||
if (startup.mirrors.set) {
|
||||
await config.setupMirrors()
|
||||
if (startup.variables.npm) {
|
||||
await config.setVariables('npm')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
const killByPort = require('./scripts/kill-by-port')
|
||||
const setupCa = require('./scripts/setup-ca')
|
||||
const getEnv = require('./scripts/get-env')
|
||||
const setEnv = require('./scripts/set-env')
|
||||
const getSystemEnv = require('./scripts/get-system-env')
|
||||
const setSystemEnv = require('./scripts/set-system-env')
|
||||
const getNpmEnv = require('./scripts/get-npm-env')
|
||||
const setNpmEnv = require('./scripts/set-npm-env')
|
||||
module.exports = {
|
||||
killByPort,
|
||||
setupCa,
|
||||
getEnv,
|
||||
setEnv
|
||||
getSystemEnv,
|
||||
setSystemEnv,
|
||||
getNpmEnv,
|
||||
setNpmEnv
|
||||
}
|
||||
|
||||
25
packages/core/src/shell/scripts/get-npm-env.js
Normal file
25
packages/core/src/shell/scripts/get-npm-env.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 获取环境变量
|
||||
*/
|
||||
const Shell = require('../shell')
|
||||
const execute = Shell.execute
|
||||
const executor = {
|
||||
async windows (exec) {
|
||||
const ret = await exec(['npm config list --json'], { type: 'cmd' })
|
||||
if (ret != null) {
|
||||
const json = ret.substring(ret.indexOf('{'))
|
||||
return JSON.parse(json)
|
||||
}
|
||||
return {}
|
||||
},
|
||||
async linux (exec, { port }) {
|
||||
throw Error('暂未实现此功能')
|
||||
},
|
||||
async mac (exec, { port }) {
|
||||
throw Error('暂未实现此功能')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async function (args) {
|
||||
return execute(executor, args)
|
||||
}
|
||||
25
packages/core/src/shell/scripts/set-npm-env.js
Normal file
25
packages/core/src/shell/scripts/set-npm-env.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 设置环境变量
|
||||
*/
|
||||
const Shell = require('../shell')
|
||||
const execute = Shell.execute
|
||||
const executor = {
|
||||
async windows (exec, { list }) {
|
||||
const cmds = []
|
||||
for (const item of list) {
|
||||
cmds.push(`npm config set ${item.key} ${item.value}`)
|
||||
}
|
||||
const ret = await exec(cmds, { type: 'cmd' })
|
||||
return ret
|
||||
},
|
||||
async linux (exec, { port }) {
|
||||
throw Error('暂未实现此功能')
|
||||
},
|
||||
async mac (exec, { port }) {
|
||||
throw Error('暂未实现此功能')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async function (args) {
|
||||
return execute(executor, args)
|
||||
}
|
||||
@@ -11,6 +11,14 @@ const executor = {
|
||||
cmds.push(`[Environment]::SetEnvironmentVariable('${item.key}', '${item.value}', 'Machine')`)
|
||||
}
|
||||
const ret = await exec(cmds, { type: 'ps' })
|
||||
|
||||
const cmds2 = []
|
||||
for (const item of list) {
|
||||
// [Environment]::SetEnvironmentVariable('FOO', 'bar', 'Machine')
|
||||
cmds2.push(`set ${item.key}=""`)
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const ret2 = await exec(cmds2, { type: 'cmd' })
|
||||
return ret
|
||||
},
|
||||
async linux (exec, { port }) {
|
||||
@@ -34,7 +34,8 @@ class DarwinSystemShell extends SystemShell {
|
||||
}
|
||||
|
||||
class WindowsSystemShell extends SystemShell {
|
||||
static async exec (cmds, { type = 'ps' }) {
|
||||
static async exec (cmds, args = { type: 'ps' }) {
|
||||
const { type } = args
|
||||
if (cmds instanceof String) {
|
||||
cmds = [cmds]
|
||||
}
|
||||
@@ -45,12 +46,11 @@ class WindowsSystemShell extends SystemShell {
|
||||
})
|
||||
|
||||
for (const cmd of cmds) {
|
||||
console.log('ps:', cmd)
|
||||
ps.addCommand(cmd)
|
||||
}
|
||||
|
||||
const ret = await ps.invoke()
|
||||
console.log('ps complete:', ret)
|
||||
console.log('ps complete:', cmds, ret)
|
||||
return ret
|
||||
} else {
|
||||
let compose = 'chcp 65001 '
|
||||
|
||||
@@ -28,7 +28,7 @@ class WindowsSystemProxy extends SystemProxy {
|
||||
ret = await winExec(`npm config set https-proxy=http://${ip}:${port}`)
|
||||
console.log('npm https proxy set success', ret)
|
||||
|
||||
ret = await winExec(`npm config set ca ${config.getDefaultCAKeyPath()}`)
|
||||
ret = await winExec(`npm config set ca ${config.getDefaultCACertPath()}`)
|
||||
console.log('npm cafile set success', ret)
|
||||
|
||||
// ret = await winExec('npm config set strict-ssl false')
|
||||
|
||||
@@ -4,7 +4,6 @@ const childProcess = require('child_process')
|
||||
const _exec = childProcess.exec
|
||||
const Registry = require('winreg')
|
||||
// const cmd = require('node-cmd')
|
||||
console.log('childProcess', childProcess)
|
||||
const exec = util.promisify(_exec)
|
||||
const refreshInternetPs = require('./refresh-internet')
|
||||
const Shell = require('node-powershell')
|
||||
|
||||
@@ -29,7 +29,7 @@ class WindowsSystemProxy extends SystemProxy {
|
||||
ret = await winExec(`yarn config set https-proxy=http://${ip}:${port}`)
|
||||
console.log('yarn https proxy set success', ret)
|
||||
|
||||
ret = await winExec(`yarn config set ca ${config.getDefaultCAKeyPath()}`)
|
||||
ret = await winExec(`yarn config set ca ${config.getDefaultCACertPath()}`)
|
||||
console.log('yarn cafile set success', ret)
|
||||
|
||||
// ret = await winExec('yarn config set strict-ssl false')
|
||||
|
||||
Reference in New Issue
Block a user