Browse Source

refactor: dns设置

pull/180/head
xiaojunnuo 4 years ago
parent
commit
be85a6c0e9
  1. 3
      package.json
  2. 58
      packages/core/package-lock.json
  3. 24
      packages/core/src/config.js
  4. 28
      packages/core/src/config/index.js
  5. 4
      packages/core/src/expose.js
  6. 12
      packages/core/src/shell/index.js
  7. 25
      packages/core/src/shell/scripts/get-npm-env.js
  8. 0
      packages/core/src/shell/scripts/get-system-env.js
  9. 25
      packages/core/src/shell/scripts/set-npm-env.js
  10. 8
      packages/core/src/shell/scripts/set-system-env.js
  11. 6
      packages/core/src/shell/shell.js
  12. 2
      packages/core/src/switch/proxy/impl/npm-proxy.js
  13. 1
      packages/core/src/switch/proxy/impl/system-proxy.js
  14. 2
      packages/core/src/switch/proxy/impl/yarn-proxy.js
  15. BIN
      packages/gui/build/icons/1024x1024.png
  16. BIN
      packages/gui/build/icons/128x128.png
  17. BIN
      packages/gui/build/icons/16x16.png
  18. BIN
      packages/gui/build/icons/24x24.png
  19. BIN
      packages/gui/build/icons/256x256.png
  20. BIN
      packages/gui/build/icons/32x32.png
  21. BIN
      packages/gui/build/icons/48x48.png
  22. BIN
      packages/gui/build/icons/512x512.png
  23. BIN
      packages/gui/build/icons/64x64.png
  24. BIN
      packages/gui/build/icons/icon.icns
  25. BIN
      packages/gui/build/icons/icon.ico
  26. 160
      packages/gui/package-lock.json
  27. 1
      packages/gui/src/bridge/index.js
  28. 2
      packages/gui/src/config.js
  29. 57
      packages/gui/src/view/components/settings.vue

3
package.json

@ -4,5 +4,8 @@
"license": "MPL-2.0",
"devDependencies": {
"lerna": "^3.22.1"
},
"dependencies": {
"sqlite3": "^5.0.0"
}
}

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",

24
packages/core/src/config.js

@ -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 })
}
}
}

28
packages/core/src/config/index.js

@ -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
}
}
}

4
packages/core/src/expose.js

@ -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)

12
packages/core/src/shell/index.js

@ -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

@ -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)
}

0
packages/core/src/shell/scripts/get-env.js → packages/core/src/shell/scripts/get-system-env.js

25
packages/core/src/shell/scripts/set-npm-env.js

@ -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)
}

8
packages/core/src/shell/scripts/set-env.js → packages/core/src/shell/scripts/set-system-env.js

