New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript support in FunctionCreate #371

Closed
nillis opened this Issue Dec 13, 2015 · 9 comments

Comments

Projects
None yet
4 participants
@nillis

nillis commented Dec 13, 2015

I would like to implement TypeScript support in the lambda functions. I would like some advice on which solution to choose:

  1. Add an enableTypeScript option to the FunctionCreate action

When enabled the following files would be copied to the generated function:

  • tsconfig.json
  • tsd.json
  • typings (empty folder)
  • ts (empty folder)

In the ts folder, users can add their ts files which will be compiled to the lib folder

  1. Write custom plugin
@ac360

This comment has been minimized.

Show comment
Hide comment
@ac360

ac360 Dec 13, 2015

Member

@nillis That would be AWESOME. I think you should write it as a Plugin. Our process for now is to keep the core lean, and encourage plugins. ...If the Plugins are in high demand, we'll merge them into the core.

Member

ac360 commented Dec 13, 2015

@nillis That would be AWESOME. I think you should write it as a Plugin. Our process for now is to keep the core lean, and encourage plugins. ...If the Plugins are in high demand, we'll merge them into the core.

@nillis

This comment has been minimized.

Show comment
Hide comment
@nillis

nillis Dec 13, 2015

Great, thx for the response!

nillis commented Dec 13, 2015

Great, thx for the response!

@nillis nillis closed this Dec 13, 2015

@jwulf

This comment has been minimized.

Show comment
Hide comment
@jwulf

jwulf Dec 14, 2015

Member

Awesome! I totally want to use Typescript with serverless too!

Where will the typescript compile take place? Does it rely on Visual Studio, or will it be part of the server less build / run / publish toolchain?

Member

jwulf commented Dec 14, 2015

Awesome! I totally want to use Typescript with serverless too!

Where will the typescript compile take place? Does it rely on Visual Studio, or will it be part of the server less build / run / publish toolchain?

@nillis

This comment has been minimized.

Show comment
Hide comment
@nillis

nillis Dec 14, 2015

I currently use tsc from the command line. Based on the tsconfig.json file it will compile/watch your ts files and publish it to the right directory.
I will share my workflow later today or tomorrow.

nillis commented Dec 14, 2015

I currently use tsc from the command line. Based on the tsconfig.json file it will compile/watch your ts files and publish it to the right directory.
I will share my workflow later today or tomorrow.

@nillis

This comment has been minimized.

Show comment
Hide comment
@nillis

nillis Dec 15, 2015

I currently have this workflow to build serverless modules with TypeScript.

Prerequisites

npm install -g typescript
npm install -g tsd

Setup
I create my serverless module using the usual command

sls module create
  1. src folder
    Under the module folder I add a src folder where I put my ts files. These files will be compiled into js to the lib folder.

screen shot 2015-12-15 at 20 13 30

  1. tsconfig.json

I add a tsconfig.json file with the TypeScript configuration. When I run tsc from the module directory it'll use this configuration file to compile the ts files from the src files to the lib folder.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": true,
        "declaration": true,
        "outDir": "lib",
        "watch": true
    }
}
  1. tsd.json

Just run the following command from the module directory to init tsd. With tsd you can easily pull declaration files. The declaration files will be stored into the typings directory.

tsd init
tsd install node --save

Run, Forest, Run!
Just run the tsc command from the module folder and see the ts files under src been compiled to the lib folder into js.

tsc

If you have any questions, I'm glad to help.

nillis commented Dec 15, 2015

I currently have this workflow to build serverless modules with TypeScript.

Prerequisites

npm install -g typescript
npm install -g tsd

Setup
I create my serverless module using the usual command

sls module create
  1. src folder
    Under the module folder I add a src folder where I put my ts files. These files will be compiled into js to the lib folder.

screen shot 2015-12-15 at 20 13 30

  1. tsconfig.json

I add a tsconfig.json file with the TypeScript configuration. When I run tsc from the module directory it'll use this configuration file to compile the ts files from the src files to the lib folder.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": true,
        "declaration": true,
        "outDir": "lib",
        "watch": true
    }
}
  1. tsd.json

Just run the following command from the module directory to init tsd. With tsd you can easily pull declaration files. The declaration files will be stored into the typings directory.

tsd init
tsd install node --save

Run, Forest, Run!
Just run the tsc command from the module folder and see the ts files under src been compiled to the lib folder into js.

tsc

If you have any questions, I'm glad to help.

@nillis

This comment has been minimized.

Show comment
Hide comment
@nillis

nillis Dec 15, 2015

If you translate this workflow into a serverless plugin this would mean the plugin does the following:
Extend the FunctionCreate, add a tsconfig.json and tsd.json file to the module directory and creates a src folder with the ts files.

nillis commented Dec 15, 2015

