diff --git a/.github/workflows/publish_npm.yml b/.github/workflows/publish_npm.yml new file mode 100644 index 0000000..af88fec --- /dev/null +++ b/.github/workflows/publish_npm.yml @@ -0,0 +1,38 @@ +name: publish npm + +on: + push: + tags: + - v*.*.* + workflow_dispatch: + +permissions: + contents: write + +jobs: + publish-npm: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + - name: Get version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Set version + run: | + apt install jq + jq '.version="${{ steps.get_version.outputs.VERSION }}"' package.json > package.json.new + mv package.json.new package.json + - name: Generate SDK + run: | + npm cache clean --force + npm install @openapitools/openapi-generator-cli -g + make build + - run: npm i + - run: npm run start + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9f5bbcb..554ce08 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ dist/ target/ codegen/ __debug_bin + +node_modules/ +dist/ +.idea +.package-lock.json \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..602b39d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 3a12da0..5e85c40 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,29 @@ Message bus accepts events and actions from various sources and delivers them to subscribers. See [openapi.yaml](./api/message_bus/openapi.yaml) for API specification. + + + + +## publish api to npm + +### edit version in package.json + +### run +```bash +yarn + +yarn start +``` + +### publish + +Manual publish +```bash +yarn publish +``` + +Auto publish +```bash +git push origin dev** +``` \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..339cf74 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "casaos-messagebus-openapi", + "version": "0.0.1", + "scripts": { + "build": "rm -rf dist && tsc && rm -rf generate", + "generate:local": "openapi-generator-cli generate -g typescript-axios -i ./api/message_bus/openapi.yaml -o ./generate", + "generate:npx": "npx @openapitools/openapi-generator-cli generate -g typescript-axios -i ./api/message_bus/openapi.yaml -o ./generate", + "generate:ts": "npx openapi-typescript-codegen --input ./api/message_bus/openapi.yaml --output ./generate", + "publish": "npm publish --access public", + "start": "yarn generate:ts && yarn build" + }, + "homepage": "https://github.com/IceWhaleTech/CasaOS-MessageBus#readme", + "description": "Casaos-MessageBus Typescript+Axios SDK", + "keywords": [ + "CasaOS-MessageBus", + "SDK", + "CasaOS-MessageBus Axios" + ], + "main": "dist/index", + "files": [ + "LICENSE", + "README.md", + "dist" + ], + "dependencies": { + "axios": "^1.1.0" + }, + "devDependencies": { + "@openapitools/openapi-generator-cli": "2.5.2", + "@types/node": "^18.8.3", + "openapi-typescript-codegen": "^0.23.0", + "typescript": "^4.9.5" + }, + "author": "casaos", + "license": "Apache-2.0" +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..89d3573 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "declaration": true, + "lib": [ + "es2017", + "DOM" + ], + "module": "commonjs", + "target": "es6", + "skipLibCheck": true, + "sourceMap": false, + "strict": true, + "useUnknownInCatchVariables": false, + "resolveJsonModule": true, + "esModuleInterop": true, + "outDir": "dist", + "types": [ + "node" + ], + }, + "exclude": [ + "node_modules" + ], + "main": "generate/index" +} \ No newline at end of file