Skip to content

Commit

Permalink
Using Gulp.js as build system
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 17, 2015
1 parent 7a28d72 commit 7c5421a
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 5,111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/node_modules/
/npm-debug.log
/var/
/www/**/*.map
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog
This file contains highlights of what changes on each version of the [Akismet.js](https://www.npmjs.org/package/akismet-js) library.
This file contains highlights of what changes on each version of the [Akismet.js](https://www.npmjs.com/package/akismet-js) library.

#### Version 0.3.5
- Using [Gulp.js](http://gulpjs.com) as build system.

#### Version 0.3.4
- CORS headers handling delegated to [`cors`](https://www.npmjs.com/package/cors) module.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Akismet.js
[![Version](http://img.shields.io/npm/v/akismet-js.svg?style=flat)](https://www.npmjs.org/package/akismet-js) [![Dependencies](http://img.shields.io/david/cedx/akismet.js.svg?style=flat)](https://david-dm.org/cedx/akismet.js) [![Downloads](http://img.shields.io/npm/dm/akismet-js.svg?style=flat)](https://www.npmjs.org/package/akismet-js) [![License](http://img.shields.io/npm/l/akismet-js.svg?style=flat)](https://github.com/cedx/akismet.js/blob/master/LICENSE.txt)
[![Version](http://img.shields.io/npm/v/akismet-js.svg?style=flat)](https://www.npmjs.com/package/akismet-js) [![Dependencies](http://img.shields.io/david/cedx/akismet.js.svg?style=flat)](https://david-dm.org/cedx/akismet.js) [![Downloads](http://img.shields.io/npm/dm/akismet-js.svg?style=flat)](https://www.npmjs.com/package/akismet-js) [![License](http://img.shields.io/npm/l/akismet-js.svg?style=flat)](https://github.com/cedx/akismet.js/blob/master/LICENSE.txt)

Prevent comment spam using [Akismet](https://akismet.com) service, in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript).

Expand All @@ -12,7 +12,7 @@ Prevent comment spam using [Akismet](https://akismet.com) service, in [JavaScrip
## Documentation
- [API Reference](http://dev.belin.io/akismet.js/api)

## Installing via [npm](https://www.npmjs.org)
## Installing via [npm](https://www.npmjs.com)

#### 1. Depend on it
Add this to your project's `package.json` file:
Expand Down Expand Up @@ -92,7 +92,7 @@ To be able to use the HTML client, we must rely on a proxy server adding [CORS](
This is why a [server implementation](https://github.com/cedx/akismet.js/blob/master/lib/server.js) is provided with this package.
To facilitate its usage, a [command line interface](https://github.com/cedx/akismet.js/blob/master/bin/cli.js) is available in the `bin` folder.

From a command prompt, run the `cli.js` script (aliased as `akismet` by [npm](https://www.npmjs.org)):
From a command prompt, run the `cli.js` script (aliased as `akismet` by [npm](https://www.npmjs.com)):

```
$ node bin/cli.js --help
Expand Down Expand Up @@ -129,4 +129,4 @@ To test the client/browser implementation, launch a server instance, and points
[Unit Tests of HTML Client](http://dev.belin.io/akismet.js)

## License
[Akismet.js](https://www.npmjs.org/package/akismet-js) is distributed under the MIT License.
[Akismet.js](https://www.npmjs.com/package/akismet-js) is distributed under the MIT License.
154 changes: 0 additions & 154 deletions bin/make.js

This file was deleted.

185 changes: 185 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/**
* Build system.
* @module gulpfile
*/
'use strict';

// Module dependencies.
var child=require('child_process');
var del=require('del');
var gulp=require('gulp');
var plugins=require('gulp-load-plugins')();
var pkg=require('./package.json');
var util=require('util');

/**
* Provides tasks for [Gulp.js](http://gulpjs.com) build system.
* @class MiniFramework.Gulpfile
* @static
*/
process.chdir(__dirname);

/**
* The task settings.
* @property config
* @type Object
*/
var config={
output: util.format('%s-%s.zip', pkg.yuidoc.name.toLowerCase(), pkg.version)
};

/**
* Runs the default tasks.
* @method default
*/
gulp.task('default', [ 'css', 'js' ]);

/**
* Checks the package dependencies.
* @method check
*/
gulp.task('check', function(callback) {
_exec('david', callback);
});

/**
* Deletes all generated files and reset any saved state.
* @method clean
*/
gulp.task('clean', function(callback) {
del('var/'+config.output, callback);
});

/**
* Builds the stylesheets.
* @method css
*/
gulp.task('css', function() {
return gulp.src(require.resolve('mocha/mocha.css'))
.pipe(gulp.dest('www/css'));
});

/**
* Creates a distribution file for this program.
* @method dist
*/
gulp.task('dist', [ 'default' ], function() {
var sources=[
'*.js',
'*.json',
'*.md',
'*.txt',
'bin/*',
'lib/*.js',
'test/*.js',
'www/**/*',
'!www/**/*.map'
];

return gulp.src(sources, { base: '.' })
.pipe(plugins.zip(config.output))
.pipe(gulp.dest('var'));
});

/**
* Builds the documentation.
* @method doc
*/
gulp.task('doc', [ 'doc:assets' ]);

gulp.task('doc:assets', [ 'doc:build' ], function() {
return gulp.src([ 'www/apple-touch-icon.png', 'www/favicon.ico' ])
.pipe(gulp.dest('doc/api/assets'));
});

gulp.task('doc:build', function(callback) {
_exec('docgen', callback);
});

/**
* Builds the client scripts.
* @method js
*/
gulp.task('js', [ 'js:tests' ], function() {
return gulp.src('www/js/main.js')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.browserify())
.pipe(plugins.uglify())
.pipe(plugins.rename('tests.js'))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('www/js'));
});

gulp.task('js:tests', function() {
return gulp.src(require.resolve('mocha/mocha.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest('www/js'));
});

/**
* Performs static analysis of source code.
* @method lint
*/
gulp.task('lint', [ 'lint:doc', 'lint:js' ]);

gulp.task('lint:doc', function(callback) {
_exec('docgen --lint', callback);
});

gulp.task('lint:js', function() {
return gulp.src([ '*.js', 'bin/*.js', 'lib/*.js', 'test/*.js', 'www/js/main.js' ])
.pipe(plugins.jshint(pkg.jshintConfig))
.pipe(plugins.jshint.reporter('default', { verbose: true }));
});

/**
* Runs the unit tests.
* @method test
*/
gulp.task('test', [ 'test:env' ], function() {
return gulp.src([ 'test/*.js' ], { read: false })
.pipe(plugins.mocha());
});

gulp.task('test:env', function(callback) {
if('AKISMET_API_KEY' in process.env) callback();
else callback(new Error('AKISMET_API_KEY environment variable not set.'));
});

/**
* Starts the Web server.
* @method serve
*/
gulp.task('serve', function(callback) {
if('_server' in config) {
config._server.kill();
delete config._server;
}

config._server=child.fork('bin/cli.js');
callback();
});

/**
* Watches for file changes.
* @method watch
*/
gulp.task('watch', [ 'default', 'serve' ], function() {
gulp.watch('lib/*.js', [ 'serve' ]);
gulp.watch('www/js/main.js', [ 'js' ]);
});

/**
* Runs a command and prints its output.
* @method _exec
* @param {String} command The command to run, with space-separated arguments.
* @param {Function} callback The function to invoke when the task is over.
* @async
* @private
*/
function _exec(command, callback) {
child.exec(command, function(err, stdout) {
console.log(stdout.trim());
callback();
});
}
Loading

0 comments on commit 7c5421a

Please sign in to comment.