Skip to content

Commit

Permalink
Merge remote-tracking branch 'bp/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Feb 26, 2024
2 parents ba06acd + 411d4f9 commit 11088cc
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 56 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ rules:
"@typescript-eslint/no-unused-vars": 0
"node/no-unpublished-import": 0
"@typescript-eslint/prefer-ts-expect-error": 0
"@typescript-eslint/no-extraneous-class": 0
"unicorn/filename-case": 0

6 changes: 4 additions & 2 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# Date: 2023.07.21
#

if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
if [[ -z $NVM_DIR ]]; then
if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
fi
fi

branch=$( git branch | grep \* | cut -d ' ' -f2 )
Expand Down
8 changes: 5 additions & 3 deletions .githooks/pre-commit.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
# Date: 2017.02.09
#

if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
if [[ -z $NVM_DIR ]]; then
if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
fi
fi

if git rev-parse --verify HEAD >/dev/null 2>&1
Expand All @@ -28,7 +30,7 @@ fi
# ------------- parse ts
files=$(git diff --cached --name-only --diff-filter=ACMR $against|grep '\.ts$')
if [[ $files != "" ]] ; then
# echo $files | xargs eslint --fix
# echo $files | xargs eslint --fix
npm run lint
rc=$?
if [[ $rc != 0 ]] ; then
Expand Down
7 changes: 4 additions & 3 deletions .githooks/pre-push.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
remote="$1"
url="$2"


if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
if [[ -z $NVM_DIR ]]; then
if [[ -f $HOME/.nvm/nvm.sh ]]; then
. $HOME/.nvm/nvm.sh
fi
fi

