-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
179 lines (149 loc) · 4.67 KB
/
index.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
const hacktoberfestRepositoryPath = '../hacktoberfest'
const simpleGit = require('simple-git')(hacktoberfestRepositoryPath)
const puppeteer = require('puppeteer')
const _async = require('async')
const path = require('path')
function dateFormat (date) {
const year = date.getFullYear()
const month = date.getMonth()
const day = date.getDate()
const hour = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
return `${year}-${month}-${day}-${hour}-${minutes}-${seconds}`
}
const alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
const toAlphName = (alph, nr, name = '') =>
nr > alph.length - 1
? toAlphName(
alph,
nr - alph.length,
name + alph[alph.length - 1]
)
: name + alph[nr]
async function takeScreenshot (name, browser) {
/* const [index, help, last] = await Promise.all([
browser.newPage(),
browser.newPage(),
browser.newPage()
]) */
const index = await browser.newPage()
await index.goto(`file:${path.join(__dirname, `${hacktoberfestRepositoryPath}/index.html`)}`)
/* await Promise.all([
index.goto(`file:${path.join(__dirname, `${hacktoberfestRepositoryPath}/index.html`)}`),
help.goto(`file:${path.join(__dirname, `${hacktoberfestRepositoryPath}/helpful-material.html`)}`),
last.goto(`file:${path.join(__dirname, `${hacktoberfestRepositoryPath}/contributors.html`)}`)
]) */
await index.setViewport({ height: 1920, width: 1024 })
/* await Promise.all([
index.setViewport({ height: 1080, width: 640 }),
help.setViewport({ height: 1080, width: 640 }),
last.setViewport({ height: 1080, width: 640 })
]) */
await index.screenshot({ path: `images/index-loong/${name}-index.png` })
/* await Promise.all([
index.screenshot({ path: `images/index/${name}-index.png` }),
help.screenshot({ path: `images/help/${name}-help.png` }),
last.screenshot({ path: `images/contri/${name}-contru.png` })
]) */
/* return await Promise.all([
index.close(),
help.close(),
last.close()
]) */
await help.close()
/* await index.close() */
/* return last.close() */
return index.close()
}
function walkGit (commits, browser) {
const commits2 = commits.slice(3, commits.length)
return new Promise((resolve, reject) => {
const length = commits2.length
let index = 0
_async.eachLimit(commits2.reverse(), 2, (commit, done) => {
index += 1
console.log(`commit: ${index} - ${length}`, commit.message)
simpleGit
.checkout(commit.hash, (error) => {
if (error) {
// swallow
console.log('Error, could not checkout', error)
return
}
takeScreenshot(toAlphName(alph, index), browser)
.then(done)
.catch((error) => {
console.log(`Error, failed on ${index}`, commit)
console.log(error)
// swallow
done()
})
})
}, (error) => {
if (error) {
return reject(error)
}
resolve()
})
})
}
function getAllCommits () {
return new Promise((resolve, reject) => {
simpleGit.log((err, commits) => {
if (err) {
return reject(err)
}
resolve(commits.all)
})
})
}
function goToMaster () {
return new Promise((resolve, reject) => {
simpleGit
.checkout('master', (error) => {
if (error) {
reject(error)
}
resolve()
})
})
}
function getAllEmails (commits) {
const mySet = new Set()
commits.forEach((commit) => {
mySet.add(commit.author_email)
})
const emails = [...mySet].filter((email) => {
if (email.includes('@hotmail.com') || email.includes('@live.com') || email.includes('@icloud.com')) {
return true
}
return false
}).join(' ')
console.log(emails)
}
async function start () {
await goToMaster()
const commits = await getAllCommits()
/* getAllEmails(commits) */
const browser = await puppeteer.launch()
await walkGit(commits, browser)
await browser.close()
}
start()
.catch((error) => {
console.log(error)
})
/*
cd images && convert -delay 0.800 -loop 0 *.png animated.gif
ffmpeg -r 10 -i *.png -vcodec mjpeg -y movie.mp4
ffmpeg -r 10 -i *.png -vcodec h264 -y -pix_fmt yuv420p movie2.mp4
ffmpeg -r 1/5 -i *.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p 001.mp4
// correcty
ffmpeg -framerate 30 -pattern_type glob -i '*.png' \
-c:v libx264 -pix_fmt yuv420p index_small_2.mp4
ffmpeg -framerate 1 -pattern_type glob -i '*.png' \
-c:v libx264 -r 1 -pix_fmt yuv420p out2.mp4
// speed
ffmpeg -i out2.mp4 -filter:v "setpts=0.5*PTS" out3.mp4
*/