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

Commit

Permalink
Merge pull request #30 from alexbuijs/master
Browse files Browse the repository at this point in the history
Add configuration option for file prefixes when deploying. Thanks to @alexbuijs .
  • Loading branch information
nikDemyankov committed May 4, 2016
2 parents 13bf5fe + b211a77 commit b6ba231
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions dist/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
secret: credentials.secret,
region: config.s3region,
bucket: config.s3bucket,
prefix: config.s3prefix,
acl: 'public-read',
headers: {
CacheControl: 'no-cache, no-store, must-revalidate',
Expand Down
22 changes: 18 additions & 4 deletions dist/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var s3bucket = {
message: 'Name must be only letters, numbers, or dashes'
};

var s3prefix = {
description: 'Path in S3 bucket (optional for cordova-hcp deploy)',
pattern: /^[a-zA-Z\-\s0-9\.\/]+\/$/,
message: 'Path must be only letters, numbers, spaces, forward slashes or dashes and must end with a forward slash'
};

var s3region = {
description: 'Amazon S3 region (required for cordova-hcp deploy)',
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)$/,
Expand Down Expand Up @@ -71,6 +77,7 @@ var schema = {
properties: {
name: name,
s3bucket: s3bucket,
s3prefix: s3prefix,
s3region: s3region,
ios_identifier: iosIdentifier,
android_identifier: androidIdentifier,
Expand Down Expand Up @@ -107,7 +114,7 @@ function execute(context) {

function validateBucket(result) {
if (!result.s3bucket) {
return _lodash2['default'].omit(result, ['s3region', 's3bucket']);
return _lodash2['default'].omit(result, ['s3region', 's3bucket', 's3prefix']);
}

return result;
Expand All @@ -116,17 +123,24 @@ function validateBucket(result) {
function getUrl(_ref) {
var region = _ref.s3region;
var bucket = _ref.s3bucket;
var path = _ref.s3prefix;

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

return { content_url: getContentUrl(region, bucket) };
return { content_url: getContentUrl(region, bucket, path) };
}

function getContentUrl(region, bucket) {
function getContentUrl(region, bucket, path) {
var url = region === 'us-east-1' ? 's3.amazonaws.com' : 's3-' + region + '.amazonaws.com';
return 'https://' + url + '/' + bucket;
url = 'https://' + url + '/' + bucket;

if (path) {
url += '/' + path;
}

return url;
}

function done(err) {
Expand Down
1 change: 1 addition & 0 deletions src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
secret: credentials.secret,
region: config.s3region,
bucket: config.s3bucket,
prefix: config.s3prefix,
acl: 'public-read',
headers: {
CacheControl: 'no-cache, no-store, must-revalidate',
Expand Down
25 changes: 19 additions & 6 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const s3bucket = {
message: 'Name must be only letters, numbers, or dashes',
};

const s3prefix = {
description: 'Path in S3 bucket (optional for cordova-hcp deploy)',
pattern: /^[a-zA-Z\-\s0-9\.\/]+\/$/,
message: 'Path must be only letters, numbers, spaces, forward slashes or dashes and must end with a forward slash',
};

const s3region = {
description: 'Amazon S3 region (required for cordova-hcp deploy)',
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)$/,
Expand Down Expand Up @@ -52,6 +58,7 @@ const schema = {
properties: {
name,
s3bucket,
s3prefix,
s3region,
ios_identifier: iosIdentifier,
android_identifier: androidIdentifier,
Expand Down Expand Up @@ -88,23 +95,29 @@ export function execute(context) {

function validateBucket(result) {
if (!result.s3bucket) {
return _.omit(result, ['s3region', 's3bucket']);
return _.omit(result, ['s3region', 's3bucket', 's3prefix']);
}

return result;
}

function getUrl({ s3region: region, s3bucket: bucket }) {
function getUrl({ s3region: region, s3bucket: bucket, s3prefix: path }) {
if (!bucket) {
return getInput(prompt, urlSchema);
}

return { content_url: getContentUrl(region, bucket) };
return { content_url: getContentUrl(region, bucket, path) };
}

function getContentUrl(region, bucket) {
const url = region === 'us-east-1' ? 's3.amazonaws.com' : `s3-${region}.amazonaws.com`;
return `https://${url}/${bucket}`;
function getContentUrl(region, bucket, path) {
let url = region === 'us-east-1' ? 's3.amazonaws.com' : `s3-${region}.amazonaws.com`;
url = `https://${url}/${bucket}`

if (path) {
url += `/${path}`;
}

return url;
}

function done(err) {
Expand Down
7 changes: 5 additions & 2 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const withBucket = {
name: 'name',
s3region: 'us-east-1',
s3bucket: 'bucket',
prefix: 'pre/fix/',
ios_identifier: 'ios',
android_identifier: 'android',
update: 'resume',
Expand All @@ -19,10 +20,11 @@ const expectedContentWithBucket = {
name: 'name',
s3region: 'us-east-1',
s3bucket: 'bucket',
prefix: 'pre/fix/',
ios_identifier: 'ios',
android_identifier: 'android',
update: 'resume',
content_url: 'https://s3.amazonaws.com/bucket'
content_url: 'https://s3.amazonaws.com/bucket/pre/fix/'
};

describe('init', () => {
Expand Down Expand Up @@ -51,10 +53,11 @@ describe('init', () => {
"name": "name",
"s3region": "us-east-1",
"s3bucket": "bucket",
"prefix": "pre/fix/",
"ios_identifier": "ios",
"android_identifier": "android",
"update": "resume",
"content_url": "https://s3.amazonaws.com/bucket"
"content_url": "https://s3.amazonaws.com/bucket/pre/fix/"
};

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

0 comments on commit b6ba231

Please sign in to comment.