| 
				
			 | 
			
			
				@@ -8,6 +8,15 @@ const ONLY_ON_BRANCH = 'v2'; 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				8
			 | 
			
			
				 const VERSION_TAG = 'alpha'; 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				9
			 | 
			
			
				 const VERSION_INC = 'patch'; 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				10
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+function run() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+  // if (!validateEnv()) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+  //   return; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+  // } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+  // setupGit(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+  // createNpmRc(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+  versionTagAndPublish(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				20
			 | 
			
			
				 function validateEnv() { 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				21
			 | 
			
			
				   if (!process.env.CI || !process.env.TRAVIS) { 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				22
			 | 
			
			
				     throw new Error(`releasing is only available from Travis CI`); 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -35,55 +44,53 @@ function setupGit() { 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				44
			 | 
			
			
				   exec.execSync(`git checkout ${ONLY_ON_BRANCH}`); 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				45
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				46
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				38
			 | 
			
				
			 | 
			
			
				-function getNextVersion() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+function createNpmRc() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+  const content = ` 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+email=\${NPM_EMAIL} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+//registry.npmjs.org/:_authToken=\${NPM_TOKEN} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+`; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+  fs.writeFileSync(`.npmrc`, content); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+function versionTagAndPublish() { 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				56
			 | 
			
			
				   const packageVersion = semver.clean(process.env.npm_package_version); 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				57
			 | 
			
			
				   console.log(`package version: ${packageVersion}`); 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				
			 | 
			
			
				-  const current = exec.execSyncRead(`npm view ${process.env.npm_package_name} dist-tags.${VERSION_TAG}`); 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				
			 | 
			
			
				-  console.log(`current published version: ${current}`); 
			 | 
		
	
		
			
			| 
				43
			 | 
			
				58
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-  if (semver.gt(packageVersion, current)) { 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				
			 | 
			
			
				-    return packageVersion; 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				-  } else { 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				
			 | 
			
			
				-    return semver.inc(current, VERSION_INC); 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				
			 | 
			
			
				-  } 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+  const currentPublished = findCurrentPublishedVersion(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+  console.log(`current published version: ${currentPublished}`); 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				61
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-function calcNewVersion() { 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-  let candidate = getNextVersion(); 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				
			 | 
			
			
				-  while (isAlreadyPublished(candidate)) { 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				
			 | 
			
			
				-    console.log(`${candidate} already published`); 
			 | 
		
	
		
			
			| 
				55
			 | 
			
				
			 | 
			
			
				-    candidate = semver.inc(candidate, VERSION_INC); 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				
			 | 
			
			
				-  } 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				
			 | 
			
			
				-  return candidate; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+  const version = semver.gt(packageVersion, currentPublished) ? packageVersion : semver.inc(currentPublished, VERSION_INC); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+  tryPublishAndTag(version); 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				64
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				65
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				60
			 | 
			
				
			 | 
			
			
				-function isAlreadyPublished(version) { 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				
			 | 
			
			
				-  return exec.execSyncRead(`npm view ${process.env.npm_package_name}@${version} version`).length > 0; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+function findCurrentPublishedVersion() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+  return exec.execSyncRead(`npm view ${process.env.npm_package_name} dist-tags.${VERSION_TAG}`); 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				68
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				63
			 | 
			
				69
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				64
			 | 
			
				
			 | 
			
			
				-function createNpmRc() { 
			 | 
		
	
		
			
			| 
				65
			 | 
			
				
			 | 
			
			
				-  const content = ` 
			 | 
		
	
		
			
			| 
				66
			 | 
			
				
			 | 
			
			
				-email=\${NPM_EMAIL} 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				
			 | 
			
			
				-//registry.npmjs.org/:_authToken=\${NPM_TOKEN} 
			 | 
		
	
		
			
			| 
				68
			 | 
			
				
			 | 
			
			
				-`; 
			 | 
		
	
		
			
			| 
				69
			 | 
			
				
			 | 
			
			
				-  fs.writeFileSync(`.npmrc`, content); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+function tryPublishAndTag(version) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+  let theCandidate = version; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+  let retry = 0; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+  while (retry < 5) { //eslint-disable-line 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+    try { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+      tagAndPublish(theCandidate); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+      console.log(`Released ${theCandidate}`); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+      return; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+    } catch (e) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+      const alreadyPublished = _.includes(e.message, 'You cannot publish over the previously published version'); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+      if (!alreadyPublished) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+        throw e; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+      } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+      retry++; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+      theCandidate = semver.inc(theCandidate, VERSION_INC); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				87
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				88
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				72
			 | 
			
				89
			 | 
			
			
				 function tagAndPublish(newVersion) { 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				-  exec.execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				90
			 | 
			
			
				+  exec.execSync(`npm --no-git-tag-version version ${newVersion}`); 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				91
			 | 
			
			
				   exec.execSync(`npm publish --tag ${VERSION_TAG}`); 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				
			 | 
			
			
				-  exec.execSyncSilent(`git push deploy --tags || true`); 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				
			 | 
			
			
				-function run() { 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				-  if (!validateEnv()) { 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				
			 | 
			
			
				-    return; 
			 | 
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				-  } 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				
			 | 
			
			
				-  setupGit(); 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				
			 | 
			
			
				-  createNpmRc(); 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				
			 | 
			
			
				-  const newVersion = calcNewVersion(); 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				
			 | 
			
			
				-  console.log(`new version is: ${newVersion}`); 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				
			 | 
			
			
				-  tagAndPublish(newVersion); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+  exec.execSync(`git tag -a ${newVersion} -m "${newVersion}"`); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+  exec.execSyncSilent(`git push deploy ${newVersion} || true`); 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				94
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				95
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				89
			 | 
			
				96
			 | 
			
			
				 run(); 
			 |