@ -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 }) {

6
packages/core/src/shell/shell.js

@ -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 '

2
packages/core/src/switch/proxy/impl/npm-proxy.js

@ -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')

1
packages/core/src/switch/proxy/impl/system-proxy.js

@ -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')

2
packages/core/src/switch/proxy/impl/yarn-proxy.js

@ -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')

BIN
packages/gui/build/icons/1024x1024.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

BIN
packages/gui/build/icons/128x128.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

BIN
packages/gui/build/icons/16x16.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 584 B

BIN
packages/gui/build/icons/24x24.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 941 B

BIN
packages/gui/build/icons/256x256.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

BIN
packages/gui/build/icons/32x32.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

BIN
packages/gui/build/icons/48x48.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

BIN
packages/gui/build/icons/512x512.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

BIN
packages/gui/build/icons/64x64.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

BIN
packages/gui/build/icons/icon.icns

Binary file not shown.

BIN
packages/gui/build/icons/icon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 KiB

160
packages/gui/package-lock.json generated

@ -2372,6 +2372,16 @@
"integrity": "sha1-/q7SVZc9LndVW4PbwIhRpsY1IPo=",
"dev": true
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-4.3.0.tgz?cache=0&sync_timestamp=1601839122515&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-4.3.0.tgz",
"integrity": "sha1-7dgDYornHATIWuegkG7a00tkiTc=",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"cacache": {
"version": "13.0.1",
"resolved": "https://registry.npm.taobao.org/cacache/download/cacache-13.0.1.tgz",
@ -2398,6 +2408,34 @@
"unique-filename": "^1.1.1"
}
},
"chalk": {
"version": "4.1.0",
"resolved": "https://registry.npm.taobao.org/chalk/download/chalk-4.1.0.tgz",
"integrity": "sha1-ThSHCmGNni7dl92DRf2dncMVZGo=",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-2.0.1.tgz",
"integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npm.taobao.org/color-name/download/color-name-1.1.4.tgz",
"integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI=",
"dev": true,
"optional": true
},
"find-cache-dir": {
"version": "3.3.1",
"resolved": "https://registry.npm.taobao.org/find-cache-dir/download/find-cache-dir-3.3.1.tgz",
@ -2419,6 +2457,25 @@
"path-exists": "^4.0.0"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/has-flag/download/has-flag-4.0.0.tgz",
"integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s=",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/loader-utils/download/loader-utils-2.0.0.tgz",
"integrity": "sha1-5MrOW4FtQloWa18JfhDNErNgZLA=",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npm.taobao.org/locate-path/download/locate-path-5.0.0.tgz",
@ -2483,6 +2540,16 @@
"minipass": "^3.1.1"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-7.2.0.tgz?cache=0&sync_timestamp=1598611709087&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-7.2.0.tgz",
"integrity": "sha1-G33NyzK4E4gBs+R4umpRyqiWSNo=",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"terser-webpack-plugin": {
"version": "2.3.8",
"resolved": "https://registry.npm.taobao.org/terser-webpack-plugin/download/terser-webpack-plugin-2.3.8.tgz?cache=0&sync_timestamp=1602701885709&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fterser-webpack-plugin%2Fdownload%2Fterser-webpack-plugin-2.3.8.tgz",
@ -2499,6 +2566,18 @@
"terser": "^4.6.12",
"webpack-sources": "^1.4.3"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.0.0-beta.9",
"resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.0.0-beta.9.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-16.0.0-beta.9.tgz",
"integrity": "sha1-UlEsthwpaCfJnA1UOYvvhL5ESPw=",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
}
}
}
},
@ -16335,87 +16414,6 @@
}
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.0.0-beta.8",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.0.0-beta.8.tgz",
"integrity": "sha512-oouKUQWWHbSihqSD7mhymGPX1OQ4hedzAHyvm8RdyHh6m3oIvoRF+NM45i/bhNOlo8jCnuJhaSUf/6oDjv978g==",
"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"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"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"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-ref": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/vue-ref/download/vue-ref-2.0.0.tgz",

1
packages/gui/src/bridge/index.js

@ -97,7 +97,6 @@ function _mergeConfig (defObj, newObj) {
delete newObj[key]
}
}
console.log('newObj', newObj)
return newObj
}

2
packages/gui/src/config.js

@ -1,2 +0,0 @@
import config from '../../../config/index.json5'
export default config

57
packages/gui/src/view/components/settings.vue

