Skip to content

Commit b94cd59

Browse files
committed
feat: check the mili version of template
resolve #30
1 parent e732e4a commit b94cd59

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/loadTemplateConfig.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const throwError = require('./throwError')
88
const paths = require('./paths')
99
const sa = require('sanitization')
1010
const semver = require('semver')
11+
const { version: miliVersion } = require('../package.json')
1112

1213

1314
// const readdir = promisify(fs.readdir)
@@ -68,6 +69,24 @@ module.exports = async templatePath => {
6869
throwError('Template configuration error')
6970
}
7071

72+
if (config.engines && semver.validRange(config.engines)) {
73+
if (!semver.satisfies(miliVersion, config.engines)) {
74+
if (semver.ltr(miliVersion, config.engines)) {
75+
throwError([
76+
'Your mili version is lower than the minimum version required by the template.',
77+
'Please upgrade the mili version first.',
78+
`Mili version range:${config.engines}`,
79+
].join('\n'))
80+
} else {
81+
throwError([
82+
'Your mili version is higher than the maximum version required by the template.',
83+
'Please downgrade the mili version first.',
84+
`Mili version range:${config.engines}`,
85+
].join('\n'))
86+
}
87+
}
88+
}
89+
7190
config.rules = config.rules
7291
.map(rule => {
7392
rule.path = join(templatePath, config.path, rule.path)

0 commit comments

Comments
 (0)