z40=0000000000000000000000000000000000000000
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-lerna
env:
cache-name: cache-lerna
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nodejs-win.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
os: [windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-lerna-win
env:
cache-name: cache-lerna-win
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-lerna
env:
cache-name: cache-lerna
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/npm-manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
Expand All @@ -34,13 +34,13 @@ jobs:
git config --global --add safe.directory $cwd
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-lerna
env:
cache-name: cache-lerna
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/npm-publish-wo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
Expand All @@ -34,13 +34,13 @@ jobs:
git config --global --add safe.directory $cwd
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-lerna
env:
cache-name: cache-lerna
Expand Down
23 changes: 23 additions & 0 deletions .scripts/set-env-local.sh.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash


export MIDWAY_SERVER_ENV=local
export NODE_ENV=local
export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4317"
export TS_NODE_PROJECT="test/tsconfig.json"
export POSTGRES_HOST="127.0.0.1"
export POSTGRES_PORT="5432"
export POSTGRES_DB=""
export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="postgres"
export ALI_ALB_IPS="120.55"
export ALI_ALB_GROUPID="sgp-7z"
export ALI_ECS_AID="LTAI5"
export ALI_ECS_ASECRET="Dr"
export ALI_ECS_IDS=""
export ALI_ECS_IPS=""
export ALI_OSS_AID="LTAI4"
export ALI_OSS_ASECRET="FRK"
export ALI_OSS_ENDPOINT="https://oss-cn-hangzhou.aliyuncs.com"
export ALI_OSS_BUCKET=""

23 changes: 23 additions & 0 deletions .scripts/set-env-test.sh.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash


export MIDWAY_SERVER_ENV=unittest
export NODE_ENV=unittest
export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4317"
export TS_NODE_PROJECT="test/tsconfig.json"
export POSTGRES_HOST="127.0.0.1"
export POSTGRES_PORT="5432"
export POSTGRES_DB=""
export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="postgres"
export ALI_ALB_IPS="120.55"
export ALI_ALB_GROUPID="sgp-7z"
export ALI_ECS_AID="LTAI5"
export ALI_ECS_ASECRET="Dr"
export ALI_ECS_IDS=""
export ALI_ECS_IPS=""
export ALI_OSS_AID="LTAI4"
export ALI_OSS_ASECRET="FRK"
export ALI_OSS_ENDPOINT="https://oss-cn-hangzhou.aliyuncs.com"
export ALI_OSS_BUCKET=""

1 change: 0 additions & 1 deletion .vscode/launch.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
],
"runtimeExecutable": "npm",
"skipFiles": [
"**/node_modules/**",
"**/node_modules/rxjs/**",
"<node_internals>/**",
"<node_internals>/**/*.js"
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"editor.tabSize": 2,
"editor.wordWrap": "on",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.run": "onSave",
"eslint.validate": [
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"devDependencies": {
"@commitlint/cli": "18",
"@commitlint/config-conventional": "18",
"@midwayjs/mock": "^3.14.0",
"@midwayjs/swagger": "^3.14.0",
"@midwayjs/mock": "^3.15.0",
"@midwayjs/swagger": "^3.15.0",
"@midwayjs/validate": "^3.15.0",
"@types/koa": "2",
"@types/koa": "2",
"@types/mocha": "10",
"@types/node": "20",
"@types/node": "20.11",
"@waiting/eslint-config": "^9.1.1",
"@waiting/shared-core": "^23.0.0",
"@waiting/shared-types": "^23.0.0",
Expand All @@ -25,8 +26,9 @@
"madge": "^6.1.0",
"mocha": "10",
"mocha-lcov-reporter": "1",
"mwtsc": "^1.4.0",
"nx": "17",
"mwtsc": "^1.7.0",
"nx": "18",
"swagger-ui-dist": "^5.11.0",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.8",
"tsconfig-paths": "4",
Expand All @@ -44,6 +46,7 @@
"add:pkg": "sh .scripts/add-pkg.sh",
"bp:add": "git remote add bp https://github.com/waitingsong/npm-mono-base",
"bp:sync": "git fetch --all -v && git pull origin && git merge bp/main -m \"Merge remote-tracking branch 'bp/main'\" ",
"bp:sync-force": "git fetch --all -v && git pull origin && git merge bp/main --allow-unrelated-histories -m \"Merge remote-tracking branch 'bp/main'\" ",
"bp:syncxo": "git fetch --all -v && git pull origin && git merge bp/main -m \"Merge remote-tracking branch 'bp/main'\" -Xours",
"bootstrap": "npm i --loglevel info --disturl=https://npmmirror.com/dist/",
"build": "sh .scripts/build.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/mw-demo/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ parserOptions:
rules:
"@typescript-eslint/no-unused-vars": 0
"@typescript-eslint/prefer-ts-expect-error": 0
"@typescript-eslint/no-extraneous-class": 0
"import/no-extraneous-dependencies":
- 2
- packageDir:
Expand Down
15 changes: 14 additions & 1 deletion packages/mw-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,31 @@ import { ILifeCycle } from '@midwayjs/core'
import { Configuration } from '@midwayjs/decorator'
import * as demo from '@mw-components/demo'

import * as DefaultConfig from './config/config.default.js'
import * as LocalConfig from './config/config.local.js'
import * as UnittestConfig from './config/config.unittest.js'

@Configuration({
importConfigs: [
{
default: DefaultConfig,
local: LocalConfig,
unittest: UnittestConfig,
},
],
imports: [
demo,
],
importConfigs: [join(__dirname, 'config')],
})
export class ContainerConfiguration implements ILifeCycle { }

```

### Add Configurations

### Swagger API
- start `npm run build && npm run dev`
- open `http://localhost:7001/swagger-ui/index.html` in browser

## License
[MIT](LICENSE)
Expand Down
5 changes: 3 additions & 2 deletions packages/mw-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"license": "MIT",
"dependencies": {
"@midwayjs/info": "^3.14.0",
"@mwcp/share": "*"
"@mwcp/otel": "20 - 22",
"@mwcp/share": "20 - 22"
},
"devDependencies": {
},
Expand All @@ -51,6 +51,7 @@
"bin",
"database",
"dist",
"src",
"!**/*.spec.*",
"!**/*.tsbuildinfo"
],
Expand Down
23 changes: 12 additions & 11 deletions packages/mw-demo/src/app/default.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ import {
Controller,
Get,
} from '@midwayjs/core'
import { ApiResponse } from '@midwayjs/swagger'

import { DefaultApi } from './default.types.js'

import { Config, ConfigKey, Msg } from '##/lib/types.js'


@Controller(`/_${ConfigKey.namespace}`)
@Controller(DefaultApi.base)
export class DefaultComponentController {

@_Config(ConfigKey.config) readonly config: Config
@_Config(ConfigKey.config) private readonly config: Config

@Get('/hello')
hello(): string {
this.valiateRoute()
@Get(DefaultApi.hello)
@ApiResponse({
type: 'string',
description: Msg.hello,
})
async hello(): Promise<string > {
void this.config
return Msg.hello
}

valiateRoute(): void {
if (! this.config.enableDefaultRoute) {
throw new Error('route is not enabled')
}
}

}

7 changes: 7 additions & 0 deletions packages/mw-demo/src/app/default.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ConfigKey } from '##/lib/types.js'


export class DefaultApi {
static readonly base = `/_${ConfigKey.namespace}`
static readonly hello = '/hello'
}
Loading

0 comments on commit 11088cc

Please sign in to comment.