forked from seajs/seajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
105 lines (80 loc) · 2.56 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
103
104
module.exports = function(grunt) {
var path = require("path")
const GCC_OPTIONS = {
compilation_level: "SIMPLE_OPTIMIZATIONS",
externs: "tools/extern.js",
warning_level: "VERBOSE",
jscomp_off: "checkTypes",
jscomp_error: "checkDebuggerStatement"
}
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
concat: {
seajs: {
src: [
"src/intro.js",
"src/sea.js",
"src/util-lang.js",
"src/util-log.js",
"src/util-events.js",
"src/util-path.js",
"src/util-request.js",
"src/util-deps.js",
"src/module.js",
"src/config.js",
"src/bootstrap.js",
"src/outro.js"
],
dest: "dist/sea-debug.js"
}
},
gcc: {
seajs: {
src: "dist/sea-debug.js",
dest: "dist/sea.js",
options: grunt.util._.merge({
banner: "/*! SeaJS <%= pkg.version %> | seajs.org/LICENSE.md */",
source_map_format: "V3",
create_source_map: "dist/sea.js.map"
}, GCC_OPTIONS)
},
plugins: {
files: grunt.file.expandMapping(
"src/plugins/*.js", "dist/",
{
"rename": function(dest, matchedSrcPath) {
return path.join(dest, matchedSrcPath.split("/").pop())
}
}
),
options: GCC_OPTIONS
}
}
})
grunt.registerTask("embed", "Embed version etc.", function() {
var filepath = "dist/sea-debug.js"
var version = grunt.config("pkg.version")
var code = grunt.file.read(filepath)
code = code.replace(/@VERSION/g, version)
grunt.file.write(filepath, code)
grunt.log.writeln("@VERSION is replaced to \"" + version + "\".")
})
grunt.registerTask("fix", "Fix sourceMap etc.", function() {
var mapfile = "dist/sea.js.map"
var minfile = "dist/sea.js"
var code = grunt.file.read(mapfile)
code = code.replace('"file":""', '"file":"sea.js"')
code = code.replace("dist/sea-debug.js", "sea-debug.js")
grunt.file.write(mapfile, code)
grunt.log.writeln('"' + mapfile + '" is fixed.')
code = grunt.file.read(minfile)
code += "//@ sourceMappingURL=sea.js.map\n"
grunt.file.write(minfile, code)
grunt.log.writeln('"' + minfile + '" is fixed.')
})
grunt.loadTasks("tools/grunt-tasks")
grunt.loadNpmTasks("grunt-contrib-concat")
grunt.registerTask("default", ["concat", "embed", "gcc:seajs", "fix"])
grunt.registerTask("plugins", ["gcc:plugins"])
grunt.registerTask("all", ["default", "plugins"])
}