NSTMレジストリ上のTelegramボットのすべてのライブラリをNPMレジストリに発行する


リンク


https://github.com/EndyKaufman/kaufman-bot - ボットのソースコード
https://telegram.me/DevelopKaufmanBot - 現在のロボット

作品の説明


このポストでは、NPMレジストリ内のすべてのライブラリを公開します.
そして、私は出版のためにそれらを準備するためにライブラリを更新する方法を示します、私はライブラリの1つだけのためにステップを書きます、他のためのステップは同じです.

図書館名変更


NPMレジスタは名前パスの2つのレベルだけで動作するので、すべての名前を更新する必要があります.
すべてのリリーに交換する

npx -y replace-in-files-cli --string=@kaufman-bot/core/server --replacement=@kaufman-bot/core './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/bot-in-groups/server --replacement=@kaufman-bot/bot-in-groups-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/currency-converter/server --replacement=@kaufman-bot/currency-converter-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/debug-messages/server --replacement=@kaufman-bot/debug-messages-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/dialogflow/server --replacement=@kaufman-bot/dialogflow-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/facts-generator/server --replacement=@kaufman-bot/facts-generator-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/first-meeting/server --replacement=@kaufman-bot/first-meeting-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/html-scraper/server --replacement=@kaufman-bot/html-scraper-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/jokes-generator/server --replacement=@kaufman-bot/jokes-generator-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/language-swither/server --replacement=@kaufman-bot/language-swither-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/prisma/server --replacement=@kaufman-bot/prisma-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/quotes-generator/server --replacement=@kaufman-bot/quotes-generator-server './libs/**'

npx -y replace-in-files-cli --string=@kaufman-bot/short-commands/server --replacement=@kaufman-bot/short-commands-server './libs/**'


すべてのアプリケーションで置換する

npx -y replace-in-files-cli --string=@kaufman-bot/core/server --replacement=@kaufman-bot/core './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/bot-in-groups/server --replacement=@kaufman-bot/bot-in-groups-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/currency-converter/server --replacement=@kaufman-bot/currency-converter-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/debug-messages/server --replacement=@kaufman-bot/debug-messages-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/dialogflow/server --replacement=@kaufman-bot/dialogflow-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/facts-generator/server --replacement=@kaufman-bot/facts-generator-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/first-meeting/server --replacement=@kaufman-bot/first-meeting-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/html-scraper/server --replacement=@kaufman-bot/html-scraper-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/jokes-generator/server --replacement=@kaufman-bot/jokes-generator-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/language-swither/server --replacement=@kaufman-bot/language-swither-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/prisma/server --replacement=@kaufman-bot/prisma-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/quotes-generator/server --replacement=@kaufman-bot/quotes-generator-server './apps/**'

npx -y replace-in-files-cli --string=@kaufman-bot/short-commands/server --replacement=@kaufman-bot/short-commands-server './apps/**'


TSCで置き換える

npx -y replace-in-files-cli --string=@kaufman-bot/core/server --replacement=@kaufman-bot/core './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/bot-in-groups/server --replacement=@kaufman-bot/bot-in-groups-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/currency-converter/server --replacement=@kaufman-bot/currency-converter-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/debug-messages/server --replacement=@kaufman-bot/debug-messages-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/dialogflow/server --replacement=@kaufman-bot/dialogflow-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/facts-generator/server --replacement=@kaufman-bot/facts-generator-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/first-meeting/server --replacement=@kaufman-bot/first-meeting-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/html-scraper/server --replacement=@kaufman-bot/html-scraper-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/jokes-generator/server --replacement=@kaufman-bot/jokes-generator-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/language-swither/server --replacement=@kaufman-bot/language-swither-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/prisma/server --replacement=@kaufman-bot/prisma-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/quotes-generator/server --replacement=@kaufman-bot/quotes-generator-server './tsconfig.base.json'

npx -y replace-in-files-cli --string=@kaufman-bot/short-commands/server --replacement=@kaufman-bot/short-commands-server './tsconfig.base.json'


ソースコードとすべての設定を更新する


プロジェクトJSON


ビルドセクションの追加
リブス/コア/サーバー/プロジェクト.JSON
{
  "root": "libs/core/server",
  "sourceRoot": "libs/core/server/src",
  "projectType": "library",
  "targets": {
    "build": {
      "executor": "@nrwl/node:package",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/core/server",
        "tsConfig": "libs/core/server/tsconfig.lib.json",
        "packageJson": "libs/core/server/package.json",
        "main": "libs/core/server/src/index.ts",
        "assets": ["libs/core/server/*.md"],
        "updateBuildableProjectDepsInPackageJson": false,
        "deleteOutputPath": true
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["libs/core/server/\*\*/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/libs/core/server"],
      "options": {
        "jestConfig": "libs/core/server/jest.config.js",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}


