Skip to content

Commit c47bebe

Browse files
committed
Updated readme.
1 parent 8bc6ff1 commit c47bebe

File tree

2 files changed

+137
-2
lines changed

2 files changed

+137
-2
lines changed

README.ja.md

+69-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ ILSpyで見れば、すべての情報も確認できるでしょう:
4646
* また、埋め込む対象の情報をカスタマイズする事もできます。例えば、MSBuildで使われる変数の値を埋め込むことで、ビルド時の詳細な情報も埋め込むことが出来ます。
4747
* バージョンの埋め込みは、完全にMSBuildに統合されます。つまり、NuGetパッケージをインストールするだけで、Visual Studio、Rider、Visual Studio CodeといったIDEや 、CIのビルドプロセスでそのままバージョン埋め込みを実現できます。
4848
* RelaxVersionerには、環境に依存するコードは含まれていないので、ほぼすべての.NET環境で動作します。
49-
* CLIインターフェイスも存在します。テキストドキュメントにバージョン番号を埋め込んだり、.NETとは異なるプロジェクトシステム(例えばNPMの`project.json``Makefile`など)に対しても、同じバージョン表記を適用できます。
49+
* CLIインターフェイスも存在します。テキストドキュメントにバージョン番号を埋め込んだり、.NETとは異なるプロジェクトシステム(例えば`Makefile`など)に対しても、同じバージョン表記を適用できます。
50+
* NPM (Node.js package manager) には専用のモードがあります。CLIを使用することで、簡単にNPMプロジェクトとバージョン操作の一元化を実現できます。
5051

5152
### 出力されるコードの例
5253

@@ -220,6 +221,70 @@ ABC0123456789abc ... XYZ
220221
例えば、GitHub ActionsのようなCI/CD環境で、NPMパッケージ生成にバージョンを適用したり、テキストのドキュメントにバージョンを埋め込んだりすることが出来ます。
221222

222223

224+
----
225+
226+
## Node.jsプロジェクトで使う
227+
228+
CLIインターフェイスには、NPM (Node.js package manager) 向けの特別なオプションがあります。
229+
`package.json` ファイルが存在するディレクトリに移動して、以下のようにCLIを実行します:
230+
231+
```bash
232+
$ rv --npm .
233+
RelaxVersioner [3.8.0]: Generated versions code: Language=NPM, Version=12.34.56
234+
```
235+
236+
すると、 `package.json` 内の `version` キーの値が、正しいバージョン値に置き換わります。
237+
238+
この機能は、NPM標準の `npm version` コマンドと似ています。
239+
バージョンの検索アルゴリズムはRelaxVersionerに準じるため、.NETプロジェクトと共通化を図りたい場合に便利です。
240+
241+
更に、 `--npmns` オプションを使用すると、パッケージが依存するパッケージバージョンも同時に変更することが出来ます。
242+
例えば、複数のパッケージ群を管理していて、かつパッケージ同士に依存関係がある場合:
243+
244+
```json
245+
{
246+
"name": "webapi-interaction",
247+
"version": "0.0.1", // <-- このパッケージのバージョン(更新前)
248+
"dependencies": {
249+
"@foobar/helpers": "^1.4.0", // <-- 依存関係にある管理パッケージのバージョン
250+
"@foobar/common": "^1.7.2", // <-- 依存関係にある管理パッケージのバージョン
251+
"dayjs": "^1.2.3"
252+
}
253+
}
254+
```
255+
256+
依存関係にあるパッケージ名の名前空間 (`@foobar`) を指定してCLIを実行します:
257+
258+
```bash
259+
$ rv --npmns @foobar .
260+
RelaxVersioner [3.8.0]: Generated versions code: Language=NPM, Version=12.34.56
261+
```
262+
263+
これにより、全てのバージョン番号が統一されます:
264+
265+
```json
266+
{
267+
"name": "webapi-interaction",
268+
"version": "13.24.5", // <-- 自動的に更新される
269+
"dependencies": {
270+
"@foobar/helpers": "^13.24.5", // <-- 自動的に更新される(依存関係)
271+
"@foobar/common": "^13.24.5", // <-- 自動的に更新される(依存関係)
272+
"dayjs": "^1.2.3" // <-- 更新されない
273+
}
274+
}
275+
```
276+
277+
* 依存関係のチェックは、 `dependencies`, `peerDependencies`, `devDependencies` キーに対して行います。
278+
* 依存関係にあるパッケージを識別するため、パッケージの名前空間を統一してください。
279+
実際には単純な前方一致で確認するため、識別可能な名前であればどのような名前でも問題ありません。
280+
* 依存関係にあるパッケージのバージョンには、自動的に `^` が付きます。
281+
282+
この機能は、 [NPM workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces) と一緒にCIプロセスで扱う事を想定しています。
283+
その場合、参照するパッケージのバージョン番号は `*` とするなど、NPM workspacesの取扱いに準じて下さい。
284+
各パッケージのバージョンを更新したら、ワークスペースルートディレクトリで `npm install` を行うことで、
285+
`package-lock.json` に正しいバージョン番号が反映されます。
286+
287+
223288
----
224289

