Skip to content

Commit 4fe63af

Browse files
authored
Release 0.1.57 (#106)
1 parent 18c1be5 commit 4fe63af

41 files changed

Lines changed: 772 additions & 347 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
__tests__
23
lib
34
docs
45
test

__tests__/execCommand.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import path from 'path';
2+
import { execCommand } from '../src';
3+
4+
test('execCommand test tracker success', async () => {
5+
const res = await execCommand({
6+
syaml: path.join(__dirname, 'fixtures', 'tracker-app-success', 's.yaml'),
7+
args: ['-y', '--use-local'],
8+
method: 'deploy',
9+
globalArgs: {
10+
debug: true,
11+
},
12+
});
13+
expect(res).toEqual({
14+
helloworld: { message: 'this is a local fc' },
15+
'next-helloworld': { message: 'this is a local fc' },
16+
});
17+
});
18+
19+
test.only('execCommand test tracker error', async () => {
20+
const res = await execCommand({
21+
syaml: path.join(__dirname, 'fixtures', 'tracker-app-error', 's.yaml'),
22+
args: ['-y', '--use-local'],
23+
method: 'deploy',
24+
globalArgs: {
25+
debug: true,
26+
},
27+
});
28+
expect(res).toEqual({
29+
helloworld: { message: 'this is a local fc' },
30+
'next-helloworld': { message: 'this is a local fc' },
31+
});
32+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var getRawBody = require('raw-body');
2+
var getFormBody = require('body/form');
3+
var body = require('body');
4+
5+
6+
/*
7+
To enable the initializer feature (https://help.aliyun.com/document_detail/156876.html)
8+
please implement the initializer function as below:
9+
exports.initializer = (context, callback) => {
10+
console.log('initializing');
11+
callback(null, '');
12+
};
13+
*/
14+
15+
exports.handler = (req, resp, context) => {
16+
console.log('hello world');
17+
18+
var params = {
19+
path: req.path,
20+
queries: req.queries,
21+
headers: req.headers,
22+
method : req.method,
23+
requestURI : req.url,
24+
clientIP : req.clientIP,
25+
}
26+
27+
getRawBody(req, function(err, body) {
28+
for (var key in req.queries) {
29+
var value = req.queries[key];
30+
resp.setHeader(key, value);
31+
}
32+
resp.setHeader('Content-Type', 'application/json');
33+
params.body = body.toString();
34+
resp.send(JSON.stringify(params, null, ' '));
35+
});
36+
37+
/*
38+
getFormBody(req, function(err, formBody) {
39+
for (var key in req.queries) {
40+
var value = req.queries[key];
41+
resp.setHeader(key, value);
42+
}
43+
params.body = formBody;
44+
console.log(formBody);
45+
resp.send(JSON.stringify(params));
46+
});
47+
*/
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { setTrackerData } = require('../../../src');
2+
const { get } = require('lodash');
3+
4+
class FC {
5+
deploy(inputs) {
6+
const functionName = get(inputs, 'props.function.name');
7+
// mock 第二个函数抛出错误
8+
if (functionName === 'next-custom-cpp-event-function') {
9+
throw new Error('custom error');
10+
}
11+
setTrackerData('fc', {
12+
uid: get(inputs, 'credentials.AccountID'),
13+
region: get(inputs, 'props.region'),
14+
service: get(inputs, 'props.service.name'),
15+
function: functionName,
16+
});
17+
return { message: 'this is a local fc' };
18+
}
19+
}
20+
21+
module.exports = FC;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# ------------------------------------
2+
# If you want to use this file directly, please add [-t/--template] parameter, for example [s deploy -t s_en.yaml]
3+
# ------------------------------------
4+
# Welcome to use Alibaba Cloud Function Compute FC components for project development
5+
# Component warehouse address: https://github.com/devsapp/fc
6+
# Component help documentation: https://www.serverless-devs.com/fc/readme
7+
# Yaml reference documentation: https://www.serverless-devs.com/fc/yaml/readme
8+
# About:
9+
# - The relationship between Serverless Devs and FC components, how to declare/deploy multiple functions, how to deploy code packages over 50M
10+
# - About the usage of .fcignore, what the .s directory in the tool does, and how to process the build product after the function performs the build operation
11+
# and other issues, you can refer to the documentation: https://www.serverless-devs.com/fc/tips
12+
# For questions about how to do CICD, please refer to: https://www.serverless-devs.com/serverless-devs/cicd
13+
# For issues such as how to divide the environment, please refer to: https://www.serverless-devs.com/serverless-devs/extend
14+
# For more function calculation cases, please refer to: https://github.com/devsapp/awesome/blob/main/README_en.md
15+
# If you have any questions, please come to the DingTalk group and ask: 33947367
16+
# ------------------------------------
17+
edition: 1.0.0
18+
name: hello-world-app
19+
# access is the key information configuration required by the current application:
20+
# Key configuration can refer to: https://www.serverless-devs.com/serverless-devs/command/config
21+
# For the order of key usage, please refer to: https://www.serverless-devs.com/serverless-devs/tool#Key usage order and specification
22+
access: default
23+
org: shl
24+
env: default
25+
26+
vars: # global variables
27+
region: cn-hangzhou
28+
service:
29+
name: hello-world-service
30+
description: 'hello world by serverless devs'
31+
32+
services:
33+
helloworld: # business name/module name
34+
# If you only want to perform related operations on the business below helloworld, you can add helloworld to the command line, for example:
35+
# Build only helloworld: s helloworld build
36+
# If s build is directly executed without helloworld, the tool will perform the same operation on all business modules at the same level as helloworld under the current Yaml (if there are other level modules, such as the next-function commented below), according to certain Sequential build operations
37+
component: ${path(./fc.js)} # The name of the component. The Serverless Devs tool itself is similar to a game console and does not have specific business capabilities. The component is similar to a game card. Users can achieve different functions by inserting different game cards into the game console, that is, by using Different components implement different specific business capabilities
38+
actions: # Customize execution logic. For the use of actions, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Behavior description
39+
pre-deploy: # run before deploy
40+
# - component: fc build --use-docker --dockerfile ./code/Dockerfile # The component to run, the format is [component: component name command parameter] (you can get the component list through s cli registry search --type Component)
41+
# - run: docker build xxx # System command to execute, similar to a hook
42+
# path: ./src # The path to execute system commands/hooks
43+
# - plugin: myplugin # and running plugins (you can get a list of components via s cli registry search --type Plugin)
44+
# args: # parameter information of the plugin
45+
# testKey: testValue
46+
# post-deploy: # run after deploy
47+
# - component: fc versions publish # command line to run
48+
props:
49+
region: ${vars.region} # For the usage of variables, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Variable assignment
50+
service: ${vars.service}
51+
function:
52+
name: custom-cpp-event-function
53+
description: 'hello world by serverless devs'
54+
runtime: nodejs14
55+
codeUri: ./code
56+
handler: index.handler
57+
memorySize: 128
58+
timeout: 60
59+
triggers:
60+
- name: httpTrigger
61+
type: http
62+
config:
63+
authType: anonymous
64+
methods:
65+
- GET
66+
customDomains:
67+
- domainName: auto
68+
protocol: HTTP
69+
routeConfigs:
70+
- path: /*
71+
methods:
72+
- GET
73+
- POST
74+
next-helloworld: # business name/module name
75+
# If you only want to perform related operations on the business below helloworld, you can add helloworld to the command line, for example:
76+
# Build only helloworld: s helloworld build
77+
# If s build is directly executed without helloworld, the tool will perform the same operation on all business modules at the same level as helloworld under the current Yaml (if there are other level modules, such as the next-function commented below), according to certain Sequential build operations
78+
component: ${path(./fc.js)} # The name of the component. The Serverless Devs tool itself is similar to a game console and does not have specific business capabilities. The component is similar to a game card. Users can achieve different functions by inserting different game cards into the game console, that is, by using Different components implement different specific business capabilities
79+
actions: # Customize execution logic. For the use of actions, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Behavior description
80+
pre-deploy: # run before deploy
81+
# - component: fc build --use-docker --dockerfile ./code/Dockerfile # The component to run, the format is [component: component name command parameter] (you can get the component list through s cli registry search --type Component)
82+
# - run: docker build xxx # System command to execute, similar to a hook
83+
# path: ./src # The path to execute system commands/hooks
84+
# - plugin: myplugin # and running plugins (you can get a list of components via s cli registry search --type Plugin)
85+
# args: # parameter information of the plugin
86+
# testKey: testValue
87+
# post-deploy: # run after deploy
88+
# - component: fc versions publish # command line to run
89+
props:
90+
region: ${vars.region} # For the usage of variables, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Variable assignment
91+
service: ${vars.service}
92+
function:
93+
name: next-custom-cpp-event-function
94+
description: 'hello world by serverless devs'
95+
runtime: nodejs14
96+
codeUri: ./code
97+
handler: index.handler
98+
memorySize: 128
99+
timeout: 60
100+
triggers:
101+
- name: httpTrigger
102+
type: http
103+
config:
104+
authType: anonymous
105+
methods:
106+
- GET
107+
customDomains:
108+
- domainName: auto
109+
protocol: HTTP
110+
routeConfigs:
111+
- path: /*
112+
methods:
113+
- GET
114+
- POST
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var getRawBody = require('raw-body');
2+
var getFormBody = require('body/form');
3+
var body = require('body');
4+
5+
6+
/*
7+
To enable the initializer feature (https://help.aliyun.com/document_detail/156876.html)
8+
please implement the initializer function as below:
9+
exports.initializer = (context, callback) => {
10+
console.log('initializing');
11+
callback(null, '');
12+
};
13+
*/
14+
15+
exports.handler = (req, resp, context) => {
16+
console.log('hello world');
17+
18+
var params = {
19+
path: req.path,
20+
queries: req.queries,
21+
headers: req.headers,
22+
method : req.method,
23+
requestURI : req.url,
24+
clientIP : req.clientIP,
25+
}
26+
27+
getRawBody(req, function(err, body) {
28+
for (var key in req.queries) {
29+
var value = req.queries[key];
30+
resp.setHeader(key, value);
31+
}
32+
resp.setHeader('Content-Type', 'application/json');
33+
params.body = body.toString();
34+
resp.send(JSON.stringify(params, null, ' '));
35+
});
36+
37+
/*
38+
getFormBody(req, function(err, formBody) {
39+
for (var key in req.queries) {
40+
var value = req.queries[key];
41+
resp.setHeader(key, value);
42+
}
43+
params.body = formBody;
44+
console.log(formBody);
45+
resp.send(JSON.stringify(params));
46+
});
47+
*/
48+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { setTrackerData } = require('../../../src');
2+
const { get } = require('lodash');
3+
4+
class FC {
5+
deploy(inputs) {
6+
setTrackerData('fc', {
7+
uid: get(inputs, 'credentials.AccountID'),
8+
region: get(inputs, 'props.region'),
9+
service: get(inputs, 'props.service.name'),
10+
function: get(inputs, 'props.function.name'),
11+
});
12+
return { message: 'this is a local fc' };
13+
}
14+
}
15+
16+
module.exports = FC;

0 commit comments

Comments
 (0)