Skip to content

Commit

Permalink
Initial draft of release script (see PR #840)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow committed Jan 25, 2018
1 parent 7b7a73f commit f9eaf27
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 6 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"babel-preset-es2015": "latest",
"browser-sync": "^2.23.3",
"bundlesize": "^0.15.3",
"event-stream": "^3.3.4",
"execa": "^0.9.0",
"gulp": "latest",
"gulp-autoprefixer": "^4.1.0",
"gulp-clean-css": "^3.9.0",
Expand All @@ -28,6 +30,7 @@
"gulp-uglify": "latest",
"mkdirp": "~0.5.1",
"pify": "^3.0.0",
"rimraf": "^2.6.2",
"rollup": "^0.51.8",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-css-only": "^0.2.0",
Expand Down Expand Up @@ -74,7 +77,8 @@
"check": "npm run check:bundlesize && npm run check:tests && npm run check:ts",
"check:bundlesize": "bundlesize -f dist/sweetalert2.all.min.js -s 15kB",
"check:tests": "testem ci",
"check:ts": "tsc sweetalert2.d.ts"
"check:ts": "tsc sweetalert2.d.ts",
"release": "node release"
},
"bugs": "https://github.com/sweetalert2/sweetalert2/issues",
"license": "MIT"
Expand Down
74 changes: 74 additions & 0 deletions release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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, cleanWorkingTree} = await getGitStatus()
if (!dryRun) {
assert.equal(branchToPublish, 'master', 'Must be on master branch')
}
assert.equal(cleanWorkingTree, 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!')
})()
19 changes: 19 additions & 0 deletions utils/execute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const execa = require('execa')
const es = require('event-stream')

module.exports = function execute (command, {skipLogging} = {}) {
const proc = execa.shell(command)

if (!skipLogging) {
const formatLine = (line, label) => ` (pid:${proc.pid})\t[${label}]\t${line}\n`
const formatStream = (stream, label) => stream
.pipe(es.split())
.pipe(es.map((line, cb) => cb(null, formatLine(line, label))))

process.stdout.write(formatLine(command, 'cmd'))
es.merge(formatStream(proc.stdout, 'out'), formatStream(proc.stderr, 'ERR'))
.pipe(process.stdout)
}

return proc
}
16 changes: 16 additions & 0 deletions utils/get-git-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const execute = require('./execute')
const assert = require('assert')

async function getGitStatus () {
const lines = (await execute('git status')).stdout.split(/\r?\n/)

const match = lines[0].match(/^On branch (\S+)$/)
assert.ok(match, 'Unable to determine current branch')
const currentBranch = match[1]

const cleanWorkingTree = lines.includes('nothing to commit, working tree clean')

return {currentBranch, cleanWorkingTree}
}

module.exports = getGitStatus
8 changes: 8 additions & 0 deletions utils/get-git-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const execute = require('./execute')

async function getGitTags () {
const {stdout} = await execute('git tag', {skipLogging: true})
return stdout.split(/\r?\n/).filter(Boolean)
}

module.exports = getGitTags
82 changes: 77 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ cross-spawn@^3.0.0:
lru-cache "^4.0.1"
which "^1.2.9"

cross-spawn@^5.1.0:
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
dependencies:
Expand Down Expand Up @@ -1360,7 +1360,7 @@ duplexer2@0.0.2:
dependencies:
readable-stream "~1.1.9"

duplexer@^0.1.1:
duplexer@^0.1.1, duplexer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"

Expand Down Expand Up @@ -1719,6 +1719,18 @@ event-emitter@~0.3.5:
d "1"
es5-ext "~0.10.14"

event-stream@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.4.tgz#4ab4c9a0f5a54db9338b4c34d86bfce8f4b35571"
dependencies:
duplexer "~0.1.1"
from "~0"
map-stream "~0.1.0"
pause-stream "0.0.11"
split "0.3"
stream-combiner "~0.0.4"
through "~2.3.1"

