Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 8f3be7e

Browse files
committed
测试上传到draft
1 parent 96761ce commit 8f3be7e

File tree

8 files changed

+33
-16
lines changed

8 files changed

+33
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
node_modules/
33
/dist-web/
4+
/dist/*.zip
45
npm-debug.log*
56
yarn-debug.log*
67
yarn-error.log*
@@ -12,3 +13,4 @@ yarn-error.log*
1213
*.ntvs*
1314
*.njsproj
1415
*.sln
16+

build/build.component.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function resolve (dir) {
3434
// 压缩文件夹
3535
function createZIP () {
3636
const fileName = `${packageInfo.name}-${packageInfo.version}.zip`
37-
const filePath = `${resolve('/')}/${fileName}`
37+
const filePath = `${config.build.assetsRoot}/${fileName}`
3838
const output = fs.createWriteStream(filePath)
3939
const archive = archiver('zip', {
4040
zlib: { level: 9}
@@ -43,8 +43,10 @@ function createZIP () {
4343
logInfo(`creating ${fileName}...`)
4444
output.on('close', async () => {
4545
const fileBuffer = fs.readFileSync(filePath, 'utf8')
46+
let fileSize = archive.pointer()
4647

47-
logInfo(`${archive.pointer()} total bytes.\n\nupading ${fileName} to github release draft...`)
48+
fileSize = fileSize.toString().length > 6 ? `${parseFloat(fileSize / 1024 / 1024).toFixed(2)} M` : `${parseFloat(fileSize / 1024).toFixed(2)} KB`
49+
logInfo(`File size ${fileSize}.\n\nupading ${fileName} to github release draft...`)
4850

4951
// 上传到github release draft
5052
const publishGH = new GitHubPushlish({ owner: packageInfo.repository.owner, project: packageInfo.name, version: packageInfo.version})
@@ -54,14 +56,14 @@ function createZIP () {
5456
throw new Error('')
5557
}
5658

57-
if (draft.assets) {
59+
if (draft.assets.length) {
5860
// 如果draft中存在资源,先删除
5961
const assetIds = draft.assets.filter(asset => asset.id)
6062

6163
await publishGH.deleteAsset(assetIds)
6264
}
6365

64-
publishGH.uploadAsset(draft.upload_url, filename, fileBuffer)
66+
publishGH.uploadAsset(draft.upload_url, fileName, fileBuffer)
6567
})
6668

6769
archive.on('error', (error) => {
@@ -153,9 +155,12 @@ spinner.start()
153155

154156
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
155157
if (err) throw err
158+
156159
webpack(webpackConfig, (err, stats) => {
157160
spinner.stop()
161+
158162
if (err) throw err
163+
159164
process.stdout.write(stats.toString({
160165
colors: true,
161166
modules: false,

build/publish/github-releases.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const _upload = Symbol('_upload')
1313
*/
1414
class GitHubPublish {
1515
constructor ({ owner = '', project = '', version = '' } = {}) {
16-
const token = process.env.GH_TOKEN
16+
const token = process.env.GH_TOKEN || 'c4b09a58e85e7245c5f5bc93a06e80dcc6ca2dc1'
1717

1818
if (!token) {
1919
logError('GitHub Personal access tokens没有设置,或者没有配置"GH_TOKEN" env')
@@ -29,7 +29,7 @@ class GitHubPublish {
2929
// 获取对应release的draft
3030
async getReleaseDraft () {
3131
logInfo(`检查${this.project}是否创建${this.version}的draft...`)
32-
const path = `/repos/${this.owner}/${this.project}/releases`
32+
const path = `/repos/${this.owner}/${this.project}/releases?access_token=${this.token}`
3333
let { code, data, message } = await GitHubPublish[_request](path)
3434

3535
if (code !== 200) {
@@ -55,7 +55,7 @@ class GitHubPublish {
5555
async deleteAsset (assetIds) {
5656
logInfo(`删除已经存在的文件...`)
5757
for (let assetId of assetIds) {
58-
const path = `/repos/${this.owner}/${this.project}/releases/assets/${assetId}`
58+
const path = `/repos/${this.owner}/${this.project}/releases/assets/${assetId}?access_token=${this.token}`
5959

6060
await GitHubPublish[_request](path, 'DELETE')
6161
}
@@ -68,12 +68,12 @@ class GitHubPublish {
6868
* @param {*} fileBuffer 二进制文件
6969
*/
7070
async uploadAsset (uploadUrl, fileName, fileBuffer) {
71-
const urlObject = url.parse(`${uploadUrl.replace(/({.*})/gi, '')}?name=${fileName}`)
71+
const urlObject = url.parse(`${uploadUrl.replace(/({.*})/gi, '')}?name=${fileName}&access_token=${this.token}`)
7272
const fileExt = fileName.substr(fileName.lastIndexOf('.') + 1)
7373

7474
logInfo(`上传${fileName}...`)
7575
const { code, data, message } = await GitHubPublish[_upload](urlObject, fileBuffer, fileExt)
76-
76+
7777
if (code !== 200) {
7878
logError(`${fileName}上传失败。${message}`)
7979
return {}
@@ -92,7 +92,7 @@ class GitHubPublish {
9292
const options = {
9393
hostname: 'api.github.com',
9494
port: 443,
95-
path: `${path}?access_token=${this.token}`,
95+
path,
9696
method,
9797
headers: {
9898
'User-Agent': 'NODEJS'
@@ -109,7 +109,16 @@ class GitHubPublish {
109109
res.on('data', chunk => {
110110
data += chunk
111111
}).on('end', () => {
112-
json.data = JSON.parse(data)
112+
data = JSON.parse(data)
113+
114+
if (data.message) {
115+
json.code = 400
116+
json.message = data.message
117+
reject(json)
118+
return
119+
}
120+
121+
json.data = data
113122
resolve(json)
114123
})
115124

@@ -127,7 +136,7 @@ class GitHubPublish {
127136
const options = {
128137
hostname: urlObject.hostname,
129138
port: urlObject.port,
130-
path: `${urlObject.path}&access_token=${this.token}`,
139+
path: urlObject.path,
131140
method: 'POST',
132141
headers: {
133142
'User-Agent': 'NODEJS',

dist/css/vue-bootstrap-selectpicker.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/vue-bootstrap-selectpicker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)