forked from fabien-d/alertify.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
161 lines (152 loc) · 5.72 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var requirejs = require("requirejs");
requirejs.config({
appDir : __dirname + "/src/",
baseUrl : __dirname + "/src/"
});
var generateInit = requirejs("generate");
module.exports = function (grunt) {
"use strict";
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-qunit");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks('grunt-contrib-compass');
var license = "/*!\n" +
" * <%= pkg.name %>.js\n" +
" * <%= pkg.description %>\n" +
" *\n" +
" * @author <%= pkg.author.name %> <<%= pkg.author.email %>>\n" +
" * @copyright <%= pkg.author.name %> <%= grunt.template.today('yyyy') %>\n" +
" * @license <%= pkg.licenses[0].type %> <<%= pkg.licenses[0].url %>>\n" +
" * @link <%= pkg.homepage %>\n" +
" * @module <%= pkg.name %>\n" +
" * @version <%= pkg.version %>\n" +
" */";
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
clean: {
build: ["build", "dist", "tmp"],
postbuild: ["build", "tmp"]
},
compass: {
dist: {
options: {
sassDir: "sass",
cssDir: "dist/themes",
environment: "production",
outputStyle: "nested"
}
}
},
copy: {
build: {
files: {
"dist/alertify.js": "build/src/alertify.js"
}
}
},
generateinit : {
build: {
src: ["tmp/alertify.init.js"]
}
},
jshint: {
files: {
src: ["src/**/*.js"]
},
options: {
curly : true,
eqeqeq : true,
immed : true,
latedef : true,
noempty : true,
newcap : true,
noarg : true,
sub : true,
undef : true,
boss : true,
eqnull : true,
node : true,
smarttabs : true,
es5 : true,
globals: {
Alertify : true,
document : true,
require : true,
define : true
}
}
},
qunit: {
all: ["test/**/*.html"]
},
requirejs: {
compile: {
options: {
dir: "build",
appDir: ".",
baseUrl: "src",
optimize: "none",
paths: {
"alertify.init": "../tmp/alertify.init"
},
modules: [{
"name": "alertify",
"include": ["alertify.init"],
"create": true
}],
wrap: {
start: license + "\n(function (global, document, undefined) {",
end: "})(this, document);"
},
fileExclusionRegExp: /^(.git|node_modules|example|test)$/,
onBuildWrite: function (id, path, contents) {
if ((/define\(.*?\{/).test(contents)) {
// this whole block is way too hacky
// need to figure something cleaner for this
var method = contents.match(/return.*;\s\S+[}\)]/);
method = method[0].split("\n")[0].replace("new ", "").split(" ")[1].replace("()", "").replace(";", "");
contents = contents.replace(/define\(.*?\{/, "var " + method + " = (function () {");
contents = contents.replace(/\}\);\s*?$/, "}());");
} else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, "");
contents = contents.replace(/\}\);\s*$/, "");
}
return contents;
}
}
}
},
stripdefine: {
build: {
src: ["dist/alertify.js"]
}
},
uglify: {
options: {
banner: "/*! <%= pkg.name %> <%= pkg.version %> (<%= pkg.author.name %>) | <%= pkg.licenses[0].type %> */\n"
},
dist: {
files: {
"dist/alertify.min.js": ["dist/alertify.js"]
}
}
},
watch: {
files: "<config:lint.files>",
tasks: "lint"
}
});
grunt.registerMultiTask("stripdefine", "Strip define call from dist file", function () {
var mod = grunt.file.read(this.files[0].src[0]).replace("define(\"alertify.init\", function(){});", "");
grunt.file.write("dist/alertify.js", mod);
});
grunt.registerMultiTask("generateinit", "Generate Init file", function () {
grunt.file.write("tmp/alertify.init.js", generateInit());
});
grunt.registerTask("build", ["jshint", "qunit", "clean:build", "generateinit", "requirejs", "copy", "clean:postbuild", "stripdefine", "compass", "uglify"]);
grunt.registerTask("test", ["jshint", "qunit"]);
grunt.registerTask("default", ["build"]);
};