Skip to content

Commit bf52e6d

Browse files
committed
feat: use glob to match rule.path
resolve #23
1 parent d29af77 commit bf52e6d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"cosmiconfig": "^5.0.6",
4949
"fs-extra": "^7.0.0",
5050
"merge-deep": "^3.0.2",
51+
"micromatch": "^3.1.10",
5152
"mustache": "^3.0.0",
5253
"sanitization": "^0.3.0",
5354
"semver": "^5.6.0",

src/genFileList/genDirList.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { flatten } = require('../utils')
22
const throwError = require('../throwError')
33
const fs = require('fs-extra')
44
const { join } = require('path')
5+
var glob = require('micromatch');
56

67

78
const genDirList = async (dir, rules) => {
@@ -15,7 +16,10 @@ const genDirList = async (dir, rules) => {
1516
const path = join(dir.path, filename)
1617
const stats = await fs.stat(path)
1718

18-
let rule = rules.find(item => item.path === path)
19+
let rule = rules.find(item => {
20+
if (item.glob) return glob.isMatch(path, item.path)
21+
return item.path === path
22+
})
1923
if (!rule) rule = { ...dir, path }
2024

2125
if (stats.isDirectory()) return await genDirList(rule, rules)

src/loadTemplateConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const checkConfig = sa.keys({
3636
rules: sa.each({
3737
path: sa.string.required,
3838
upgrade: sa.valid(['cover', 'keep', 'exist', 'merge']),
39+
glob: sa.bool.defaulted(true),
3940
handler: sa.any,
4041
handlers: sa.array,
4142
}),

0 commit comments

Comments
 (0)