milesight-powermeter-api 0.0.2-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/.eslintrc.js +25 -0
- package/.nvmrc +1 -0
- package/.prettierrc +10 -0
- package/Dockerfile +11 -0
- package/README.md +85 -0
- package/bitbucket-pipelines.yml +121 -0
- package/nest-cli.json +8 -0
- package/npm-shrinkwrap.json +8501 -0
- package/package.json +71 -0
- package/scripts/build-app.sh +13 -0
- package/scripts/setup-docker.sh +3 -0
- package/scripts/setup-env.sh +30 -0
- package/src/app.controller.spec.ts +22 -0
- package/src/app.controller.ts +12 -0
- package/src/app.module.ts +10 -0
- package/src/app.service.ts +8 -0
- package/src/main.ts +8 -0
- package/test/app.e2e-spec.ts +24 -0
- package/test/jest-e2e.json +9 -0
- package/timestamp.sh +1 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +21 -0
package/package.json
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
{
|
2
|
+
"name": "milesight-powermeter-api",
|
3
|
+
"version": "0.0.2-0",
|
4
|
+
"description": "Milesight Powermeter API is an internal tool accessible on backend. The API allows detail retrieval and command sending to its powermeters.",
|
5
|
+
"author": "Lester Vitor",
|
6
|
+
"license": "UNLICENSED",
|
7
|
+
"scripts": {
|
8
|
+
"build": "nest build",
|
9
|
+
"build:ci": "tsc -p tsconfig.build.json",
|
10
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
11
|
+
"start": "nest start",
|
12
|
+
"start:dev": "nest start --watch",
|
13
|
+
"start:debug": "nest start --debug --watch",
|
14
|
+
"start:prod": "node dist/main",
|
15
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
16
|
+
"test": "jest",
|
17
|
+
"test:watch": "jest --watch",
|
18
|
+
"test:cov": "jest --coverage",
|
19
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
20
|
+
"test:e2e": "jest --config ./test/jest-e2e.json",
|
21
|
+
"build:kube": "docker build -t mewe/lorawan-milesight-powermeter-api-service -f Dockerfile .",
|
22
|
+
"build:kube:ci": "scripts/build-app.sh mewe/lorawan-milesight-powermeter-api-service"
|
23
|
+
},
|
24
|
+
"dependencies": {
|
25
|
+
"@nestjs/common": "^10.0.0",
|
26
|
+
"@nestjs/core": "^10.0.0",
|
27
|
+
"@nestjs/platform-express": "^10.0.0",
|
28
|
+
"reflect-metadata": "^0.2.0",
|
29
|
+
"rxjs": "^7.8.1"
|
30
|
+
},
|
31
|
+
"devDependencies": {
|
32
|
+
"@nestjs/cli": "^10.0.0",
|
33
|
+
"@nestjs/schematics": "^10.0.0",
|
34
|
+
"@nestjs/testing": "^10.0.0",
|
35
|
+
"@types/express": "^4.17.17",
|
36
|
+
"@types/jest": "^29.5.2",
|
37
|
+
"@types/node": "^20.3.1",
|
38
|
+
"@types/supertest": "^6.0.0",
|
39
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
40
|
+
"@typescript-eslint/parser": "^8.0.0",
|
41
|
+
"eslint": "^8.42.0",
|
42
|
+
"eslint-config-prettier": "^9.0.0",
|
43
|
+
"eslint-plugin-prettier": "^5.0.0",
|
44
|
+
"jest": "^29.5.0",
|
45
|
+
"prettier": "^3.0.0",
|
46
|
+
"source-map-support": "^0.5.21",
|
47
|
+
"supertest": "^7.0.0",
|
48
|
+
"ts-jest": "^29.1.0",
|
49
|
+
"ts-loader": "^9.4.3",
|
50
|
+
"ts-node": "^10.9.1",
|
51
|
+
"tsconfig-paths": "^4.2.0",
|
52
|
+
"typescript": "^5.1.3"
|
53
|
+
},
|
54
|
+
"jest": {
|
55
|
+
"moduleFileExtensions": [
|
56
|
+
"js",
|
57
|
+
"json",
|
58
|
+
"ts"
|
59
|
+
],
|
60
|
+
"rootDir": "src",
|
61
|
+
"testRegex": ".*\\.spec\\.ts$",
|
62
|
+
"transform": {
|
63
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
64
|
+
},
|
65
|
+
"collectCoverageFrom": [
|
66
|
+
"**/*.(t|j)s"
|
67
|
+
],
|
68
|
+
"coverageDirectory": "../coverage",
|
69
|
+
"testEnvironment": "node"
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
REPO=$1
|
4
|
+
TAG=${2:-latest}
|
5
|
+
ALIAS=${3:-develop}
|
6
|
+
IMAGE=$REPO:$TAG
|
7
|
+
IMAGE_ALIAS=$REPO:$ALIAS
|
8
|
+
|
9
|
+
echo "Using image: $IMAGE"
|
10
|
+
docker build -t $IMAGE -f Dockerfile . --build-arg NPM_TOKEN=${NPM_TOKEN}
|
11
|
+
docker tag $IMAGE $IMAGE_ALIAS
|
12
|
+
docker push $IMAGE
|
13
|
+
docker push $IMAGE_ALIAS
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
npm ci
|
3
|
+
|
4
|
+
source timestamp.sh
|
5
|
+
|
6
|
+
# BUILD_NAME can be develop, release, or master
|
7
|
+
export BUILD_NAME=master
|
8
|
+
export BUILD_TAG=$BITBUCKET_TAG
|
9
|
+
export CLIENT_ENV=$APP_PROD_ENV
|
10
|
+
|
11
|
+
if [ -z "$BUILD_TAG" ]; then
|
12
|
+
# Remove the date from the release branch if it is a release branch. i.e release/2019.10.17 -> release
|
13
|
+
export BUILD_NAME=$(echo $BITBUCKET_BRANCH | awk -F/ '{print $1}')
|
14
|
+
export BUILD_TAG="${BUILD_NAME}_${BITBUCKET_COMMIT}_${DT}"
|
15
|
+
fi
|
16
|
+
|
17
|
+
# If the build name is release or a git tag, we'll build all the applications
|
18
|
+
if [[ "$BUILD_NAME" == "release" || "$BUILD_NAME" == "master" ]]; then
|
19
|
+
export FORCE_BUILD=true
|
20
|
+
fi
|
21
|
+
|
22
|
+
if [ "$BUILD_NAME" == "release" ]; then
|
23
|
+
export CLIENT_ENV=$APP_STG_ENV
|
24
|
+
elif [ "$BUILD_NAME" == "develop" ]; then
|
25
|
+
export CLIENT_ENV=$APP_DEV_ENV
|
26
|
+
fi
|
27
|
+
|
28
|
+
echo "Build: $BUILD_NAME"
|
29
|
+
echo "Build tag: $BUILD_TAG"
|
30
|
+
echo "Client environment: $CLIENT_ENV"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
2
|
+
import { AppController } from './app.controller';
|
3
|
+
import { AppService } from './app.service';
|
4
|
+
|
5
|
+
describe('AppController', () => {
|
6
|
+
let appController: AppController;
|
7
|
+
|
8
|
+
beforeEach(async () => {
|
9
|
+
const app: TestingModule = await Test.createTestingModule({
|
10
|
+
controllers: [AppController],
|
11
|
+
providers: [AppService],
|
12
|
+
}).compile();
|
13
|
+
|
14
|
+
appController = app.get<AppController>(AppController);
|
15
|
+
});
|
16
|
+
|
17
|
+
describe('root', () => {
|
18
|
+
it('should return "Hello World!"', () => {
|
19
|
+
expect(appController.getHello()).toBe('Hello World!');
|
20
|
+
});
|
21
|
+
});
|
22
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Controller, Get } from '@nestjs/common';
|
2
|
+
import { AppService } from './app.service';
|
3
|
+
|
4
|
+
@Controller()
|
5
|
+
export class AppController {
|
6
|
+
constructor(private readonly appService: AppService) {}
|
7
|
+
|
8
|
+
@Get()
|
9
|
+
getHello(): string {
|
10
|
+
return this.appService.getHello();
|
11
|
+
}
|
12
|
+
}
|
package/src/main.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
2
|
+
import { INestApplication } from '@nestjs/common';
|
3
|
+
import * as request from 'supertest';
|
4
|
+
import { AppModule } from './../src/app.module';
|
5
|
+
|
6
|
+
describe('AppController (e2e)', () => {
|
7
|
+
let app: INestApplication;
|
8
|
+
|
9
|
+
beforeEach(async () => {
|
10
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
11
|
+
imports: [AppModule],
|
12
|
+
}).compile();
|
13
|
+
|
14
|
+
app = moduleFixture.createNestApplication();
|
15
|
+
await app.init();
|
16
|
+
});
|
17
|
+
|
18
|
+
it('/ (GET)', () => {
|
19
|
+
return request(app.getHttpServer())
|
20
|
+
.get('/')
|
21
|
+
.expect(200)
|
22
|
+
.expect('Hello World!');
|
23
|
+
});
|
24
|
+
});
|
package/timestamp.sh
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export DT=20240904045917
|
package/tsconfig.json
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"module": "commonjs",
|
4
|
+
"declaration": true,
|
5
|
+
"removeComments": true,
|
6
|
+
"emitDecoratorMetadata": true,
|
7
|
+
"experimentalDecorators": true,
|
8
|
+
"allowSyntheticDefaultImports": true,
|
9
|
+
"target": "ES2021",
|
10
|
+
"sourceMap": true,
|
11
|
+
"outDir": "./dist",
|
12
|
+
"baseUrl": "./",
|
13
|
+
"incremental": true,
|
14
|
+
"skipLibCheck": true,
|
15
|
+
"strictNullChecks": true,
|
16
|
+
"noImplicitAny": true,
|
17
|
+
"strictBindCallApply": true,
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
19
|
+
"noFallthroughCasesInSwitch": true
|
20
|
+
}
|
21
|
+
}
|