forked from summernote/summernote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrunt-build.js
78 lines (68 loc) · 2.11 KB
/
grunt-build.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) {
'use strict';
var requirejs = require('requirejs');
var path = require('path');
var rDefineStart = /define\([^{]*?{/;
var rDefineEndWithReturn = /\s*return\s+[^\}]+(\}\);[^\w\}]*)$/;
var rDefineEnd = /\}\);[^}\w]*$/;
grunt.registerMultiTask('build', 'concatenate source: summernote.js', function () {
/**
* Strip all definitions generated by requirejs
*
* @param {String} name
* @param {String} path
* @param {String} contents The contents to be written (including their AMD wrappers)
*/
var convert = function (name, path, contents) {
contents = contents.replace(rDefineStart, '');
if (rDefineEndWithReturn.test(contents)) {
contents = contents.replace(rDefineEndWithReturn, '');
} else {
contents = contents.replace(rDefineEnd, '');
}
return contents;
};
var outputPath = this.data.outFile;
/**
* Handle final output from the optimizer
*/
var out = function (compiled) {
// 01. Embed version
var version = grunt.config('pkg.version');
compiled = compiled.replace(/@VERSION/g, version);
// 02. Embed Date
var date = (new Date()).toISOString().replace(/:\d+\.\d+Z$/, 'Z');
compiled = compiled.replace(/@DATE/g, date);
grunt.file.write(outputPath, compiled);
};
var config = {
name: 'summernote/summernote',
baseUrl: this.data.baseUrl,
out: out,
optimize: 'none',
wrap: {
startFile: path.join(this.data.baseUrl, this.data.startFile),
endFile: path.join(this.data.baseUrl, this.data.endFile)
},
findNestedDependencies: true,
skipSemiColonInsertion: true,
onBuildWrite: convert,
excludeShallow: ['jquery', 'CodeMirror', 'app'],
paths: {
jquery: 'empty:',
CodeMirror: 'empty:'
},
packages: [{
name: 'summernote',
location: './',
main: 'summernote'
}]
};
var done = this.async();
requirejs.optimize(config, function () {
done();
}, function (err) {
done(err);
});
});
};