Skip to content

Commit de87d2d

Browse files
committed
feat: add template control option
resolve #21
1 parent dd4d6cc commit de87d2d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

bin/init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ const git = require('simple-git/promise')
1717
const statusCheck = require('../src/statusCheck')
1818

1919

20-
module.exports = async (name, repository, force) => {
20+
module.exports = async (name, repository, force, version) => {
2121
if (!force) await statusCheck(process.cwd())
2222

2323
// const miliConfig = await loadMiliConfig()
24-
const { templatePath: templateProjectPath, currentBranch } = await cloneRepository(repository)
24+
const { templatePath: templateProjectPath, currentBranch } = await cloneRepository(repository, version)
2525
try {
2626
const templateConfig = await loadTemplateConfig(templateProjectPath)
2727
const templatePath = join(templateProjectPath, templateConfig.path)

bin/mili

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ program
1717
.description('initialize the project')
1818
.option('-n --app-name [app_name]', `Set your app name.`)
1919
.option('--force')
20+
.option('-v --version [version]', 'Set the template version')
2021
.action((repository, option) => {
2122
if (!repository) program.help()
2223

2324
const { appName, force = false } = option
2425

25-
return init(appName, repository, force)
26+
let version
27+
if (typeof option.version === 'string') version = option.version
28+
29+
return init(appName, repository, force, version)
2630
.then(() => log.info('initialize complete'))
2731
.catch(err => log.error('program', 'initialize break', err))
2832
})
@@ -43,10 +47,14 @@ program
4347
.command('update')
4448
.description('Update the project with the current version of the template')
4549
.option('--force')
50+
.option('-v --version [version]', 'Set the template version')
4651
.action((option) => {
4752
const { force = false } = option
4853

49-
update(force)
54+
let version
55+
if (typeof option.version === 'string') version = option.version
56+
57+
update(force, version)
5058
.then(() => log.info('update complete'))
5159
.catch(err => log.error('program', 'update break', err))
5260
})

bin/update

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ const log = require('../src/log')
1515
const { join, basename } = require('path')
1616
const git = require('simple-git/promise')
1717
const statusCheck = require('../src/statusCheck')
18+
const semver = require('semver')
19+
const throwError = require('../src/throwError')
1820

1921

20-
module.exports = async (force) => {
22+
module.exports = async (force, version) => {
2123
if (!force) await statusCheck(process.cwd())
2224

2325
const miliConfig = await loadMiliConfig()
2426
const repository = miliConfig.repository
2527

28+
if (!force && version && semver.lt(version, miliConfig.version)) {
29+
throwError([
30+
'The version number setted is lower than the current template version.',
31+
"If you're sure you want to run this command, rerun it with --force.",
32+
].join('\n'))
33+
}
34+
2635
const { templatePath: templateProjectPath, currentBranch } = await cloneRepository(repository, miliConfig.version)
2736
try {
2837
const templateConfig = await loadTemplateConfig(templateProjectPath)

0 commit comments

Comments
 (0)