-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
63 lines (51 loc) · 1.72 KB
/
index.js
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
import fs from 'fs'
import path from 'path'
export const getDir = (PATH) => {
const _path = path.dirname(
path.resolve('/', decodeURI(PATH.replace(/^file:\/\/(?:\/)?/, '')))
).replace(/\\/g, '/')
return {
path: _path,
name: path.basename(_path)
}
}
export const getDirName = (PATH) => path.basename(PATH)
export const { path: dirPath, name: PluginName } = getDir(import.meta.url)
const copyFolderContents = (src, dest) => {
const entries = fs.readdirSync(src, { withFileTypes: true })
entries.forEach(entry => {
const srcPath = path.join(src, entry.name)
const destPath = path.join(dest, entry.name)
if (entry.isDirectory()) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath, { recursive: true })
}
copyFolderContents(srcPath, destPath)
} else {
fs.renameSync(srcPath, destPath)
}
})
}
const compath = dirPath + '/lib/components/'
if (!fs.existsSync(compath)) {
fs.mkdirSync(compath)
}
// /** 迁移组件至lib目录 */
// const oldcompath = dirPath + '/components/'
// if (fs.existsSync(oldcompath)) {
// logger.info(`${PluginName} 转移组件至 ${compath}`)
// copyFolderContents(oldcompath, compath)
// fs.rmSync(oldcompath, { recursive: true, force: true })
// }
if (fs.existsSync(dirPath + '/apps/index.js')) {
fs.unlinkSync(dirPath + '/apps/index.js')
}
// /** 迁移旧数据 */
// const old_dataPath = dirPath + '/data/'
// const new_dataPath = './data/' + PluginName + '/'
// if (fs.existsSync(old_dataPath)) {
// logger.info(`${PluginName} 转移数据至 ${new_dataPath}`)
// copyFolderContents(old_dataPath, new_dataPath)
// fs.rmSync(old_dataPath, { recursive: true, force: true })
// }
logger.info(`${PluginName} 插件初始化~`)