Skip to content

Commit 5897da7

Browse files
committed
feat: init project
0 parents  commit 5897da7

23 files changed

+817
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
indent_size = 2
11+
indent_style = space
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage
2+
dist
3+
node_modules
4+
example
5+
*.test.js

.eslintrc.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['prettier'],
4+
plugins: ['import', 'prettier'],
5+
env: {
6+
es6: true,
7+
jest: true,
8+
node: true
9+
},
10+
parser: 'babel-eslint',
11+
parserOptions: {
12+
ecmaVersion: 2018,
13+
sourceType: 'module',
14+
ecmaFeatures: {
15+
jsx: true
16+
}
17+
},
18+
globals: {
19+
on: true // for the Socket file
20+
},
21+
rules: {
22+
'array-bracket-spacing': [
23+
'error',
24+
'never',
25+
{
26+
objectsInArrays: false,
27+
arraysInArrays: false
28+
}
29+
],
30+
'arrow-parens': ['error', 'always'],
31+
'arrow-spacing': ['error', { before: true, after: true }],
32+
'comma-dangle': ['error', 'never'],
33+
curly: 'error',
34+
'eol-last': 'error',
35+
'func-names': 'off',
36+
'id-length': [
37+
'error',
38+
{
39+
min: 1,
40+
max: 50,
41+
properties: 'never',
42+
exceptions: ['e', 'i', 'n', 't', 'x', 'y', 'z', '_', '$']
43+
}
44+
],
45+
'no-alert': 'error',
46+
'no-console': 'off',
47+
'no-const-assign': 'error',
48+
'no-else-return': 'error',
49+
'no-empty': 'off',
50+
'no-shadow': 'error',
51+
'no-undef': 'error',
52+
'no-unused-vars': 'error',
53+
'no-use-before-define': 'error',
54+
'no-useless-constructor': 'error',
55+
'object-curly-newline': 'off',
56+
'object-shorthand': 'off',
57+
'prefer-const': 'error',
58+
'prefer-destructuring': ['error', { object: true, array: false }],
59+
quotes: [
60+
'error',
61+
'single',
62+
{
63+
allowTemplateLiterals: true,
64+
avoidEscape: true
65+
}
66+
],
67+
semi: ['error', 'never'],
68+
'spaced-comment': 'error',
69+
strict: ['error', 'global'],
70+
'prettier/prettier': 'error'
71+
}
72+
}

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
*.sublime-project
3+
*.sublime-workspace
4+
*.log
5+
.serverless
6+
v8-compile-cache-*
7+
jest
8+
coverage
9+
.serverless_plugins
10+
testProjects/*/package-lock.json
11+
testProjects/*/yarn.lock
12+
.serverlessUnzipped
13+
node_modules
14+
.vscode
15+
.eslintcache
16+
dist
17+
.idea
18+
build
19+
.env*
20+
env.js
21+
package-lock.json
22+
yarn.lock

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHANGELOG.md
2+
*.test.js

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: node_js
2+
3+
node_js:
4+
- 8
5+
- 10
6+
7+
install:
8+
- npm install
9+
10+
jobs:
11+
include:
12+
# Define the release stage that runs semantic-release
13+
- stage: release
14+
node_js: 10.18
15+
# Advanced: optionally overwrite your default `script` step to skip the tests
16+
# script: skip
17+
deploy:
18+
provider: script
19+
skip_cleanup: true
20+
on:
21+
branch: master
22+
script:
23+
- npm run release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 serverless-tencent
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# tencent-component-monitor
2+
3+
[![npm](https://img.shields.io/npm/v/tencent-component-monitor)](http://www.npmtrends.com/tencent-component-monitor)
4+
[![NPM downloads](http://img.shields.io/npm/dm/tencent-component-monitor.svg?style=flat-square)](http://www.npmtrends.com/tencent-component-monitor)
5+
[![Build Status](https://travis-ci.com/serverless-tencent/tencent-component-monitor.svg?branch=master)](https://travis-ci.com/serverless-tencent/tencent-component-monitor)
6+
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7+
8+
Tencent component monitor.
9+
10+
## Usage
11+
12+
```bash
13+
$ npm install tencent-component-monitor --save
14+
```
15+
16+
## License
17+
18+
MIT License

commitlint.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Configuration = {
2+
/*
3+
* Resolve and load @commitlint/config-conventional from node_modules.
4+
* Referenced packages must be installed
5+
*/
6+
extends: ['@commitlint/config-conventional']
7+
}
8+
9+
module.exports = Configuration

package.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "tencent-component-monitor",
3+
"version": "0.0.1",
4+
"description": "Tencent component monitor",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "npm run lint && npm run prettier",
8+
"commitlint": "commitlint -f HEAD@{15}",
9+
"lint": "eslint --ext .js,.ts,.tsx .",
10+
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
11+
"prettier": "prettier --check **/*.{css,html,js,json,md,yaml,yml}",
12+
"prettier:fix": "prettier --write **/*.{css,html,js,json,md,yaml,yml}",
13+
"release": "semantic-release",
14+
"release-local": "node -r dotenv/config node_modules/semantic-release/bin/semantic-release --no-ci --dry-run",
15+
"check-dependencies": "npx npm-check --skip-unused --update"
16+
},
17+
"engines": {
18+
"node": ">=10.18"
19+
},
20+
"husky": {
21+
"hooks": {
22+
"pre-commit": "lint-staged",
23+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
24+
"pre-push": "npm run lint:fix && npm run prettier:fix"
25+
}
26+
},
27+
"lint-staged": {
28+
"**/*.{js,ts,tsx}": [
29+
"npm run lint:fix",
30+
"git add ."
31+
],
32+
"**/*.{css,html,js,json,md,yaml,yml}": [
33+
"npm run prettier:fix",
34+
"git add ."
35+
]
36+
},
37+
"repository": {
38+
"type": "git",
39+
"url": "git+https://github.com/serverless-tencent/tencent-component-toolkit.git"
40+
},
41+
"keywords": [
42+
"template",
43+
"release",
44+
"ci"
45+
],
46+
"author": "Tencent Cloud Inc.",
47+
"license": "MIT",
48+
"bugs": {
49+
"url": "https://github.com/serverless-tencent/tencent-component-toolkit/issues"
50+
},
51+
"homepage": "https://github.com/serverless-tencent/tencent-component-toolkit#readme",
52+
"devDependencies": {
53+
"@commitlint/cli": "^8.3.5",
54+
"@commitlint/config-conventional": "^8.3.4",
55+
"@semantic-release/changelog": "^5.0.0",
56+
"@semantic-release/commit-analyzer": "^8.0.1",
57+
"@semantic-release/git": "^9.0.0",
58+
"@semantic-release/npm": "^7.0.4",
59+
"@semantic-release/release-notes-generator": "^9.0.1",
60+
"babel-eslint": "^10.1.0",
61+
"dotenv": "^8.2.0",
62+
"eslint": "^6.8.0",
63+
"eslint-config-prettier": "^6.10.0",
64+
"eslint-plugin-import": "^2.20.1",
65+
"eslint-plugin-prettier": "^3.1.2",
66+
"husky": "^4.2.3",
67+
"lint-staged": "^10.0.8",
68+
"prettier": "^1.19.1",
69+
"semantic-release": "^17.0.4"
70+
},
71+
"dependencies": {
72+
"@tencent-sdk/capi": "0.2.15"
73+
}
74+
}

prettier.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
arrowParens: 'always',
3+
printWidth: 100,
4+
semi: false,
5+
singleQuote: true,
6+
tabWidth: 2,
7+
trailingComma: 'none'
8+
}

release.config.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module.exports = {
2+
verifyConditions: [
3+
'@semantic-release/changelog',
4+
'@semantic-release/npm',
5+
'@semantic-release/git',
6+
'@semantic-release/github'
7+
],
8+
plugins: [
9+
[
10+
'@semantic-release/commit-analyzer',
11+
{
12+
preset: 'angular',
13+
parserOpts: {
14+
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING']
15+
}
16+
}
17+
],
18+
[
19+
'@semantic-release/release-notes-generator',
20+
{
21+
preset: 'angular',
22+
parserOpts: {
23+
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING']
24+
},
25+
writerOpts: {
26+
commitsSort: ['subject', 'scope']
27+
}
28+
}
29+
],
30+
[
31+
'@semantic-release/changelog',
32+
{
33+
changelogFile: 'CHANGELOG.md'
34+
}
35+
],
36+
[
37+
'@semantic-release/npm',
38+
{
39+
pkgRoot: '.',
40+
npmPublish: true,
41+
tarballDir: false
42+
}
43+
],
44+
[
45+
'@semantic-release/git',
46+
{
47+
assets: ['package.json', 'src/**', 'CHANGELOG.md'],
48+
message: 'chore(release): version ${nextRelease.version} \n\n${nextRelease.notes}'
49+
}
50+
],
51+
[
52+
'@semantic-release/github',
53+
{
54+
assets: ['!.env']
55+
}
56+
]
57+
]
58+
}

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Monitor = require('./monitor')
2+
3+
module.exports = {
4+
Monitor
5+
}

src/monitor/agent.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { EventEmitter } = require('events')
2+
const util = require('util')
3+
4+
function Agent() {}
5+
6+
util.inherits(Agent, EventEmitter)
7+
8+
module.exports = Agent

src/monitor/constants.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Enumeration of module instrumentation types.
3+
*
4+
* @private
5+
* @readonly
6+
* @enum {string}
7+
*/
8+
const MODULE_TYPE = {
9+
/** Web server framework module, such as Express or Koa. */
10+
WEB_FRAMEWORK: 'web-framework',
11+
PROXY: 'proxy'
12+
}
13+
14+
exports.MODULE_TYPE = MODULE_TYPE
15+
16+
/**
17+
* 请求开始时间存储key值(context内)
18+
*/
19+
const REUQEST_START = '__request_start__'
20+
21+
exports.REUQEST_START_KEY = REUQEST_START

src/monitor/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const shimmer = require('./shimmer')
2+
const Agent = require('./agent')
3+
4+
function initialize() {
5+
const agent = new Agent()
6+
// 封装 module的_load方法,在load时针对基础组件附加探针
7+
shimmer.patchModule()
8+
// 初始化一系列基础组件
9+
shimmer.bootstrapInstrumentation(agent)
10+
}
11+
12+
module.exports = initialize

0 commit comments

Comments
 (0)