eventemitter3@1.x.x:
version "1.2.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-1.2.0.tgz#1c86991d816ad1e504750e73874224ecf3bec508"
Expand All @@ -1727,6 +1739,18 @@ events-to-array@^1.0.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/events-to-array/-/events-to-array-1.1.2.tgz#2d41f563e1fe400ed4962fe1a4d5c6a7539df7f6"

execa@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.9.0.tgz#adb7ce62cf985071f60580deb4a88b9e34712d01"
dependencies:
cross-spawn "^5.0.1"
get-stream "^3.0.0"
is-stream "^1.1.0"
npm-run-path "^2.0.0"
p-finally "^1.0.0"
signal-exit "^3.0.0"
strip-eof "^1.0.0"

exit-hook@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8"
Expand Down Expand Up @@ -2041,6 +2065,10 @@ fresh@0.5.2, fresh@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"

from@~0:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"

front-matter@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/front-matter/-/front-matter-2.1.2.tgz#f75983b9f2f413be658c93dfd7bd8ce4078f5cdb"
Expand Down Expand Up @@ -2134,6 +2162,10 @@ get-stdin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"

get-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"

getpass@^0.1.1:
version "0.1.7"
resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"
Expand Down Expand Up @@ -2983,7 +3015,7 @@ is-resolvable@^1.0.0:
dependencies:
tryit "^1.0.1"

is-stream@^1.0.1:
is-stream@^1.0.1, is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"

Expand Down Expand Up @@ -3448,6 +3480,10 @@ map-stream@~0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.0.7.tgz#8a1f07896d82b10926bd3744a2420009f88974a8"

map-stream@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194"

math-clamp-x@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/math-clamp-x/-/math-clamp-x-1.2.0.tgz#8b537be0645bbba7ee73ee16091e7d6018c5edcf"
Expand Down Expand Up @@ -3754,6 +3790,12 @@ normalize-space-x@^3.0.0:
trim-x "^3.0.0"
white-space-x "^3.0.0"

npm-run-path@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
dependencies:
path-key "^2.0.0"

"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.0, npmlog@^4.0.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
Expand Down Expand Up @@ -3937,6 +3979,10 @@ osenv@0, osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"

p-limit@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc"
Expand Down Expand Up @@ -4027,6 +4073,10 @@ path-is-inside@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53"

path-key@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"

path-parse@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
Expand Down Expand Up @@ -4066,6 +4116,12 @@ path@^0.12.7:
process "^0.11.1"
util "^0.10.3"

pause-stream@0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445"
dependencies:
through "~2.3"

performance-now@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
Expand Down Expand Up @@ -4521,7 +4577,7 @@ restore-cursor@^2.0.0:
onetime "^2.0.0"
signal-exit "^3.0.2"

rimraf@2, rimraf@^2.2.8, rimraf@^2.4.4, rimraf@^2.5.1, rimraf@^2.6.1:
rimraf@2, rimraf@^2.2.8, rimraf@^2.4.4, rimraf@^2.5.1, rimraf@^2.6.1, rimraf@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
dependencies:
Expand Down Expand Up @@ -4908,6 +4964,12 @@ spdx-license-ids@^1.0.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57"

split@0.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f"
dependencies:
through "2"

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
Expand Down Expand Up @@ -4963,6 +5025,12 @@ stdout-stream@^1.4.0:
dependencies:
readable-stream "^2.0.1"

stream-combiner@~0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14"
dependencies:
duplexer "~0.1.1"

stream-consume@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/stream-consume/-/stream-consume-0.1.0.tgz#a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f"
Expand Down Expand Up @@ -5043,6 +5111,10 @@ strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"

strip-eof@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"

strip-indent@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"
Expand Down Expand Up @@ -5175,7 +5247,7 @@ through2@^0.6.0, through2@^0.6.1:
readable-stream ">=1.0.33-1 <1.1.0-0"
xtend ">=4.0.0 <4.1.0-0"

through@^2.3.6, through@~2.3.8:
through@2, through@^2.3.6, through@~2.3, through@~2.3.1, through@~2.3.8:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"

Expand Down

0 comments on commit f9eaf27

Please sign in to comment.