Skip to content

Commit

Permalink
fix(nx-serverless): fixed deploy not working. Both deploy and deploy …
Browse files Browse the repository at this point in the history
…function works now
  • Loading branch information
wickstargazer committed Nov 18, 2021
1 parent c887109 commit ec8f760
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libs/aws-cdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@flowaccount/aws-cdk-core",
"version": "1.0.0-beta.8"
}
}
2 changes: 1 addition & 1 deletion libs/aws-cdk-stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"@aws-cdk/aws-elasticsearch": "~1.121.0",
"@aws-cdk/aws-lambda-event-sources": "~1.121.0"
}
}
}
2 changes: 1 addition & 1 deletion libs/nx-aws-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"type": "git",
"url": "https://github.com/flowaccount/nx-plugins/tree/master/libs/nx-aws-cdk"
}
}
}
10 changes: 5 additions & 5 deletions libs/nx-serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Simplify any workflow that can be abstracted into one command using the same con

### Frameworks Schematics

| Framework Name | AWS | Azure | GCP |
| --------------------------------------- | ------------------ | ---------- | ---------- |
| Node-Typescript (Webpack) | :white_check_mark: | :calendar: | :calendar: |
:white_check_mark: | :calendar: | :calendar: |
| Express-js (Typescript-compiler) | :white_check_mark: | :calendar: | :calendar: |
| Framework Name | AWS | Azure | GCP |
| -------------------------------- | ------------------ | ---------- | ---------- |
| Node-Typescript (Webpack) | :white_check_mark: | :calendar: | :calendar: |
| :white_check_mark: | :calendar: | :calendar: |
| Express-js (Typescript-compiler) | :white_check_mark: | :calendar: | :calendar: |

### Serverless Framework Commands

Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"test": "yarn nx test nx-serverless"
},
"author": "Wickstargazer"
}
}
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/deploy/deploy.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function deployExecutor(
if (!prepResult.success) {
throw new Error(`There was an error with the build. ${prepResult.error}`);
}

await makeDistFileReadyForPackaging(options);
const extraArgs = [];
const commands = [];
Expand Down
50 changes: 30 additions & 20 deletions libs/nx-serverless/src/utils/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ export class ServerlessWrapper {
configuration: configurationInput,
serviceDir: buildOptions.servicePath,
configurationFilename: 'serverless.yml',
}
if(deployOptions && deployOptions.function && deployOptions.function != '') {
serverlessConfig.servicePath = getPackagePath(deployOptions)
};
if (
deployOptions &&
deployOptions.function &&
deployOptions.function != ''
) {
serverlessConfig.servicePath = getPackagePath(deployOptions);
}
this.serverless$ = new Serverless(serverlessConfig);
// if (componentsV2.runningComponents()) return () => componentsV2.runComponents();
Expand Down Expand Up @@ -163,18 +167,24 @@ export class ServerlessWrapper {
}
}

function getPackagePath(deployOptions:
| (JsonObject & ServerlessDeployBuilderOptions)
| (JsonObject & ServerlessSlsBuilderOptions)) {
let packagePath = ""
if (!deployOptions.serverlessPackagePath &&
deployOptions.location.indexOf('dist/') > -1) {
packagePath = deployOptions.location.replace('dist/', 'dist/.serverlessPackages/');
}
else if (deployOptions.serverlessPackagePath) {
function getPackagePath(
deployOptions:
| (JsonObject & ServerlessDeployBuilderOptions)
| (JsonObject & ServerlessSlsBuilderOptions)
) {
let packagePath = '';
if (
!deployOptions.serverlessPackagePath &&
deployOptions.location.indexOf('dist/') > -1
) {
packagePath = deployOptions.location.replace(
'dist/',
'dist/.serverlessPackages/'
);
} else if (deployOptions.serverlessPackagePath) {
packagePath = deployOptions.serverlessPackagePath;
}
return packagePath
}
return packagePath;
}

export function getExecArgv(
Expand All @@ -200,7 +210,7 @@ export async function runServerlessCommand(
// review: Change options from location to outputpath?\
let args = getExecArgv(options);
const serviceDir = ServerlessWrapper.serverless.serviceDir;
if (extraArgs) {
if (extraArgs) {
args = args.concat(extraArgs);
}
logger.info('running serverless commands');
Expand All @@ -210,11 +220,11 @@ export async function runServerlessCommand(
};
ServerlessWrapper.serverless.isTelemetryReportedExternally = true;
try {
const packagePath = getPackagePath(options)
logger.debug(`Serverless service path is ${packagePath}`)
ServerlessWrapper.serverless.serviceDir = packagePath
const packagePath = getPackagePath(options);
logger.debug(`Serverless service path is ${packagePath}`);
ServerlessWrapper.serverless.serviceDir = packagePath;
await ServerlessWrapper.serverless.run();
ServerlessWrapper.serverless.serviceDir = serviceDir
ServerlessWrapper.serverless.serviceDir = serviceDir;
} catch (ex) {
throw new Error(`There was an error with the build. ${ex}.`);
}
Expand All @@ -226,7 +236,7 @@ export async function makeDistFileReadyForPackaging(
| (JsonObject & ServerlessSlsBuilderOptions)
): Promise<void> {
let readyToPackaged: BuilderOutput = null;
options.serverlessPackagePath = getPackagePath(options);
options.serverlessPackagePath = getPackagePath(options);
readyToPackaged = await copyBuildOutputToBePackaged(options);
if (readyToPackaged == null) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion libs/scully-plugin-angular-delay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
],
"author": "Wickstargazer",
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion libs/scully-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
],
"author": "Wickstargazer",
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion libs/scully-plugin-lazy-load-picture-tag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
],
"author": "Wickstargazer",
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@
"pre-push": "yarn checkcommit && yarn format:check"
}
}
}
}

0 comments on commit ec8f760

Please sign in to comment.