🦁

textlintプラグインの作り方(例:オンドゥル語変換) リリース編

2022/10/16に公開

本記事はtextlintプラグインの作り方(例:オンドゥル語変換) プラグイン作成編の続きにあたります。

本記事概要

最後にパッケージをリリース、実際のvisual studio codeで動くかまで実施していきます。

リリース

ソースコードのマージ

本当は一人開発でここまでやる必要はないのですが、せっかくなので手順を記載しておきます。

まずはGitHub上に移動すると、以下のようにPull Requestのボタンがあるので押します。

ondul-style-img

Pull Requestの概要を以下のように記載し、「Create Pull Request」を押します。

ondul-style-img

そのままマージできるので実行しましょう!

ondul-style-img

tag v1.0.0 作成

リリースしたものにtag v1.0.0を付与し、リリースします。

リポジトリのTop画面に「Create a new release」があるので押してください。

ondul-style-img

「Choose a tag」を選び、 v1.0.0 を入れてタグを作りましょう。

ondul-style-img

リリースの概要を記載します。

ondul-style-img

リリースが正常に終了すると、リポジトリのトップ画面が以下のようになるはずです。

ondul-style-img

npmリリース

npmサイトの登録は済んでいるものとして進めてきます。

mainリポジトリに変更

ブランチをmainに変更し、マージされたソースコードを取得します。

$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git pull origin main

npm login

まずは npm login をしてログインします。

$ npm login
npm notice Log in on https://registry.npmjs.org/
Username: shivase
Password: x
Email: (this IS public) keitti05@gmail.com
npm notice Please check your email for a one-time password (OTP)
Enter one-time password: 04499239
Logged in as shivase on https://registry.npmjs.org/.

npm publish ./ を実行し、ビルドされたソースコードをアップロードします。

$ npm publish ./
npm notice
npm notice 📦  textlint-rule-ondul-style@1.0.0
npm notice === Tarball Contents ===
npm notice 649B  README.md
npm notice 2.5kB lib/index.js
npm notice 3.1kB lib/index.js.map
npm notice 2.6kB lib/lib/ondulish.js
npm notice 6.1kB lib/lib/ondulish.js.map
npm notice 1.8kB package.json
npm notice 1.6kB src/index.ts
npm notice 2.9kB src/lib/ondulish.ts
npm notice === Tarball Details ===
npm notice name:          textlint-rule-ondul-style
npm notice version:       1.0.0
npm notice filename:      textlint-rule-ondul-style-1.0.0.tgz
npm notice package size:  5.8 kB
npm notice unpacked size: 21.4 kB
npm notice shasum:        54b2b92bd5fb3c4003cf25bedd58583c545c129e
npm notice integrity:     sha512-FmI6t9KOy9ve1[...]GrEV8jmOSszXg==
npm notice total files:   8
npm notice
npm notice Publishing to https://registry.npmjs.org/
+ textlint-rule-ondul-style@1.0.0

これですべて完了です!

動作確認

実際にvisual studio codeで動作するか確認してみましょう。

パッケージの登録

$ yarn add -D textlint-rule-ondul-style
yarn add v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ textlint-rule-ondul-style@1.0.0
info All dependencies
└─ textlint-rule-ondul-style@1.0.0
$ yarn build
yarn run v1.22.19
$ rimraf lib
$ textlint-scripts build
Successfully compiled 2 files with Babel (780ms).
✨  Done in 7.95s.
$ husky install
husky - Git hooks installed
✨  Done in 16.84s.

.textlintrc.ymlをプロジェクトに追加します。

rules:
  ondul-style: true

visual studio codeでREADME.mdを見てみます。

ondul-style-img

できました!

もちろんFixもできます!

ondul-style-gif

最後に

いかがでしたでしょうか。簡易的な単純変換ですので、正しいオンドゥル語にはならない部分はあるのですが、とりあえずtexlintプラグインとして動くものはできました。本当は細かいロジックをもっと書かないと、ムダな警告も増えVisual Studio Codeが真っ赤になる恐れがあるのですが、今回はなるべく単純化させていただきました。

長い記事になりましたが、textlintのプラグインの作成の参考になれば幸いです。

何かコードで気になることがありましたらコメントください!

GitHubで編集を提案

Discussion