Skip to content

Commit 3037ce7

Browse files
committed
initial commit
0 parents  commit 3037ce7

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-0
lines changed

.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
dist
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
29+
node_modules
30+
31+
#IDE Stuff
32+
**/.idea
33+
34+
#OS STUFF
35+
.DS_Store
36+
.tmp
37+
38+
#SERVERLESS STUFF
39+
admin.env
40+
.env

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Serverless Plugin Boilerplate
2+
=============================
3+
4+
This is a starter project to help you build plugins for the Serverless Framework. You can install this boilerplate Plugin in its current form into your Serverless Projects and it will run. All that's left for you to do is write your custom logic. We've filled this with useful comments to help you along your way. Also, the entire Serverless Framework is comprised of Plugins. When you write your own Plugin, it's no hack, you're simply extending and customizing the Serverless Framework to suite your needs and build processes :)
5+
6+
**A Serverless Plugin can do the following:**
7+
8+
* Add a Custom Action to the Serverless Framework which can be called via the command line, programatically via a handler, or both.
9+
* Add a Custom Action that overwrites a Core Action in the Serverless Framework.
10+
* Add a Custom Hook that fires *before* or *after* a Core Action or a Custom Action.
11+
12+
One plugin can do all of the above, and include several Hooks and Actions at once.
13+
14+
###Get Started
15+
16+
* Plugins must be written in a Serverless Project, so create one specifically for authoring/testing plugins, or write your plugin in a Project you are working on.
17+
18+
* Make sure you are using Serverless `v0.0.11` or greater and create a new project via `serverless project create`.
19+
20+
* cd into your new project and you will see a `plugins` folder available. cd into the `plugins` folder and then run:
21+
22+
```
23+
npm install serverless-plugin-boilerplate --save
24+
```
25+
26+
* Once installed, open the 's-project.json' in your Project's root folder and add the plugin to the `plugins` property, like this:
27+
28+
```
29+
"plugins": [
30+
{
31+
"path": "serverless-plugin-boilerplate"
32+
}
33+
]
34+
```
35+
36+
* Use the Serverless CLI within your project and run `serverless` to see the help screen. You should now see an option entitled `custom` with a `run` Action. This was added by the boilerplate plugin.
37+
38+
* To start working on your own plugin, copy the `serverless-plugin-boilerplate` folder in `yourproject/plugins/node_modules`, create this folder `yourproject/plugins/custom` and paste it in there. The `custom` folder is the designated place to write your plugins. Be sure to change the folder name to something other than `serverless-plugin-boilerplate`.
39+
40+
* Next, open the `s-project.json` in your Project's root folder, **remove the original boilerplate plugin** and replace it with the new name of your Plugin located in the `custom` folder, like this:
41+
42+
```
43+
"plugins": [
44+
{
45+
"path": "your-custom-plugin"
46+
}
47+
]
48+
```
49+
50+
* You don't need to specify the `custom` folder, the Serverless Framework checks both the `node_modules` and `custom` folders for your plugin, just make sure you have a unique folder name.
51+
52+
* Now, your custom plugin is installed and ready to worked on! Read the comments in the `index.js` for further instructions.
53+
54+
55+
If you would like to learn more about plugins, please check out our [Documentation](http://docs.serverless.com).
56+
57+
Good luck! - [Serverless](http://www.serverless.com)
58+
59+

index.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
3+
/**
4+
* Serverless Optimizer Plugin
5+
*/
6+
7+
module.exports = function(serverlessPath) {
8+
9+
const SPlugin = require(path.join(serverlessPath, 'ServerlessPlugin')),
10+
fs = require('fs'),
11+
os = require('os'),
12+
path = require('path'),
13+
babelify = require('babelify'),
14+
browserify = require('browserify'),
15+
UglifyJS = require('uglify-js'),
16+
wrench = require('wrench'),
17+
BbPromise = require('bluebird');
18+
19+
/**
20+
* ServerlessOptimizer
21+
*/
22+
23+
class ServerlessOptimizer extends SPlugin {
24+
25+
/**
26+
* Constructor
27+
*/
28+
29+
constructor(S, config) {
30+
super(S, config);
31+
}
32+
33+
/**
34+
* Define your plugins name
35+
*/
36+
37+
static getName() {
38+
return 'com.serverless.' + ServerlessOptimizer.name;
39+
}
40+
41+
/**
42+
* Register Hooks
43+
*/
44+
45+
registerHooks() {
46+
47+
this.S.addHook(this._optimize.bind(this), {
48+
action: 'codePackageLambdaNodeJs',
49+
event: 'post'
50+
});
51+
52+
return Promise.resolve();
53+
}
54+
55+
/**
56+
* Optimize
57+
*/
58+
59+
_optimize(evt) {
60+
61+
let _this = this;
62+
63+
return new BbPromise(function (resolve, reject) {
64+
65+
66+
return resolve(evt);
67+
68+
});
69+
}
70+
}
71+
72+
// Export Plugin Class
73+
return ServerlessOptimizer;
74+
75+
};

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "serverless-optimizer-plugin",
3+
"version": "0.0.1",
4+
"engines": {
5+
"node": ">=4.0"
6+
},
7+
"description": "Serverless Optimizer Plugin - Optimizers for reducing Lambda file sizes and improving performance",
8+
"author": "serverless.com",
9+
"license": "MIT",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/serverless/serverless-optimizer-plugin"
13+
},
14+
"keywords": [
15+
"serverless optimizer plugin",
16+
"serverless optimizer",
17+
"serverless framework plugin",
18+
"serverless applications",
19+
"serverless plugins",
20+
"lambda browserify",
21+
"lambda minify",
22+
"api gateway",
23+
"lambda",
24+
"aws",
25+
"aws lambda",
26+
"amazon",
27+
"amazon web services",
28+
"serverless.com"
29+
],
30+
"main": "index.js",
31+
"bin": {},
32+
"scripts": {
33+
"test": "mocha tests/all"
34+
},
35+
"devDependencies": {
36+
"chai": "^3.2.0",
37+
"mocha": "^2.2.5"
38+
},
39+
"dependencies": {
40+
"babelify": "^7.2.0",
41+
"bluebird": "^3.0.6",
42+
"browserify": "^12.0.1",
43+
"uglify-js": "^2.6.1",
44+
"wrench": "^1.5.8"
45+
}
46+
}

0 commit comments

Comments
 (0)