From 9acff4c7e0b6afc0f727167c88045978e284faa0 Mon Sep 17 00:00:00 2001 From: "tianxiang.wly" Date: Sun, 10 Jan 2016 19:34:16 +0800 Subject: [PATCH] :smile: --- README.md | 20 +++++++++++++++++++- index.js | 4 ++-- test/test.js | 14 +++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fd98ac7..5a97b3b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![License](http://img.shields.io/npm/l/check-taggable.svg?style=flat-square)](LICENSE) [![npm download](https://img.shields.io/npm/dm/check-taggable.svg?style=flat-square)](https://npmjs.org/package/check-taggable) -Check whether the tag can be used +> Check whether the tag can be used ## Installation @@ -19,6 +19,24 @@ $ npm install --save check-taggable ## Usage +Promise check(tag[, cwd]) + +```javascript +const checker = require('check-taggable'); +checker('publish/sometag', '/Users/xxx/project_dir') // default process.cwd() + .then(result => { + /* + result = { + // check result + success: true|false + } + */ + if(result.success) + console.log('Passed'); + }) + .catch(e => console.error(e.message)); +``` + ## Test ```bash diff --git a/index.js b/index.js index 0aa9b04..6edeee6 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,8 @@ const co = require('co'); module.exports = co.wrap(function*(tag, cwd) { cwd = cwd || process.cwd(); - if (typeof tag !== 'string') throw Promise.reject(new TypeError('Expected tag to be a string')); - if (typeof cwd !== 'string') throw Promise.reject(new TypeError('Expected cwd to be a string')); + if (typeof tag !== 'string') return Promise.reject(new TypeError('Expected tag to be a string')); + if (typeof cwd !== 'string') return Promise.reject(new TypeError('Expected cwd to be a string')); let cmdRst = ''; try { cmdRst = execSync('git tag', { diff --git a/test/test.js b/test/test.js index deea854..b19c154 100644 --- a/test/test.js +++ b/test/test.js @@ -2,8 +2,6 @@ require('should'); const checker = require('../index'); -const fs = require('fs'); -const path = require('path'); const os = require('os'); const execSync = require('child_process').execSync; @@ -16,8 +14,8 @@ describe('check-tracked', () => { }); }); describe('fail', () => { - beforeEach(() => execSync('git tag -a publish/test')); - afterEach(() => execSync('git tag -d publish/test')); + beforeEach(() => execSync('git tag -a publish/fail -m fail')); + afterEach(() => execSync('git tag -d publish/fail')); it('should resolve object with success false if tag had been used', () => { return checker('publish/fail').should.be.fulfilledWith({ success: false @@ -31,9 +29,15 @@ describe('check-tracked', () => { }); }); it('should reject with an error when cwd is not a string', () => { - return checker('publish/test', {}).should.be.rejectedWith(TypeError, { + return checker('publish/error', {}).should.be.rejectedWith(TypeError, { message: 'Expected cwd to be a string' }); }); + it('should reject with an error when no git repository found', () => { + let dir = os.tmpdir(); + return checker('publish/error', dir).should.be.rejectedWith(Error, { + message: `No git repository was found in ${dir}` + }); + }); }); });