forked from Martin0809/poseidon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
66 lines (60 loc) · 1.55 KB
/
plopfile.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
64
65
66
const fs = require('fs')
const path = require('path')
const SYMBOL = {
caret: '^',
tilde: '~',
exact: ''
}
module.exports = plop => {
plop.setGenerator('upgrade', {
description: '批量修改组建中依赖版本',
prompts: [
{
type: 'input',
name: 'name',
message: '请输入要修改的依赖包名称',
default: 'react'
},
{
type: 'input',
name: 'version',
message: '请输入要修改版本号',
validate: input => {
if (/^\d+(\.\d+){2}.*$/.test(input)) {
return true
}
return '请输入正确的版本号,如:12.1.9'
}
},
{
type: 'list',
name: 'symbol',
message: '请选择版本号前缀',
choices: [
{ name: 'caret', value: 'caret' },
{ name: 'tilde', value: 'tilde' },
{ name: 'exact', value: 'exact' }
]
}
],
actions: data => {
const symbol = SYMBOL[data.symbol]
const files = []
const dir = './packages'
const dirs = fs.readdirSync(dir)
dirs.forEach(item => {
const resolvePath = path.resolve(dir, item)
const stat = fs.statSync(resolvePath)
if (stat.isDirectory()) files.push(path.join(dir, item, 'package.json'))
})
return files.map(item => {
return {
type: 'modify',
path: item,
pattern: new RegExp(`"${data.name}": ".+"`),
template: `"{{name}}": "${symbol}{{version}}"`
}
})
}
})
}