Skip to content

Commit ff1898d

Browse files
committed
feat: add cwd setting in cli
resolve #63
1 parent 6f6e2af commit ff1898d

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

bin/mili

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
const program = require('commander')
3-
const { join } = require('path')
3+
const { join, resolve } = require('path')
44
const log = require('../src/utils/log')
55
const mili = require('../src/mili')
66
const { version } = require('../package.json')
@@ -9,6 +9,8 @@ const { version } = require('../package.json')
99
program
1010
.version(version)
1111

12+
const absolutize = val => resolve(val)
13+
1214
program
1315
.command('init [repository]')
1416
.usage('[options] <repository>')
@@ -17,16 +19,16 @@ program
1719
.option('--no-deps', 'Need not install dependencies', false)
1820
.option('--force')
1921
.option('-v --version [version]', 'Set the template version')
22+
.option('--cwd [cwd]', 'Set the current work directory', absolutize, process.cwd())
2023
.action((repository, option) => {
2124
if (!repository) program.help()
2225

23-
const { appName, force = false, deps = true } = option
26+
const { appName, force = false, deps = true, cwd } = option
2427

2528
let version
2629
if (typeof option.version === 'string') version = option.version
2730

28-
// return init(appName, repository, force, version)
29-
return mili.init({ name: appName, force, repository, version, noDeps: !deps })
31+
return mili.init({ cwd, name: appName, force, repository, version, noDeps: !deps })
3032
.then(() => log.info('initialize complete'))
3133
.catch(err => log.error('program', 'initialize break', err))
3234
})
@@ -43,12 +45,12 @@ program
4345
.option('--no-deps', 'Need not install dependencies', false)
4446
.option('-r, --recursive', 'Upgrade recursive all subfolder')
4547
.option('--ignore [file]', 'the folder need not search', collect, [])
48+
.option('--cwd [cwd]', 'Set the current work directory', absolutize, process.cwd())
4649
.action(option => {
47-
const { force = false, deps = true, recursive } = option
48-
const cwd = process.cwd()
50+
const { cwd, force = false, deps = true, recursive } = option
4951
const ignore = option.ignore.map(item => join(cwd, item))
5052

51-
mili.upgrade({ force, noDeps: !deps, recursive, ignore })
53+
mili.upgrade({ cwd, force, noDeps: !deps, recursive, ignore })
5254
.catch(err => log.error('program', 'upgrade break', err))
5355
})
5456

@@ -58,13 +60,14 @@ program
5860
.option('--force')
5961
.option('-v --version [version]', 'Set the template version')
6062
.option('--no-deps', 'Need not install dependencies', false)
63+
.option('--cwd [cwd]', 'Set the current work directory', absolutize, process.cwd())
6164
.action(option => {
62-
const { force = false, deps = true } = option
65+
const { cwd, force = false, deps = true } = option
6366

6467
let version
6568
if (typeof option.version === 'string') version = option.version
6669

67-
mili.update({ force, version, noDeps: !deps })
70+
mili.update({ cwd, force, version, noDeps: !deps })
6871
.then(() => log.info('update complete'))
6972
.catch(err => log.error('program', 'update break', err))
7073
})

src/commands/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = async(options = {}) => {
1616
const noDeps = options.noDeps
1717
let version = options.version
1818

19-
if (!options.force) await securityCheck(process.cwd())
19+
if (!options.force) await securityCheck(cwd)
2020
if (version) checkParams.version(version)
2121

2222
let config = await loadConfig({

src/commands/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = async options => {
2121
// template version expected
2222
let version = options.version
2323

24-
if (!force) await securityCheck(process.cwd())
24+
if (!force) await securityCheck(cwd)
2525
if (version) checkParams.version(version)
2626

2727
let config = await loadConfig({ cwd, operation: 'update' })

src/commands/upgrade/upgrade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = async(options = {}) => {
1717
noDeps = false,
1818
} = options
1919

20-
if (!force) await securityCheck(process.cwd())
20+
if (!force) await securityCheck(cwd)
2121
let config = await loadConfig({ cwd, operation: 'upgrade' })
2222

2323

0 commit comments

Comments
 (0)