-
Notifications
You must be signed in to change notification settings - Fork 14
/
Gruntfile.js
78 lines (74 loc) · 2.48 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
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
htmlmin: {
src: {
options: {
removeComments: true,
collapseWhitespace: true,
},
files: {
'src/modules/editor.min.html': 'src/modules/editor.html',
'src/modules/form-input.min.html':
'src/modules/form-input.html',
},
},
},
injectHTML: {
options: {
editorHtml: 'src/modules/editor.min.html',
formInputHtml: 'src/modules/form-input.min.html',
src: 'src/modules/ui.js',
},
},
concat: {
build: {
src: [
'src/modules/expression-backend.js',
'src/modules/cursor.js',
'src/modules/ui.js',
],
dest: 'src/mjxgui.js',
},
buildExample: {
src: [
'src/modules/expression-backend.js',
'src/modules/cursor.js',
'src/modules/ui.js',
],
dest: 'docs/js/mjxgui.js',
},
},
uglify: {
options: {
banner: '/*! mjxgui <%= grunt.template.today("yyyy-mm-dd") %> | (C) Hrushikesh Vaidya (@hrushikeshrv) | MIT License */',
},
build: {
src: 'src/mjxgui.js',
dest: 'src/mjxgui.min.js',
},
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask('injectHTML', function () {
const options = this.options();
const editorTemplate = grunt.file.read(options.editorHtml);
const formInputTemplate = grunt.file.read(options.formInputHtml);
const src = grunt.file.read(options.src);
let content = src.replace(/\{\{\seditor_html\s}}/, editorTemplate);
content = content.replace(
/\{\{\sform_input_html\s}}/,
formInputTemplate,
);
grunt.file.write(options.src, content);
});
grunt.registerTask('default', [
'htmlmin',
'injectHTML',
'concat',
'uglify',
]);
grunt.registerTask('inject-ui', ['htmlmin', 'injectHTML']);
};