@lntvow/dev 2.2.6 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/script/postinstall.js +50 -1
package/package.json
CHANGED
package/script/postinstall.js
CHANGED
|
@@ -1 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import { exec } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
7
|
+
const __dirname = path.dirname(__filename)
|
|
8
|
+
|
|
9
|
+
const [cwd] = process.cwd().split('node_modules')
|
|
10
|
+
console.log('cwd: ', cwd)
|
|
11
|
+
|
|
12
|
+
function copyDirectorySync(source, target) {
|
|
13
|
+
// 创建目标目录(如果不存在)
|
|
14
|
+
if (!fs.existsSync(target)) {
|
|
15
|
+
fs.mkdirSync(target)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 获取源目录下的所有文件和子目录
|
|
19
|
+
const files = fs.readdirSync(source, { withFileTypes: true })
|
|
20
|
+
|
|
21
|
+
// 遍历并复制文件和子目录
|
|
22
|
+
files.forEach(file => {
|
|
23
|
+
const sourcePath = path.resolve(source, file.name)
|
|
24
|
+
const filePath = path.resolve(target, file.name)
|
|
25
|
+
|
|
26
|
+
if (file.isDirectory()) {
|
|
27
|
+
// 如果是子目录,递归复制
|
|
28
|
+
copyDirectorySync(sourcePath, filePath)
|
|
29
|
+
} else {
|
|
30
|
+
if (fs.existsSync(filePath)) return
|
|
31
|
+
|
|
32
|
+
// 如果是文件,使用流复制
|
|
33
|
+
fs.createReadStream(sourcePath).pipe(fs.createWriteStream(filePath))
|
|
34
|
+
console.log(`文件复制成功: ${sourcePath}`)
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 复制模板文件
|
|
40
|
+
// copyDirectorySync(path.resolve(__dirname, './tmp'), cwd)
|
|
41
|
+
|
|
42
|
+
// // 初始化
|
|
43
|
+
// exec('npx simple-git-hooks', { cwd }, (err, str) => {
|
|
44
|
+
// console.log('npx simple-git-hooks')
|
|
45
|
+
// if (err) {
|
|
46
|
+
// console.log('npx simple-git-hooks err', err)
|
|
47
|
+
// } else {
|
|
48
|
+
// console.log(str)
|
|
49
|
+
// }
|
|
50
|
+
// })
|