forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload-previous-version.js
47 lines (43 loc) · 1.35 KB
/
download-previous-version.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
"use strict";
var grunt = require('grunt');
var http = require('http');
var fs = require('fs');
module.exports = function() {
var completedSuccessfully = this.async();
get(
"http://react.zpao.com/builds/master/latest/react.min.js",
__dirname + '/../../build/react-previous.min.js',
function(success){
if (!success) {
return completedSuccessfully(success);
}
get(
"http://react.zpao.com/builds/master/latest/JSXTransformer.js",
__dirname + '/../../build/JSXTransformer-previous.js',
completedSuccessfully
);
}
);
function get(url, targetFilePath, completedSuccessfully) {
grunt.verbose.writeln('getting url "' + url + '"');
http.get(url, function(response) {
grunt.verbose.writeln('Received status code ' + response.statusCode + ' for "' + url + '"');
if (response.statusCode != 200) {
if (response.headers.location) {
get(response.headers.location, targetFilePath);
return;
} else {
grunt.fatal('Nothing else to do.');
completedSuccessfully(false);
return;
}
}
grunt.verbose.writeln('Writing url to "' + targetFilePath + '"');
response.pipe(fs.createWriteStream(targetFilePath))
.on('close', function() {
completedSuccessfully(true);
})
;
});
}
};