Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(git-diff): add @d-zero/git-diff #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/@d-zero/git-diff/CHANGELOG.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yusasa16 このファイルはpublish時に自動的に生成されるため、最初は不要です。ここでは削除しておいてください。

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.0.0]
19 changes: 19 additions & 0 deletions packages/@d-zero/git-diff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `@d-zero/git-diff`

gitの差分を持つファイルの一覧を取得するためのツールです。

## CLI

```sh
# HEADからタグが付いているコミットまでの差分を取得する場合
npx @d-zero/git-diff

# HEADから特定のコミットまでの差分を取得する場合
npx @d-zero/git-diff <commit-hash>

# 特定のコミットから特定のコミットまでの差分を取得する場合
npx @d-zero/git-diff <commit-hash> <commit-hash>
```

差分を取得したいローカルリポジトリに移動し、上記コマンドを入力してください。
コミットのハッシュ値を指定する場合、古い方のコミットを先に入力してください
22 changes: 22 additions & 0 deletions packages/@d-zero/git-diff/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@d-zero/git-diff",
"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yusasa16

Suggested change
"version": "1.0.0",
"version": "1.0.0-alpha.0",

最初はアルファ版でマークしましょう。

"description": "Get a list of files with git diffs",
"author": "D-ZERO",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"bin": {
"git-diff": "./dist/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"clean": "tsc --build --clean"
}
}
10 changes: 10 additions & 0 deletions packages/@d-zero/git-diff/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { execSync } from 'node:child_process';

const tag =
process.argv[2] || execSync('git describe --tags --abbrev=0').toString('utf8').trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.argv[2] || execSync('git describe --tags --abbrev=0').toString('utf8').trim();
process.argv[2] ?? execSync('git describe --tags --abbrev=0').toString('utf8').trim();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yusasa16

論理値ではないものの代入なので || ではなく ?? を使いましょう。

const tag2 = process.argv[3] || 'HEAD';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const tag2 = process.argv[3] || 'HEAD';
const tag2 = process.argv[3] ?? 'HEAD';

@yusasa16

論理値ではないものの代入なので || ではなく ?? を使いましょう。

// cspell:disable-next-line
const gitDiff = `git diff --name-only ${tag} ${tag2} --diff-filter=ACMR`;
const list = execSync(gitDiff).toString('utf8').trim();
// eslint-disable-next-line no-console
console.log(list);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yusasa16

出力がどんなものになるのか、出力されたものの何を読んで、何を判断するのか、ドキュメントか何かに記載してほしいです。

Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-console
console.log(list);
process.stdout.write(`${list}\n`);

10 changes: 10 additions & 0 deletions packages/@d-zero/git-diff/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["./src/**/*"],
"exclude": ["node_modules", "dist", "./src/**/*.spec.ts"]
}