Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-vers

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-vers - npm Package Compare versions

Comparing version 0.1.0 to 0.3.0

src/global.js

4

package.json
{
"name": "auto-vers",
"version": "0.1.0",
"version": "0.3.0",
"description": "",

@@ -15,2 +15,3 @@ "main": "./dist/index.js",

"beta": "npm run build && ./bin/auto-vers -i prerelease",
"tip": "./bin/auto-vers -t",
"test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha && ./node_modules/.bin/codecov"

@@ -39,2 +40,3 @@ },

"codecov": "^3.1.0",
"inquirer-test": "^2.0.1",
"istanbul": "^0.4.5",

@@ -41,0 +43,0 @@ "mocha": "^5.2.0"

@@ -39,3 +39,3 @@ # auto-vers

bash
bash
```

@@ -57,6 +57,14 @@ ./bin/auto-vers -i

```
-i --increment [<level>]
auto-vers 0.2.0
Auto update version for your application
Usage: auto-vers [options] <version> [[...]]
Options
-v --version <version>
Can change version directly.
-i --inc --increment [<level>]
Increment a version by the specified level. Level can
be one of: major, minor, patch or prerelease.
Default level is 'patch'.
be one of: major, minor, patch, premajor, preminor
, prepatch or prerelease. Default level is 'patch'.
Only one version may be specified.

@@ -66,4 +74,7 @@ -e --extra [<value>]

