Repository navigation
Expand file tree
/
Copy pathcheck.ts
More file actions
115 lines (96 loc) · 3.72 KB
/
Copy pathcheck.ts
File metadata and controls
115 lines (96 loc) · 3.72 KB
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
import { Update } from './update/update'
import { getEventSignal } from './update/eventSignal'
import { Logger } from './logger'
export interface ICheckResult {
message: string
commitDate: string
committerName: string
data: {
message: string
name: string
date: string
}
encodedMessage: string
}
export const check = (
{
branch = 'master',
repoUrl,
sourceFolderPath,
isNeedDefaultProcess,
force = false
}: {
branch: string
repoUrl?: string
sourceFolderPath: string
isNeedDefaultProcess?: boolean
force: boolean
}
): Promise<ICheckResult | undefined> => {
return new Promise((resolve)=>{
let updater = new Update()
if (sourceFolderPath === undefined)
sourceFolderPath = process.cwd()
if (isNeedDefaultProcess == true || isNeedDefaultProcess == undefined) {
updater.events.on(
getEventSignal('newVersionDetected'),
(eventInfo) => {
updater.getNewestGitHubCommit(eventInfo.repoUrl, async (data) => {
if(!data) {
resolve()
return
}
let {
message,
date: commitDate,
name: committerName
} = data
let encodedMessage = ``
encodedMessage += Logger('New updates of the application have been found at Github.', true)
encodedMessage += Logger(`Repository URL: ${eventInfo.repoUrl}, Branch: ${eventInfo.branch}\r\n`, true)
encodedMessage += Logger(`Installed Application Version: ${eventInfo.localVersion}`, true)
encodedMessage += Logger(`Update available version of application: ${eventInfo.webVersion}\r\n`, true)
encodedMessage += Logger('[Github commit Information]', true)
encodedMessage += Logger(`Message: ${message}`, true)
encodedMessage += Logger(`Comitter: ${committerName}`, true)
encodedMessage += Logger(`CommitDate: ${commitDate}\r\n`, true)
resolve({
message,
commitDate,
committerName,
data,
encodedMessage
})
})
}
)
}
let localGitInfo = updater.getLocalGitInfo(sourceFolderPath)
if (localGitInfo.type != "git") return
if (repoUrl === undefined) repoUrl = localGitInfo.url
if (repoUrl[repoUrl.length - 1] != '/') repoUrl += '/'
if (branch === undefined) branch = 'master'
let webGitInfoCallback = async (webGitInfo) => {
if (webGitInfo.type != "git"){
resolve()
return
}
let eventInfo = {
repoUrl,
sourceFolderPath,
branch,
localVersion: localGitInfo.version,
webVersion: webGitInfo.version
}
if (!force && (webGitInfo.version == localGitInfo.version || webGitInfo.version == null)) {
resolve()
} else {
updater.events.emit(
getEventSignal('newVersionDetected'),
eventInfo
)
}
}
updater.getWebGitInfo(repoUrl, branch, webGitInfoCallback)
})
}