forked from MithrilJS/mithril.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·223 lines (207 loc) · 7.28 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
module.exports = function(grunt) {
_ = require('lodash');
var version = "0.1.34";
var inputFolder = "./docs";
var tempFolder = "./temp";
var archiveFolder = "./archive";
var outputFolder = "../mithril";
var guideLayout = "guide";
var guide = [
"auto-redrawing",
"benchmarks",
"community",
"optimizing-performance",
"comparison",
"components",
"getting-started",
"installation",
"integration",
"practices",
"refactoring",
"routing",
"tools",
"web-services"
];
var apiLayout = "api";
var api = [
"change-log",
"roadmap",
"how-to-read-signatures",
"mithril",
"mithril.computation",
"mithril.deferred",
"mithril.module",
"mithril.prop",
"mithril.redraw",
"mithril.render",
"mithril.deps",
"mithril.request",
"mithril.route",
"mithril.sync",
"mithril.trust",
"mithril.withAttr",
"mithril.xhr"
];
var md2htmlTasks = {};
var makeTasks = function(layout, pages) {
pages.map(function(name) {
var src = inputFolder + "/" + name + ".md";
var title = (grunt.file.exists(src)) ? grunt.file.read(src).split(/\n/)[0].substring(3) + ' - ' : '';
md2htmlTasks[name] = {
options: {layout: inputFolder + "/layout/" + layout + ".html", templateData: { "topic": title }},
files: [{src: [src], dest: tempFolder + "/" + name + ".html"}]
}
})
};
makeTasks("guide", guide);
makeTasks("api", api);
var sauceBrowsers =[
{ browserName: 'firefox', version: '19', platform: 'XP' },
{ browserName: "internet explorer", platform: "XP", version: "6"},
{ browserName: "safari", platform: "OS X 10.9", version: "7"},
{ browserName: "iPad", platform: "OS X 10.9", version: "7.1"},
{ browserName: "opera", platform: "Linux", version: "12"},
{ browserName: "chrome", platform: "XP", version: "26"},
{ browserName: "chrome", platform: "Windows 8", version: "26"}
];
var sauceOnTestComplete = function(result, callback) {
var request = require('request');
var user = process.env.SAUCE_USERNAME;
var pass = process.env.SAUCE_ACCESS_KEY;
request.put({
url: ['https://saucelabs.com/rest/v1', user, 'jobs', result.job_id].join('/'),
auth: { user: user, pass: pass },
json: { passed: result.passed }
}, function (error, response, body) {
if (error) {
callback(error);
} else if (response.statusCode !== 200) {
callback(new Error('Unexpected response status: '
+ response.statusCode + "\n "));
} else {
callback(null, result.passed);
}
});
};
var sauceBaseOptions = {
username: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
testname: "Mithril Tests " + new Date().toJSON(),
browsers: sauceBrowsers,
sauceConfig: {
"record-video": false,
"record-screenshots": false,
},
build: process.env.TRAVIS_JOB_ID,
onTestComplete: sauceOnTestComplete,
tunnelTimeout: 5,
};
var sauceCustomOptions = {
testname: "Mithril Custom Tests "+ new Date().toJSON(),
urls: ["http://127.0.0.1:8000/tests/index.html"],
};
_.assign(sauceCustomOptions, sauceBaseOptions);
var sauceQunitOptions = {
testname: "qUnit Tests "+ new Date().toJSON(),
urls: ["http://127.0.0.1:8000/tests/e2e/test.html"],
};
_.assign(sauceQunitOptions, sauceBaseOptions);
var currentVersionArchiveFolder = archiveFolder + "/v" + version;
grunt.initConfig({
md2html: md2htmlTasks,
uglify: {
options: {banner: "/*\nMithril v" + version + "\nhttp://github.com/lhorie/mithril.js\n(c) Leo Horie\nLicense: MIT\n*/", sourceMap: true},
mithril: {src: "mithril.js", dest: "mithril.min.js"}
},
concat: {
test: {src: ["mithril.js", "./tests/test.js", "./tests/mock.js", "./tests/mithril-tests.js"], dest: currentVersionArchiveFolder + "/mithril-tests.js"}
},
zip: {
distribution: {
cwd: currentVersionArchiveFolder + "/",
src: [currentVersionArchiveFolder + "/mithril.min.js", currentVersionArchiveFolder + "/mithril.min.js.map", currentVersionArchiveFolder + "/mithril.js"],
dest: currentVersionArchiveFolder + "/mithril.min.zip"
}
},
replace: {
options: {force: true, patterns: [{match: /\.md/g, replacement: ".html"}, {match: /\$version/g, replacement: version}]},
links: {expand: true, flatten: true, src: [tempFolder + "/**/*.html"], dest: currentVersionArchiveFolder + "/"},
index: {src: inputFolder + "/layout/index.html", dest: currentVersionArchiveFolder + "/index.html"},
commonjs: {expand: true, flatten: true, src: [inputFolder + "/layout/*.json"], dest: currentVersionArchiveFolder},
cdnjs: {src: "deploy/cdnjs-package.json", dest: "../cdnjs/ajax/libs/mithril/package.json"}
},
copy: {
style: {src: inputFolder + "/layout/style.css", dest: currentVersionArchiveFolder + "/style.css"},
pages: {src: inputFolder + "/layout/pages.json", dest: currentVersionArchiveFolder + "/pages.json"},
lib: {expand: true, cwd: inputFolder + "/layout/lib/", src: "./**", dest: currentVersionArchiveFolder + "/lib/"},
tools: {expand: true, cwd: inputFolder + "/layout/tools/", src: "./**", dest: currentVersionArchiveFolder + "/tools/"},
comparisons: {expand: true, cwd: inputFolder + "/layout/comparisons/", src: "./**", dest: currentVersionArchiveFolder + "/comparisons/"},
unminified: {src: "mithril.js", dest: currentVersionArchiveFolder + "/mithril.js"},
minified: {src: "mithril.min.js", dest: currentVersionArchiveFolder + "/mithril.min.js"},
readme: {src: "README.md", dest: currentVersionArchiveFolder + "/README.md"},
map: {src: "mithril.min.js.map", dest: currentVersionArchiveFolder + "/mithril.min.js.map"},
typescript: {src: "mithril.d.ts", dest: currentVersionArchiveFolder + "/mithril.d.ts"},
publish: {expand: true, cwd: currentVersionArchiveFolder, src: "./**", dest: outputFolder},
archive: {expand: true, cwd: currentVersionArchiveFolder, src: "./**", dest: outputFolder + "/archive/v" + version},
},
execute: {
tests: {src: [currentVersionArchiveFolder + "/mithril-tests.js"]}
},
qunit: {
all: ['tests/e2e/**/*.html']
},
"saucelabs-custom": {
all:{
options: sauceCustomOptions
}
},
"saucelabs-qunit": {
all:{
options: sauceQunitOptions
}
},
watch: {},
connect: {
server: {
options: {
port: 8888,
base: '.'
}
}
},
clean: {
options: {force: true},
generated: [tempFolder]
},
jsfmt: {
default: {
files: [{
expand: true,
src: ['mithril.js'],
cwd: '.',
dest: '.'
}]
}
}
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks('grunt-execute');
grunt.loadNpmTasks("grunt-md2html");
grunt.loadNpmTasks("grunt-replace");
grunt.loadNpmTasks('grunt-zip');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-jsfmt');
grunt.registerTask("build", ["test", "uglify", "zip", "md2html", "replace", "copy", "clean"]);
grunt.registerTask("testall", ["test", "teste2e"]);
grunt.registerTask("test", ["concat", "execute"]);
grunt.registerTask('teste2e', ['connect', 'qunit']);
grunt.registerTask("default", ["build"]);
grunt.registerTask("sauce-qunit", ["connect", "saucelabs-qunit"]);
grunt.registerTask("sauce-custom", ["connect", "saucelabs-custom"]);
grunt.registerTask("sauce-all", ["connect", "saucelabs-qunit", "saucelabs-custom"]);
};