玛氪宕·梦魔(Markdown Memo),使用Markdown的云端备忘录,百度IFE的RIA启航班的不合格的作业,才……才没有什么阴谋呢! 源gitee链接https://gitee.com/arathi/MarkdownMemo?_from=gitee_search
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
13 KiB

10 years ago
"use strict";
10 years ago
10 years ago
var os = require("os");
10 years ago
var gulp = require("gulp");
10 years ago
var gutil = require("gulp-util");
10 years ago
var sass = require("gulp-ruby-sass");
var jshint = require("gulp-jshint");
10 years ago
var uglify = require("gulp-uglifyjs");
10 years ago
var rename = require("gulp-rename");
var concat = require("gulp-concat");
var notify = require("gulp-notify");
var header = require("gulp-header");
var minifycss = require("gulp-minify-css");
10 years ago
//var jsdoc = require("gulp-jsdoc");
//var jsdoc2md = require("gulp-jsdoc-to-markdown");
10 years ago
var pkg = require("./package.json");
var dateFormat = require("dateformatter").format;
10 years ago
var replace = require("gulp-replace");
10 years ago
pkg.name = "Editor.md";
pkg.today = dateFormat;
var headerComment = ["/*",
" * <%= pkg.name %>",
10 years ago
" *",
10 years ago
" * @file <%= fileName(file) %> ",
" * @version v<%= pkg.version %> ",
" * @description <%= pkg.description %>",
" * @license MIT License",
" * @author <%= pkg.author %>",
" * {@link <%= pkg.homepage %>}",
" * @updateTime <%= pkg.today('Y-m-d') %>",
" */",
"\r\n"].join("\r\n");
var headerMiniComment = "/*! <%= pkg.name %> v<%= pkg.version %> | <%= fileName(file) %> | <%= pkg.description %> | MIT License | By: <%= pkg.author %> | <%= pkg.homepage %> | <%=pkg.today('Y-m-d') %> */\r\n";
var scssTask = function(fileName, path) {
10 years ago
path = path || "scss/";
var distPath = "css";
10 years ago
10 years ago
return sass(path + fileName + ".scss", { style: "expanded", sourcemap: false, noCache : true })
.pipe(gulp.dest(distPath))
.pipe(header(headerComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace("\\", "");
}}))
.pipe(gulp.dest(distPath))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(distPath))
.pipe(minifycss())
.pipe(gulp.dest(distPath))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace("\\", "");
}}))
.pipe(gulp.dest(distPath))
.pipe(notify({ message: fileName + ".scss task completed!" }));
10 years ago
};
10 years ago
gulp.task("scss", function() {
return scssTask("editormd");
10 years ago
});
10 years ago
gulp.task("scss2", function() {
return scssTask("editormd.preview");
10 years ago
});
10 years ago
gulp.task("scss3", function() {
return scssTask("editormd.logo");
10 years ago
});
10 years ago
gulp.task("js", function() {
return gulp.src("./src/editormd.js")
.pipe(jshint("./.jshintrc"))
.pipe(jshint.reporter("default"))
10 years ago
.pipe(header(headerComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
10 years ago
return name[1].replace(/[\\\/]?/, "");
10 years ago
}}))
10 years ago
.pipe(gulp.dest("./"))
.pipe(rename({ suffix: ".min" }))
10 years ago
.pipe(uglify()) // {outSourceMap: true, sourceRoot: './'}
10 years ago
.pipe(gulp.dest("./"))
10 years ago
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + ( (os.platform() === "win32") ? "\\" : "/") );
10 years ago
return name[1].replace(/[\\\/]?/, "");
10 years ago
}}))
10 years ago
.pipe(gulp.dest("./"))
.pipe(notify({ message: "editormd.js task complete" }));
});
gulp.task("amd", function() {
var replaceText1 = [
'var cmModePath = "codemirror/mode/";',
' var cmAddonPath = "codemirror/addon/";',
'',
' var codeMirrorModules = [',
' "jquery", "marked", "prettify",',
' "katex", "raphael", "underscore", "flowchart", "jqueryflowchart", "sequenceDiagram",',
'',
' "codemirror/lib/codemirror",',
' cmModePath + "css/css",',
' cmModePath + "sass/sass",',
' cmModePath + "shell/shell",',
' cmModePath + "sql/sql",',
' cmModePath + "clike/clike",',
' cmModePath + "php/php",',
' cmModePath + "xml/xml",',
' cmModePath + "markdown/markdown",',
' cmModePath + "javascript/javascript",',
' cmModePath + "htmlmixed/htmlmixed",',
' cmModePath + "gfm/gfm",',
' cmModePath + "http/http",',
' cmModePath + "go/go",',
' cmModePath + "dart/dart",',
' cmModePath + "coffeescript/coffeescript",',
' cmModePath + "nginx/nginx",',
' cmModePath + "python/python",',
' cmModePath + "perl/perl",',
' cmModePath + "lua/lua",',
' cmModePath + "r/r", ',
' cmModePath + "ruby/ruby", ',
' cmModePath + "rst/rst",',
' cmModePath + "smartymixed/smartymixed",',
' cmModePath + "vb/vb",',
' cmModePath + "vbscript/vbscript",',
' cmModePath + "velocity/velocity",',
' cmModePath + "xquery/xquery",',
' cmModePath + "yaml/yaml",',
' cmModePath + "erlang/erlang",',
' cmModePath + "jade/jade",',
'',
' cmAddonPath + "edit/trailingspace", ',
' cmAddonPath + "dialog/dialog", ',
' cmAddonPath + "search/searchcursor", ',
' cmAddonPath + "search/search", ',
' cmAddonPath + "scroll/annotatescrollbar", ',
' cmAddonPath + "search/matchesonscrollbar", ',
' cmAddonPath + "display/placeholder", ',
' cmAddonPath + "edit/closetag", ',
' cmAddonPath + "fold/foldcode",',
' cmAddonPath + "fold/foldgutter",',
' cmAddonPath + "fold/indent-fold",',
' cmAddonPath + "fold/brace-fold",',
' cmAddonPath + "fold/xml-fold", ',
' cmAddonPath + "fold/markdown-fold",',
' cmAddonPath + "fold/comment-fold", ',
' cmAddonPath + "mode/overlay", ',
' cmAddonPath + "selection/active-line", ',
' cmAddonPath + "edit/closebrackets", ',
' cmAddonPath + "display/fullscreen",',
' cmAddonPath + "search/match-highlighter"',
' ];',
'',
' define(codeMirrorModules, factory);'
].join("\r\n");
var replaceText2 = [
"if (typeof define == \"function\" && define.amd) {",
" $ = arguments[0];",
" marked = arguments[1];",
" prettify = arguments[2];",
" katex = arguments[3];",
" Raphael = arguments[4];",
" _ = arguments[5];",
" flowchart = arguments[6];",
" CodeMirror = arguments[9];",
" }"
].join("\r\n");
gulp.src("src/editormd.js")
.pipe(rename({ suffix: ".amd" }))
.pipe(gulp.dest('./'))
.pipe(header(headerComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace(/[\\\/]?/, "");
}}))
.pipe(gulp.dest("./"))
.pipe(replace("/* Require.js define replace */", replaceText1))
.pipe(gulp.dest('./'))
.pipe(replace("/* Require.js assignment replace */", replaceText2))
.pipe(gulp.dest('./'))
.pipe(rename({ suffix: ".min" }))
10 years ago
.pipe(uglify()) //{outSourceMap: true, sourceRoot: './'}
10 years ago
.pipe(gulp.dest("./"))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + ( (os.platform() === "win32") ? "\\" : "/") );
return name[1].replace(/[\\\/]?/, "");
}}))
.pipe(gulp.dest("./"))
.pipe(notify({ message: "amd version task complete"}));
});
10 years ago
var codeMirror = {
path : {
src : {
mode : "lib/codemirror/mode",
addon : "lib/codemirror/addon"
},
dist : "lib/codemirror"
},
modes : [
"css",
"sass",
"shell",
"sql",
"clike",
"php",
"xml",
"markdown",
"javascript",
"htmlmixed",
"gfm",
"http",
"go",
"dart",
"coffeescript",
"nginx",
"python",
"perl",
"lua",
"r",
"ruby",
"rst",
"smartymixed",
"vb",
"vbscript",
"velocity",
"xquery",
"yaml",
"erlang",
"jade",
],
addons : [
"edit/trailingspace",
"dialog/dialog",
"search/searchcursor",
10 years ago
"search/search",
10 years ago
"scroll/annotatescrollbar",
"search/matchesonscrollbar",
"display/placeholder",
"edit/closetag",
10 years ago
"fold/foldcode",
"fold/foldgutter",
"fold/indent-fold",
"fold/brace-fold",
10 years ago
"fold/xml-fold",
10 years ago
"fold/markdown-fold",
"fold/comment-fold",
10 years ago
"mode/overlay",
"selection/active-line",
"edit/closebrackets",
"display/fullscreen",
"search/match-highlighter"
]
};
10 years ago
gulp.task("cm-mode", function() {
10 years ago
var modes = [
codeMirror.path.src.mode + "/meta.js"
];
for(var i in codeMirror.modes) {
var mode = codeMirror.modes[i];
modes.push(codeMirror.path.src.mode + "/" + mode + "/" + mode + ".js");
}
10 years ago
return gulp.src(modes)
10 years ago
.pipe(concat("modes.min.js"))
10 years ago
.pipe(gulp.dest(codeMirror.path.dist))
10 years ago
.pipe(uglify()) // {outSourceMap: true, sourceRoot: codeMirror.path.dist}
10 years ago
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
10 years ago
var name = file.path.split(file.base + "\\");
return (name[1]?name[1]:name[0]).replace(/\\/g, "");
10 years ago
}}))
.pipe(gulp.dest(codeMirror.path.dist))
10 years ago
.pipe(notify({ message: "codemirror-mode task complete!" }));
10 years ago
});
10 years ago
gulp.task("cm-addon", function() {
10 years ago
var addons = [];
for(var i in codeMirror.addons) {
var addon = codeMirror.addons[i];
addons.push(codeMirror.path.src.addon + "/" + addon + ".js");
}
10 years ago
return gulp.src(addons)
10 years ago
.pipe(concat("addons.min.js"))
10 years ago
.pipe(gulp.dest(codeMirror.path.dist))
10 years ago
.pipe(uglify()) //{outSourceMap: true, sourceRoot: codeMirror.path.dist}
10 years ago
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + "\\");
10 years ago
return (name[1]?name[1]:name[0]).replace(/\\/g, "");
10 years ago
}}))
.pipe(gulp.dest(codeMirror.path.dist))
10 years ago
.pipe(notify({ message: "codemirror-addon.js task complete" }));
10 years ago
});
10 years ago
/*
10 years ago
gulp.task("jsdoc", function(){
return gulp.src(["./src/editormd.js", "README.md"])
.pipe(jsdoc.parser())
10 years ago
.pipe(jsdoc.generator("./docs/html"));
10 years ago
});
gulp.task("jsdoc2md", function() {
return gulp.src("src/js/editormd.js")
10 years ago
.pipe(jsdoc2md())
.on("error", function(err){
10 years ago
gutil.log(gutil.colors.red("jsdoc2md failed"), err.message);
10 years ago
})
.pipe(rename(function(path) {
path.extname = ".md";
}))
.pipe(gulp.dest("docs/markdown"));
10 years ago
});
10 years ago
*/
10 years ago
gulp.task("watch", function() {
10 years ago
gulp.watch("scss/editormd.scss", ["scss"]);
gulp.watch("scss/editormd.preview.scss", ["scss", "scss2"]);
gulp.watch("scss/editormd.logo.scss", ["scss", "scss3"]);
10 years ago
gulp.watch("src/editormd.js", ["js", "amd"]);
10 years ago
});
10 years ago
gulp.task("default", function() {
gulp.run("scss");
gulp.run("scss2");
gulp.run("scss3");
gulp.run("js");
gulp.run("amd");
gulp.run("cm-addon");
gulp.run("cm-mode");
10 years ago
});