Skip to content

Commit

Permalink
zip at install
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelcroi committed May 24, 2024
1 parent 89ef9f2 commit e5eb81f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
!lambda/**/*.js
!resources/**/*/*.*

!scripts/*.js

!package.json
!package-lock.json

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Use one CloudFront Function template per framework
- Generate the necessary dummy zip file required by the Pipeline during installation, instead of using the CLI deploy command

### Fixed
17 changes: 0 additions & 17 deletions bin/cli/actions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ interface Command {
cmd: any;
}

export async function createZipArchive() {
const outputFile = getBuildConfigS3Folder() + "/dummy.zip";
// Check if the zip file already exists
if (fs.existsSync(outputFile)) {
return;
}

const zip = new AdmZip();

zip.addLocalFile(getBuildConfigS3Folder() + "/dummy.txt");
zip.writeZip(outputFile);

}

export default async function handleDeployCommand() {
await checkAWSConnection();
Expand All @@ -95,10 +82,6 @@ export default async function handleDeployCommand() {
var counter = 1;
const hostingConfiguration = await loadHostingConfiguration();

if (isS3Config(hostingConfiguration)) {
await createZipArchive();
}

var certificateArnCmdParam = "";
if (hostingConfiguration.domainName) {
console.log(
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"audit": "npm audit && cdk synth | cfn_nag",
"cloudfront-hosting-toolkit": "node bin/cli/index.js",
"test": "jest --coverage",
"postinstall": "cd lambda/layers/aws_sdk/nodejs && npm install"
"zipfile": "node scripts/createDummyZip.js",
"postinstall": "cd lambda/layers/aws_sdk/nodejs && npm install && cd ../../../.. && npm run zipfile"
},

"devDependencies": {
"@types/archiver": "5.3.2",
"@types/aws-lambda": "^8.10.133",
Expand Down
4 changes: 2 additions & 2 deletions resources/cff_templates/index_angularjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ async function handler(event) {
var request = event.request;
var uri = request.uri;

//console.log("URI BEFORE: " + request.uri); -> Uncomment if needed
//console.log("URI BEFORE: " + request.uri); // Uncomment if needed
request.uri = await updateURI(uri);
//console.log("URI AFTER: " + request.uri);-> Uncomment if needed
//console.log("URI AFTER: " + request.uri); // Uncomment if needed

return request;
}
5 changes: 3 additions & 2 deletions resources/cff_templates/index_basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ async function handler(event) {
var request = event.request;
var uri = request.uri;

//console.log("URI BEFORE: " + request.uri); -> Uncomment if needed
//console.log("URI BEFORE: " + request.uri); // Uncomment if needed
request.uri = await updateURI(uri);
//console.log("URI AFTER: " + request.uri);-> Uncomment if needed
//console.log("URI AFTER: " + request.uri); // Uncomment if needed



return request;
Expand Down
5 changes: 3 additions & 2 deletions resources/cff_templates/index_nextjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ async function handler(event) {
var request = event.request;
var uri = request.uri;

//console.log("URI BEFORE: " + request.uri); -> Uncomment if needed
//console.log("URI BEFORE: " + request.uri); // Uncomment if needed
request.uri = await updateURI(uri);
//console.log("URI AFTER: " + request.uri);-> Uncomment if needed
//console.log("URI AFTER: " + request.uri); // Uncomment if needed



return request;
Expand Down
5 changes: 3 additions & 2 deletions resources/cff_templates/index_reactjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ async function handler(event) {
var request = event.request;
var uri = request.uri;

//console.log("URI BEFORE: " + request.uri); -> Uncomment if needed
//console.log("URI BEFORE: " + request.uri); // Uncomment if needed
request.uri = await updateURI(uri);
//console.log("URI AFTER: " + request.uri);-> Uncomment if needed
//console.log("URI AFTER: " + request.uri); // Uncomment if needed



return request;
Expand Down
5 changes: 3 additions & 2 deletions resources/cff_templates/index_vuejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ async function handler(event) {
var request = event.request;
var uri = request.uri;

//console.log("URI BEFORE: " + request.uri); -> Uncomment if needed
//console.log("URI BEFORE: " + request.uri); // Uncomment if needed
request.uri = await updateURI(uri);
//console.log("URI AFTER: " + request.uri);-> Uncomment if needed
//console.log("URI AFTER: " + request.uri); // Uncomment if needed



return request;
Expand Down
26 changes: 26 additions & 0 deletions scripts/createDummyZip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// scripts/createZipArchive.js

const fs = require("fs");
const AdmZip = require("adm-zip");

console.log("createZipArchive");
const outputFile = "resources/s3_trigger/dummy.zip"; // Adjust the path as needed

// Check if the zip file already exists
if (fs.existsSync(outputFile)) {
console.log("Zip file already exists.");
return;
}

console.log("Creating new zip file...");

const zip = new AdmZip();

try {
zip.addLocalFile("resources/s3_trigger/dummy.txt"); // Adjust the path as needed
zip.writeZip(outputFile);
console.log("Zip file written successfully.");
} catch (error) {
console.error("Error writing zip file:", error);
process.exit(1);
}

0 comments on commit e5eb81f

Please sign in to comment.