Skip to content

Commit 231df8a

Browse files
committed
chore: build script of broswer plugin
1 parent 66d3081 commit 231df8a

File tree

6 files changed

+115
-24
lines changed

6 files changed

+115
-24
lines changed

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module.exports = {
55
'no-console': ['error', { allow: ['warn', 'error', 'debug'] }],
66
'vue/v-on-event-hyphenation': 'off',
77
},
8+
ignorePatterns: ['node_modules/', 'dist/', 'browserPlugin/'],
89
}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
node_modules
33
bun.lockb
44
/dist
5-
5+
/browserPlugin
66

77
# local env files
88
.env.local

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"prepare": "simple-git-hooks",
88
"serve": "vue-cli-service serve",
99
"build": "vue-cli-service build",
10+
"build:plugin": "npm run build && node ./scripts/build-plugin.mjs",
1011
"lint": "eslint .",
1112
"lint:fix": "eslint . --fix"
1213
},
1314
"dependencies": {
1415
"ant-design-vue": "^4.0.3",
1516
"axios": "^1.5.0",
17+
"chalk": "^4.0.0",
1618
"url-loader": "^4.1.1",
1719
"vue": "^3.2.13",
1820
"vue-grid-layout": "npm:@nrr/[email protected]",

scripts/build-plugin.mjs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import fs from 'node:fs/promises'
2+
import { statSync } from 'node:fs'
3+
import path from 'node:path'
4+
import process from 'node:process'
5+
import chalk from 'chalk'
6+
7+
const sourceSrc = path.join(process.cwd(), 'dist')
8+
const targetSrc = path.join(process.cwd(), 'browserPlugin')
9+
// fs/promises写法
10+
function move(sourceRoot, targetRoot) {
11+
console.debug(chalk.green(`开始移动${sourceRoot}中的文件至${targetRoot}`))
12+
fs.readdir(sourceRoot)
13+
.then((files) => {
14+
files.forEach((file) => {
15+
const sourceFile = path.join(sourceRoot, file)
16+
const targetFile = path.join(targetRoot, file)
17+
18+
if (statSync(sourceFile).isDirectory()) {
19+
fs.stat(targetFile)
20+
.catch((err) => {
21+
if (err.code === 'ENOENT') {
22+
// 在targetSrc中新建同名文件夹
23+
fs.mkdir(targetFile)
24+
.then(() => {
25+
console.debug(chalk.green(`新建${targetFile}文件夹成功`))
26+
})
27+
.catch((err) => {
28+
console.debug(chalk.red(`新建失败ERROR:${err}`))
29+
})
30+
}
31+
else {
32+
console.debug(chalk.red(`新建失败ERROR:${err}`))
33+
}
34+
})
35+
move(sourceFile, targetFile)
36+
}
37+
else {
38+
const copyFn = () => {
39+
fs.copyFile(sourceFile, targetFile)
40+
.catch(() => {
41+
console.debug(chalk.red('复制失败'))
42+
})
43+
}
44+
fs.unlink(targetFile)
45+
.then(() => {
46+
copyFn()
47+
})
48+
.catch(() => {
49+
copyFn()
50+
})
51+
}
52+
})
53+
})
54+
console.debug(chalk.green('复制成功'))
55+
}
56+
// fs写法
57+
// fs.readdir(sourceSrc, (err, files) => {
58+
// if (err) {
59+
// console.debug("读取文件夹失败");
60+
// } else {
61+
// files.forEach((file) => {
62+
// const sourceFile = path.join(sourceSrc, file);
63+
// const targetFile = path.join(targetSrc, file);
64+
// fs.unlink(targetFile, (err) => {
65+
// if (!err || err.code !== "ENOENT") {
66+
// fs.copyFile(sourceFile, targetFile, (err) => {
67+
// if (err) {
68+
// console.debug("复制失败");
69+
// } else {
70+
// console.debug("复制成功")
71+
// }
72+
// })
73+
// } else {
74+
// console.debug("删除失败");
75+
// }
76+
// })
77+
78+
// });
79+
// }
80+
// })
81+
fs.stat(targetSrc)
82+
.then((result) => {
83+
if (result.isDirectory())
84+
move(sourceSrc, targetSrc)
85+
else
86+
console.debug(chalk.red('browserPlugin不是一个文件夹'))
87+
})
88+
.catch((err) => {
89+
if (err.code === 'ENOENT') {
90+
// 新建browserPlugin文件夹
91+
fs.mkdir('browserPlugin')
92+
.then(() => {
93+
move(sourceSrc, targetSrc)
94+
})
95+
.catch((err) => {
96+
console.debug(chalk.red(`新建失败ERROR:${err}`))
97+
})
98+
}
99+
else {
100+
console.error(chalk.red('发生错误:', err))
101+
}
102+
})

src/components/TagsBox.vue

+2-19
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { GridItem, GridLayout } from 'vue3-drr-grid-layout'
33
import 'vue3-drr-grid-layout/dist/style.css'
44
import { nextTick } from 'vue'
55
6-
import Kxz from '@/assets/ico/kxz.png'
7-
86
export default ({
97
components: {
108
GridLayout,
@@ -66,11 +64,11 @@ export default ({
6664
localStorage.setItem('vuex-state', JSON.stringify(this.$store.state))
6765
this.layout = JSON.parse(localStorage.getItem('vuex-state')).tagList
6866
}
69-
const tagRadius = lsState.tagRadius
70-
const tagOpacity = lsState.tagOpacity / 100
7167
nextTick().then(() => {
7268
// 在下一个 tick 中执行操作
7369
const tagIcons = document.querySelectorAll('.tagIcon')
70+
const tagRadius = lsState.tagRadius
71+
const tagOpacity = lsState.tagOpacity / 100
7472
tagIcons.forEach((item) => {
7573
item.style.borderRadius = `${tagRadius}%`
7674
item.style.opacity = `${tagOpacity}`
@@ -85,21 +83,6 @@ export default ({
8583
showModal() {
8684
this.open = true
8785
},
88-
handleOk() {
89-
if (this.url === '')
90-
return
91-
const newTag = {}
92-
newTag.url = `https://${this.url}`
93-
newTag.name = this.name
94-
newTag.key = 0
95-
newTag.icon = Kxz
96-
this.url = ''
97-
this.name = ''
98-
// this.tags.push(newTag)
99-
this.tags.push(newTag)
100-
this.$store.commit('updateTagList', this.tags)
101-
this.open = false
102-
},
10386
rightClick(tag) {
10487
console.debug(tag)
10588
this.tags = this.tags.filter(item => item !== tag)

src/components/UserBox.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { nextTick } from 'vue'
33
4-
// import Avatar from '@/assets/ico/Avatar.png'
4+
import Kxz from '@/assets/ico/kxz.png'
55
66
export default {
77
data() {
@@ -21,7 +21,7 @@ export default {
2121
bgPicList: [],
2222
activeKey: 1,
2323
imgUrl: [],
24-
newTabIconIndex: 0,
24+
newTabIconIndex: -1,
2525
tagRadius: this.$store.state.tagRadius,
2626
tagOpacity: this.$store.state.tagRadius,
2727
searchBoxSize: this.$store.state.searchBoxSize,
@@ -215,9 +215,12 @@ export default {
215215
newTag.url = `https://${this.newTabUrl}`
216216
newTag.name = this.newTabName
217217
newTag.key = 0
218-
newTag.icon = this.imgUrl[this.newTabIconIndex]
218+
if (this.newTabIconIndex === -1)
219+
newTag.icon = Kxz
220+
else
221+
newTag.icon = this.imgUrl[this.newTabIconIndex]
219222
this.imgUrl = []
220-
this.newTabIconIndex = 0
223+
this.newTabIconIndex = -1
221224
const tags = this.$store.state.tagList
222225
let x = 2
223226
let y = 0

0 commit comments

Comments
 (0)