/
china.js
executable file
·67 lines (60 loc) · 1.88 KB
/
china.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
'use strict';
const { promisify } = require('util');
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const Cos = require('cos-nodejs-sdk-v5');
const distPath = path.resolve(__dirname, '../../../dist');
const TENCENT_BUCKET_NAME = 'sls-standalone-1300963013';
const TENCENT_REGION = 'ap-shanghai';
module.exports = async (versionTag, { isLegacyVersion }) => {
if (!process.env.TENCENT_SECRET_KEY) {
process.stdout.write(chalk.red('Missing TENCENT_SECRET_KEY env var \n'));
process.exitCode = 1;
return;
}
if (!process.env.TENCENT_SECRET_ID) {
process.stdout.write(chalk.red('Missing TENCENT_SECRET_ID env var \n'));
process.exitCode = 1;
return;
}
const cos = new Cos({
SecretId: process.env.TENCENT_SECRET_ID,
SecretKey: process.env.TENCENT_SECRET_KEY,
});
cos.putObjectAsync = promisify(cos.putObject);
const bucketConf = {
Bucket: TENCENT_BUCKET_NAME,
Region: TENCENT_REGION,
};
await Promise.all([
!isLegacyVersion &&
cos
.putObjectAsync({
Key: 'latest-tag',
Body: Buffer.from(versionTag),
...bucketConf,
})
.then(() => {
process.stdout.write(chalk.green("'latest-tag' uploaded to Tencent\n"));
}),
cos
.putObjectAsync({
Key: `${versionTag}/serverless-linux-x64`,
Body: fs.createReadStream(path.resolve(distPath, 'serverless-linux')),
...bucketConf,
})
.then(() => {
process.stdout.write(chalk.green("'serverless-linux-x64' uploaded to Tencent\n"));
}),
cos
.putObjectAsync({
Key: `${versionTag}/serverless-macos-x64`,
Body: fs.createReadStream(path.resolve(distPath, 'serverless-macos')),
...bucketConf,
})
.then(() => {
process.stdout.write(chalk.green("'serverless-macos-x64' uploaded to Tencent\n"));
}),
]);
};