This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·83 lines (76 loc) · 2.27 KB
/
cli.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
const cli = require('@ianwalter/cli')
const execa = require('execa')
const { print, md } = require('@ianwalter/print')
const semver = require('semver')
const { oneLine } = require('common-tags')
const latestVersion = require('latest-version')
const pkg = require('./package.json')
const { release } = require('.')
async function run () {
// Build the config.
const { packageJson, ...config } = cli({
name: 'release',
usage: 'release [options]',
options: {
version: {
alias: 'v'
},
branch: {
alias: 'b'
},
logLevel: {
alias: 'l',
default: 'info'
}
}
})
// Display a warning message if the current release version is outdated.
const latestReleaseVersion = await latestVersion('@ianwalter/release')
if (semver.lt(pkg.version, latestReleaseVersion)) {
process.stdout.write('\n')
print.warn(
'Warning!',
md(oneLine`
**The version of @ianwalter/release being used (\`${pkg.version}\`) is
outdated, you should probably update to \`${latestReleaseVersion}\`
before continuing to publish.**
`)
)
}
// Display the list of commits added since the last version was published.
process.stdout.write('\n')
config.isVersionZero = config.version === '0.0.0'
if (config.isVersionZero) {
await execa('commits', ['100'], { stdio: 'inherit' })
} else {
await execa('commits', [packageJson.version], { stdio: 'inherit' })
}
// If there was an argument passed to the command, attempt to use it as the
// new version number.
if (config._.length) {
const version = config._[0]
if (semver.valid(version) && version[0] !== 'v') {
if (semver.lt(version, packageJson.version)) {
print.warn(oneLine`
The specified version \`${version}\` is lower than the current
version \`${packageJson.version}>\`
`)
}
config.version = version
} else {
print.error(oneLine`
The specified version \`${version}\` is not a valid semantic version
`)
}
delete config._
}
await release({ packageJson, ...config })
}
run().catch(err => {
print.error(err)
const output = err.output || err.stdout || err.stderr
if (output) {
print.debug('Output', output)
}
})