Skip to content

Commit

Permalink
fix(nx-serverless): fix stage during init serverless (#111)
Browse files Browse the repository at this point in the history
* fix(nx-serverless): fix stage during init serverless

* fix(nx-serverless): graceful-fs 4.2.1 so its not failing in ubuntu

* fix(nx-serverless): fixed `copyBuildOutputToBePackaged` by added remove old build output files before copy

* docs(nx-serverless): update release version 1.0.2 => 1.0.3

* docs(nx-serverless): update release version 1.0.2 => 1.1.0

Co-authored-by: Narong <narong@flowaccount.com>
  • Loading branch information
wickstargazer and NarongOk committed Dec 21, 2021
1 parent 74df250 commit 7e0df3e
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 102 deletions.
1 change: 1 addition & 0 deletions .scully/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
identifier: kaxe4dp4kelcv7w1
5 changes: 3 additions & 2 deletions libs/nx-serverless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flowaccount/nx-serverless",
"version": "1.0.2",
"version": "1.1.0",
"main": "src/index.js",
"description": "Serverless schematics for nx workspace",
"keywords": [
Expand Down Expand Up @@ -46,7 +46,8 @@
"serverless-offline": "^7.0.0",
"serverless-apigw-binary": "^0.4.4",
"is-builtin-module": "^3.0.0",
"rxjs-for-await": "0.0.2"
"rxjs-for-await": "0.0.2",
"graceful-fs": "4.2.1"
},
"devDependencies": {},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/deploy/deploy.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Serverless Deploy Builder', () => {
buildTarget: 'serverlessapp:build:production',
location: 'dist/apps/serverlessapp',
package: 'dist/apps/serverlessapp',
config: 'apps/serverlessapp/serverless.yml',
config: 'apps/serverlessapp/serverless.ts',
waitUntilTargets: [],
inspect: false,
host: null,
Expand Down
1 change: 0 additions & 1 deletion libs/nx-serverless/src/builders/deploy/deploy.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BuilderOutput } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import * as _ from 'lodash';
import {
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/deploy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"config": {
"type": "string",
"description": "The serverless.yml location"
"description": "The serverless.yml/serverless.ts location"
},
"location": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/destroy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"config": {
"type": "string",
"description": "The serverless.yml location"
"description": "The serverless.yml/serverless.ts location"
},
"location": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/offline/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"config": {
"type": "string",
"description": "The serverless.yml location"
"description": "The serverless.yml/serverless.ts location"
},
"location": {
"type": "string",
Expand Down
10 changes: 9 additions & 1 deletion libs/nx-serverless/src/builders/scully/scully.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ async function runScully(
) {
const commands: { command: string }[] = [];
const args = getExecArgv(options);

options.configFiles.forEach((fileName) => {
commands.push({
command: `scully --configFile=${fileName} ${args.join(' ')}`,
command: `scully --configFile=${fileName} --disableProjectFolderCheck ${args.join(
' '
)}`,
});
console.log(
`scully --configFile=${fileName} --disableProjectFolderCheck ${args.join(
' '
)}`
);
});
const root = getSourceRoot(context);
await runCommand(
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/sls/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"config": {
"type": "string",
"description": "The serverless.yml location"
"description": "The serverless.yml/serverless.ts location"
},
"location": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-serverless/src/builders/sls/sls.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// buildTarget: 'serverlessapp:build:production',
// location: 'dist/apps/serverlessapp',
// package: 'dist/apps/serverlessapp',
// config: 'apps/serverlessapp/serverless.yml',
// config: 'apps/serverlessapp/serverless.ts',
// waitUntilTargets: [],
// inspect: false,
// host: null,
Expand Down
1 change: 0 additions & 1 deletion libs/nx-serverless/src/builders/sls/sls.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BuilderOutput } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import * as _ from 'lodash';
import {
Expand Down
12 changes: 6 additions & 6 deletions libs/nx-serverless/src/schematics/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('node api app', () => {
outputPath: 'dist/apps/my-serveless-app',
package: 'apps/my-serveless-app',
processEnvironmentFile: 'env.json',
serverlessConfig: 'apps/my-serveless-app/serverless.yml',
serverlessConfig: 'apps/my-serveless-app/serverless.ts',
servicePath: 'apps/my-serveless-app',
tsConfig: 'apps/my-serveless-app/tsconfig.app.json',
},
Expand All @@ -87,7 +87,7 @@ describe('node api app', () => {
builder: '@flowaccount/nx-serverless:deploy',
options: {
buildTarget: 'my-serveless-app:build:production',
config: 'apps/my-serveless-app/serverless.yml',
config: 'apps/my-serveless-app/serverless.ts',
location: 'dist/apps/my-serveless-app',
package: 'dist/apps/my-serveless-app',
stage: 'dev',
Expand All @@ -97,7 +97,7 @@ describe('node api app', () => {
builder: '@flowaccount/nx-serverless:destroy',
options: {
buildTarget: 'my-serveless-app:build:production',
config: 'apps/my-serveless-app/serverless.yml',
config: 'apps/my-serveless-app/serverless.ts',
location: 'dist/apps/my-serveless-app',
package: 'dist/apps/my-serveless-app',
},
Expand All @@ -124,7 +124,7 @@ describe('node api app', () => {
},
options: {
buildTarget: 'my-serveless-app:build',
config: 'apps/my-serveless-app/serverless.yml',
config: 'apps/my-serveless-app/serverless.ts',
location: 'dist/apps/my-serveless-app',
},
},
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('node api app', () => {
tree.exists('apps/my-serveless-app/environment.prod.ts')
).toBeTruthy();
expect(tree.exists('apps/my-serveless-app/src/handler.ts')).toBeTruthy();
expect(tree.exists('apps/my-serveless-app/serverless.yml')).toBeTruthy();
expect(tree.exists('apps/my-serveless-app/serverless.ts')).toBeTruthy();

const tsconfig = readJsonInTree(
tree,
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('node api app', () => {
'apps/my-dir/my-serveless-app/environment.ts',
'apps/my-dir/my-serveless-app/environment.prod.ts',
'apps/my-dir/my-serveless-app/src/handler.ts',
'apps/my-dir/my-serveless-app/serverless.yml',
'apps/my-dir/my-serveless-app/serverless.ts',
].forEach((path) => {
expect(tree.exists(path)).toBeTruthy();
});
Expand Down
9 changes: 5 additions & 4 deletions libs/nx-serverless/src/schematics/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getServeConfig(project: any, options: NormalizedSchema) {
builder: '@flowaccount/nx-serverless:offline',
options: {
buildTarget: options.name + ':build',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
port: 7777,
},
Expand All @@ -61,7 +61,7 @@ function getDeployConfig(project: any, options: NormalizedSchema) {
builder: '@flowaccount/nx-serverless:deploy',
options: {
buildTarget: options.name + ':build:production',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
package: joinPathFragments(normalize('dist'), options.appProjectRoot),
stage: 'dev',
Expand All @@ -74,7 +74,7 @@ function getDestroyConfig(options: NormalizedSchema) {
builder: '@flowaccount/nx-serverless:destroy',
options: {
buildTarget: options.name + ':build:production',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
package: joinPathFragments(normalize('dist'), options.appProjectRoot),
},
Expand Down Expand Up @@ -119,6 +119,7 @@ function addAppFiles(host: Tree, options: NormalizedSchema) {
offset: offsetFromRoot(options.appProjectRoot),
template: '',
root: options.appProjectRoot,
serviceName: options.name.replace('.', '-'),
baseWorkspaceTsConfig: options.baseWorkspaceTsConfig,
};
generateFiles(
Expand All @@ -145,7 +146,7 @@ function addAppFiles(host: Tree, options: NormalizedSchema) {
// function addServerlessYMLFile(host: Tree, options: NormalizedSchema) {
// // return (host: Tree) => {
// host.create(
// join(options.appProjectRoot, 'serverless.yml'),
// join(options.appProjectRoot, 'serverless.ts'),
// `service: ${options.name}
// frameworkVersion: ">=1.1.0"
// plugins:
Expand Down
36 changes: 36 additions & 0 deletions libs/nx-serverless/src/schematics/api/files/serverless.ts.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Serverless } from 'serverless';
const serverlessConfiguration: Serverless = {
service: '<%= serviceName %>',
frameworkVersion: '>=1.1.0',
plugins: [
'serverless-offline'
],
package: {
individually: true,
excludeDevDependencies: false
},
provider: {
name: '<%= provider %>',
region: '<%= region %>',
<% if(endpointType) { %> ? endpointType: '<%= endpointType %>', <% } %>
runtime: 'nodejs14.x'
},
functions: {
helloWorld: {
handler: `src/handler.helloWorld`,
events: [
{
http: {
method: 'get',
path: 'hello-world',
},
},
],
},
},
resources: {

},
};

module.exports = serverlessConfiguration;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ provider:
name: <%= provider %>
region: <%= region %>
<% if(endpointType) { %> ? endpointType: <%= endpointType %> <% } %>
runtime: nodejs10.x
runtime: nodejs14.x
functions:
hello-world:
handler: src/handler.helloWorld
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const helloWorld: APIGatewayProxyHandler = async (event, _context, callba
input: event,
}, null, 2),
};
};
};
3 changes: 1 addition & 2 deletions libs/nx-serverless/src/schematics/api/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"provider": {
"type": "string",
"description": "The cloud provider for this serverless api.",
"default": "aws",
"x-prompt": "Which cloud provider are you using for this serverless api? ( aws | azure | google ) etc."
"default": "aws"
},
"baseWorkspaceTsConfig": {
"type": "boolean",
Expand Down
12 changes: 6 additions & 6 deletions libs/nx-serverless/src/schematics/express/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('express app', () => {
outputPath: 'dist',
package: 'apps/my-app',
processEnvironmentFile: 'env.json',
serverlessConfig: 'apps/my-app/serverless.yml',
serverlessConfig: 'apps/my-app/serverless.ts',
servicePath: 'apps/my-app',
tsConfig: 'apps/my-app/tsconfig.serverless.json',
skipClean: true,
Expand All @@ -85,7 +85,7 @@ describe('express app', () => {
options: {
waitUntilTargets: ['my-app:build:production'],
buildTarget: 'my-app:compile:production',
config: 'apps/my-app/serverless.yml',
config: 'apps/my-app/serverless.ts',
location: 'dist/apps/my-app',
package: 'dist/apps/my-app',
stage: 'dev',
Expand All @@ -95,7 +95,7 @@ describe('express app', () => {
executor: '@flowaccount/nx-serverless:destroy',
options: {
buildTarget: 'my-app:compile:production',
config: 'apps/my-app/serverless.yml',
config: 'apps/my-app/serverless.ts',
location: 'dist/apps/my-app',
package: 'dist/apps/my-app',
},
Expand All @@ -113,7 +113,7 @@ describe('express app', () => {
options: {
waitUntilTargets: ['my-app:build'],
buildTarget: 'my-app:compile',
config: 'apps/my-app/serverless.yml',
config: 'apps/my-app/serverless.ts',
location: 'dist/apps/my-app',
},
},
Expand All @@ -130,7 +130,7 @@ describe('express app', () => {
expect(tree.exists('apps/my-app/env.json')).toBeTruthy();
expect(tree.exists('apps/my-app/handler.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/tsconfig.serverless.json')).toBeTruthy();
expect(tree.exists('apps/my-app/serverless.yml')).toBeTruthy();
expect(tree.exists('apps/my-app/serverless.ts')).toBeTruthy();
const tsconfig = readJsonInTree(
tree,
'apps/my-app/tsconfig.serverless.json'
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('express app', () => {
'apps/my-dir/my-app/env.json',
'apps/my-dir/my-app/handler.ts',
'apps/my-dir/my-app/tsconfig.serverless.json',
'apps/my-dir/my-app/serverless.yml',
'apps/my-dir/my-app/serverless.ts',
].forEach((path) => {
expect(tree.exists(path)).toBeTruthy();
});
Expand Down
8 changes: 4 additions & 4 deletions libs/nx-serverless/src/schematics/express/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getServeConfig(options: NormalizedSchema) {
options: {
waitUntilTargets: [options.name + ':build'],
buildTarget: options.name + ':compile',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
},
configurations: {
Expand All @@ -51,7 +51,7 @@ function getDeployConfig(options: NormalizedSchema) {
options: {
waitUntilTargets: [options.name + ':build:production'],
buildTarget: options.name + ':compile:production',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
package: joinPathFragments(normalize('dist'), options.appProjectRoot),
stage: 'dev',
Expand All @@ -64,7 +64,7 @@ function getDestroyConfig(options: NormalizedSchema) {
executor: '@flowaccount/nx-serverless:destroy',
options: {
buildTarget: options.name + ':compile:production',
config: joinPathFragments(options.appProjectRoot, 'serverless.yml'),
config: joinPathFragments(options.appProjectRoot, 'serverless.ts'),
location: joinPathFragments(normalize('dist'), options.appProjectRoot),
package: joinPathFragments(normalize('dist'), options.appProjectRoot),
},
Expand Down Expand Up @@ -167,7 +167,7 @@ function addAppFiles(host: Tree, options: NormalizedSchema) {
// function addServerlessYMLFile(options: NormalizedSchema): Rule {
// return (host: Tree) => {
// host.create(
// join(options.appProjectRoot, 'serverless.yml'),
// join(options.appProjectRoot, 'serverless.ts'),
// `service: ${options.name}
// frameworkVersion: ">=1.1.0"
// plugins:
Expand Down
Loading

0 comments on commit 7e0df3e

Please sign in to comment.