forked from samizdatco/skia-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
47 lines (42 loc) · 1.29 KB
/
publish.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
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const util = require('util')
const execAsync = util.promisify(childProcess.exec)
const readFileAsync = util.promisify(fs.readFile)
const commitMessage = process.env.CI_COMMIT_MESSAGE
const branchName = process.env.CI_COMMIT_REF_NAME
console.log(`commitMessage: ${commitMessage}`)
console.log(`branchName: ${branchName}`)
if (
!commitMessage ||
!commitMessage.includes(`chore(release): publish`) ||
(branchName !== 'master' && !branchName.startsWith('release/'))
) {
console.log(`publish skipped.`)
process.exit()
}
const main = async () => {
const buffer = await readFileAsync(path.resolve(__dirname, 'package.json'))
const pkg = JSON.parse(buffer.toString())
let versions
try {
versions = (await execAsync(`npm view ${pkg.name} versions`)).stdout
} catch (error) {
if (typeof error.message === 'string' && error.message.includes('404 Not Found')) {
versions = ''
} else {
console.error(error)
process.exit(1)
}
}
const version = pkg.version
if (!versions.includes(`'${version}'`)) {
console.log(`publishing ${pkg.name}@${version} to @arkie npm...`)
await execAsync(`npm publish`)
}
}
main().catch((e) => {
console.error(e)
process.exit(1)
})