Comparing version 2.0.0 to 2.1.0
@@ -5,3 +5,3 @@ /** | ||
*/ | ||
/*global target, exec, echo, find, which, test, mkdir*/ | ||
/*global target, exec, echo, find, which, test, exit, mkdir*/ | ||
@@ -16,3 +16,4 @@ 'use strict'; | ||
var util = require('util'); | ||
var util = require('util'), | ||
nodeCLI = require('shelljs-nodecli'); | ||
@@ -26,2 +27,3 @@ //------------------------------------------------------------------------------ | ||
BUILD_DIR = './build/', | ||
DIST_DIR = './dist/', | ||
LIB_DIR = './lib/', | ||
@@ -51,2 +53,31 @@ | ||
/** | ||
* Executes a Node CLI and exits with a non-zero exit code if the | ||
* CLI execution returns a non-zero exit code. Otherwise, it does | ||
* not exit. | ||
* @param {...string} [args] Arguments to pass to the Node CLI utility. | ||
* @returns {void} | ||
* @private | ||
*/ | ||
function nodeExec(args) { | ||
args = arguments; // make linting happy | ||
var code = nodeCLI.exec.apply(nodeCLI, args).code; | ||
if (code !== 0) { | ||
exit(code); | ||
} | ||
} | ||
/** | ||
* Runs exec() but exits if the exit code is non-zero. | ||
* @param {string} cmd The command to execute. | ||
* @returns {void} | ||
* @private | ||
*/ | ||
function execOrExit(cmd) { | ||
var code = exec(cmd).code; | ||
if (code !== 0) { | ||
exit(code); | ||
} | ||
} | ||
/** | ||
* Generates a function that matches files with a particular extension. | ||
@@ -88,13 +119,15 @@ * @param {string} extension The file extension (i.e. 'js') | ||
target.test(); | ||
exec('npm version ' + type); | ||
// npm version changes indentation to spaces, this changes it to tabs | ||
exec('git add package.json'); | ||
exec('git commit --amend --no-edit'); | ||
target.generateDist(); | ||
execOrExit('git add -A'); | ||
execOrExit('git commit --amend --no-edit'); | ||
execOrExit('npm version ' + type); | ||
// ...and publish | ||
exec('git push origin master --tags'); | ||
execOrExit('git push origin master --tags'); | ||
// also publish to npm (requires authentication) | ||
exec('npm publish'); | ||
execOrExit('npm publish'); | ||
} | ||
@@ -124,3 +157,9 @@ | ||
target.lint(); | ||
exec(ISTANBUL + ' cover ' + MOCHA + TEST_FILES); | ||
echo('Running Node.js tests'); | ||
exec(ISTANBUL + ' cover ' + MOCHA + ' -- -R dot ' + TEST_FILES); | ||
echo('Running browser tests'); | ||
target.browserify(); | ||
nodeExec("mocha-phantomjs", "-R dot", "tests/tests.htm"); | ||
}; | ||
@@ -134,4 +173,30 @@ | ||
target.generateDist = function() { | ||
var pkg = require('./package.json'), | ||
distFilename = DIST_DIR + pkg.name + '.js', | ||
minDistFilename = distFilename.replace(/\.js$/, '.min.js'); | ||
if (!test('-d', DIST_DIR)) { | ||
mkdir(DIST_DIR); | ||
} | ||
exec(util.format('%s %s.js -o %s -s %s -i mocha', BROWSERIFY, LIB_DIR + pkg.name, | ||
distFilename, pkg.name)); | ||
nodeExec('uglifyjs', distFilename, '-o', minDistFilename); | ||
// Add copyrights | ||
cat('./config/copyright.txt', distFilename).to(distFilename); | ||
cat('./config/copyright.txt', minDistFilename).to(minDistFilename); | ||
// ensure there's a newline at the end of each file | ||
(cat(distFilename) + '\n').to(distFilename); | ||
(cat(minDistFilename) + '\n').to(minDistFilename); | ||
}; | ||
target.browserify = function() { | ||
var pkg = require('./package.json'); | ||
var pkg = require('./package.json'), | ||
buildFilename = BUILD_DIR + pkg.name + '.js', | ||
minDistFilename = buildFilename.replace(/\.js$/, '.min.js'); | ||
@@ -142,6 +207,4 @@ if (!test('-d', BUILD_DIR)) { | ||
exec(util.format('%s %s.js -o %s-%s.js -s %s -i mocha', BROWSERIFY, LIB_DIR + pkg.name, | ||
BUILD_DIR + pkg.name, pkg.version, pkg.name)); | ||
// exec(BROWSERIFY + ' ' + LIB_DIR + pkg.name + '.js -o ' + BUILD_DIR + pkg.name + '-' + pkg.version + '.js -s ' + pkg.name); | ||
exec(util.format('%s %s.js -o %s -s %s -i mocha', BROWSERIFY, LIB_DIR + pkg.name, | ||
buildFilename, pkg.name)); | ||
}; | ||
@@ -148,0 +211,0 @@ |
{ | ||
"name": "leche", | ||
"author": "nzakas", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A JavaScript testing utility designed to work with Mocha and Sinon", | ||
@@ -38,6 +38,10 @@ "main": "./lib/leche.js", | ||
"mocha": "^2.1.0", | ||
"mocha-phantomjs": "^3.5.3", | ||
"mockery": "~1.4", | ||
"phantomjs": "^1.9.15", | ||
"shelljs": "^0.3.0", | ||
"sinon": "^1.10.3" | ||
"shelljs-nodecli": "^0.1.1", | ||
"sinon": "^1.12.2", | ||
"uglify-js": "^2.4.16" | ||
} | ||
} |
[![Build Status](https://travis-ci.org/box/leche.png?branch=master)](https://travis-ci.org/box/leche) | ||
[![Project Status](http://opensource.box.com/badges/maintenance.svg)](http://opensource.box.com/badges) | ||
[![Project Status](http://opensource.box.com/badges/stable.svg)](http://opensource.box.com/badges) | ||
@@ -31,14 +31,30 @@ # Leche | ||
To include Leche in a web page, you first need to build the browser version. Checkout Leche from GitHub and run: | ||
To include Leche in a web page, you can use [RawGit](http://rawgit.com). | ||
The last published release: | ||
``` | ||
npm run browserify | ||
<script src="https://cdn.rawgit.com/box/leche/master/dist/leche.js"></script> | ||
``` | ||
This will create a file that can be used in a web page and output it into `/build`. Include the file in your page: | ||
Minified: | ||
```html | ||
<script src="leche-01.1.js"></script> | ||
``` | ||
<script src="https://cdn.rawgit.com/box/leche/master/dist/leche.min.js"></script> | ||
``` | ||
A specific version (in this example v2.1.0): | ||
``` | ||
<script src="https://cdn.rawgit.com/box/leche/v2.1.0/dist/leche.js"></script> | ||
``` | ||
Minified: | ||
``` | ||
<script src="https://cdn.rawgit.com/box/leche/v2.1.0/dist/leche.min.js"></script> | ||
``` | ||
**Note:** We highly recommend using a specific version as the master branch may change without notice. | ||
A global `leche` object is created and is the same as the Node.js version. | ||
@@ -45,0 +61,0 @@ |
@@ -6,3 +6,3 @@ /** | ||
/*global describe, it, afterEach*/ | ||
/*global describe, it, afterEach, sinon, leche, chai*/ | ||
@@ -15,5 +15,5 @@ 'use strict'; | ||
var sinon = require('sinon'), | ||
assert = require('chai').assert, | ||
leche = require('../../lib/leche'); | ||
var sinon = compatRequire('sinon') || sinon, | ||
assert = (compatRequire('chai') || chai).assert, | ||
leche = compatRequire('../../lib/leche') || leche; | ||
@@ -30,2 +30,16 @@ //------------------------------------------------------------------------------ | ||
/** | ||
* An abstraction over require() to allow these tests to be run in a browser. | ||
* @param {string} name The name of the package to load. | ||
* @returns {?Object} The module in Node.js, null in browsers. | ||
* @private | ||
*/ | ||
function compatRequire(name) { | ||
if (typeof require === 'function') { | ||
return require(name); | ||
} else { | ||
return null; | ||
} | ||
} | ||
//------------------------------------------------------------------------------ | ||
@@ -32,0 +46,0 @@ // Public |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
61245
17
954
257
14
2
5