forked from pandao/editor.md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
232 lines (207 loc) · 7.53 KB
/
Gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
'use strict';
var os = require("os");
var gulp = require('gulp');
var gutil = require("gulp-util");
var sass = require('gulp-ruby-sass');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
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');
var autoprefixer = require('gulp-autoprefixer');
var jsdoc = require("gulp-jsdoc");
var jsdoc2md = require("gulp-jsdoc-to-markdown");
var pkg = require('./package.json');
var dateFormat = require('dateformatter').format;
pkg.name = "Editor.md";
pkg.today = dateFormat;
var headerComment = ["/*",
" * <%= pkg.name %>",
" * @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) {
path = path || 'src/scss/';
return gulp.src(path + fileName + ".scss")
.pipe(sass({ style: 'expanded' })) //nested,compact,expanded,compressed
.pipe(gulp.dest('dist/css'))
.pipe(header(headerComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest('dist/css'))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'))
.pipe(minifycss())
.pipe(gulp.dest('dist/css'))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest('dist/css'))
.pipe(notify({ message: fileName + '.scss task completed!' }));
};
gulp.task('scss', function() {
return scssTask('editormd');
});
gulp.task('scss2', function() {
return scssTask('editormd.preview');
});
gulp.task('scss3', function() {
return scssTask('editormd.logo');
});
gulp.task('js', function() {
return gulp.src('src/js/**/*.js')
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(header(headerComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base);
return name[1].replace(/[\\\/]?/, '');
}}))
.pipe(gulp.dest('dist/js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
.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('dist/js'))
.pipe(notify({ message: 'js task complete' }));
});
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",
"search/search",
"scroll/annotatescrollbar",
"search/matchesonscrollbar",
"display/placeholder",
"edit/closetag",
"fold/xml-fold",
"mode/overlay",
"selection/active-line",
"edit/closebrackets",
"display/fullscreen",
"search/searchcursor",
"search/match-highlighter"
]
};
gulp.task('codemirror-mode', function() {
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");
}
return gulp.src(modes)
.pipe(concat('modes.min.js'))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(uglify())
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + "\\");
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(notify({ message: 'codemirror-mode task complete' }));
});
gulp.task('codemirror-addon', function() {
var addons = [];
for(var i in codeMirror.addons) {
var addon = codeMirror.addons[i];
addons.push(codeMirror.path.src.addon + "/" + addon + ".js");
}
return gulp.src(addons)
.pipe(concat('addons.min.js'))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(uglify())
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(header(headerMiniComment, {pkg : pkg, fileName : function(file) {
var name = file.path.split(file.base + "\\");
return name[1].replace('\\', '');
}}))
.pipe(gulp.dest(codeMirror.path.dist))
.pipe(notify({ message: 'codemirror-addon task complete' }));
});
gulp.task("jsdoc", function(){
return gulp.src(["./src/editormd.js", "README.md"])
.pipe(jsdoc.parser())
.pipe(jsdoc.generator('./docs/html'));
});
gulp.task("jsdoc2md", function() {
return gulp.src("src/js/editormd.js")
.pipe(jsdoc2md())
.on("error", function(err){
gutil.log(gutil.colors.red("jsdoc2md failed"), err.message)
})
.pipe(rename(function(path) {
path.extname = ".md";
}))
.pipe(gulp.dest("docs/markdown"));
});
gulp.task('watch', function() {
gulp.watch('src/scss/editormd.scss', ['scss']);
gulp.watch('src/scss/editormd.preview.scss', ['scss2']);
gulp.watch('src/scss/editormd.logo.scss', ['scss3']);
gulp.watch('src/js/**/*.js', ['js']);
});
gulp.task('default', function() {
gulp.run('scss');
gulp.run('scss2');
gulp.run('scss3');
gulp.run('js');
gulp.run("codemirror-addon");
gulp.run("codemirror-mode");
gulp.run('jsdoc');
});