Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 9aad483

Browse files
committed
feat(cli): Add newest options to cli.js
1 parent bc3eab9 commit 9aad483

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

README.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,46 @@ This module is not brilliant - I implemented it after incurring costs for invali
2222
You can use the module programmatically.
2323

2424
```javascript
25-
let deploy = require("aws-cloudfront-s3-deploy");
25+
let deploy = require('aws-cloudfront-s3-deploy');
2626

27-
deploy("path-to-files", "mybucketname", "ABCDEFGHIJKLM", "dev").then(msg => {
28-
console.log(msg);
29-
}).catch(e=>{
30-
console.log(e);
27+
let additionalParams = {
28+
cli: false,
29+
verbose: false,
30+
reuploadAll: false,
31+
distribution: {
32+
id: yourDistributionId
33+
},
34+
authentication: {
35+
profile: yourProfileName,
36+
keyId: yourKeyId,
37+
accessKey: yourAccessKey
38+
}
39+
};
40+
41+
deploy('path-to-files', 'mybucketname', additionalParams).then(response => {
42+
//Do more stuff here
43+
}).catch(e => {
44+
//Do more stuff here
3145
})
3246
```
3347

3448
The method has params in sequence:
3549
* `path` - the path to the directory to upload, this will be excluded on s3 - i.e. if you upload `public`, then the contents of `public` will be uploaded to the root of your bucket.
3650
* `bucketName` - Amazon S3 bucket name to upload to
37-
* `distributionID` - ID of the CloudFront distribution to invalidate files in
38-
* `profile` - local AWS credentials profile ID
51+
* `additionalParams` - if passed as an option should be an object of type [additionalParams](#additionalparams-object).
52+
53+
#### additionalParams object
54+
55+
Keys as follows:
56+
* `cli` - boolean indicating whether the program is being run in CLI mode (default: `false`)
57+
* `verbose` - boolean indicating whether to run the program in verbose mode i.e. output a message for each upload (default: `false`)
58+
* `reuploadAll` - boolean indicating whether to reupload all files regardless of if they have changed (default: `false`)
59+
* `distribution` - object containing details of CloudFront distribution, absence will lead to no CloudFront distribution not being updated.
60+
* `id` - ID of Amazon CloudFront distribution
61+
* `authentication` - object containing authentication options, absence will lead to using system defaults.
62+
* `profile` - identifier of profile in local AWS credentials ini file. (cannot be used in conjunction with `accessKey` or `keyId`)
63+
* `keyId` - AWS access key ID (cannot be used in conjunction with `profile`, must be used in conjunction with `accessKey`)
64+
* `accessKey` - AWS access key (cannot be used in conjunction with `profile`, must be used in conjunction with `keyId`)
3965

4066
### CLI
4167

@@ -45,8 +71,17 @@ The module can be used from the CLI as follows
4571
aws-cloudfront-deploy --path public --bucket mybucketname --distribution ABCDEFGHIJKLM --profile dev
4672
```
4773

48-
## Note
74+
Options as follows
75+
```bash
76+
-V, --version output the version number
77+
-p, --path <required> path
78+
-b, --bucket <required> bucket name
79+
-d, --distribution [id] cloudfront distribution id
80+
-p, --profile [profile name] profile to use
81+
-i, --keyId [keyId] AWS access key ID
82+
-k, --accessKey [accessKey] AWS access key
83+
-r, --reupload Re-upload all items
84+
-v, --verbose run in verbose mode
85+
-h, --help output usage information
86+
```
4987

50-
This module is a heavy work in progress. The following features are still missing:
51-
* Specification of your own AWS keys as opposed to relying on profiles
52-
* Full test suite

bin/cli.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,40 @@ program
3232
.option('-b, --bucket <required>', 'bucket name')
3333
.option('-d, --distribution [id]', 'cloudfront distribution id')
3434
.option('-p, --profile [profile name]', 'profile to use')
35-
.option('-V, --verbose', 'run in verbose mode')
35+
.option('-i, --keyId [keyId]', 'AWS access key ID')
36+
.option('-k, --accessKey [accessKey]', 'AWS access key')
37+
.option('-r, --reupload', 'Re-upload all items')
38+
.option('-v, --verbose', 'run in verbose mode')
3639
.parse(process.argv);
3740

3841
if (program.path && program.bucket) {
39-
deploy(program.path, program.bucket, program.distribution, program.profile, program.verbose, true).then((msg) => {
42+
const additionalParams = {};
43+
additionalParams.cli = true;
44+
additionalParams.verbose = program.verbose;
45+
additionalParams.reuploadAll = program.reupload;
46+
47+
if (program.distribution) {
48+
additionalParams.distribution = {};
49+
additionalParams.distribution.id = program.distribution;
50+
}
51+
52+
if (program.profile || program.key || program.keyId) {
53+
additionalParams.authentication = {};
54+
}
55+
56+
if (program.profile) {
57+
additionalParams.authentication.profile = program.profile;
58+
}
59+
60+
if (program.accessKey) {
61+
additionalParams.authentication.accessKey = program.accessKey;
62+
}
63+
64+
if (program.keyId) {
65+
additionalParams.authentication.keyId = program.keyId;
66+
}
67+
68+
deploy(program.path, program.bucket, additionalParams).then((msg) => {
4069
console.log(chalk.greenBright(msg));
4170
}).catch((e) => {
4271
if (e.message) {

0 commit comments

Comments
 (0)