simplemde-markdown-editor/gulpfile.babel.js

97 lines
2.7 KiB
JavaScript
Raw Normal View History

"use strict";
2017-01-16 19:19:40 +08:00
import babelify from 'babelify'
import gulp from 'gulp'
import minifycss from 'gulp-clean-css'
import uglify from 'gulp-uglify'
import concat from 'gulp-concat'
import header from 'gulp-header'
import buffer from 'vinyl-buffer'
import pkg from './package.json'
import debug from 'gulp-debug'
import eslint from 'gulp-eslint'
import prettify from 'gulp-jsbeautifier'
import browserify from 'browserify'
import source from 'vinyl-source-stream'
import rename from 'gulp-rename'
2017-01-16 19:19:40 +08:00
const banner = `/**
* <%= pkg.name %> v<%= pkg.version %>
* Copyright <%= pkg.company %>
* @link <%= pkg.homepage %>
* @license <%= pkg.license %>
*/\n`
2015-11-03 10:16:20 -06:00
gulp.task("prettify-js", [], function() {
return gulp.src("./src/js/simplemde.js")
2016-03-14 21:28:56 -05:00
.pipe(prettify({js: {brace_style: "collapse", indent_char: "\t", indent_size: 1, max_preserve_newlines: 3, space_before_conditional: false}}))
2015-11-03 10:16:20 -06:00
.pipe(gulp.dest("./src/js"));
});
gulp.task("prettify-css", [], function() {
return gulp.src("./src/css/simplemde.css")
.pipe(prettify({css: {indentChar: "\t", indentSize: 1}}))
.pipe(gulp.dest("./src/css"));
});
gulp.task("lint", ["prettify-js"], function() {
gulp.src("./src/js/**/*.js")
.pipe(debug())
.pipe(eslint())
2015-11-03 14:54:29 -06:00
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
function taskBrowserify(opts) {
return browserify("./src/js/simplemde.js", opts)
2017-01-16 19:19:40 +08:00
.transform("babelify", {presets: ['es2015', 'stage-3']})
.bundle();
}
gulp.task("browserify:debug", ["lint"], function() {
return taskBrowserify({debug:true, standalone:"SimpleMDE"})
.pipe(source("simplemde.debug.js"))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest("./debug/"));
});
gulp.task("browserify", ["lint"], function() {
return taskBrowserify({standalone:"SimpleMDE"})
.pipe(source("simplemde.js"))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest("./debug/"));
});
2015-07-21 15:12:32 +01:00
gulp.task("scripts", ["browserify:debug", "browserify", "lint"], function() {
var js_files = ["./debug/simplemde.js"];
2015-11-03 10:16:20 -06:00
2015-08-11 11:45:45 -05:00
return gulp.src(js_files)
.pipe(concat("simplemde.min.js"))
2015-08-11 11:45:45 -05:00
.pipe(uglify())
.pipe(buffer())
2015-08-11 11:45:45 -05:00
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest("./dist/"));
2015-07-21 15:12:32 +01:00
});
2015-11-03 10:16:20 -06:00
gulp.task("styles", ["prettify-css"], function() {
var css_files = [
"./node_modules/codemirror/lib/codemirror.css",
"./src/css/*.css",
"./node_modules/codemirror-spell-checker/src/css/spell-checker.css"
];
2015-11-03 10:16:20 -06:00
return gulp.src(css_files)
.pipe(concat("simplemde.css"))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest("./debug/"))
2015-08-11 11:45:45 -05:00
.pipe(minifycss())
.pipe(rename("simplemde.min.css"))
.pipe(buffer())
2015-08-11 11:45:45 -05:00
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest("./dist/"));
2015-07-21 15:12:32 +01:00
});
2015-11-03 14:54:29 -06:00
gulp.task("default", ["scripts", "styles"]);