This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
123 lines (107 loc) · 3.75 KB
/
deploy.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
'use strict'
import fsExtra from 'fs-extra'
import archiver from 'archiver'
import octokitRequest from '@octokit/request'
const { ensureDirSync, createWriteStream, copy, remove, readFile } = fsExtra
const { request } = octokitRequest
const version = process.argv[2]
const accessToken = process.argv[3]
const projectName = 'viewify'
const staticLibExtensionName = '.lib'
const bundleOutDirPath = 'libs/'
const archiveExtensionName = 'zip'
async function bundleInclude() {
const includeDirPath = `${bundleOutDirPath}${projectName}-${version}/include/`
ensureDirSync(`${includeDirPath}${projectName}/`)
return copy(`${projectName}/src/main/`, `${includeDirPath}${projectName}/`, { recursive: true, filter: (src, dest) => {
return !src.endsWith('.cpp')
} })
}
async function bundleX86Debug() {
const x86DebugDirPath = `${bundleOutDirPath}${projectName}-${version}/lib/x86/Debug/`
ensureDirSync(x86DebugDirPath)
return copy(`${projectName}/Debug/${projectName}${staticLibExtensionName}`, `${x86DebugDirPath}${projectName}${staticLibExtensionName}`)
}
async function bundleX86Release() {
const x86ReleaseDirPath = `${bundleOutDirPath}${projectName}-${version}/lib/x86/Release/`
ensureDirSync(x86ReleaseDirPath)
return copy(`${projectName}/Release/${projectName}${staticLibExtensionName}`, `${x86ReleaseDirPath}${projectName}${staticLibExtensionName}`)
}
async function bundleX64Debug() {
const x64DebugDirPath = `${bundleOutDirPath}${projectName}-${version}/lib/x64/Debug/`
ensureDirSync(x64DebugDirPath)
return copy(`${projectName}/x64/Debug/${projectName}${staticLibExtensionName}`, `${x64DebugDirPath}${projectName}${staticLibExtensionName}`)
}
async function bundleX64Release() {
const x64ReleaseDirPath = `${bundleOutDirPath}${projectName}-${version}/lib/x64/Release/`
ensureDirSync(x64ReleaseDirPath)
return copy(`${projectName}/x64/Release/${projectName}${staticLibExtensionName}`, `${x64ReleaseDirPath}${projectName}${staticLibExtensionName}`)
}
async function bundleX86() {
return Promise.all([
bundleX86Debug(),
bundleX86Release()
])
}
async function bundleX64() {
return Promise.all([
bundleX64Debug(),
bundleX64Release()
])
}
async function bundleLib() {
return Promise.all([
bundleX86(),
bundleX64()
])
}
async function bundle() {
return Promise.all([
bundleInclude(),
bundleLib()
])
}
async function zip() {
const archive = archiver(archiveExtensionName, { zlib: { level: 9 } })
archive.on('warning', err => {
if (err.code == 'ENOENT') console.log(err)
else throw err
}).on('error', err => {
throw err
}).pipe(createWriteStream(`${bundleOutDirPath}${projectName}-${version}.${archiveExtensionName}`))
return archive.directory(`${bundleOutDirPath}${projectName}-${version}/`, `${projectName}-${version}/`).finalize()
}
async function publish() {
const owner = 'ii887522'
const result = await request('POST /repos/{owner}/{repo}/releases', {
headers: {
authorization: `token ${accessToken}`
},
owner,
repo: projectName,
tag_name: `v${version}`,
name: version
})
return request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', {
headers: {
authorization: `token ${accessToken}`,
'content-type': 'application/zip'
},
baseUrl: 'https://uploads.github.com',
owner,
repo: projectName,
release_id: result.data.id,
name: `${projectName}-${version}.${archiveExtensionName}`,
data: await readFile(`${bundleOutDirPath}${projectName}-${version}.${archiveExtensionName}`)
})
}
function clean() {
remove(`${bundleOutDirPath}${projectName}-${version}`)
remove(`${bundleOutDirPath}${projectName}-${version}.${archiveExtensionName}`)
}
(async () => {
await bundle()
await zip()
await publish()
clean()
})()