forked from lepture/editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
102 lines (95 loc) · 3 KB
/
Gruntfile.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
var path = require('path');
module.exports = function(grunt) {
var pkg = require('./package.json');
pkg.spm = pkg.spm || {};
pkg.spm.sourcedir = 'tmp/src';
pkg.spm.output = ['editor.js'];
grunt.initConfig({
pkg: pkg,
connect: {
livereload: {
options: {
port: 8000,
middleware: function(connect) {
return [
require('connect-livereload')(),
connect.static(path.resolve('build')),
connect.directory(path.resolve('build'))
];
}
}
},
},
watch: {
editor: {
files: ['*.css', 'src/*'],
tasks: ['build'],
options: {
livereload: true
}
}
},
transport: {
seajs: {
options: {
dest: 'tmp/src/editor.js',
header: 'define(function(require, exports, module) {',
footer: [
'module.exports = Editor',
'});'
].join('\n')
}
},
component: {
options: {
dest: 'index.js',
header: '',
footer: 'module.exports = Editor'
}
},
window: {}
}
});
grunt.registerTask('concat', function() {
var data = grunt.file.read('vendor/codemirror.js');
data = data.replace('window.CodeMirror', 'var CodeMirror');
['continuelist', 'xml', 'markdown'].forEach(function(name) {
data += '\n' + grunt.file.read('vendor/' + name + '.js');
});
data += '\n' + grunt.file.read('src/intro.js');
data += '\n' + grunt.file.read('src/editor.js');
grunt.file.write('tmp/editor.js', data);
});
grunt.registerMultiTask('transport', function() {
var options = this.options({
src: 'tmp/editor.js',
dest: 'build/editor.js',
header: '(function(global) {',
footer: 'global.Editor = Editor;\n})(this);'
});
var data = grunt.file.read(options.src);
data = [options.header, data, options.footer].join('\n');
grunt.file.write(options.dest, data);
});
grunt.registerTask('copy', function() {
var dir = 'vendor/icomoon/fonts';
grunt.file.recurse(dir, function(fpath) {
var fname = path.relative(dir, fpath);
grunt.file.copy(fpath, path.join('build', 'fonts', fname));
});
var data = grunt.file.read('vendor/icomoon/style.css');
data += grunt.file.read('paper.css');
data += grunt.file.read('editor.css');
grunt.file.write('build/editor.css', data);
grunt.file.copy('docs/index.html', 'build/index.html');
grunt.file.copy('docs/markdown.md', 'build/markdown.md');
grunt.file.copy('docs/markdown.html', 'build/markdown.html');
grunt.file.copy('docs/yue.css', 'build/yue.css');
grunt.file.copy('docs/marked.js', 'build/marked.js');
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('build', ['concat', 'transport:window', 'copy']);
grunt.registerTask('server', ['build', 'connect', 'watch']);
grunt.registerTask('default', ['server']);
};