Skip to content

Commit e707f67

Browse files
committed
feat(command): new command used to check template is outdated
resolve #38
1 parent 22ccbfb commit e707f67

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

bin/mili

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ program
6767
.catch(err => log.error('clean', 'clean break', err))
6868
})
6969

70+
program
71+
.command('outdated')
72+
.description('Check template is outdated')
73+
.action(() => {
74+
mili.outdated()
75+
})
76+
7077

7178
// error on unknown commands
7279
program.on('command:*', function () {

src/commands/outdated.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const loadMiliConfig = require('../loadMiliConfig')
2+
const semver = require('semver')
3+
const log = require('../log')
4+
const throwError = require('../throwError')
5+
const getTemplateVersions = require('../getTemplateVersions')
6+
7+
8+
module.exports = async () => {
9+
const miliConfig = await loadMiliConfig()
10+
const repository = miliConfig.repository
11+
12+
const versions = await getTemplateVersions(repository)
13+
14+
if (semver.valid(miliConfig.version) && semver.lt(miliConfig.version, versions[0].version)) {
15+
log.warn([
16+
'',
17+
'',
18+
'Project Mili Template Is Outdated',
19+
'run `npx mili upgrade` to upgrade template',
20+
'',
21+
'',
22+
].join('\n'))
23+
}
24+
}

src/getTemplateVersions.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const git = require('simple-git/promise')
2+
const semver = require('semver')
3+
4+
5+
6+
module.exports = async (repository) => {
7+
const result = await git().listRemote(['--tags', repository])
8+
const arr = result.split('\n')
9+
return arr
10+
.filter(item => item.length && !/\^{}$/.test(item))
11+
.map(item => {
12+
const [commit, ref] = item.split(/\s+/)
13+
const version = ref.substring('refs/tags/v'.length)
14+
return { commit, ref, version }
15+
})
16+
.filter(item => semver.valid(item.version))
17+
.sort((a, b) => semver.lt(a.version, b.version) ? 1 : -1)
18+
}

src/mili.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ const init = require('./commands/init')
22
const upgrade = require('./commands/upgrade')
33
const update = require('./commands/update')
44
const clean = require('./commands/clean')
5+
const outdated = require('./commands/outdated')
56

67
module.exports = {
78
init,
89
upgrade,
910
update,
1011
clean,
12+
outdated,
1113
}

0 commit comments

Comments
 (0)