-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-cz.js
55 lines (48 loc) · 1.27 KB
/
run-cz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @file mycz
* @author Cuttle Cong
* @date 2018/10/11
*
*/
const nps = require('path')
const fs = require('fs')
const inquirer = require('inquirer')
const exampleRoot = nps.join(__dirname, 'examples')
const choices = fs
.readdirSync(exampleRoot)
.filter(name => fs.statSync(nps.join(exampleRoot, name)).isDirectory())
const which = process.argv[2]
let p = () => Promise.resolve(which)
if (!choices.includes(which)) {
p = () =>
inquirer
.prompt([
{
type: 'list',
name: 'which',
message: 'please select an example',
choices
}
])
.then(({ which }) => {
return which
})
}
p()
.then(which => {
const examplePath = nps.join(exampleRoot, which)
process.chdir(examplePath)
const { getPackageJsonConfigs } = require('./lib/utils')
const engine = require('./lib/engine')
const cz = engine({
gitRemoteUrl: require(nps.join(examplePath, 'gitRemoteUrl')),
pkg: getPackageJsonConfigs(examplePath)
})
return cz.prompter(inquirer, function(msg, options) {
console.log('\n------------ OUTPUT --------------')
console.log(msg)
console.log('----------------------------------')
console.log(options)
})
})
.catch(console.error)