This repository was archived by the owner on Aug 13, 2021. It is now read-only.
forked from sweetalert2/sweetalert2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
74 lines (58 loc) · 2.29 KB
/
Copy pathrelease.js
File metadata and controls
74 lines (58 loc) · 2.29 KB
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
const pify = require('pify')
const rimraf = require('rimraf')
const fs = require('fs')
const assert = require('assert')
const getGitStatus = require('./utils/get-git-status')
const getGitTags = require('./utils/get-git-tags')
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 {version} = require('./package.json')
;(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')
const gitTags = await getGitTags()
assert.ok(!gitTags.includes(`v${version}`), 'Must have a unique version in package.json')
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(`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...')
await execute('git push origin dist:dist --tags')
}
log(`Switching back to "${branchToPublish}" (so you can continue to work)...`)
await execute(`git checkout "${branchToPublish}"`)
log('OK!')
})().catch(console.error)