Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #556 from oliverturner/oliver/s3-path-flag
Browse files Browse the repository at this point in the history
Make S3 paths configurable via CLI flag
  • Loading branch information
oliverturner authored Mar 8, 2019
2 parents 849d111 + 1c98230 commit d87ca90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
27 changes: 27 additions & 0 deletions lib/normalize-name.unit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var normalize = require("./normalize-name");

describe("normalize", function() {
it("removes ft prefixes without options", function() {
var alpha = normalize("ft-alpha");
var beta = normalize("next-beta");
var gamma = normalize("@financial-times/gamma");

expect(alpha).toBe("alpha");
expect(beta).toBe("beta");
expect(gamma).toBe("@financial-times/gamma");
});

it("removes ft prefixes and versions", function() {
var alpha = normalize("ft-alpha-v1", { version: false });
var beta = normalize("next-beta-v99", { version: false });
var gamma = normalize("ft-gamma-v123", { version: false });
var delta = normalize("next-delta-v123", { version: false });
var epsilon = normalize("@financial-times/epsilon", { version: false });

expect(alpha).toBe("alpha-v1");
expect(beta).toBe("beta-v99");
expect(gamma).toBe("gamma");
expect(delta).toBe("delta");
expect(epsilon).toBe("epsilon");
});
});
10 changes: 7 additions & 3 deletions tasks/deploy-hashed-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const euRegion = 'eu-west-1';
const usRegion = 'us-east-1';
const gzip = denodeify(require('zlib').gzip);


function task (opts) {

aws.config.update({
Expand All @@ -44,7 +43,12 @@ function task (opts) {

const shouldMonitorAssets = opts.monitorAssets;
const directory = opts.directory || 'public';
const appName =
normalizeName(opts.app) ||
normalizeName(packageJson.name, { version: false });

let assetHashes;

try {
console.log(process.cwd() + `/${directory}/assets-hashes.json`); // eslint-disable-line no-console
assetHashes = require(process.cwd() + `/${directory}/asset-hashes.json`);
Expand All @@ -56,14 +60,14 @@ function task (opts) {
return Promise.reject('Must set AWS_ACCESS_HASHED_ASSETS and AWS_SECRET_HASHED_ASSETS');
}

const app = normalizeName(packageJson.name, { version: false });


console.log('Deploying hashed assets to S3...'); // eslint-disable-line no-console

return Promise.all(Object.keys(assetHashes)
.map(file => {
const hashedName = assetHashes[file];
const key = 'hashed-assets/' + app + '/' + hashedName;
const key = 'hashed-assets/' + appName + '/' + hashedName;
// get the extension, ignoring brotli
const extension = (/\.(js|css)(\.br)?$/.exec(file) || [])[1];

Expand Down

0 comments on commit d87ca90

Please sign in to comment.