Stackedit/Gulpfile.js

286 lines
6.4 KiB
JavaScript
Raw Normal View History

2014-08-31 19:51:13 +00:00
/* jshint -W015 */
var gulp = require('gulp');
var util = require('gulp-util');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var requirejs = require('gulp-requirejs');
var bowerRequirejs = require('bower-requirejs');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var inject = require('gulp-inject');
var replace = require('gulp-replace');
var bump = require('gulp-bump');
2014-09-02 22:19:42 +00:00
var childProcess = require('child_process');
2014-08-31 19:51:13 +00:00
var runSequence = require('run-sequence');
var fs = require('fs');
/** __________________________________________
* constants.js
*/
function getVersion() {
var packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', {
encoding: 'utf8'
}));
return packageJson.version;
}
gulp.task('constants', function() {
return gulp.src('./public/res/constants.js')
.pipe(replace(/constants\.VERSION = .*/, 'constants.VERSION = "' + getVersion() + '";'))
.pipe(gulp.dest('./public/res/'));
});
/** __________________________________________
* JSHint
*/
gulp.task('jshint', function() {
return gulp.src([
'./*.js',
'./app/**/*.js',
'./public/res/classes/**/*.js',
'./public/res/extensions/**/*.js',
'./public/res/helpers/**/*.js',
'./public/res/providers/**/*.js',
'./public/res/*.js'
2014-08-31 19:51:13 +00:00
])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
/** __________________________________________
* RequireJS
*/
gulp.task('clean-requirejs', function() {
return gulp.src([
'./public/res-min/main.js',
'./public/res-min/require.js'
])
.pipe(clean());
});
gulp.task('copy-requirejs', ['clean-requirejs'], function() {
return gulp.src('./public/res/bower-libs/requirejs/require.js')
.pipe(gulp.dest('./public/res-min/'));
});
gulp.task('requirejs', [
'copy-requirejs',
'constants'
], function() {
return requirejs({
baseUrl: 'public/res',
name: 'main',
out: 'main.js',
mainConfigFile: 'public/res/main.js',
2018-01-07 19:32:46 +00:00
// optimize: 'uglify2',
2014-08-31 19:51:13 +00:00
inlineText: true,
2014-09-01 21:27:15 +00:00
paths: {
mathjax: 'empty:'
},
2014-08-31 19:51:13 +00:00
excludeShallow: [
'css/css-builder',
'less/lessc-server',
'less/lessc'
]
})
.pipe(uglify({
output: {
beautify: true,
indent_level: 1,
ascii_only: true
2014-08-31 19:51:13 +00:00
}
}))
.pipe(gulp.dest('./public/res-min/'));
});
2017-09-29 19:16:04 +00:00
gulp.task('bower-requirejs', function() {
return new Promise(function (resolve) {
bowerRequirejs({
config: './public/res/main.js'
}, resolve);
})
2014-09-01 21:27:15 +00:00
});
2014-08-31 19:51:13 +00:00
/** __________________________________________
* Less
*/
gulp.task('clean-less', function() {
return gulp.src('./public/res-min/themes')
.pipe(clean());
});
gulp.task('less', ['clean-less'], function() {
return gulp.src([
'./public/res/styles/base.less',
'./public/res/themes/*.less'
])
.pipe(less({
compress: true
}))
.pipe(gulp.dest('./public/res-min/themes/'));
});
/** __________________________________________
* Fonts
*/
gulp.task('clean-font', function() {
return gulp.src('./public/res-min/font')
.pipe(clean());
});
gulp.task('copy-font', ['clean-font'], function() {
return gulp.src('./public/res/font/*')
.pipe(gulp.dest('./public/res-min/font/'));
});
/** __________________________________________
* Images
*/
gulp.task('clean-img', function() {
return gulp.src('./public/res-min/img')
.pipe(clean());
});
gulp.task('copy-img', ['clean-img'], function() {
return gulp.src('./public/res/img/*')
.pipe(gulp.dest('./public/res-min/img/'));
});
/** __________________________________________
* cache.manifest
*/
2014-09-06 00:11:06 +00:00
gulp.task('cache-manifest', function() {
2014-08-31 19:51:13 +00:00
return gulp.src('./public/cache.manifest')
.pipe(replace(/(#Date ).*/, '$1' + Date()))
2014-09-06 00:11:06 +00:00
.pipe(inject(gulp.src([
'./res-min/**/*.*'
], {
2014-08-31 19:51:13 +00:00
read: false,
cwd: './public'
}),
{
starttag: '# start_inject_resources',
endtag: '# end_inject_resources',
ignoreExtensions: true,
transform: function(filepath) {
2014-09-06 00:11:06 +00:00
return filepath.substring(1);
2014-09-01 21:27:15 +00:00
}
}))
.pipe(inject(gulp.src([
2014-09-06 00:11:06 +00:00
'./res/bower-libs/MathJax/MathJax.js',
'./res/bower-libs/MathJax/config/Safe.js',
'./res/bower-libs/MathJax/config/TeX-AMS_SVG.js',
2014-09-06 00:11:06 +00:00
'./res/bower-libs/MathJax/images/CloseX-31.png',
'./res/bower-libs/MathJax/images/MenuArrow-15.png',
'./res/bower-libs/MathJax/jax/output/SVG/jax.js',
2014-09-06 00:11:06 +00:00
'./res/bower-libs/MathJax/extensions/**/*.*',
'./res/bower-libs/MathJax/jax/element/**/*.*',
'./res/bower-libs/MathJax/jax/output/SVG/autoload/**/*.*',
'./res/bower-libs/MathJax/jax/output/SVG/fonts/TeX/**/*.*'
2014-09-01 21:27:15 +00:00
], {
read: false,
2014-09-06 00:11:06 +00:00
cwd: './public'
2014-09-01 21:27:15 +00:00
}),
{
starttag: '# start_inject_mathjax',
endtag: '# end_inject_mathjax',
ignoreExtensions: true,
transform: function(filepath) {
2014-09-06 00:11:06 +00:00
if(filepath == '/res/bower-libs/MathJax/MathJax.js') {
filepath += '?config=TeX-AMS_SVG';
2014-08-31 19:51:13 +00:00
}
2014-09-01 21:27:15 +00:00
else {
filepath += '?rev=2.6.1';
2014-09-01 21:27:15 +00:00
}
2014-09-06 00:11:06 +00:00
return filepath.substring(1);
2014-08-31 19:51:13 +00:00
}
}))
2014-09-06 00:11:06 +00:00
.pipe(gulp.dest('./public/'));
2014-08-31 19:51:13 +00:00
});
gulp.task('clean', [
'clean-requirejs',
'clean-less',
'clean-font',
'clean-img'
]);
2014-08-31 20:35:18 +00:00
gulp.task('default', function(cb) {
runSequence([
2017-09-27 19:59:14 +00:00
// 'jshint',
2014-08-31 19:51:13 +00:00
'requirejs',
'less',
'copy-font',
'copy-img'
],
2014-08-31 20:35:18 +00:00
'cache-manifest',
cb);
2014-08-31 19:51:13 +00:00
});
function bumpTask(importance) {
return function() {
return gulp.src([
'./package.json',
'./bower.json'
])
.pipe(bump({type: importance}))
.pipe(gulp.dest('./'));
};
}
gulp.task('bump-patch', bumpTask('patch'));
gulp.task('bump-minor', bumpTask('minor'));
gulp.task('bump-major', bumpTask('major'));
2017-09-29 19:16:04 +00:00
function exec(cmd) {
return new Promise (function (resolve, reject) {
childProcess.exec(cmd, {cwd: process.cwd()}, function(err, stdout, stderr) {
if (err) {
reject(err);
} else {
util.log(stdout, stderr);
resolve();
}
});
2014-09-02 22:19:42 +00:00
});
}
2014-08-31 19:51:13 +00:00
2017-09-29 19:16:04 +00:00
gulp.task('git-tag', function() {
2014-09-02 22:19:42 +00:00
var tag = 'v' + getVersion();
2014-08-31 19:51:13 +00:00
util.log('Tagging as: ' + util.colors.cyan(tag));
2017-09-29 19:16:04 +00:00
return exec('git add ./public/res-min')
.then(function () {
return exec('git commit -a -m "Prepare release"');
})
.then(function () {
return exec('git tag -a ' + tag + ' -m "Version ' + getVersion() + '"');
})
.then(function () {
return exec('npm publish');
})
.then(function () {
2018-01-07 16:28:16 +00:00
return exec('git push origin v4 --tags');
2014-09-02 22:19:42 +00:00
});
2014-08-31 19:51:13 +00:00
});
function releaseTask(importance) {
2014-08-31 20:35:18 +00:00
return function(cb) {
runSequence(
2014-08-31 19:51:13 +00:00
'bump-' + importance,
'default',
2014-08-31 20:05:34 +00:00
'git-tag',
2014-08-31 20:35:18 +00:00
cb);
2014-08-31 19:51:13 +00:00
};
}
2014-08-31 20:35:18 +00:00
gulp.task('patch', releaseTask('patch'));
gulp.task('minor', releaseTask('minor'));
2014-09-01 21:27:15 +00:00
gulp.task('major', releaseTask('major'));