@lntvow/dev 0.1.8 → 0.2.1
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 +2 -1
- package/script/postinstall.js +2 -69
- package/script/preinstall.js +67 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/dev",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "开发环境依赖包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"commit": "git add . && git-cz && git push",
|
|
37
37
|
"rimraf": "rimraf ./node_modules/",
|
|
38
38
|
"release": "git add . && bumpp package.json --all --commit --no-tag --push",
|
|
39
|
+
"preinstall": "node ./script/preinstall.js",
|
|
39
40
|
"postinstall": "node ./script/postinstall.js"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/script/postinstall.js
CHANGED
|
@@ -1,71 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import { execSync } from 'node:child_process'
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
7
|
-
const __dirname = path.dirname(__filename)
|
|
8
|
-
|
|
9
|
-
const cwd = process.cwd().split('node_modules')[0]
|
|
10
|
-
|
|
11
|
-
function copyDirectorySync(source, target) {
|
|
12
|
-
// 创建目标目录(如果不存在)
|
|
13
|
-
if (!fs.existsSync(target)) {
|
|
14
|
-
fs.mkdirSync(target)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 获取源目录下的所有文件和子目录
|
|
18
|
-
const files = fs.readdirSync(source, { withFileTypes: true })
|
|
19
|
-
|
|
20
|
-
// 遍历并复制文件和子目录
|
|
21
|
-
files.forEach(file => {
|
|
22
|
-
const sourcePath = path.resolve(source, file.name)
|
|
23
|
-
const filePath = path.resolve(target, file.name)
|
|
24
|
-
|
|
25
|
-
if (file.isDirectory()) {
|
|
26
|
-
// 如果是子目录,递归复制
|
|
27
|
-
copyDirectorySync(sourcePath, filePath)
|
|
28
|
-
} else {
|
|
29
|
-
if (fs.existsSync(filePath)) return
|
|
30
|
-
|
|
31
|
-
// 如果是文件,使用流复制
|
|
32
|
-
fs.createReadStream(sourcePath).pipe(fs.createWriteStream(filePath))
|
|
33
|
-
console.log(`文件复制成功: ${sourcePath}`)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 复制模板文件
|
|
39
|
-
copyDirectorySync(path.resolve(__dirname, './tmp'), cwd)
|
|
1
|
+
import { exec } from 'node:child_process'
|
|
40
2
|
|
|
41
3
|
// 初始化 husky
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// 写入 lint-staged 配置
|
|
45
|
-
const packageJson = fs.readFileSync(path.resolve(cwd, './package.json'), 'utf8')
|
|
46
|
-
const packageJsonObj = JSON.parse(packageJson)
|
|
47
|
-
|
|
48
|
-
if (!packageJsonObj['lint-staged']) {
|
|
49
|
-
packageJsonObj['lint-staged'] = {
|
|
50
|
-
'*.{js,jsx,ts,tsx,vue}': ['eslint --fix'],
|
|
51
|
-
'*.{json,css,scss,md}': ['prettier --write'],
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!packageJsonObj.scripts) {
|
|
56
|
-
packageJsonObj.scripts = {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
packageJsonObj.scripts = {
|
|
60
|
-
dev: 'vite --host',
|
|
61
|
-
'build:test': 'vite build --mode development',
|
|
62
|
-
'build:uat': 'vite build --mode uat',
|
|
63
|
-
'build:prod': 'vite build',
|
|
64
|
-
commit: 'git add . && git-cz && git push',
|
|
65
|
-
rimraf: 'rimraf ./node_modules/',
|
|
66
|
-
release: 'git add . && bumpp package.json --all --commit --no-tag --push',
|
|
67
|
-
...packageJsonObj.scripts,
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
fs.writeFileSync(path.resolve(cwd, './package.json'), `${JSON.stringify(packageJsonObj, null, 2)}\n`)
|
|
71
|
-
console.log('lint-staged 配置写入成功')
|
|
4
|
+
exec('npx husky install', { cwd: process.cwd().split('node_modules')[0] })
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
6
|
+
const __dirname = path.dirname(__filename)
|
|
7
|
+
|
|
8
|
+
const cwd = process.cwd().split('node_modules')[0]
|
|
9
|
+
|
|
10
|
+
function copyDirectorySync(source, target) {
|
|
11
|
+
// 创建目标目录(如果不存在)
|
|
12
|
+
if (!fs.existsSync(target)) {
|
|
13
|
+
fs.mkdirSync(target)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 获取源目录下的所有文件和子目录
|
|
17
|
+
const files = fs.readdirSync(source, { withFileTypes: true })
|
|
18
|
+
|
|
19
|
+
// 遍历并复制文件和子目录
|
|
20
|
+
files.forEach(file => {
|
|
21
|
+
const sourcePath = path.resolve(source, file.name)
|
|
22
|
+
const filePath = path.resolve(target, file.name)
|
|
23
|
+
|
|
24
|
+
if (file.isDirectory()) {
|
|
25
|
+
// 如果是子目录,递归复制
|
|
26
|
+
copyDirectorySync(sourcePath, filePath)
|
|
27
|
+
} else {
|
|
28
|
+
if (fs.existsSync(filePath)) return
|
|
29
|
+
|
|
30
|
+
// 如果是文件,使用流复制
|
|
31
|
+
fs.createReadStream(sourcePath).pipe(fs.createWriteStream(filePath))
|
|
32
|
+
console.log(`文件复制成功: ${sourcePath}`)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 复制模板文件
|
|
38
|
+
copyDirectorySync(path.resolve(__dirname, './tmp'), cwd)
|
|
39
|
+
|
|
40
|
+
// 写入 lint-staged 配置
|
|
41
|
+
const packageJson = fs.readFileSync(path.resolve(cwd, './package.json'), 'utf8')
|
|
42
|
+
const packageJsonObj = JSON.parse(packageJson)
|
|
43
|
+
|
|
44
|
+
if (!packageJsonObj['lint-staged']) {
|
|
45
|
+
packageJsonObj['lint-staged'] = {
|
|
46
|
+
'*.{js,jsx,ts,tsx,vue}': ['eslint --fix'],
|
|
47
|
+
'*.{json,css,scss,md}': ['prettier --write'],
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!packageJsonObj.scripts) {
|
|
52
|
+
packageJsonObj.scripts = {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
packageJsonObj.scripts = {
|
|
56
|
+
dev: 'vite --host',
|
|
57
|
+
'build:test': 'vite build --mode development',
|
|
58
|
+
'build:uat': 'vite build --mode uat',
|
|
59
|
+
'build:prod': 'vite build',
|
|
60
|
+
commit: 'git add . && git-cz && git push',
|
|
61
|
+
rimraf: 'rimraf ./node_modules/',
|
|
62
|
+
release: 'git add . && bumpp package.json --all --commit --no-tag --push',
|
|
63
|
+
...packageJsonObj.scripts,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fs.writeFileSync(path.resolve(cwd, './package.json'), `${JSON.stringify(packageJsonObj, null, 2)}\n`)
|
|
67
|
+
console.log('lint-staged 配置写入成功')
|