アップデートパッケージ。JSON


すべての使用済みのインポートを収集し、依存関係セクションに追加します.
リブス/コア/サーバー/パッケージ.JSON
{
  "name": "@kaufman-bot/core-server",
  "description": "Core commands and tools",
  "license": "MIT",
  "author": "EndyKaufman <[email protected]>",
  "keywords": [
    "kaufman-bot",
    "nx",
    "nests",
    "telegram",
    "core"
  ],
  "bugs": {
    "url": "https://github.com/EndyKaufman/kaufman-bot/issues"
  },
  "homepage": "https://github.com/EndyKaufman/kaufman-bot",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/EndyKaufman/kaufman-bot.git"
  },
  "maintainers": [
    {
      "name": "EndyKaufman",
      "email": "[email protected]"
    }
  ],
  "readme": "README.md",
  "i18n": [
    {
      "scope": "core-server",
      "path": "src/i18n",
      "strategy": "join"
    },
    {
      "scope": "core-server-getText",
      "path": "src/i18n/getText",
      "strategy": "join"
    }
  ],
  "version": "2.1.0",
  "peerDependencies": {
    "@nestjs/common": "^8.0.0",
    "nestjs-custom-injector": "^1.0.1",
    "nestjs-translates": "^1.0.3",
    "class-validator-multi-lang": "^0.130.201",
    "micromatch": "^4.0.5",
    "mustache": "^4.2.0",
    "telegraf": "^4.7.0"
  }
}

これらの変更をすべてのライブラリに適用する必要があります.

ルートファイルの更新


アップデートパッケージ。JSON


パッケージ.JSON
...
 "scripts": {
    ...
    "publish:core": "npm publish ./dist/libs/core/server",
    "publish:bot-in-groups": "npm publish ./dist/libs/bot-in-groups/server",
    "publish:currency-converter": "npm publish ./dist/libs/currency-converter/server",
    "publish:debug-messages": "npm publish ./dist/libs/debug-messages/server",
    "publish:dialogflow": "npm publish ./dist/libs/dialogflow/server",
    "publish:facts-generator": "npm publish ./dist/libs/facts-generator/server",
    "publish:first-meeting": "npm publish ./dist/libs/first-meeting/server",
    "publish:html-scraper": "npm publish ./dist/libs/html-scraper/server",
    "publish:jokes-generator": "npm publish ./dist/libs/jokes-generator/server",
    "publish:language-swither": "npm publish ./dist/libs/language-swither/server",
    "publish:quotes-generator": "npm publish ./dist/libs/quotes-generator/server",
    "publish:short-commands": "npm publish ./dist/libs/short-commands/server",
    "publish": "npm run publish:core && npm run publish:bot-in-groups && npm run publish:currency-converter && npm run publish:debug-messages && npm run publish:dialogflow && npm run publish:facts-generator && npm run publish:first-meeting && npm run publish:html-scraper && npm run publish:jokes-generator && npm run publish:language-swither && npm run publish:quotes-generator && npm run publish:short-commands"
  },
...

アップデートの設定


. github/ワークフロー/パブリッシュ.気象研
name: Publish

on:
  push:
    tags:
      - v*

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Node.js 16.x to publish to npmjs.org
        uses: actions/setup-node@v1
        with:
          node-version: '16.x'
          registry-url: 'https://registry.npmjs.org'

      - name: Install Packages
        run: npm i --force

      - name: Build
        run: npm run build

      - name: Generate Release Body
        run: npx extract-changelog-release > RELEASE_BODY.md

      - name: Publish to NPM
        run: npm run publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Create GitHub Release
        uses: ncipollo/release-action@v1
        with:
          bodyFile: 'RELEASE_BODY.md'
          token: ${{ secrets.GITHUB_TOKEN }}

githubアクション環境にNPMトークンを追加する


NPMでトークンを作成する


移動するhttps://www.npmjs.com/settings//トークン
クリックでトークンを作る

クリックして生成

その後、生成されたトークン

にトークンを追加する


移動するhttps://github.com///設定/秘密/アクション
共通環境変数

チェックNPMライブラリ


移動するhttps://www.npmjs.com/package/@kaufman-bot/core-server

次のポストでは、コマンドラインからCREATEアプリケーションのための回路図を追加します.