Skip to content

Commit 33bd1df

Browse files
committed
feat: check template engines and throw error
1 parent a1e18e0 commit 33bd1df

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/check-params.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const semver = require('semver')
2+
const throwError = require('./utils/throw-error')
23

34

45
module.exports = {
@@ -10,5 +11,13 @@ module.exports = {
1011
'Semantic Versioning: https://semver.org',
1112
].join('\n'))
1213
}
14+
},
15+
engine: config => {
16+
if (!semver.satisfies(config.mili.version, config.template.engines)) {
17+
throwError([
18+
`The mili version template need is ${config.template.engines}`,
19+
`But mili version used is ${config.mili.version}`
20+
].join('\n'))
21+
}
1322
}
1423
}

src/commands/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ module.exports = async (options = {}) => {
4545
templateVersion: version,
4646
})
4747

48+
checkParams.engine(config)
49+
4850
if (config.template.status !== 'loaded') {
4951
throwError([
5052
'The template configuration file could not be loaded',

src/commands/update.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = async (options) => {
8383
config = await config.reload({
8484
templateVersion: version,
8585
})
86+
checkParams.engine(config)
8687

8788
await prompt(config)
8889
config.template.files = config.template.files.filter(file => file.upgrade !== 'keep')

src/commands/upgrade.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = async (options = {}) => {
3232
config = await config.reload({
3333
templateVersion: version,
3434
})
35+
checkParams.engine(config)
3536

3637
await prompt(config)
3738
config.template.files = config.template.files.filter(file => file.upgrade !== 'keep')

0 commit comments

Comments
 (0)