Newer
Older
var minimist = require('minimist');
var lazypipe = require('lazypipe');
// command line arguments
var varg = minimist(process.argv.slice(2), {
string: 'env',
var options = {
opt: varg.env !== 'debug' || varg.release, // optimize
inc: !varg.force, // incremental build
beauty: varg.beauty || varg.rainbow,
dst: varg.dst
};
// gulp
// common
var changed = require('gulp-changed');
var through = require('through');
var empty = function () {
return through(function (data) {
this.emit('data', data);
}, function () {
this.emit('end');
});
};
// var plumber = require('gulp-plumber');
// var gulpif = require('gulp-if');
// var rename = require('gulp-rename'); //переименовывание
// var watch = require('gulp-watch');
// var filter = require('gulp-filter');
// css/less
var prefix = require('gulp-autoprefixer'); //префиксы
var minifyCss = require('gulp-minify-css'); //минификация
// var concatCss = require('gulp-concat-css'); //конкатенация
// js
var uglify = require('gulp-uglify');
var prettify = options.beauty ? require('gulp-jsbeautifier') : empty;
var self = this;
var src = '.';
var dst = options.dst || self.root + '/~dev_rating';
var app = self.root + '/~dev_rating';
var media = src + '/media';
var stat = dst + '/static';
self.src = {
css: media + '/css/**/*.css',
less: media + '/less/**/*.less',
js: media + '/js/**/*.js',
config: src + '/deploy/phpConfig/**/*',
css_components: media + '/components/**/*.css',
js_components: media + '/components/**/*.js',
twig_components: media + '/components/**/*.twig'
};
self.dst = {
css: stat + '/css/',
less: stat + '/css/',
js: stat + '/js/',
js_components: stat + '/components/',
twig_components: stat + '/components/'
};
})();
var cssPipe = lazypipe()
.pipe(prefix, 'last 2 versions', '> 1%', 'ie9')
//.pipe(rename, {suffix: '.min'})
var lessPipe = lazypipe()
.pipe(less)
.pipe(cssPipe);
var jsPipe = lazypipe()
.pipe(babel, { presets: ['es2015-without-strict'], ignore: /js\/lib/ })
return {
css: cssPipe,
less: lessPipe,
js: jsPipe,
css_components: cssPipe,
js_components: jsPipe,
twig_components: twigPipe
}
})();
var ext = {
css: '.css',
js: '.js',
'css_components': '.css',
'js_components': '.js',
'twig_components': '.twig'
// =============================
// helpers
// =============================
process.stdout.write('>>> ' + msg + '\n');
};
var _src = src || paths.src[type];
var _dst = dst || paths.dst[type];
var _pipe = pipe || pipes[type];
return {
src: _src,
dst: _dst,
pipe: _pipe,
changed: options.inc,
ext: ext[type],
error: constructHandler(type + ' error')
};
var constructTask = function (config) {
var dump = function (e) {
throw e;
};
var errorHandler = config.error || dump;
var midPipe = config.pipe || empty;
var ext = config.ext ? {extension: config.ext} : {};
var chgPipe = config.changed ?
lazypipe().pipe(changed, config.dst, ext) :
empty;
.pipe(chgPipe())
.pipe(midPipe())
.on('error', errorHandler)
.pipe(gulp.dest(config.dst));
var constructWatch = function (config) {
gulp.watch(config.src, function (event) {
constructTask(config);
// =============================
// rules
// =============================
src: paths.src.config,
dst: paths.dst.config
});
gulp.task('components:copy', function () {
constructTask(getConfig('css_components'));
constructTask(getConfig('twig_components'));
// todo:
gulp.task('folders:create', function () {
var app = paths.root + '/~dev_rating/application';
dirs.forEach(function (dir) {
try {
fs.mkdirSync(dir);
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
// =============================
// watch
// =============================
gulp.task('watch', function (event) {
constructWatch(getConfig('less', event.path));
constructWatch(getConfig('css', event.path));
constructWatch(getConfig('js', event.path));
constructWatch(getConfig('css_components', event.path));
constructWatch(getConfig('js_components', event.path));
constructWatch(getConfig('twig_components', event.path));
// =============================
// common tasks
// =============================
gulp.task('config', [
'config:copy'
]);
gulp.task('default', [
'less:compile',
'css:copy',
]);
gulp.task('install', [
'folders:create',
'config',
'default'
gulp.task('apidoc', function(done){
apidoc({
src: "~dev_rating/application/classes",
dest: "apidoc/",
config: "./"
},done);
});