-
Notifications
You must be signed in to change notification settings - Fork 578
/
Gruntfile.js
111 lines (110 loc) · 2.83 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
module.exports = function(grunt) {
grunt.initConfig({
connect: {
options: {
// useAvailablePort: true,
port: 8000,
hostname: '*',
base: '.',
// keepalive: true,
livereload: true
// debug: true,
},
server: {
options: {
open: 'http://localhost:8000/examples/testsuite.html'
}
},
test: {
options: {
open: 'http://localhost:8000/test/'
}
}
},
watch: {
options: {
livereload: true
},
static: {
files: ['smartcrop.js', 'examples/*', 'test/*'],
options: {
livereload: true
}
}
},
rsync: {
options: {
recursive: true
},
release: {
options: {
src: 'examples smartcrop.js doc/example.jpg',
dest: '/var/www/static/sandbox/2014/smartcrop/',
host: '29a.ch',
port: '22',
dryRun: false
}
}
},
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});
grunt.registerTask('default', ['connect:server', 'watch']);
grunt.registerTask('test', ['connect:test', 'watch']);
grunt.registerTask(
'fetchSamples',
'fetch sample images from 500px api',
function() {
var done = this.async();
var API500px = require('500px').API500px;
var http = require('http');
var fs = require('fs');
var consumerKey = grunt.file
.read('.500px-consumer-key')
.replace(/\n$/, '');
var api500px = new API500px(consumerKey);
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var options = {
rpp: 100,
image_size: 4,
license_type: 4,
sort: 'rating'
};
api500px.photos.searchByTerm('', options, function(error, results) {
var downloaded = 0;
var samples = results.photos.map(function(photo) {
var name = 'images/' + photo.id * 1 + '.jpg';
var f = fs.createWriteStream('examples/' + name);
http.get(photo.image_url, function(response) {
response.pipe(f);
});
f.on('finish', function() {
f.close();
if (++downloaded == samples.length) {
done();
}
});
return {
id: photo.id,
name: photo.name,
url: name,
attribution: photo.user.fullname,
thumb: photo.image_url.replace('4.jpg', '2.jpg'),
href: 'http://500px.com/photo/' + photo.id
};
});
grunt.file.write(
'examples/images/images.json',
JSON.stringify(samples)
);
// jscs:enable
});
}
);
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-rsync');
};