Skip to content

Commit 201b1ac

Browse files
committed
迭代新版本
1 parent ae436b2 commit 201b1ac

File tree

4 files changed

+79
-34
lines changed

4 files changed

+79
-34
lines changed

examples/s.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
edition: 1.0.0
2+
name: buildApp
3+
# access: aliyun-release
4+
5+
services:
6+
image-test:
7+
component: ${path(..)}
8+
# component: wss-git/upload-oss-regions
9+
props:
10+
Region: cn-shenzhen # 上传到指定的单个地区
11+
# Region: all # 上传到所有地区
12+
# Region: # 上传到指定的多个地区
13+
# - cn-shenzhen
14+
# - cn-hangzhou
15+
Uri: ../src # 制定要上传的文件夹
16+
BucketName: cn-shenzhen-images # 指定上传的 bucket; 支持 {region} 和 {accountId} 写法
17+
ObjectPath: create-function-demo-code # 上传到 oss 的哪个目录下
18+
Ignore: # 指定哪些文件不上传
19+
- .DS_Store

src/package.json renamed to package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "upload-oss-regions",
33
"version": "0.0.1",
4+
"main": "./src/index.js",
45
"dependencies": {
5-
"@serverless-devs/s-core": "0.0.22",
6+
"@serverless-devs/core": "^0.0.*",
67
"ali-oss": "^6.12.0",
78
"inquirer": "^7.3.3",
89
"ora": "^5.1.0",

readme.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
yml 配置
44
````
5-
UploadOssComponent:
6-
Component: upload-oss-regions
7-
Provider: alibaba
8-
# Access: wss # 密钥别名
9-
Properties:
10-
# Region: cn-shenzhen # 上传到指定的单个地区
11-
# Region: all # 上传到所有地区
12-
Region: # 上传到指定的多个地区
13-
- cn-shenzhen
14-
- cn-hangzhou
15-
Uri: ./zips # 制定要上传的文件夹
16-
BucketName: fc-console-gen-{region}-{accountId} # 指定上传的 bucket; 支持 {region} 和 {accountId} 写法
17-
ObjectPath: create-function-demo-code # 上传到 oss 的哪个目录下
18-
Ignore: # 指定哪些文件不上传
19-
- .DS_Store
5+
edition: 1.0.0
6+
name: buildApp
7+
# access: aliyun-release
8+
9+
services:
10+
image-test:
11+
component: wss-git/upload-oss-regions
12+
props:
13+
# Region: cn-shenzhen # 上传到指定的单个地区
14+
# Region: all # 上传到所有地区
15+
Region: # 上传到指定的多个地区
16+
- cn-shenzhen
17+
- cn-hangzhou
18+
Uri: ./zips # 制定要上传的文件夹
19+
BucketName: fc-console-gen-{region}-{accountId} # 指定上传的 bucket; 支持 {region} 和 {accountId} 写法
20+
ObjectPath: create-function-demo-code # 上传到 oss 的哪个目录下
21+
Ignore: # 指定哪些文件不上传
22+
- .DS_Store
2023
````
2124
#### BucketName 占位符
2225

src/index.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
/** @format */
22

3-
const { Component } = require('@serverless-devs/s-core');
3+
const { commandParse, help, getCredential } = require('@serverless-devs/core');
44
const ClientProvider = require('./utils/client-provider');
55
const { REGIONLIST } = require('./utils/constants');
66

7-
class MyComponent extends Component {
8-
handlerInput (inputs) {
9-
const {
10-
Credentials,
11-
Properties
7+
class MyComponent {
8+
async handlerInput (inputs) {
9+
let {
10+
credentials,
11+
props,
12+
project = {},
1213
} = inputs;
14+
if (!(credentials && credentials.AccessKeyID)) {
15+
credentials = await getCredential(project.access);
16+
}
1317

1418
return {
15-
accessKeyId: Credentials.AccessKeyID,
16-
accessKeySecret: Credentials.AccessKeySecret,
17-
securityToken: Credentials.SecurityToken,
18-
accountID: Credentials.AccountID,
19+
accessKeyId: credentials.AccessKeyID,
20+
accessKeySecret: credentials.AccessKeySecret,
21+
securityToken: credentials.SecurityToken,
22+
accountID: credentials.AccountID,
1923

20-
region: Properties.Region,
21-
bucketName: Properties.BucketName,
22-
objectPath: Properties.ObjectPath || '',
23-
ignore: Properties.Ignore || [],
24-
uri: Properties.Uri
24+
region: props.Region,
25+
bucketName: props.BucketName,
26+
objectPath: props.ObjectPath || '',
27+
ignore: props.Ignore || [],
28+
uri: props.Uri
2529
}
2630
}
2731

@@ -35,8 +39,26 @@ class MyComponent extends Component {
3539
}
3640

3741
async upload(inputs) {
38-
const { Parameters } = this.args(inputs.Args);
39-
const { y, n } = Parameters;
42+
const { Parameters = {} } = commandParse(inputs.args) || {};
43+
const { y, n, h } = Parameters;
44+
if (h) {
45+
return help({
46+
header: 'Options',
47+
optionList: [
48+
{
49+
name: 'y',
50+
description: '覆盖 ObjectPath 已经存在的文件',
51+
type: Boolean,
52+
},
53+
{
54+
name: 'n',
55+
description: '不上传 ObjectPath 已经存在的文件',
56+
type: Boolean,
57+
},
58+
],
59+
});
60+
}
61+
4062
if (y && n) {
4163
throw new Error('-y 和 -n 不能同时存在');
4264
}
@@ -51,7 +73,7 @@ class MyComponent extends Component {
5173
objectPath,
5274
ignore,
5375
uri
54-
} = this.handlerInput(inputs);
76+
} = await this.handlerInput(inputs);
5577

5678
if (!region) {
5779
throw new Error('Region 是必填项');

0 commit comments

Comments
 (0)