forked from sweetalert2/sweetalert2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
86 lines (65 loc) · 2.71 KB
/
release.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
84
85
86
const pify = require('pify')
const rimraf = require('rimraf')
const fs = require('fs')
const assert = require('assert')
const getGitStatus = require('./utils/get-git-status')
const execute = require('./utils/execute')
const log = console.log
const removeDir = pify(rimraf)
const readFile = pify(fs.readFile)
const writeFile = pify(fs.writeFile)
const dryRun = process.argv.includes('--dry-run')
const semver = process.argv[2]
assert.ok(['patch', 'minor', 'major'].includes(semver), 'Must specify the valid semver version: patch | minor | major')
;(async () => {
log('Doing sanity checks...')
const {currentBranch: branchToPublish, isCleanWorkingTree} = await getGitStatus()
if (!dryRun) {
assert.equal(branchToPublish, 'master', 'Must be on master branch')
}
assert.equal(isCleanWorkingTree, true, 'Must have clean working tree')
log(`Pulling the latest ${branchToPublish} branch from Github...`)
await execute('git pull origin')
log(`Running npm version ${semver}...`)
await execute(`npm version --no-git-tag-version ${semver}`)
const {version} = require('./package.json')
log(`Making a version change commit...`)
await execute(`git add package.json && git commit -m "${version}"`)
log('Deleting the dist folder (it will conflict with the next step)...')
await removeDir('dist')
log('Switching to the dist branch...')
await execute('git checkout dist')
log('Pulling the latest dist branch from Github...')
await execute('git pull origin')
log(`Merging from "${branchToPublish}" branch...`)
await execute(`git merge ${branchToPublish}`)
log('Running the build...')
await execute('npm run build')
log('Running the checks...')
await execute('npm run check')
if (dryRun) {
log('Skipping publishing on npm...')
} else {
log('Publishing on npm...')
await execute('npm publish')
}
log('Removing "dist" from .gitignore...')
const gitignore = await readFile('.gitignore', 'utf8')
const gitignoreWithoutDist = gitignore.split(/\r?\n/).filter(line => line !== 'dist').join('\n')
await writeFile('.gitignore', gitignoreWithoutDist)
log('Committing the dist dir...')
await execute(`git add dist/ && git commit -m "Release v${version}"`)
log('Reverting the change to .gitignore...')
await execute('git reset --hard HEAD')
log(`Tagging commit as "v${version}"...`)
await execute(`git tag "v${version}"`)
if (dryRun) {
log('Skipping pushing to Github...')
} else {
log('Pushing to Github both master and dist branches...')
await execute('git push origin master:master dist:dist --tags')
}
log(`Switching back to "${branchToPublish}" (so you can continue to work)...`)
await execute(`git checkout "${branchToPublish}"`)
log('OK!')
})().catch(console.error)