Skip to content
Snippets Groups Projects
Commit f3d5a0cc authored by Владислав Яковлев's avatar Владислав Яковлев Committed by Роман Штейнберг
Browse files

#158 Replace gulp

parent 8575139e
Branches
No related merge requests found
Showing
with 159 additions and 224 deletions
...@@ -7,9 +7,6 @@ db/disciplines activity.sql ...@@ -7,9 +7,6 @@ db/disciplines activity.sql
~dev_rating/application/logs/*/ ~dev_rating/application/logs/*/
~dev_rating/application/config/ ~dev_rating/application/config/
~dev_rating/static/* ~dev_rating/static/*
!~dev_rating/static/img/
!~dev_rating/static/other/
!~dev_rating/static/font-awesome/
node_modules/ node_modules/
/config /config
......
...@@ -19,7 +19,7 @@ fw_deploy: fw_migrate Tasker_deploy ...@@ -19,7 +19,7 @@ fw_deploy: fw_migrate Tasker_deploy
# copy server files # copy server files
copy_files: Tasker_deploy copy_files: Tasker_deploy
$(GULP) --release --force $(GULP) release
rsync -ru --info=PROGRESS2 --exclude="application/config" --exclude="news.md" --exclude="updates.md" \ rsync -ru --info=PROGRESS2 --exclude="application/config" --exclude="news.md" --exclude="updates.md" \
\~dev_rating/ $(DST_PATH) \~dev_rating/ $(DST_PATH)
......
'use strict'; 'use strict';
var minimist = require('minimist');
var fs = require('fs');
var lazypipe = require('lazypipe');
var babel = require('gulp-babel');
var apidoc = require('gulp-apidoc');
// command line arguments
var varg = minimist(process.argv.slice(2), {
string: 'env',
default: {env: process.env.NODE_ENV || 'debug'}
});
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 gulp = require('gulp'); var gulp = require('gulp');
var changed = require('gulp-changed'); var fs = require('fs');
var through = require('through'); var del = require('del');
var console = require('console');
var lazypipe = require('lazypipe');
var empty = function () { var empty = function () {
return through(function (data) { return require('through')(function (data) {
this.emit('data', data); this.emit('data', data);
}, function () { }, function () {
this.emit('end'); 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 less = require('gulp-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 paths = new (function () {
var self = this;
self.root = '.';
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/**/*', var DIR_ROOT = '.';
css_components: media + '/components/**/*.css', var DIR_SRC = DIR_ROOT + '/media';
js_components: media + '/components/**/*.js', var DIR_DST = DIR_ROOT + '/~dev_rating/static';
twig_components: media + '/components/**/*.twig'
}; // Настройки для типов файлов
var types = {};
types.css = {
self.dst = { path: {
css: stat + '/css/', src: DIR_SRC + '/css/**/*.css',
less: stat + '/css/', dst: DIR_DST + '/css/'
js: stat + '/js/', },
config: dst + '/application/config/', pipe: lazypipe()
css_components: stat + '/components/', .pipe(require('gulp-autoprefixer'), 'last 2 versions', '> 1%', 'ie9'),
js_components: stat + '/components/', minify: require('gulp-cssnano')
twig_components: stat + '/components/' };
}; types.less = {
})(); path: {
src: DIR_SRC + '/less/**/*.less',
dst: DIR_DST + '/css/'
// ============================= },
// pipes pipe: lazypipe()
// ============================= .pipe(require('gulp-less'))
.pipe(types.css.pipe),
var pipes = (function () { minify: types.css.minify
var cssPipe = lazypipe() };
.pipe(prefix, 'last 2 versions', '> 1%', 'ie9') types.js = {
//.pipe(rename, {suffix: '.min'}) path: {
.pipe(options.opt ? minifyCss : prettify); src: DIR_SRC + '/js/**/*.js',
dst: DIR_DST + '/js/'
var lessPipe = lazypipe() },
.pipe(less) pipe: lazypipe()
.pipe(cssPipe); .pipe(require('gulp-babel'), { presets: [ 'es2015-without-strict' ], ignore: /js\/lib/ }),
minify: require('gulp-uglify')
var jsPipe = lazypipe() };
.pipe(babel, { presets: ['es2015-without-strict'], ignore: /js\/lib/ }) types.css_components = {
.pipe(options.opt ? uglify : prettify); path: {
src: DIR_SRC + '/components/**/*.css',
var twigPipe = empty; dst: DIR_DST + '/components/'
},
return { pipe: types.css.pipe,
css: cssPipe, minify: types.css.minify
less: lessPipe, };
js: jsPipe, types.js_components = {
css_components: cssPipe, path: {
js_components: jsPipe, src: DIR_SRC + '/components/**/*.js',
twig_components: twigPipe dst: DIR_DST + '/components/'
},
pipe: types.js.pipe,
minify: types.js.minify
};
types.twig_components = {
path: {
src: DIR_SRC + '/components/**/*.twig',
dst: DIR_DST + '/components/'
} }
})();
var ext = {
css: '.css',
less: '.less',
js: '.js',
'css_components': '.css',
'js_components': '.js',
'twig_components': '.twig'
}; };
types.config = {
path: {
// ============================= src: DIR_ROOT + '/deploy/phpConfig/**/*',
// helpers dst: DIR_ROOT + '/~dev_rating/application/config/'
// ============================= }
var constructHandler = function (msg) {
return function () {
process.stdout.write('>>> ' + msg + '\n');
};
}; };
types.etc = {
path: {
var getConfig = function (type, src, dst, pipe) { src: (function () {
var _src = src || paths.src[type]; var list = [ DIR_SRC + '/**/*' ];
var _dst = dst || paths.dst[type]; Object.keys(types).forEach(function (type) {
var _pipe = pipe || pipes[type]; list.push('!' + types[type].path.src);
});
return { return list;
src: _src, })(),
dst: _dst, dst: DIR_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;
return gulp.src(config.src) var opts = {
.pipe(chgPipe()) minify: process.argv.indexOf('release') !== -1
.pipe(midPipe())
.on('error', errorHandler)
.pipe(gulp.dest(config.dst));
}; };
var constructWatch = function (config) { //=========================
gulp.watch(config.src, function (event) { // Обработчик ошибок
constructTask(config); //=========================
});
};
var errorHandler = function (error) {
console.error(error.message);
};
// =============================
// rules
// =============================
//=========================
// Работа с потоками
//=========================
gulp.task('less:compile', function () { // Добавление задач для каждого из типа файлов
return constructTask(getConfig('less')); Object.keys(types).forEach(function (type) {
gulp.task(type, function () {
executePipe(type);
});
}); });
gulp.task('css:copy', function () { // Выполнить поток
return constructTask(getConfig('css')); var executePipe = function (type) {
}); gulp.src(types[type].path.src)
.pipe(types[type].pipe ? types[type].pipe() : empty()).on('error', errorHandler)
.pipe(opts.minify && types[type].minify ? types[type].minify() : empty())
.pipe(gulp.dest(types[type].path.dst));
};
gulp.task('js:copy', function () {
return constructTask(getConfig('js'));
});
gulp.task('config:copy', function () { //=========================
return constructTask({ // Задачи
src: paths.src.config, //=========================
dst: paths.dst.config
// Задачи, выполняемые по-умолчанию
var defTasks = [
'css',
'less',
'js',
'css_components',
'js_components',
'twig_components',
'etc'
];
// Сборка
// По-умолчанию
gulp.task('default', defTasks);
// Сборка релиза
// Заглушка, чтобы не выдавалась ошибка, детект флага находится выше
gulp.task('release', defTasks);
// Отслеживание изменений
//TODO: исправить отслеживание новых файлов
gulp.task('watch', function () {
defTasks.forEach(function (type) {
gulp.watch(types[type].path.src, [ type ]);
}); });
}); });
gulp.task('components:copy', function () { // Очистка папки сборки
constructTask(getConfig('css_components')); gulp.task('clean', function () {
constructTask(getConfig('twig_components')); del(DIR_DST);
return constructTask(getConfig('js_components'));
}); });
gulp.task('folders', function () {
// todo: var app = DIR_ROOT + '/~dev_rating/application';
gulp.task('folders:create', function () {
var app = paths.root + '/~dev_rating/application';
var dirs = [ var dirs = [
app + '/logs/', app + '/logs/',
...@@ -224,54 +186,30 @@ gulp.task('folders:create', function () { ...@@ -224,54 +186,30 @@ gulp.task('folders:create', function () {
dirs.forEach(function (dir) { dirs.forEach(function (dir) {
try { try {
fs.mkdirSync(dir); fs.mkdirSync(dir);
} catch (err) { } catch (error) {
if (err.code !== 'EEXIST') { if (error.code !== 'EEXIST') {
throw err; errorHandler(error);
} }
} }
}); });
}); });
// Копирование конфигурации
// Визуальная заглушка, задача генерируется в конфигурации
// gulp.task('config', ['config']);
// ============================= // Установка и сборка
// 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',
'js:copy',
'components:copy'
]);
gulp.task('install', [ gulp.task('install', [
'folders:create', 'folders',
'config', 'config',
'default' 'default'
]); ]);
gulp.task('apidoc', function(done){ // Генерациа документации
apidoc({ gulp.task('apidoc', function (done) {
src: "~dev_rating/application/classes", require('gulp-apidoc')({
dest: "apidoc/", src: DIR_ROOT + '/~dev_rating/application/classes',
config: "./" dest: DIR_ROOT + '/apidoc/',
},done); config: DIR_ROOT
}); }, done);
});
\ No newline at end of file
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment