aliyun-oss-deploy
Advanced tools
@@ -7,2 +7,3 @@ /** | ||
const { h, render, Component, Color } = require('ink'); | ||
const Link = require('ink-link'); | ||
@@ -19,4 +20,39 @@ module.exports = class Deploy extends Component { | ||
render() { | ||
fileList() { | ||
const { results } = this.state; | ||
return results.map(r => { | ||
const props = (r.res && r.res.status === 200) ? { green: true } : { red: true }; | ||
return h( | ||
'div', | ||
{}, | ||
[ | ||
h( | ||
Color, | ||
props, | ||
'*', | ||
), | ||
' ', | ||
r.url, | ||
] | ||
); | ||
}) | ||
} | ||
poweredBy() { | ||
return h( | ||
'div', | ||
{}, | ||
[ | ||
'Powered by ', | ||
h(Link, { | ||
url: 'https://github.com/hustcc/aliyun-oss-deploy' | ||
}, 'aliyun-oss-deploy'), | ||
'.' | ||
] | ||
); | ||
} | ||
count() { | ||
const { results } = this.state; | ||
const success = results.filter(r => r && r.res && (r.res.status === 200)).length; | ||
@@ -40,3 +76,3 @@ const error = results.length - success; | ||
`${error} fail.`, | ||
) | ||
), | ||
] | ||
@@ -46,2 +82,16 @@ ); | ||
render() { | ||
// 显示成功个数 | ||
return h( | ||
'div', | ||
{}, | ||
[ | ||
this.fileList(), | ||
'\n', | ||
this.count(), | ||
this.poweredBy(), | ||
] | ||
); | ||
} | ||
async process() { | ||
@@ -60,3 +110,3 @@ const { dg, onExit } = this.props; | ||
onExit(); | ||
}, 10); | ||
}, 100); | ||
} | ||
@@ -69,4 +119,3 @@ | ||
componentWillUnmount() { | ||
clearInterval(this.timer); | ||
} | ||
}; |
41
index.js
@@ -16,32 +16,3 @@ /** | ||
/** | ||
* 使用 putObject 上传 | ||
* @param client | ||
* @param ossTarget | ||
* @param stream | ||
*/ | ||
const uploadByPutObject = async (client, ossTarget, stream) => { | ||
return await co(function*() { | ||
return Promise.resolve( | ||
yield client.put(ossTarget, stream), | ||
); | ||
}); | ||
}; | ||
/** | ||
* 使用 putStream 上传 | ||
* @param client | ||
* @param ossTarget | ||
* @param stream | ||
*/ | ||
const uploadByPutStream = async (client, ossTarget, stream) => { | ||
return await co(function*() { | ||
return Promise.resolve( | ||
yield client.putStream(ossTarget, stream), | ||
); | ||
}); | ||
}; | ||
/** | ||
* 上传文件的 generator | ||
@@ -61,3 +32,3 @@ * @param filePath | ||
const files = fileList(filePath); | ||
const func = byStream ? uploadByPutStream : uploadByPutObject; | ||
// const func = byStream ? uploadByPutStream : uploadByPutObject; | ||
@@ -72,3 +43,5 @@ const r = []; | ||
// 使用 oss 上传文件 file 到 targetFile | ||
const result = yield func(client, ossTarget, stream); | ||
const result = yield byStream ? | ||
co(client.putStream(ossTarget, stream)) : | ||
co(client.put(ossTarget, stream)); | ||
@@ -88,9 +61,5 @@ r.push(result); | ||
module.exports = async (filePath, config, prefix, byStream) => { | ||
return await co(function*() { | ||
return Promise.resolve( | ||
yield deployGenerator(filePath, config, prefix, byStream), | ||
); | ||
}); | ||
return await co(deployGenerator(filePath, config, prefix, byStream)); | ||
}; | ||
module.exports.deployGenerator = deployGenerator; |
{ | ||
"name": "aliyun-oss-deploy", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "An aliyun oss deploy tool, putObject and putStream are all supported.", | ||
@@ -35,4 +35,5 @@ "main": "index.js", | ||
"ink": "^0.5.0", | ||
"ink-link": "^0.2.0", | ||
"yargs": "^11.0.0" | ||
} | ||
} |
@@ -8,2 +8,3 @@ # aliyun-oss-deploy | ||
 | ||
@@ -10,0 +11,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
46673
1.73%204
9.09%83
1.22%7
16.67%