Such as 'beta','alpha'
-c --confirm
Do not update the version directly, you can confirm.
This is a safe mode.
-t --tip
Do not update the version directly, you can confirm.
Provide choice to you.
```

@@ -105,2 +116,3 @@

{
version?: <version>,
type: major | minor | patch | prerelease,

@@ -124,2 +136,6 @@ url?: package.json's url,

open the tip(-t --tip), this is a safe way to update.
![](https://s3.qiufengh.com/github/auto-ver.png)
# License

@@ -126,0 +142,0 @@

const semver = require('semver');
const colors = require('colors');
const { prompt } = require('enquirer');
const { prompt, Select } = require('enquirer');
const global = require('./global');
const {pkgRead, pkgUpdate} = require('./pkg');
function autoVersion({type, extra, url, confirm}) {
const {version, text} = updateVersion({type, extra, url});
function autoVersion({version, type, extra, url, confirm, tip}) {
if(version) {
pkgUpdate(url, Object.assign(pkgRead(url), {version}));
return version;
}
if(tip) {
const [list, preList] = tipToUpdate({extra, url});
const prompt = new Select({
name: 'version',
message: 'Update to version',
choices: list
});
prompt.run()
.then(answer => {
if(answer === 'prerelease') {
const prerPompt = new Select({
name: 'pre-version',
message: 'Update to pre-version',
choices: preList
})
prerPompt.run()
.then(res => {
pkgUpdate(url, Object.assign(pkgRead(url), {version: res}));
})
.catch(console.error);
} else {
pkgUpdate(url, Object.assign(pkgRead(url), {version: answer}));
}
})
.catch(console.error);
return;
}
const {oldVer, newVer} = updateVersion({type, extra, url});
const text = `version will update ${oldVer} -> ${newVer}`.red;
if(confirm) {

@@ -19,3 +53,3 @@ const question = {

if(answer.progress) {
pkgUpdate(url, Object.assign(pkgRead(url), {version}));
pkgUpdate(url, Object.assign(pkgRead(url), {version: newVer}));
} else {

@@ -28,11 +62,58 @@ console.log('cancel');

console.log(text);
pkgUpdate(url, Object.assign(pkgRead(url), {version}));
pkgUpdate(url, Object.assign(pkgRead(url), {version: newVer}));
}
return version;
return newVer;
}
function tipType(type, oldVer, newVer) {
let text = '';
switch (type) {
case 'major':
case 'minor':
case 'patch':
case 'premajor':
case 'preminor':
case 'prepatch':
case 'prerelease':
text = `[${type}] ${global[type.toUpperCase()]}`;
break;
default:
return 'prerelease';
}
return `${text}(${oldVer} -> ${newVer})`
}
function tipToUpdate({extra, url}) {
const oldVer = getCurrentVersion(url);
const list = [];
const preList = [];
const major = getNewVersion(oldVer, 'major', extra);
const minor = getNewVersion(oldVer, 'minor', extra);
const patch = getNewVersion(oldVer, 'patch', extra);
const arr = [['patch', patch], ['minor', minor], ['major', major], ['preRelease', 'prerelease']].map(item => {
return {
message: tipType(item[0], oldVer, item[1]),
value: item[1]
}
});
list.push(...arr);
const premajor = getNewVersion(oldVer, 'premajor', extra);
const preminor = getNewVersion(oldVer, 'preminor', extra);
const prepatch = getNewVersion(oldVer, 'prepatch', extra);
const prerelease = getNewVersion(oldVer, 'prerelease', extra);
const preArr = [['premajor', premajor], ['preminor', preminor], ['prepatch', prepatch], ['prerelease', prerelease]].map(item => {
return {
message: tipType(item[0], oldVer, item[1]),
value: item[1]
}
});
preList.push(...preArr);
return [list, preList];
}
function updateVersion({type, extra, url, version}) {
const oldVer = getCurrentVersion(url);
let newVer = version ? version : getNewVersion(oldVer, type, extra);
return {version: newVer, text: `version will update ${oldVer} -> ${newVer}`.red};
return {oldVer, newVer};
}

@@ -52,2 +133,6 @@

newVersion = semver.inc(oldVersion, type);
break;
case 'premajor':
case 'preminor':
case 'prepatch':
case 'prerelease':

@@ -57,4 +142,4 @@ if(extra) {

} else {
if(!semver.prerelease(oldVersion)) {
extra = 'bata';
if(!semver.prerelease(oldVersion) || type !== 'prerelease') {
extra = 'bata'
newVersion = semver.inc(oldVersion, type, extra);

@@ -72,2 +157,7 @@ } else {

module.exports = autoVersion;
module.exports = {
autoVersion,
getNewVersion,
getCurrentVersion,
tipToUpdate
};

@@ -1,3 +0,3 @@

const autoVers = require('./auto-vers');
const {autoVersion} = require('./auto-vers');
module.exports = autoVers;
module.exports = autoVersion;
const path = require('path');
const assert = require('chai').assert;
const autoVersion = require('../src/auto-vers');
const {autoVersion, tipToUpdate} = require('../src/auto-vers');
const global = require('../src/global');
const {pkgUpdate, pkgRead} = require('../src/pkg');

@@ -83,2 +84,11 @@

})
it('tip type text', () => {
const curPath = path.join(__dirname, './package.json');
const result = tipToUpdate({url: curPath});
const expect = `[[{"message":"[patch] ${global.PATCH}(1.0.0 -> 1.0.1)","value":"1.0.1"},{"message":"[minor] ${global.MINOR}(1.0.0 -> 1.1.0)","value":"1.1.0"},{"message":"[major] ${global.MAJOR}(1.0.0 -> 2.0.0)","value":"2.0.0"},{"message":"prerelease","value":"prerelease"}],[{"message":"[premajor] ${global.PREMAJOR}(1.0.0 -> 2.0.0-bata.0)","value":"2.0.0-bata.0"},{"message":"[preminor] ${global.PREMINOR}(1.0.0 -> 1.1.0-bata.0)","value":"1.1.0-bata.0"},{"message":"[prepatch] ${global.PREPATCH}(1.0.0 -> 1.0.1-bata.0)","value":"1.0.1-bata.0"},{"message":"[prerelease] ${global.PRERELEASE}(1.0.0 -> 1.0.1-bata.0)","value":"1.0.1-bata.0"}]]`;
assert.equal(JSON.stringify(result), expect);
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc