npm-update
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -1,86 +0,7 @@ | ||
/* ================================================================ | ||
* npm-update by xdf(xudafeng[at]126.com) | ||
* | ||
* first created at : Tue Aug 04 2015 11:20:24 GMT+0800 (CST) | ||
* | ||
* ================================================================ | ||
* Copyright xdf | ||
* | ||
* Licensed under the MIT License | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* ================================================================ */ | ||
'use strict'; | ||
var util = require('util'); | ||
var path = require('path'); | ||
var logger = require('xlogger'); | ||
var TYPES = ['log', 'info', 'debug', 'warn', 'error']; | ||
var COLORS = ['\u001b[32m', '\u001b[36m', '\u001b[37m', '\u001b[33m', '\u001b[31m']; | ||
var logger = {}; | ||
function format(msg, data, type) { | ||
var res = msg[0]; | ||
if (msg.length === 1) { | ||
return '>> ' + data.file + ':' + data.line + ':' + data.pos + ' ' + res; | ||
} | ||
var match = res.match(new RegExp('%s|%d|%j', 'g')); | ||
if (match) { | ||
match.forEach(function(type, index) { | ||
var content = msg[index + 1]; | ||
if (!content) { | ||
res += type; | ||
} else if (type === '%s') { | ||
res = res.replace(new RegExp('%s', 'i'), String(content)); | ||
} else if (type === '%d') { | ||
res = res.replace(new RegExp('%d', 'i'), Number(content)); | ||
} else if (type === '%j') { | ||
res = res.replace(new RegExp('%j', 'i'), util.inspect(content, {showHidden: true, depth: null})); | ||
} | ||
}); | ||
var num = msg.length - match.length - 1; | ||
if (num > 0) { | ||
while (num --) { | ||
res += ' ' + msg[msg.length - num - 1]; | ||
} | ||
} | ||
} | ||
if (type !== 'info') { | ||
res = data.file + ':' + data.line + ':' + data.pos + ' ' + res; | ||
} | ||
res = '>> ' + res; | ||
return res; | ||
} | ||
TYPES.forEach(function(type, k) { | ||
logger[type] = function() { | ||
var debug = type === 'debug'; | ||
if (!debug) { | ||
return; | ||
} | ||
var stack = (new Error()).stack.split('\n'); | ||
var reg = new RegExp('at\\s+(.*)\\s+\\((.*):(\\d*):(\\d*)\\)', 'g'); | ||
var reg2 = new RegExp('at\\s+()(.*):(\\d*):(\\d*)', 'g'); | ||
var arr = reg.exec(stack[2]) || reg2.exec(stack[2]); | ||
var data = {}; | ||
data.path = arr[2]; | ||
data.line = arr[3]; | ||
data.pos = arr[4]; | ||
data.file = path.basename(data.path); | ||
data.stack = stack.join('\n'); | ||
console.info(COLORS[k] + TYPES[k].toUpperCase() + ' ' + format(arguments, data, type) + '\u001b[0m'); | ||
if (type === 'error') { | ||
throw new Error(data); | ||
} | ||
}; | ||
module.exports = logger.Logger({ | ||
closeFile: true | ||
}); | ||
module.exports = logger; |
@@ -19,8 +19,9 @@ /* ================================================================ | ||
module.exports = function *(options) { | ||
var pkg = options.pkg; | ||
var pkg = options.pkg || {}; | ||
var callback = options.callback; | ||
var name = pkg.name || options.name; | ||
var protocol = options.protocol || 'http'; | ||
var opt = { | ||
uri: protocol + '://registry.npmjs.org/' + pkg.name + '/latest', | ||
uri: protocol + '://registry.npmjs.org/' + name + '/latest', | ||
method: 'get', | ||
@@ -27,0 +28,0 @@ timeout: options.timeout || 1000 |
{ | ||
"name": "npm-update", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "npm-update", | ||
"keywords": ["npm-update"], | ||
"keywords": [ | ||
"npm-update" | ||
], | ||
"bin": { | ||
@@ -15,10 +17,13 @@ "npm-update": "./bin/npm-update" | ||
"dependencies": { | ||
"co-request": "~0.2.0" | ||
"co-request": "~0.2.0", | ||
"xlogger": "~1.0.0" | ||
}, | ||
"devDependencies": { | ||
"co": "^4.6.0", | ||
"co-mocha": "^1.1.3", | ||
"istanbul": "*", | ||
"jshint": "*", | ||
"mocha": "*", | ||
"should": "*", | ||
"jshint": "*", | ||
"istanbul": "*", | ||
"pre-commit": "1.1.1" | ||
"pre-commit": "1.1.1", | ||
"should": "*" | ||
}, | ||
@@ -25,0 +30,0 @@ "scripts": { |
@@ -1,3 +0,2 @@ | ||
npm-update | ||
==== | ||
# npm-update | ||
@@ -21,7 +20,7 @@ [![NPM version][npm-image]][npm-url] | ||
> npm-update | ||
> npm update | ||
## Installment | ||
```bash | ||
```shell | ||
$ npm i npm-update --save | ||
@@ -32,3 +31,3 @@ ``` | ||
```js | ||
```javascript | ||
var update = require('npm-update'); | ||
@@ -35,0 +34,0 @@ var pkg = require('../package'); |
@@ -16,5 +16,53 @@ /* ================================================================ | ||
var npm-update = require('../'); | ||
var update = require('../lib/npm-update'); | ||
var co = require('co'); | ||
describe('test', function(){ | ||
var pkg = { | ||
name: 'npm-update' | ||
}; | ||
describe('#npm-update', function() { | ||
this.timeout(50000); | ||
it('only pkg', function(done) { | ||
co(update, { | ||
pkg: pkg, | ||
callback: function(err, data) { | ||
data.name.should.be.eql(pkg.name); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('only name', function(done) { | ||
co(update, { | ||
name: pkg.name, | ||
callback: function(err, data) { | ||
data.name.should.be.eql(pkg.name); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('pkg.name and name are same', function(done) { | ||
co(update, { | ||
pkg: pkg, | ||
name: pkg.name, | ||
callback: function(err, data) { | ||
data.name.should.be.eql(pkg.name); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('pkg.name and name are different', function(done) { | ||
co(update, { | ||
pkg: 'express', | ||
name: 'koa', | ||
callback: function(err, data) { | ||
data.name.should.be.eql('koa'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7628
2
7
139
46
+ Addedxlogger@~1.0.0
+ Addedaddress@1.2.2(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.13.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchalk@1.1.32.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcopy-paste@1.5.3(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddetect-port@1.6.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedipv4@1.0.4(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-wsl@1.1.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedmoment@2.24.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedopn@5.5.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedshelljs@0.8.5(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.05.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxlogger@1.0.6(transitive)
+ Addedxutil@1.0.12(transitive)