Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Updated API + all streams/tasks are back in 1 file to make loading fast
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Feb 10, 2016
1 parent e7520d4 commit 38d22ff
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 212 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.jscsrc
.jshintrc

.maelstrom.yml
.travis.yml
appveyor.yml
gulpfile.js
Expand Down
148 changes: 141 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,174 @@
*/
'use strict';

const _ = require('underscore');
const Confirge = require('confirge');
const GulpConcat = require('gulp-concat');
const GulpIf = require('gulp-if');
const GulpJsCs = require('gulp-jscs');
const GulpJsCsStylish = require('gulp-jscs-stylish');
const GulpJsHint = require('gulp-jshint');
const GulpSize = require('gulp-size');
const GulpSourceMaps = require('gulp-sourcemaps');
const GulpUglify = require('gulp-uglify');

// // // // // // // // // // // // // // // // // // // // // // // // // // //

module.exports = function()
{
let $plugin = new this.Plugin(__filename, 'js',
const Maelstrom = this;
const Config = Maelstrom.config;
const Gulp = Maelstrom.gulp;
const Utils = Maelstrom.utils;

// -------------------------------------------------------------------------

let $plugin = new Maelstrom.Plugin(__filename, 'js',
{
/**
* Return the location of the JavaScript source files.
*/
src: function($src)
{
let $defaultSrc = this.maelstrom.config.src.js + '/**/*.js';
return this.maelstrom.utils.extendArgs($src, $defaultSrc);
let $defaultSrc = Config.src.js + '/**/*.js';
return Utils.extendArgs($src, $defaultSrc);
},

/**
* Return the location of the JavaScript output folder.
*/
dest: function()
{
return this.maelstrom.config.dest.js;
return Config.dest.js;
},

/**
* Add files to concat to config
*/
concat: function($destFile, $srcFiles)
{
this.maelstrom.config.js.concat[$destFile] = $srcFiles;
Config.js.concat[$destFile] = $srcFiles;
}
});

// -------------------------------------------------------------------------

/**
* Concatenate JavaScript files and further uglify the result when not
* `--dev`.
*/
$plugin.addStream('concat', function($destFile)
{
// make sure the dest filename has a js file extension
if ($destFile.substr($destFile.length - 3) !== '.js')
{
$destFile += '.js';
}

let $stream = GulpConcat($destFile);
if (Utils.isProd())
{
$stream.pipe( GulpUglify(Config.js.uglify) );
}

return $stream;
});

/**
* Lint JavaScript files with _jshint_ and display the results with
* _jshint-stylish_.
*/
$plugin.addStream('lint', function()
{
let $config = Confirge.read(Config.js.jshintFile);
$config = Confirge.extend({}, Config.js.jshint, $config);

let $stream = GulpJsHint($config);
$stream.pipe( GulpJsCs(Config.js.jscs) )
.on('error', Utils.noop);

$stream.pipe( GulpJsCsStylish.combineWithHintResults() );
$stream.pipe( GulpJsHint.reporter('jshint-stylish') );

return $stream;
});

// -------------------------------------------------------------------------

/**
* Execute the `js:lint` and `js:concat` tasks.
*/
$plugin.addTask('js', function()
{
// read files in /assets/js dir
// check wich files are not in jsConcat
// export only those files to /public/js
// concat all other files according to jsConcat

// Maelstrom.task('js:lint');
// Maelstrom.task('js:concat');

const RunSequence = require('run-sequence').use(Gulp);

return RunSequence('js:lint', 'js:concat');
});

/**
* Concatenate JavaScript files according to the `jsConcat` config option.
* The result will be further uglified when not `--dev`.
*/
$plugin.addTask('js:concat', function()
{
let $concat = Config.js.concat;
let $createSourceMaps = (Config.js.sourcemaps !== false);

if (!_.isEmpty($concat))
{
for (let $destFile in $concat)
{
if (!$concat.hasOwnProperty($destFile))
{
continue;
}

let $srcFiles = $concat[$destFile];

Gulp.src($srcFiles)
.pipe( Maelstrom.stream('plumber') )

.pipe( GulpIf((Utils.isDev() && $createSourceMaps),
GulpSourceMaps.init()) )
.pipe( $plugin.stream('concat', [$destFile]) )
.pipe( GulpIf((Utils.isDev() && $createSourceMaps),
GulpSourceMaps.write()) )

// .pipe( GulpSize(Config.main.size) )
.pipe( Maelstrom.stream('size') )
.pipe( Gulp.dest($plugin.dest()) );
}
}
});

$plugin.readStreams();
$plugin.readTasks();
/**
* Lint the JavaScript files located in the `src.js` folder with _jshint_
* and display the results with _jshint-stylish_.
*/
$plugin.addTask('js:lint', function()
{
return Gulp.src( $plugin.src() )
.pipe( Maelstrom.stream('plumber') )
.pipe( $plugin.stream('lint') );
});

/**
*/
// this.addTask('js:test', function()
// {
// return Gulp.src( self.src() )
// .pipe( Maelstrom.stream('plumber') )
// .pipe( self.stream('test') );
// });


return $plugin;
};
37 changes: 0 additions & 37 deletions lib/streams/concat.js

This file was deleted.

37 changes: 0 additions & 37 deletions lib/streams/lint.js

This file was deleted.

29 changes: 0 additions & 29 deletions lib/tasks/js.js

This file was deleted.

56 changes: 0 additions & 56 deletions lib/tasks/js_concat.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/tasks/js_lint.js

This file was deleted.

0 comments on commit 38d22ff

Please sign in to comment.