wikijs-fork/gulpfile.js

219 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-08-17 00:56:55 +00:00
var gulp = require("gulp");
2016-11-21 01:09:50 +00:00
var watch = require('gulp-watch');
2016-08-17 00:56:55 +00:00
var merge = require('merge-stream');
var babel = require("gulp-babel");
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var nodemon = require('gulp-nodemon');
var plumber = require('gulp-plumber');
var zip = require('gulp-zip');
var tar = require('gulp-tar');
var gzip = require('gulp-gzip');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var include = require("gulp-include");
var run = require('run-sequence');
var _ = require('lodash');
2016-08-17 00:56:55 +00:00
/**
* Paths
*
* @type {Object}
*/
var paths = {
2016-11-21 01:09:50 +00:00
scripts: {
combine: [
2016-11-29 15:11:14 +00:00
'./node_modules/socket.io-client/dist/socket.io.min.js',
2016-11-21 01:09:50 +00:00
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/vue/dist/vue.min.js',
'./node_modules/jquery-smooth-scroll/jquery.smooth-scroll.min.js',
'./node_modules/jquery-simple-upload/simpleUpload.min.js',
'./node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.js',
'./node_modules/sticky-js/dist/sticky.min.js',
'./node_modules/simplemde/dist/simplemde.min.js',
'./node_modules/ace-builds/src-min-noconflict/ace.js',
'./node_modules/ace-builds/src-min-noconflict/ext-modelist.js',
'./node_modules/ace-builds/src-min-noconflict/mode-markdown.js',
'./node_modules/ace-builds/src-min-noconflict/theme-tomorrow_night.js',
'./node_modules/filesize.js/dist/filesize.min.js',
'./node_modules/lodash/lodash.min.js'
],
ace: [
'./node_modules/ace-builds/src-min-noconflict/mode-*.js',
'!./node_modules/ace-builds/src-min-noconflict/mode-markdown.js'
],
compile: [
'./client/js/*.js'
],
watch: [
'./client/js/**/*.js'
]
},
css: {
combine: [
'./node_modules/font-awesome/css/font-awesome.min.css',
'./node_modules/highlight.js/styles/tomorrow.css',
'./node_modules/simplemde/dist/simplemde.min.css'
],
compile: [
'./client/scss/*.scss'
],
includes: [
'./node_modules/requarks-core' //! MUST BE LAST
2016-11-21 01:09:50 +00:00
],
watch: [
'./client/scss/**/*.scss',
'../core/core-client/scss/**/*.scss'
]
},
2016-08-17 00:56:55 +00:00
fonts: [
'./node_modules/font-awesome/fonts/*-webfont.*',
2016-11-21 01:09:50 +00:00
'!./node_modules/font-awesome/fonts/*-webfont.svg',
'../node_modules/requarks-core/core-client/fonts/**/*' //! MUST BE LAST
2016-08-17 00:56:55 +00:00
],
2016-11-21 01:09:50 +00:00
deploy: [
2016-09-12 14:35:42 +00:00
'./**/*',
'!node_modules', '!node_modules/**',
'!coverage', '!coverage/**',
'!client/js', '!client/js/**',
'!client/scss', '!client/scss/**',
'!dist', '!dist/**',
'!tests', '!tests/**',
2016-11-03 16:42:18 +00:00
'!data', '!data/**',
'!repo', '!repo/**',
2016-09-12 14:35:42 +00:00
'!.babelrc', '!.gitattributes', '!.gitignore', '!.snyk', '!.travis.yml',
'!gulpfile.js', '!inch.json', '!config.yml', '!wiki.sublime-project'
2016-08-17 00:56:55 +00:00
]
};
/**
* TASK - Starts server in development mode
*/
2016-11-21 01:09:50 +00:00
gulp.task('server', ['scripts', 'css', 'fonts'], function() {
2016-08-17 00:56:55 +00:00
nodemon({
script: './server',
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
2016-08-17 00:56:55 +00:00
ext: 'js json',
env: { 'NODE_ENV': 'development' }
});
});
2016-08-18 03:52:23 +00:00
/**
* TASK - Process all scripts processes
*/
gulp.task("scripts", ['scripts-libs', 'scripts-app']);
/**
* TASK - Combine js libraries
*/
gulp.task("scripts-libs", function () {
2016-09-11 02:53:21 +00:00
return merge(
2016-11-21 01:09:50 +00:00
gulp.src(paths.scripts.combine)
2016-09-25 21:32:39 +00:00
.pipe(concat('libs.js', {newLine: ';\n'}))
2016-09-11 02:53:21 +00:00
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest("./assets/js")),
2016-11-21 01:09:50 +00:00
gulp.src(paths.scripts.ace)
2016-09-11 02:53:21 +00:00
.pipe(gulp.dest("./assets/js/ace"))
);
2016-08-18 03:52:23 +00:00
});
/**
* TASK - Combine, make compatible and compress js app scripts
*/
gulp.task("scripts-app", function () {
2016-11-21 01:09:50 +00:00
return gulp.src(paths.scripts.compile)
2016-08-18 03:52:23 +00:00
.pipe(plumber())
2016-08-28 15:27:05 +00:00
.pipe(include({ extensions: "js" }))
2016-08-18 03:52:23 +00:00
.pipe(babel())
.pipe(uglify())
.pipe(plumber.stop())
2016-08-24 01:09:09 +00:00
.pipe(gulp.dest("./assets/js"));
2016-08-18 03:52:23 +00:00
});
/**
* TASK - Process all css processes
*/
gulp.task("css", ['css-libs', 'css-app']);
/**
* TASK - Combine css libraries
*/
gulp.task("css-libs", function () {
2016-11-21 01:09:50 +00:00
return gulp.src(paths.css.combine)
2016-08-18 03:52:23 +00:00
.pipe(plumber())
.pipe(concat('libs.css'))
.pipe(cleanCSS({ keepSpecialComments: 0 }))
.pipe(plumber.stop())
.pipe(gulp.dest("./assets/css"));
});
/**
* TASK - Combine app css
*/
gulp.task("css-app", function () {
2016-11-21 01:09:50 +00:00
return gulp.src(paths.css.compile)
2016-08-18 03:52:23 +00:00
.pipe(plumber())
2016-11-21 01:09:50 +00:00
.pipe(sass.sync({ includePaths: paths.css.includes }))
2016-08-18 03:52:23 +00:00
.pipe(cleanCSS({ keepSpecialComments: 0 }))
.pipe(plumber.stop())
.pipe(gulp.dest("./assets/css"));
});
/**
* TASK - Copy web fonts
*/
gulp.task("fonts", function () {
return gulp.src(paths.fonts)
.pipe(gulp.dest("./assets/fonts"));
});
2016-08-17 00:56:55 +00:00
/**
* TASK - Start dev watchers
*/
gulp.task('watch', function() {
2016-11-21 01:09:50 +00:00
return merge(
watch(paths.scripts.watch, {base: './'}, function() { return gulp.start('scripts-app'); }),
watch(paths.css.watch, {base: './'}, function() { return gulp.start('css-app'); })
);
2016-08-17 00:56:55 +00:00
});
/**
* TASK - Starts development server with watchers
*/
gulp.task('default', ['watch', 'server']);
gulp.task('dev', function() {
paths.css.includes.pop();
paths.css.includes.push('../core');
paths.fonts.pop();
paths.fonts.push('../core/core-client/fonts/**/*');
return run('default');
})
2016-08-17 00:56:55 +00:00
/**
* TASK - Creates deployment packages
*/
gulp.task('deploy', ['scripts', 'css', 'fonts'], function() {
2016-11-21 01:09:50 +00:00
var zipStream = gulp.src(paths.deploy)
.pipe(zip('wiki-js.zip'))
2016-08-17 00:56:55 +00:00
.pipe(gulp.dest('dist'));
2016-11-21 01:09:50 +00:00
var targzStream = gulp.src(paths.deploy)
.pipe(tar('wiki-js.tar'))
2016-08-17 00:56:55 +00:00
.pipe(gzip())
.pipe(gulp.dest('dist'));
return merge(zipStream, targzStream);
2016-09-12 13:35:07 +00:00
});