forked from jwagner/smartcrop.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
96 lines (95 loc) · 2.95 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
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(),
API500px = require('500px').API500px,
http = require('http'),
fs = require('fs'),
consumerKey = grunt.file.read('.500px-consumer-key').replace(/\n$/, ''),
api500px = new API500px(consumerKey);
api500px.photos.searchByTerm('', {rpp: 100, image_size: 4, license_type: 4, sort: 'rating'}, function(error, results){
var downloaded = 0,
samples = results.photos.map(function(photo){
var name = 'images/' + photo.id*1 + '.jpg',
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));
//console.log(JSON.stringify(consumerKey), error, results);
//done();
});
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-rsync');
};