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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ReidWeb/aws-cloudfront-s3-deploy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.11
Choose a base ref
...
head repository: ReidWeb/aws-cloudfront-s3-deploy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.12
Choose a head ref
  • 7 commits
  • 6 files changed
  • 2 contributors

Commits on Sep 14, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    9f64ec7 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    c1647b1 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    2c4c64d View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    514200c View commit details
  5. style(s3): Cleanup S3.js

    ReidWeb committed Sep 14, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    50b06f1 View commit details
  6. Verified

    This commit was signed with the committer’s verified signature.
    ReidWeb Peter Reid
    Copy the full SHA
    19f39b4 View commit details
  7. chore(release): 1.0.12

    Travis CI[bot] committed Sep 14, 2018
    Copy the full SHA
    b16c949 View commit details
Showing with 333 additions and 50 deletions.
  1. +15 −0 CHANGELOG.md
  2. +1 −1 bin/cli.js
  3. +1 −1 package.json
  4. +1 −1 src/index.js
  5. +54 −35 src/s3.js
  6. +261 −12 test/testS3.js
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="1.0.12"></a>
## [1.0.12](https://github.com/ReidWeb/aws-cloudfront-s3-deploy/compare/v1.0.11...v1.0.12) (2018-09-14)


### Bug Fixes

* **s3:** Remove distributionId from params of uploadChangedFilesInDir ([c1647b1](https://github.com/ReidWeb/aws-cloudfront-s3-deploy/commit/c1647b1))


### Features

* **s3:** Add better error handling to invocation of `recursive` ([2c4c64d](https://github.com/ReidWeb/aws-cloudfront-s3-deploy/commit/2c4c64d))



<a name="1.0.11"></a>
## [1.0.11](https://github.com/ReidWeb/aws-cloudfront-s3-deploy/compare/v1.0.10...v1.0.11) (2018-09-13)

2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ if (program.path && program.bucket) {
deploy(program.path, program.bucket, program.distributuon, program.profile, program.verbose, true).then((msg) => {
console.log(chalk.greenBright(msg));
}).catch((e) => {
console.log(chalk.bold.red(e));
console.log(chalk.bold.red(`ERROR: ${e.message}`));
});
} else {
program.outputHelp();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-cloudfront-s3-deploy",
"version": "1.0.11",
"version": "1.0.12",
"description": "Package to upload files to s3 distribution, and also invalidate those paths in CloudFront if necessary",
"engines": {
"node": ">=8.0.0"
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ function deploy(path, bucketName, distributionId, profile, verboseMode) {

AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile });

s3.uploadChangedFilesInDir(path, bucketName, distributionId, verboseMode).then((res) => {
s3.uploadChangedFilesInDir(path, bucketName, verboseMode).then((res) => {
if (distributionId && res.changedFiles.length > 0) {
console.log(chalk.green(res.message));
console.log(chalk.yellow(`Commencing invalidation operation for distribution ${distributionId}...`));
89 changes: 54 additions & 35 deletions src/s3.js
Original file line number Diff line number Diff line change
@@ -155,46 +155,65 @@ function uploadFiles(pathToUpload, fileList, bucketName, verboseMode, isCli) {
});
}

function uploadChangedFilesInDir(pathToUpload, bucketName, distId, verboseMode, isCli) {
function uploadChangedFilesInDir(pathToUpload, bucketName, verboseMode, isCli) {
return new Promise((resolve, reject) => {
const changedFiles = [];
recursive(pathToUpload, (err, fileList) => {
const s3 = new AWS.S3();

let testedFiles = 0;
const fileListLength = fileList.length;

fileList.forEach((fileName) => {
const bucketPath = fileName.substring(pathToUpload.length + 1);
hasFileChanged(pathToUpload, bucketPath, bucketName, s3, getFileLastModifiedDate)
.then((hasChanged) => {
if (hasChanged) {
changedFiles.push(bucketPath);
}
testedFiles++;

if (testedFiles === fileListLength) {
if (changedFiles.length > 0) {
// eslint-disable-next-line no-console
console.log(chalk.yellow(`${fileListLength} objects found, ${changedFiles.length} objects require updates...`));
uploadFiles(pathToUpload, changedFiles, bucketName, verboseMode, isCli)
.then((msg) => {
if (err) {
if (err.code === 'ENOTDIR') {
reject(new Error('Specified path is not a directory, please specify a valid directory path - this module cannot process individual files'));
} else if (err.code === 'ENOENT') {
reject(new Error('Specified path does not exist. Please specify a valid directory path.'));
} else {
reject(err);
}
} else {
const s3 = new AWS.S3();

let testedFiles = 0;
const fileListLength = fileList.length;

if (fileListLength === 0) {
resolve({
changedFiles: [],
message: 'No files found at specified path',
});
} else {
fileList.forEach((fileName) => {
const bucketPath = fileName.substring(pathToUpload.length + 1);
hasFileChanged(pathToUpload, bucketPath, bucketName, s3, getFileLastModifiedDate)
.then((hasChanged) => {
if (hasChanged) {
changedFiles.push(bucketPath);
}
testedFiles++;

if (testedFiles === fileListLength) {
if (changedFiles.length > 0) {
// eslint-disable-next-line no-console
console.log(chalk.yellow(`${fileListLength} objects found, ${changedFiles.length} objects require updates...`));
uploadFiles(pathToUpload, changedFiles, bucketName, verboseMode, isCli)
.then((msg) => {
resolve({
changedFiles,
message: msg,
});
})
.catch(e => reject(e));
} else {
resolve({
changedFiles,
message: msg,
changedFiles: [],
message: 'No file updates required, skipping upload...',
});
})
.catch(e => reject(e));
} else {
resolve({
changedFiles: [],
message: 'No file updates required, skipping upload...',
});
}
}
})
.catch(e => reject(e));
});
}
}
})
.catch((e) => {
reject(e);
});
});
}
}
});
});
}
Loading