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

Commit b211a77

Browse files
committedDec 10, 2015
Add configuration option for file prefixes when deploying
1 parent 5f07f76 commit b211a77

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed
 

‎dist/deploy.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
secret: credentials.secret,
6868
region: config.s3region,
6969
bucket: config.s3bucket,
70+
prefix: config.s3prefix,
7071
acl: 'public-read',
7172
headers: {
7273
CacheControl: 'no-cache, no-store, must-revalidate',

‎dist/init.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ var s3bucket = {
4242
message: 'Name must be only letters, numbers, or dashes'
4343
};
4444

45+
var s3prefix = {
46+
description: 'Path in S3 bucket (optional for cordova-hcp deploy)',
47+
pattern: /^[a-zA-Z\-\s0-9\.\/]+\/$/,
48+
message: 'Path must be only letters, numbers, spaces, forward slashes or dashes and must end with a forward slash'
49+
};
50+
4551
var s3region = {
4652
description: 'Amazon S3 region (required for cordova-hcp deploy)',
4753
pattern: /^(us-east-1|us-west-2|us-west-1|eu-west-1|eu-central-1|ap-southeast-1|ap-southeast-2|ap-northeast-1|sa-east-1)$/,
@@ -71,6 +77,7 @@ var schema = {
7177
properties: {
7278
name: name,
7379
s3bucket: s3bucket,
80+
s3prefix: s3prefix,
7481
s3region: s3region,
7582
ios_identifier: iosIdentifier,
7683
android_identifier: androidIdentifier,
@@ -107,7 +114,7 @@ function execute(context) {
107114

108115
function validateBucket(result) {
109116
if (!result.s3bucket) {
110-
return _lodash2['default'].omit(result, ['s3region', 's3bucket']);
117+
return _lodash2['default'].omit(result, ['s3region', 's3bucket', 's3prefix']);
111118
}
112119

113120
return result;
@@ -116,17 +123,24 @@ function validateBucket(result) {
116123
function getUrl(_ref) {
117124
var region = _ref.s3region;
118125
var bucket = _ref.s3bucket;
126+
var path = _ref.s3prefix;
119127

120128
if (!bucket) {
121129
return (0, _utils.getInput)(_prompt2['default'], urlSchema);
122130
}
123131

124-
return { content_url: getContentUrl(region, bucket) };
132+
return { content_url: getContentUrl(region, bucket, path) };
125133
}
126134

127-
function getContentUrl(region, bucket) {
135+
function getContentUrl(region, bucket, path) {
128136
var url = region === 'us-east-1' ? 's3.amazonaws.com' : 's3-' + region + '.amazonaws.com';
129-
return 'https://' + url + '/' + bucket;
137+
url = 'https://' + url + '/' + bucket;
138+
139+
if (path) {
140+
url += '/' + path;
141+
}
142+
143+
return url;
130144
}
131145

132146
function done(err) {

‎src/deploy.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
secret: credentials.secret,
6666
region: config.s3region,
6767
bucket: config.s3bucket,
68+
prefix: config.s3prefix,
6869
acl: 'public-read',
6970
headers: {
7071
CacheControl: 'no-cache, no-store, must-revalidate',

‎src/init.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const s3bucket = {
2323
message: 'Name must be only letters, numbers, or dashes',
2424
};
2525

26+
const s3prefix = {
27+
description: 'Path in S3 bucket (optional for cordova-hcp deploy)',
28+
pattern: /^[a-zA-Z\-\s0-9\.\/]+\/$/,
29+
message: 'Path must be only letters, numbers, spaces, forward slashes or dashes and must end with a forward slash',
30+
};
31+
2632
const s3region = {
2733
description: 'Amazon S3 region (required for cordova-hcp deploy)',
2834
pattern: /^(us-east-1|us-west-2|us-west-1|eu-west-1|eu-central-1|ap-southeast-1|ap-southeast-2|ap-northeast-1|sa-east-1)$/,
@@ -52,6 +58,7 @@ const schema = {
5258
properties: {
5359
name,
5460
s3bucket,
61+
s3prefix,
5562
s3region,
5663
ios_identifier: iosIdentifier,
5764
android_identifier: androidIdentifier,
@@ -88,23 +95,29 @@ export function execute(context) {
8895

8996
function validateBucket(result) {
9097
if (!result.s3bucket) {
91-
return _.omit(result, ['s3region', 's3bucket']);
98+
return _.omit(result, ['s3region', 's3bucket', 's3prefix']);
9299
}
93100

94101
return result;
95102
}
96103

97-
function getUrl({ s3region: region, s3bucket: bucket }) {
104+
function getUrl({ s3region: region, s3bucket: bucket, s3prefix: path }) {
98105
if (!bucket) {
99106
return getInput(prompt, urlSchema);
100107
}
101108

102-
return { content_url: getContentUrl(region, bucket) };
109+
return { content_url: getContentUrl(region, bucket, path) };
103110
}
104111

105-
function getContentUrl(region, bucket) {
106-
const url = region === 'us-east-1' ? 's3.amazonaws.com' : `s3-${region}.amazonaws.com`;
107-
return `https://${url}/${bucket}`;
112+
function getContentUrl(region, bucket, path) {
113+
let url = region === 'us-east-1' ? 's3.amazonaws.com' : `s3-${region}.amazonaws.com`;
114+
url = `https://${url}/${bucket}`
115+
116+
if (path) {
117+
url += `/${path}`;
118+
}
119+
120+
return url;
108121
}
109122

110123
function done(err) {

‎test/init.test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const withBucket = {
66
name: 'name',
77
s3region: 'us-east-1',
88
s3bucket: 'bucket',
9+
prefix: 'pre/fix/',
910
ios_identifier: 'ios',
1011
android_identifier: 'android',
1112
update: 'resume',
@@ -19,10 +20,11 @@ const expectedContentWithBucket = {
1920
name: 'name',
2021
s3region: 'us-east-1',
2122
s3bucket: 'bucket',
23+
prefix: 'pre/fix/',
2224
ios_identifier: 'ios',
2325
android_identifier: 'android',
2426
update: 'resume',
25-
content_url: 'https://s3.amazonaws.com/bucket'
27+
content_url: 'https://s3.amazonaws.com/bucket/pre/fix/'
2628
};
2729

2830
describe('init', () => {
@@ -51,10 +53,11 @@ describe('init', () => {
5153
"name": "name",
5254
"s3region": "us-east-1",
5355
"s3bucket": "bucket",
56+
"prefix": "pre/fix/",
5457
"ios_identifier": "ios",
5558
"android_identifier": "android",
5659
"update": "resume",
57-
"content_url": "https://s3.amazonaws.com/bucket"
60+
"content_url": "https://s3.amazonaws.com/bucket/pre/fix/"
5861
};
5962

6063
var content = JSON.parse(writeFile.args[0][1]);

0 commit comments

Comments
 (0)
This repository has been archived.