blessing-skin-server/gulpfile.js

198 lines
6.0 KiB
JavaScript
Raw Normal View History

2016-07-21 22:01:57 +08:00
/*
2017-01-18 23:05:32 +08:00
* @Author: printempw
2016-07-21 22:01:57 +08:00
* @Date: 2016-07-21 13:38:26
2017-04-26 15:58:53 +08:00
* @Last Modified by: g-plane
* @Last Modified time: 2017-04-26 15:39:46
2016-07-21 22:01:57 +08:00
*/
2017-01-18 23:05:32 +08:00
'use strict';
var gulp = require('gulp'),
babel = require('gulp-babel'),
2016-08-28 11:49:22 +08:00
elixir = require('laravel-elixir'),
2016-07-22 08:54:50 +08:00
uglify = require('gulp-uglify'),
2016-08-28 11:49:22 +08:00
sass = require('gulp-sass'),
2016-07-22 08:54:50 +08:00
cleanCss = require('gulp-clean-css'),
2016-08-28 18:34:41 +08:00
del = require('del'),
zip = require('gulp-zip'),
notify = require('gulp-notify');
2016-07-23 16:24:44 +08:00
2016-08-28 11:49:22 +08:00
require('laravel-elixir-replace');
2016-08-28 10:05:21 +08:00
2017-01-20 18:17:56 +08:00
var version = require('./package.json').version;
2016-07-21 22:01:57 +08:00
2017-01-20 18:17:56 +08:00
var srcPath = 'resources/assets/src/';
var distPath = 'resources/assets/dist/';
var vendorScripts = [
2016-09-25 09:00:40 +08:00
'jquery/dist/jquery.min.js',
'bootstrap/dist/js/bootstrap.min.js',
2017-06-30 12:13:45 +08:00
'admin-lte/dist/js/app.min.js',
2016-09-25 09:00:40 +08:00
'bootstrap-fileinput/js/fileinput.min.js',
2017-06-30 12:13:45 +08:00
'admin-lte/plugins/datatables/jquery.dataTables.min.js',
'admin-lte/plugins/datatables/dataTables.bootstrap.min.js',
'icheck/icheck.min.js',
'toastr/build/toastr.min.js',
'es6-promise/dist/es6-promise.auto.min.js',
2016-09-25 09:00:40 +08:00
'sweetalert2/dist/sweetalert2.min.js',
2017-06-30 12:13:45 +08:00
'jqPaginator/dist/1.2.0/jqPaginator.min.js',
2017-07-03 20:54:19 +08:00
'resources/assets/dist/js/general.js',
2016-08-28 11:49:22 +08:00
];
2017-01-20 18:17:56 +08:00
var vendorStyles = [
2016-09-25 09:00:40 +08:00
'bootstrap/dist/css/bootstrap.min.css',
2017-06-30 12:13:45 +08:00
'admin-lte/dist/css/AdminLTE.min.css',
'admin-lte/plugins/datatables/dataTables.bootstrap.css',
2016-09-25 09:00:40 +08:00
'bootstrap-fileinput/css/fileinput.min.css',
'font-awesome/css/font-awesome.min.css',
2017-06-30 12:13:45 +08:00
'icheck/skins/square/blue.css',
'toastr/build/toastr.min.css',
'sweetalert2/dist/sweetalert2.min.css',
2016-08-28 11:49:22 +08:00
];
var styleReplacements = [
2016-09-24 23:48:52 +08:00
['blue.png', '"../images/blue.png"'],
['blue@2x.png', '"../images/blue@2x.png"'],
['../img/loading.gif', '"../images/loading.gif"'],
['../img/loading-sm.gif', '"../images/loading-sm.gif"'],
['@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic);', ''],
];
var scriptReplacements = [
['$.AdminLTE.layout.activate(),', '']
];
2017-01-20 18:17:56 +08:00
var fonts = [
'font-awesome/fonts/**',
'bootstrap/dist/fonts/**',
2017-01-20 18:17:56 +08:00
'resources/assets/src/fonts/**',
];
2017-01-20 18:17:56 +08:00
var images = [
2017-06-30 12:13:45 +08:00
'icheck/skins/square/blue.png',
'icheck/skins/square/blue@2x.png',
2017-01-20 18:17:56 +08:00
'resources/assets/src/images/**',
'bootstrap-fileinput/img/loading.gif',
'bootstrap-fileinput/img/loading-sm.gif',
2016-08-28 11:49:22 +08:00
];
2016-09-25 09:00:40 +08:00
elixir.config.sourcemaps = false;
2017-01-18 23:05:32 +08:00
elixir((mix) => {
mix // compile sass files & ES6 scripts first
.task('compile-es6')
2017-01-20 18:17:56 +08:00
.task('compile-sass')
2017-07-03 20:54:19 +08:00
.scripts(convertNpmRelativePath(vendorScripts), distPath + 'js/app.js', './')
.styles(convertNpmRelativePath(vendorStyles), distPath + 'css/style.css', './')
.replace(distPath + 'css/style.css', styleReplacements)
.replace(distPath + 'js/app.js', scriptReplacements)
2016-08-28 11:49:22 +08:00
2016-08-28 18:34:41 +08:00
// copy fonts & images
2017-06-30 12:13:45 +08:00
.copy(convertNpmRelativePath(fonts), distPath + 'fonts/')
.copy(convertNpmRelativePath(images), distPath + 'images/')
2017-07-03 20:54:19 +08:00
.copy(convertNpmRelativePath(['admin-lte/dist/css/skins']), distPath + 'css/skins')
2017-06-30 12:13:45 +08:00
.copy(
['skin-preview/**', 'Chart.min.js'].map(relativePath => `${srcPath}vendor/${relativePath}`),
2017-07-03 20:54:19 +08:00
distPath + 'js/'
2017-06-30 12:13:45 +08:00
);
2016-07-21 22:01:57 +08:00
});
2016-08-28 11:49:22 +08:00
// compile sass
gulp.task('compile-sass', () => {
2017-07-03 20:54:19 +08:00
gulp.src(srcPath + 'sass/*.scss')
2016-08-28 11:49:22 +08:00
.pipe(sass().on('error', sass.logError))
2016-07-21 22:01:57 +08:00
.pipe(cleanCss())
2017-07-03 20:54:19 +08:00
.pipe(gulp.dest(distPath + 'css'));
2016-07-21 22:01:57 +08:00
});
gulp.task('compile-es6', () => {
2017-07-03 20:54:19 +08:00
gulp.src(srcPath + 'js/*.js')
2017-01-20 18:17:56 +08:00
.pipe(babel({ presets: ['es2015'] }))
2016-07-21 22:01:57 +08:00
.pipe(uglify())
2017-07-03 20:54:19 +08:00
.pipe(gulp.dest(distPath + 'js'));
2016-07-21 22:01:57 +08:00
});
2016-12-30 16:18:13 +08:00
// delete cache files
2017-01-18 23:05:32 +08:00
gulp.task('clear', () => {
2016-12-30 16:18:13 +08:00
clearCache();
2017-01-20 18:17:56 +08:00
clearDist();
2016-12-30 16:18:13 +08:00
});
// release
2017-01-18 23:05:32 +08:00
gulp.task('zip', () => {
2016-12-30 16:18:13 +08:00
clearCache();
2016-08-28 18:34:41 +08:00
console.info("============================================================================")
console.info("= Don't forget to compile Sass & ES2015 files before publishing a release! =");
console.info("============================================================================")
let zipPath = `blessing-skin-server-v${version}.zip`;
console.log(`Zip archive will be saved to ${zipPath}.`);
2016-07-23 16:24:44 +08:00
return gulp.src([
'**/*.*',
2016-07-29 16:13:21 +08:00
'LICENSE',
2016-07-24 11:13:41 +08:00
'!tests/**/*.*',
2016-07-23 16:24:44 +08:00
'!node_modules/**/*.*',
2016-09-15 11:10:13 +08:00
'!storage/textures/**/*.*',
2016-07-23 16:24:44 +08:00
'!.env',
'!.bowerrc',
'!.gitignore',
'!.git/**/*.*',
'!.git/',
2017-01-22 22:19:19 +08:00
'!.gitmodules',
'!.gitattributes',
2016-08-28 18:34:41 +08:00
'!artisan',
2016-07-23 16:24:44 +08:00
'!gulpfile.js',
'!package.json',
'!composer.json',
'!composer.lock',
'!bower.json',
'!plugins/**/*.*',
2016-09-25 00:03:07 +08:00
'!resources/assets/src/**/*.*',
2017-01-20 18:17:56 +08:00
// do not pack packages for developments
'!vendor/fzaninotto/**/*.*',
'!vendor/mockery/**/*.*',
'!vendor/phpunit/**/*.*',
'!vendor/symfony/css-selector/**/*.*',
'!vendor/symfony/dom-crawler/**/*.*'
2016-07-23 16:24:44 +08:00
], { dot: true })
.pipe(zip(zipPath))
.pipe(gulp.dest('../'))
.pipe(notify({ message: `Zip archive saved to ${zipPath}!` }));
2016-07-23 16:24:44 +08:00
});
gulp.task('watch', () => {
2017-01-20 18:17:56 +08:00
// watch .scss files
2017-07-03 20:54:19 +08:00
gulp.watch(srcPath + 'sass/*.scss', ['compile-sass'], () => notify({ message: 'Sass files compiled!' }));
2017-01-20 18:17:56 +08:00
// watch .js files
2017-07-03 20:54:19 +08:00
gulp.watch(srcPath + 'js/*.js', ['compile-es6'], () => notify({ message: 'ES6 scripts compiled!' }));
gulp.watch(srcPath + 'js/general.js', ['scripts']);
});
2017-06-30 12:13:45 +08:00
function convertNpmRelativePath(paths) {
2017-01-20 18:17:56 +08:00
return paths.map(relativePath => {
2017-06-30 12:13:45 +08:00
return relativePath.startsWith('resources') ? relativePath : ('node_modules/' + relativePath);
2017-01-20 18:17:56 +08:00
});
}
function clearCache() {
return del([
'storage/logs/*',
'storage/debugbar/*',
'storage/update_cache/*',
'storage/yaml-translation/*',
'storage/framework/cache/*',
'storage/framework/sessions/*',
'storage/framework/views/*'
]);
}
2017-01-20 18:17:56 +08:00
function clearDist() {
return del([
distPath + '**/*'
]);
}