If you translate this workflow into a serverless plugin this would mean the plugin does the following:
Extend the FunctionCreate, add a tsconfig.json and tsd.json file to the module directory and creates a src folder with the ts files.

@ac360

This comment has been minimized.

Show comment
Hide comment
@ac360

ac360 Dec 16, 2015

Member

@nillis I haven't tried TypeScript yet, so you're the export here. I have a few thoughts on Plugin development though. I think the Plugin you write should absolutely create a POST hook on FunctionCreate to add the Typescript files. You can also write PRE hook on FunctionDeploy to run the compiling (although I'm unclear as to how all of this works). Further, every s-project.json, s-module.json and s-function.json includes a custom property where Plugins can store config data. I recommend you check that out as an alternative to creating more JSON files. We will be starting work on the Serverless Dashboard project soon and it will help people visualize the data in those custom properties. Hope this helps and I'm really looking forward to this @nillis. This will prompt me to start playing with TypeScript. Also don't forget to log the evt object to see what cool Action-specific data is passed into your Plugin Hooks. Lots of useful stuff in there, we made sure of that :)

Member

ac360 commented Dec 16, 2015

@nillis I haven't tried TypeScript yet, so you're the export here. I have a few thoughts on Plugin development though. I think the Plugin you write should absolutely create a POST hook on FunctionCreate to add the Typescript files. You can also write PRE hook on FunctionDeploy to run the compiling (although I'm unclear as to how all of this works). Further, every s-project.json, s-module.json and s-function.json includes a custom property where Plugins can store config data. I recommend you check that out as an alternative to creating more JSON files. We will be starting work on the Serverless Dashboard project soon and it will help people visualize the data in those custom properties. Hope this helps and I'm really looking forward to this @nillis. This will prompt me to start playing with TypeScript. Also don't forget to log the evt object to see what cool Action-specific data is passed into your Plugin Hooks. Lots of useful stuff in there, we made sure of that :)

@nillis

This comment has been minimized.

Show comment
Hide comment
@nillis

nillis Dec 16, 2015

Great, thanks for the guidelines aboit plugins. I just noticed the serverless-plugin project. Thumbs up!
If you could use any help with developing the dashboard, I would be glad to
be involved in this.

On Wed, 16 Dec 2015, 08:41 Austen notifications@github.com wrote:

@nillis https://github.com/nillis I haven't tried TypeScript yet, so
you're the export here. I have a few thoughts on Plugin development though.
I think the Plugin you write should absolutely create a POST hook on
FunctionCreate to add the Typescript files. You can also write PRE hook on
FunctionDeploy to run the compiling (although I'm unclear as to how all of
this works). Further, every s-project.json, s-module.json and
s-function.json includes a custom property where Plugins can store config
data. I recommend you check that out as an alternative to creating more
JSON files. We will be starting work on the Serverless Dashboard project
soon and it will help people visualize the data in those custom
properties. Hope this helps and I'm really looking forward to this @nillis
https://github.com/nillis. This will prompt me to start playing wit h
TypeScript. Also don't forget to log the evt object to see what cool
Action-specific data is passed into your Plugin Hooks. Lots of useful stuff
in there, we made sure of that :)


Reply to this email directly or view it on GitHub
#371 (comment)
.

nillis commented Dec 16, 2015

Great, thanks for the guidelines aboit plugins. I just noticed the serverless-plugin project. Thumbs up!
If you could use any help with developing the dashboard, I would be glad to
be involved in this.

On Wed, 16 Dec 2015, 08:41 Austen notifications@github.com wrote:

@nillis https://github.com/nillis I haven't tried TypeScript yet, so
you're the export here. I have a few thoughts on Plugin development though.
I think the Plugin you write should absolutely create a POST hook on
FunctionCreate to add the Typescript files. You can also write PRE hook on
FunctionDeploy to run the compiling (although I'm unclear as to how all of
this works). Further, every s-project.json, s-module.json and
s-function.json includes a custom property where Plugins can store config
data. I recommend you check that out as an alternative to creating more
JSON files. We will be starting work on the Serverless Dashboard project
soon and it will help people visualize the data in those custom
properties. Hope this helps and I'm really looking forward to this @nillis
https://github.com/nillis. This will prompt me to start playing wit h
TypeScript. Also don't forget to log the evt object to see what cool
Action-specific data is passed into your Plugin Hooks. Lots of useful stuff
in there, we made sure of that :)


Reply to this email directly or view it on GitHub
#371 (comment)
.

@pie6k

This comment has been minimized.

Show comment
Hide comment
@pie6k

pie6k May 9, 2017

I've created example of serverless lambda with typescript with local development support - https://github.com/pietrasiak/serverless-typescript-starter

It's based on serverless-webpack and serverless-offline

pie6k commented May 9, 2017

I've created example of serverless lambda with typescript with local development support - https://github.com/pietrasiak/serverless-typescript-starter

It's based on serverless-webpack and serverless-offline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment