Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Move other compilers over to Task subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed May 26, 2016
1 parent f201410 commit c25f6c5
Show file tree
Hide file tree
Showing 18 changed files with 282 additions and 260 deletions.
4 changes: 4 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ const config = {
sass: {
folder: 'sass',

search: '/**/*.+(sass|scss)',

// https://github.com/sass/node-sass#options
pluginOptions: {
outputStyle: Elixir.inProduction ? 'compressed' : 'nested',
Expand All @@ -225,6 +227,8 @@ const config = {
less: {
folder: 'less',

search: '/**/*.less',

// https://github.com/plus3network/gulp-less#options
pluginOptions: {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/SetDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Elixir.Plugins = require('gulp-load-plugins')();
*
* @type {Task}
*/
Elixir.Task = require('../Task').default;
Elixir.Task = require('../tasks/conductors/Task').default;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/combine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import combine from './shared/Combine';
import CombineTask from './conductors/CombineTask';

/*
|----------------------------------------------------------------
Expand All @@ -24,7 +24,7 @@ Elixir.extend('compress', task);
* @param {string|null} baseDir
*/
function task(src, output, baseDir) {
combine('combine', getPaths(src, baseDir, output));
new CombineTask('combine', getPaths(src, baseDir, output));
}


Expand Down
78 changes: 0 additions & 78 deletions src/tasks/compilers/Compiler.js

This file was deleted.

69 changes: 0 additions & 69 deletions src/tasks/compilers/CssCompiler.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/tasks/conductors/CombineTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class CombineTask extends Elixir.Task {
/**
* Create a new TestingTask instance.
*
* @param {string} name
* @param {GulpPaths} paths
*/
constructor(name, paths) {
super(name, null, paths);
}


/**
* Build the Gulp task.
*/
gulpTask() {
return (
gulp
.src(this.src.path)
.pipe(this.initSourceMaps())
.pipe(this.concat())
.pipe(this.minify())
.pipe(this.writeSourceMaps())
.pipe(this.saveAs(gulp))
.pipe(this.onSuccess('Assets Combined!'))
);
}


/**
* Register file watchers.
*/
registerWatchers() {
this.watch(this.src.path)
.ignore(this.output.path);
}
}


export default CombineTask;
56 changes: 56 additions & 0 deletions src/tasks/conductors/CssTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class CssTask extends Elixir.Task {
/**
* Create a new TestingTask instance.
*
* @param {string} name
* @param {GulpPaths} paths
* @param {object|null} options
*/
constructor(name, paths, options) {
super(name, null, paths);

this.options = options;
}


/**
* Build the Gulp task.
*/
gulpTask() {
return (
gulp
.src(this.src.path)
.pipe(this.initSourceMaps())
.pipe(this.compile())
.on('error', this.onError)
.pipe(this.autoPrefix())
.pipe(this.concat())
.pipe(this.minify())
.pipe(this.writeSourceMaps())
.pipe(this.saveAs(gulp))
.pipe(this.onSuccess())
);
}


/**
* Register file watchers.
*/
registerWatchers() {
this.watch(this.src.baseDir + Elixir.config.css[this.name].search)
.ignore(this.output.path);
}


/**
* Compile the CSS.
*/
compile() {
return Elixir.Plugins[this.name](
this.options || Elixir.config.css[this.name].pluginOptions
);
}
}


export default CssTask;
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import fs from 'fs';
import map from 'vinyl-map';
import {extend} from 'underscore';
import Compiler from './Compiler';
import gulpWebpack from 'webpack-stream';

class JavaScriptCompiler extends Compiler {
class JavaScriptTask extends Elixir.Task {
/**
* Create a new compiler instance.
* Create a new JavaScriptTask instance.
*
* @param {string} name
* @param {GulpPaths} paths
* @param {object|null} options
*/
constructor(options) {
super(options);
constructor(name, paths, options) {
super(name, null, paths);

this.options = options;

if (fs.existsSync('webpack.config.js')) {
this.webpackConfig = require(process.cwd()+'/webpack.config.js');
Expand All @@ -20,16 +23,12 @@ class JavaScriptCompiler extends Compiler {


/**
* Retrieve the full Gulp task.
*
* @param {Task} task
* Build up the Gulp task.
*/
toGulp(task) {
this.task = task;

gulpTask() {
return (
gulp
.src(task.src.path)
.src(this.src.path)
.pipe(this.webpack())
.on('error', this.onError)
.pipe(this.minify())
Expand All @@ -47,28 +46,14 @@ class JavaScriptCompiler extends Compiler {
watch: Elixir.isWatching(),
devtool: Elixir.config.sourcemaps ? 'source-map' : '',
output: {
filename: this.task.output.name
filename: this.output.name
},
module: {
loaders: Elixir.config.js.webpack.loaders
}
}, this.webpackConfig, this.options), require('webpack'));
}


/**
* Uglify the code.
*/
minify() {
if (Elixir.inProduction) {
return Elixir.Plugins.uglify(
Elixir.config.js.uglify.options
);
}

return map(function () {});
}
}


export default JavaScriptCompiler;
export default JavaScriptTask;

0 comments on commit c25f6c5

Please sign in to comment.