@ -17,19 +17,24 @@
:style="{ height: '100%' }"
>
<a-tab-pane tab="拦截设置" key="1" >
<vue-json-editor style="height:100%;" ref="editor" v-model="targetConfig.intercepts" :show-btns="false" :expandedOnStart="true" @json-change="onJsonChange" ></vue-json-editor>
<vue-json-editor style="height:100%;" ref="editor" v-model="targetConfig.intercepts" mode="code" :show-btns="false" :expandedOnStart="true" @json-change="onJsonChange" ></vue-json-editor>
</a-tab-pane>
<a-tab-pane tab="DNS设置" key="2">
<div>
<div>某些域名有时候需要通过其他DNS服务器获取到的IP才可以访问</div>
<a-row style="margin-top:10px">
<a-col>
<a-button type="primary" icon="plus" @click="addDnsMapping()" />
</a-col>
</a-row>
<a-row :gutter="10" style="margin-top: 10px" v-for="(item,index) of dnsMappings" :key = 'index'>
<a-col :span="14">
<a-input :disabled="item.value ===false" v-model="item.key"></a-input>
</a-col>
<a-col :span="5">
<a-select :disabled="item.value ===false" v-model="item.value">
<a-select-option value="usa">USA</a-select-option>
<a-select-option value="aliyun">Aliyun</a-select-option>
<a-select-option value="usa">USA DNS</a-select-option>
<a-select-option value="aliyun">Aliyun DNS</a-select-option>
</a-select>
</a-col>
<a-col :span="3">
@ -37,28 +42,24 @@
<a-button v-if="item.value===false" style="margin-left:10px" type="primary" icon="checked" @click="restoreDefDnsMapping(item,index)" ></a-button>
</a-col>
</a-row>
<a-row style="margin-top:10px">
<a-col>
<a-button type="primary" icon="plus" @click="addDnsMapping()" />
</a-col>
</a-row>
</div>
</a-tab-pane>
<a-tab-pane tab="镜像变量" key="3">
<a-tab-pane tab="环境变量" key="3">
<div>
<div>某些库需要自己设置代理环境变量才能安装比如electron</div>
<div>某些库需要自己设置镜像变量才能下载比如electron</div>
<div>
<a-form-item label="镜像环境变量" >
<a-switch v-model="targetConfig.setting.startup.mirrors.set" default-checked v-on:click="(checked)=>{targetConfig.setting.startup.mirrors.set = checked}">
<a-switch v-model="targetConfig.setting.startup.variables.npm" default-checked v-on:click="(checked)=>{targetConfig.setting.startup.variables.npm = checked}">
<a-icon slot="checkedChildren" type="check" />
<a-icon slot="unCheckedChildren" type="close" />
</a-switch>
启动后自动检查设置
<a-button style="margin-left:10px" @click="doSetMirrorEnvNow">立即设置</a-button>
<a-button style="margin-left:10px" @click="doSetNpmVariablesNow">立即设置</a-button>
</a-form-item>
</div>
<a-row :gutter="10" style="margin-top: 10px" v-for="(item,index) of mirrorEnvs" :key = 'index'>
<a-row :gutter="10" style="margin-top: 10px" v-for="(item,index) of npmVariables" :key = 'index'>
<a-col :span="10">
<a-input :disabled="item.key ===false" v-model="item.key"></a-input>
</a-col>
@ -121,7 +122,7 @@ export default {
return {
targetConfig: {},
dnsMappings: [],
mirrorEnvs: []
npmVariables: []
}
},
created () {
@ -139,8 +140,8 @@ export default {
})
}
api.config.getMirrorEnv().then(ret => {
this.mirrorEnvs = ret
api.config.getVariables('npm').then(ret => {
this.npmVariables = ret
})
},
onJsonChange (config) {
@ -159,6 +160,8 @@ export default {
this.$confirm({
title: '提示',
content: '是否需要保存?',
cancelText: '取消',
okText: '确定',
onOk: () => {
this.doSave()
},
@ -175,11 +178,11 @@ export default {
}
this.targetConfig.dns.mapping = mapping
const mirrors = {}
for (const item of this.mirrorEnvs) {
mirrors[item.key] = item.value
const variables = {}
for (const item of this.npmVariables) {
variables[item.key] = item.value
}
this.targetConfig.mirrors = mirrors
this.targetConfig.variables.npm = variables
},
isChanged () {
this.syncTargetConfig()
@ -197,22 +200,22 @@ export default {
},
addDnsMapping () {
this.dnsMappings.push({ key: '', value: 'usa' })
this.dnsMappings.unshift({ key: '', value: 'usa' })
},
doSetMirrorEnvNow () {
doSetNpmVariablesNow () {
this.syncTargetConfig()
this.doSave().then(() => {
return api.config.setupMirrors()
return api.config.setVariables('npm')
}).then(() => {
return api.config.getMirrorEnv().then(ret => {
this.mirrorEnvs = ret
return api.config.getVariables('npm').then(ret => {
this.npmVariables = ret
})
}).then(() => {
this.$message.info('设置成功')
})
},
addMirrors () {
this.mirrorEnvs.push({ key: '', value: '', exists: false })
addNpmVariable () {
this.npmVariables.push({ key: '', value: '', exists: false })
}
}
}

Loading…
Cancel
Save