225290
## ヒントや参考情報
@@ -480,6 +545,9 @@ nuspecファイルを使ってパッケージを生成する場合は、デフ
480545

481546
## 履歴
482547

548+
* 3.8.0:
549+
* NPM `package.json` のバージョンを自動挿入する、NPMモードを追加。
550+
* NuGetパッケージをビルドする時に、ビルドログにバージョン番号のゴミが出力されていたのを修正。
483551
* 3.7.0:
484552
* CLIでカスタムブラケット指定に対応しました。
485553
* 3.6.0:

README.md

+68-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ If you look in ILSpy, you will also see all the information:
4747
* You can also customize the information to be embedded. For example, by embedding the value of variables used in MSBuild, you can also embed detailed information at build time.
4848
* Version embedding is fully integrated into MSBuild. This means that you can simply install the NuGet package and embed versions directly in the build process of IDEs such as Visual Studio, Rider, Visual Studio Code or in the build process of CI.
4949
* RelaxVersioner does not contain any environment-dependent code, so it works in almost any .NET environment.
50-
* A CLI interface also exists. You can embed version numbers in text documents and apply the same version notation to different project systems than .NET (e.g. NPM's `project.json`, `Makefile` and etc.).
50+
* A CLI interface also exists. You can embed version numbers in text documents and apply the same version notation to different project systems than .NET (e.g. `Makefile` and etc.).
51+
* CLI has a dedicated NPM (Node.js package manager) mode, which allows you to easily centralize NPM project and version operations.
5152

5253
## Sample output code
5354

@@ -218,6 +219,69 @@ With this CLI, you can use a combination of RelaxVersioner for different targets
218219
For example, in a CI/CD environment like GitHub Actions, you can apply versions to NPM package generation or embed versions in your text documentation.
219220

220221

222+
----
223+
224+
## Using with Node.js projects
225+
226+
The CLI interface has special options for NPM (Node.js package manager).
227+
Change to the directory where the `package.json` file is located and run the CLI as follows:
228+
229+
```bash
230+
$ rv --npm .
231+
RelaxVersioner [3.8.0]: Generated versions code: Language=NPM, Version=12.34.56
232+
```
233+
234+
The value of the `version` key in `package.json` will then be replaced with the correct version value.
235+
236+
* This function is similar to the standard NPM `npm version` command.
237+
* The version search algorithm is based on RelaxVersioner, so it is useful if you want to share the same version with .NET projects.
238+
239+
Furthermore, if you use the `--npmns` option, you can also change the package versions that the package depends on at the same time.
240+
For example, if you are managing multiple packages and there are dependencies between the packages:
241+
242+
```json
243+
{
244+
"name": "webapi-interaction",
245+
"version": "0.0.1", // <-- The version of this package (before updating)
246+
"dependencies": {
247+
"@foobar/helpers": "^1.4.0", // <-- Version of the managed package that is a dependency
248+
"@foobar/common": "^1.7.2", // <-- Version of the managed package that is a dependency
249+
"dayjs": "^1.2.3"
250+
}
251+
}
252+
```
253+
254+
Run the CLI specifying the namespace of the package name (`@foobar`) that is a dependency:
255+
256+
```bash
257+
$ rv --npmns @foobar .
258+
```
259+
260+
This will unify all the version numbers:
261+
262+
```json
263+
{
264+
"name": "webapi-interaction",
265+
"version": "13.24.5", // <-- Automatically updated
266+
"dependencies": {
267+
"@foobar/helpers": "^13.24.5", // <-- automatically updated (dependency)
268+
"@foobar/common": "^13.24.5", // <-- automatically updated (dependency)
269+
"dayjs": "^1.2.3" // <-- not updated
270+
}
271+
}
272+
```
273+
274+
* Dependency checks are performed on the `dependencies`, `peerDependencies` and `devDependencies` keys.
275+
* Please use a consistent package namespace to identify dependent packages.
276+
* In practice, this is a simple prefix match, so any name that can be identified is fine.
277+
* If you are targeting multiple namespaces, specify them separated by commas.
278+
* The version of a dependent package is automatically prefixed with `^`.
279+
280+
This function is intended to be used with [NPM workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces) and inside the CI process.
281+
In that case, please follow the NPM workspaces handling, such as using `*` as the version number of the referenced package.
282+
After updating the version of each package, run `npm install` in the workspace root directory to update the correct version numbers in `package-lock.json`.
283+
284+
221285
----
222286

223287
## Hints and Tips
@@ -462,6 +526,9 @@ When you are using a nuspec file to generate a NuGet package, there are addition
462526

463527
## History
464528

529+
* 3.8.0:
530+
* Added NPM mode, which automatically inserts the version of NPM `package.json`.
531+
* Fixed version number print garbage in the build log when building NuGet packages.
465532
* 3.7.0:
466533
* CLI now supports custom bracket specification.
467534
* 3.6.0:

0 commit comments

Comments
 (0)