Mota Web Dev Tools
Tools to make the lives of web developers easier.
Features
var tools = require( "mota-webdevtools" );
Building
tools.findFiles( {
src: [ "src/index.js" ],
micromatch: false
} )
.lift( tools.transformers.Rollup( {
options: {},
generate: {
format: "es6"
}
} ) )
.lift( tools.transformers.rename( function( file ) {
return file.replace( "src/", "dist/" );
} ) )
.lift( tools.transformers.write() )
.subscribe( {
complete: function() {
console.log( "Build done!" );
},
error: function( e ) {
console.log( e );
}
} );
Linting
tools.readFiles( {
cwd: "src",
src: [ "**/**.js" ],
micromatch: {}
} )
.lift( tools.transformers.Lint() )
.subscribe( {
complete: function() {
console.log( "Files lint free!" );
},
error: function( e ) {
console.log( e );
}
} );
tools.lint( {
cwd: "src",
src: [ "**/**.js" ]
}, {} ).then( null, function( e ) {
console.log( e );
} );
Server and livereload
var server = tools.createServer( 9009, function() {
} );
var watcher = tools.watch( "src/**/*.js" );
watcher.on( "all", server.liveReloader );
Testing
Includes features so that you can use the same testing code on the NodeJS side or Browser side.
tools.test.exportGlobals();
tools.test.load();
tools.test.loadTests( [
"./spec_1.js",
"./spec_2.js"
] );
[ "./spec_1.js", "./spec_2.js" ].forEach( function( file ) {
require( file );
} );
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Suite</title>
<link rel="stylesheet" href="/mota-webdevtools/index.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="/mota-webdevtools/index.js"></script>
<script src="/mota-webdevtools/livereload.js"></script>
<script>
motaWebDevTools.test.exportGlobals();
motaWebDevTools.test.load();
motaWebDevTools.test.loadTests( [
"./spec_1.js",
"./spec_2.js"
] );
</script>
</body>
</html>
Benchmarking
var suite = tools.createBenchSuite( "Search in a string" );
suite.add( "RegExp#test", function() {
/o/.test( "Hello World!" );
} )
.add( "String#indexOf", function() {
"Hello World!".indexOf( "o" ) > -1;
} )
.add( "String#match", function() {
!!"Hello World!".match( /o/ );
} )
.run();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Benchmark Suite</title>
</head>
<body>
<div id="benchmark"></div>
<script src="/mota-webdevtools/index.js"></script>
<script>
var suite = motaWebDevTools.createBenchSuite( "Search in a string" );
suite.add( "RegExp#test", function() {
/o/.test( "Hello World!" );
} )
.add( "String#indexOf", function() {
"Hello World!".indexOf( "o" ) > -1;
} )
.add( "String#match", function() {
!!"Hello World!".match( /o/ );
} );
</script>
</body>
</html>