-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
98 lines (91 loc) · 3.01 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
var gulp = require('gulp'),
rename = require('gulp-rename'),
gulpKmd = require('gulp-kmd')
kmc = require('gulp-kmc'),
minify = require('gulp-minify'),
gulpJoycss =require('gulp-joycss'),
through2 = require('through2'),
packageJson = require('./package.json');
kmc.config({
depFilePath : './build/mods.js',
packages : [
{
name : 'kg/editor-plugins/' + packageJson.version,
combine : false,
base : './lib'
}
]
});
gulp.task('turnHtmlAsModule', function(cb){ //先将html文件转为nodejs风格的模块代码
gulp.src('./lib/**/*.html')
.pipe(through2.obj(function(file, enc, callback){
file.contents = new Buffer("module.exports=" + JSON.stringify(file.contents.toString()));
this.push(file);
callback();
}))
.pipe(rename(function(path){
path.basename = path.basename.replace('.tpl', '-tpl');
path.extname = '.js';
}))
.pipe(gulp.dest('./lib'));
cb();
});
gulp.task('kmc', ['turnHtmlAsModule'], function(cb){
gulp.src('./lib/**/*.js')
.pipe(gulpKmd())
.pipe(kmc.convert({
deps : 'mods.js',
define : true
}))
.pipe(kmc.combo())
.pipe(minify())
.pipe(rename(function(path){
if(path.basename.indexOf('-min') > -1){
path.basename = path.basename.replace('-min', '');
}else{
path.basename = path.basename + '-debug';
}
}))
.pipe(gulp.dest('./build'));
});
gulp.task('buildCss', function(cb){
gulp.src('assets/*.less')
.pipe(gulpJoycss({
layout:'close',
'editor.less' : {
imgPath : 'build/assets',
dest : 'build/assets/editor.css',
prefixUrl : '/kg/editor-plugins/' + packageJson.version + '/assets'
},
'iframe.less' : {
dest : 'build/assets/iframe.css'
}
}))
.pipe(gulp.dest('build/assets'));
});
gulp.task('buildApi', function(cb){
var process = require('child_process');
process.exec('node ./node_modules/yuidocjs/lib/cli.js .', function(){
cb();
});
})
gulp.task('server', function () {
var app = require('express')();
var fs = require('fs');
var path = require('path');
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');
app.use(serveIndex(process.cwd(), {
hidden: true,
view: 'details'
}));
app.use('/lib/', function (req, res, next) {
var filePath = path.resolve(process.cwd(), 'lib', req.path.substring(1));
var code = fs.readFileSync(filePath, 'utf-8');
res.set('content-type', 'application/javascript;charset=utf-8');
res.end('define(function(require,exports,module){' + code + '});');
});
app.use(serveStatic(process.cwd()));
app.listen(8001);
});
gulp.task('default', ['kmc', 'buildCss', 'buildApi']);