@kravc/serverless 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build.js +11 -11
- package/eslint.config.mjs +14 -50
- package/package.json +9 -13
- package/src/build.js +37 -37
- package/src/index.js +2 -2
- package/test/index.js +0 -3
package/bin/build.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
'use strict'
|
|
3
|
+
'use strict';
|
|
4
4
|
|
|
5
|
-
const fs
|
|
6
|
-
const config
|
|
7
|
-
const { dump }
|
|
8
|
-
const { build } = require('../src')
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const config = require('config');
|
|
7
|
+
const { dump } = require('js-yaml');
|
|
8
|
+
const { build } = require('../src');
|
|
9
9
|
|
|
10
10
|
const main = () => {
|
|
11
|
-
const input = JSON.parse(JSON.stringify(config))
|
|
11
|
+
const input = JSON.parse(JSON.stringify(config));
|
|
12
12
|
|
|
13
|
-
const result = build(input)
|
|
14
|
-
const yaml
|
|
13
|
+
const result = build(input);
|
|
14
|
+
const yaml = dump(result);
|
|
15
15
|
|
|
16
|
-
fs.writeFileSync('serverless.yaml', yaml)
|
|
17
|
-
}
|
|
16
|
+
fs.writeFileSync('serverless.yaml', yaml);
|
|
17
|
+
};
|
|
18
18
|
|
|
19
|
-
main()
|
|
19
|
+
main();
|
package/eslint.config.mjs
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import js from "@eslint/js";
|
|
5
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import { globalIgnores, defineConfig } from 'eslint/config';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
baseDirectory: __dirname,
|
|
11
|
-
recommendedConfig: js.configs.recommended,
|
|
12
|
-
allConfig: js.configs.all
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export default [...compat.extends("eslint:recommended"), {
|
|
5
|
+
export default defineConfig(
|
|
6
|
+
globalIgnores([ '**/dist/', '**/coverage/' ]),
|
|
7
|
+
{
|
|
16
8
|
languageOptions: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
ecmaVersion: 2018,
|
|
23
|
-
sourceType: "commonjs",
|
|
9
|
+
globals: {
|
|
10
|
+
...globals.node,
|
|
11
|
+
},
|
|
24
12
|
},
|
|
25
|
-
|
|
26
13
|
rules: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
indent: ["error", 2, {
|
|
31
|
-
SwitchCase: 1,
|
|
32
|
-
VariableDeclarator: 2,
|
|
33
|
-
}],
|
|
34
|
-
|
|
35
|
-
"keyword-spacing": "error",
|
|
36
|
-
"no-multi-spaces": "off",
|
|
37
|
-
"no-spaced-func": "error",
|
|
38
|
-
"no-trailing-spaces": "error",
|
|
39
|
-
quotes: ["error", "single"],
|
|
40
|
-
semi: ["error", "never"],
|
|
41
|
-
curly: ["error"],
|
|
42
|
-
"prefer-arrow-callback": "error",
|
|
43
|
-
"space-before-blocks": "error",
|
|
44
|
-
|
|
45
|
-
"space-before-function-paren": [1, {
|
|
46
|
-
anonymous: "always",
|
|
47
|
-
named: "never",
|
|
48
|
-
}],
|
|
49
|
-
|
|
50
|
-
"space-infix-ops": "error",
|
|
51
|
-
"space-unary-ops": "error",
|
|
52
|
-
"no-return-await": "error",
|
|
53
|
-
eqeqeq: "error",
|
|
14
|
+
semi: ['error', 'always'],
|
|
15
|
+
quotes: ['error', 'single'],
|
|
54
16
|
},
|
|
55
|
-
}
|
|
17
|
+
},
|
|
18
|
+
eslint.configs.recommended,
|
|
19
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kravc/serverless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Serverless configuration builder and deployment tool for @kravc/dos service.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"url": "http://github.com/alexkravets/serverless.git"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "eslint src/
|
|
11
|
+
"test": "eslint --fix src/ bin/"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
14
14
|
"build": "bin/build.js",
|
|
@@ -19,18 +19,14 @@
|
|
|
19
19
|
"author": "Alexander Kravets <a@kra.vc>",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"config": "^4.
|
|
23
|
-
"js-yaml": "^4.1.
|
|
24
|
-
"lodash": "^4.17.
|
|
25
|
-
"serverless": "^3.
|
|
22
|
+
"config": "^4.3.0",
|
|
23
|
+
"js-yaml": "^4.1.1",
|
|
24
|
+
"lodash": "^4.17.23",
|
|
25
|
+
"serverless": "^3.40.0-19128fad"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@eslint/
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"eslint": "^9.15.0",
|
|
32
|
-
"globals": "^15.12.0",
|
|
33
|
-
"mocha": "^10.8.2",
|
|
34
|
-
"nyc": "^17.1.0"
|
|
28
|
+
"@eslint/js": "^10.0.1",
|
|
29
|
+
"eslint": "^10.0.0",
|
|
30
|
+
"globals": "^17.3.0"
|
|
35
31
|
}
|
|
36
32
|
}
|
package/src/build.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const { get } = require('lodash')
|
|
3
|
+
const { get } = require('lodash');
|
|
4
4
|
|
|
5
|
-
const NODE_ENV = process.env.NODE_ENV || 'serverless'
|
|
6
|
-
const INSTANCE = process.env.NODE_APP_INSTANCE || 'localhost'
|
|
7
|
-
const ROOT_PATH = process.cwd()
|
|
5
|
+
const NODE_ENV = process.env.NODE_ENV || 'serverless';
|
|
6
|
+
const INSTANCE = process.env.NODE_APP_INSTANCE || 'localhost';
|
|
7
|
+
const ROOT_PATH = process.cwd();
|
|
8
8
|
|
|
9
|
-
const { name, version } = require(`${ROOT_PATH}/package.json`)
|
|
10
|
-
const [ MAJOR_VERSION ] = version.split('.')
|
|
11
|
-
const DEFAULT_SERVICE = name.replace('@', '').replace('/', '-') + `-v${MAJOR_VERSION}
|
|
12
|
-
const DEFAULT_TABLE = name.replace('@', '').replace('/', '-')
|
|
13
|
-
const DEFAULT_RUNTIME = 'nodejs22.x'
|
|
9
|
+
const { name, version } = require(`${ROOT_PATH}/package.json`);
|
|
10
|
+
const [ MAJOR_VERSION ] = version.split('.');
|
|
11
|
+
const DEFAULT_SERVICE = name.replace('@', '').replace('/', '-') + `-v${MAJOR_VERSION}`;
|
|
12
|
+
const DEFAULT_TABLE = name.replace('@', '').replace('/', '-');
|
|
13
|
+
const DEFAULT_RUNTIME = 'nodejs22.x';
|
|
14
14
|
|
|
15
15
|
const build = config => {
|
|
16
|
-
const AWS = get(config, 'aws', {})
|
|
17
|
-
const SERVERLESS = get(config, 'serverless', {})
|
|
16
|
+
const AWS = get(config, 'aws', {});
|
|
17
|
+
const SERVERLESS = get(config, 'serverless', {});
|
|
18
18
|
|
|
19
19
|
const result = {
|
|
20
20
|
service: SERVERLESS.service || DEFAULT_SERVICE,
|
|
21
21
|
variablesResolutionMode: 20210326
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
result.provider = {
|
|
25
25
|
name: 'aws',
|
|
@@ -44,14 +44,14 @@ const build = config => {
|
|
|
44
44
|
shouldStartNameWithService: true
|
|
45
45
|
},
|
|
46
46
|
lambdaHashingVersion: '20201221'
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
if (AWS.region) {
|
|
50
|
-
result.provider.region = AWS.region
|
|
50
|
+
result.provider.region = AWS.region;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (AWS.profile) {
|
|
54
|
-
result.provider.profile = AWS.profile
|
|
54
|
+
result.provider.profile = AWS.profile;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
result.package = {
|
|
@@ -59,7 +59,7 @@ const build = config => {
|
|
|
59
59
|
'!test/**',
|
|
60
60
|
'!bin/**'
|
|
61
61
|
]
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
|
|
64
64
|
result.functions = {
|
|
65
65
|
api: {
|
|
@@ -73,7 +73,7 @@ const build = config => {
|
|
|
73
73
|
}
|
|
74
74
|
]
|
|
75
75
|
}
|
|
76
|
-
}
|
|
76
|
+
};
|
|
77
77
|
|
|
78
78
|
const DEFAULT_HTTP_METHODS = [
|
|
79
79
|
'get',
|
|
@@ -81,10 +81,10 @@ const build = config => {
|
|
|
81
81
|
'patch',
|
|
82
82
|
'delete',
|
|
83
83
|
'options'
|
|
84
|
-
]
|
|
84
|
+
];
|
|
85
85
|
|
|
86
86
|
for (const method of DEFAULT_HTTP_METHODS) {
|
|
87
|
-
const path = '/{operationId}'
|
|
87
|
+
const path = '/{operationId}';
|
|
88
88
|
const http = {
|
|
89
89
|
path,
|
|
90
90
|
method,
|
|
@@ -95,25 +95,25 @@ const build = config => {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
}
|
|
98
|
+
};
|
|
99
99
|
|
|
100
|
-
result.functions.api.events.push({ http })
|
|
100
|
+
result.functions.api.events.push({ http });
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if (SERVERLESS.iamRoleStatements) {
|
|
104
104
|
result.provider.iamRoleStatements =
|
|
105
|
-
result.provider.iamRoleStatements.concat(SERVERLESS.iamRoleStatements)
|
|
105
|
+
result.provider.iamRoleStatements.concat(SERVERLESS.iamRoleStatements);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (SERVERLESS.timeout) {
|
|
109
|
-
result.provider.timeout = SERVERLESS.timeout
|
|
109
|
+
result.provider.timeout = SERVERLESS.timeout;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (SERVERLESS.custom) {
|
|
113
|
-
result.custom = SERVERLESS.custom
|
|
113
|
+
result.custom = SERVERLESS.custom;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
const TABLES = get(config, 'tables')
|
|
116
|
+
const TABLES = get(config, 'tables');
|
|
117
117
|
|
|
118
118
|
if (TABLES) {
|
|
119
119
|
const DEFAULT_TABLE_ACTIONS = [
|
|
@@ -123,13 +123,13 @@ const build = config => {
|
|
|
123
123
|
'dynamodb:PutItem',
|
|
124
124
|
'dynamodb:UpdateItem',
|
|
125
125
|
'dynamodb:DeleteItem'
|
|
126
|
-
]
|
|
126
|
+
];
|
|
127
127
|
|
|
128
128
|
for (const tableKey in TABLES) {
|
|
129
|
-
const tableConfig = TABLES[tableKey]
|
|
130
|
-
const { name = DEFAULT_TABLE, actions = DEFAULT_TABLE_ACTIONS } = tableConfig
|
|
129
|
+
const tableConfig = TABLES[tableKey];
|
|
130
|
+
const { name = DEFAULT_TABLE, actions = DEFAULT_TABLE_ACTIONS } = tableConfig;
|
|
131
131
|
|
|
132
|
-
const tableName = `${name}-${INSTANCE}
|
|
132
|
+
const tableName = `${name}-${INSTANCE}`;
|
|
133
133
|
|
|
134
134
|
const statement = {
|
|
135
135
|
Effect: 'Allow',
|
|
@@ -138,18 +138,18 @@ const build = config => {
|
|
|
138
138
|
`arn:aws:dynamodb:\${opt:region, self:provider.region}:*:table/${tableName}`,
|
|
139
139
|
`arn:aws:dynamodb:\${opt:region, self:provider.region}:*:table/${tableName}/*`
|
|
140
140
|
]
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
|
-
result.provider.iamRoleStatements.push(statement)
|
|
143
|
+
result.provider.iamRoleStatements.push(statement);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
if (result.provider.iamRoleStatements) {
|
|
148
|
-
result.provider.iam = { role: { statements: result.provider.iamRoleStatements } }
|
|
149
|
-
delete result.provider.iamRoleStatements
|
|
148
|
+
result.provider.iam = { role: { statements: result.provider.iamRoleStatements } };
|
|
149
|
+
delete result.provider.iamRoleStatements;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
return result
|
|
153
|
-
}
|
|
152
|
+
return result;
|
|
153
|
+
};
|
|
154
154
|
|
|
155
|
-
module.exports = build
|
|
155
|
+
module.exports = build;
|
package/src/index.js
CHANGED
package/test/index.js
DELETED