Skip to content

Commit

Permalink
relay fodler should have npm packages installed
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Jul 24, 2023
1 parent e3e0a30 commit 35ec98f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 496 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "samp-cli",
"version": "1.0.18",
"version": "1.0.20",
"description": "CLI tool for extended productivity with AWS Serverless Application Model (SAM)",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/commands/local/cdk-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ for (const key of Object.keys(resources)) {
const resource = synthedTemplate.Resources[fn];
if (resource.Type === "AWS::Lambda::Function") {
if (resource.Metadata?.["aws:asset:is-bundled"] === false) continue;
if (resource.Metadata?.['aws:cdk:path'].includes(`/${key}/`) && resource.Metadata?.['aws:cdk:path'].includes('/Resource')) {
if (resource.Metadata?.['aws:cdk:path'].includes(`/${key}/`) && resource.Metadata?.['aws:cdk:path'].includes('/Resource')) {
//get filename from entry

const entryFile = entry.substring(entry.lastIndexOf("/") + 1).split(".")[0];
logicalId = fn;
handler = resource.Properties.Handler;
handler = `${entryFile}.${resource.Properties.Handler.split(".")[1]}`;
break;
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/commands/local/lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ini from 'ini';
import getMac from 'getmac';
import archiver from 'archiver';
import { fileURLToPath } from 'url';
import { spawnSync } from 'child_process';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const mac = getMac();
Expand Down Expand Up @@ -46,7 +47,7 @@ const timer = new Date().getTime();
let certData, endpoint, stack, functions, template;
const policyName = "lambda-debug-policy";

const packageVersion = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).version;
const packageVersion = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', '..','..', 'package.json'))).version;

const zipFilePath = path.join(os.homedir(), '.lambda-debug', `relay-${accountId}-${packageVersion}.zip`);

Expand Down Expand Up @@ -164,6 +165,15 @@ if (!fs.existsSync(".lambda-debug")) {
if (!fs.existsSync(zipFilePath)) {
console.log(`Creating Lambda artifact zip`);
fs.writeFileSync(path.join(__dirname, 'relay', 'config.json'), JSON.stringify({ mac: mac, endpoint: endpoint }));
// install npm package sin relay folder
const npm = os.platform() === 'win32' ? 'npm.cmd' : 'npm';
console.log(`Installing npm packages in relay lambda function folder`);
const npmInstall = spawnSync(npm, ['install'], { cwd: path.join(__dirname, 'relay') });
if (npmInstall.error) {
console.log(`Error installing npm packages in relay folder: ${npmInstall.error}`);
process.exit(1);
}

//create zip file of relay folder
const output = fs.createWriteStream(zipFilePath);
const archive = archiver('zip', {
Expand Down
Loading

0 comments on commit 35ec98f

Please sign in to comment.