Skip to content
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@d-zero/fontend-env",
"name": "@d-zero/frontend-env",
"description": "D-ZERO Frontend Developer's Environment",
"repository": "https://github.com/d-zero-dev/frontend-env.git",
"author": "D-ZERO Co., Ltd.",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"build": "lerna run build --scope=@d-zero/builder --scope=@d-zero/custom-components",
"build": "lerna run build --scope=@d-zero/builder --scope=@d-zero/check-frontend-env --scope=@d-zero/custom-components",
"dev": "lerna run dev",
"test": "vitest run --test-timeout 60000",
"lint": "run-s lint:eslint lint:prettier lint:textlint lint:cspell",
Expand Down
2 changes: 2 additions & 0 deletions packages/@d-zero/check-frontend-env/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
81 changes: 81 additions & 0 deletions packages/@d-zero/check-frontend-env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# @d-zero/check-frontend-env

Check Frontend Environment for D-ZERO

フロントエンド開発環境のチェックツールです。Node.js、npm、yarn、Husky、Voltaのインストール状況とバージョンを確認できます。

## Installation

```bash
npm install @d-zero/check-frontend-env
```

## Usage

### CLI として使用

```bash
# 環境チェックを実行
npx check-frontend-env

# Voltaのインストールテストを実行
npx check-frontend-env --test
```

### プログラムとして使用

```typescript
import { volta } from '@d-zero/check-frontend-env';

// Voltaのインストール状況をチェック
const voltaInfo = volta.checkVolta();
console.log('Volta installed:', voltaInfo.present);
console.log('Version:', voltaInfo.version);

// Voltaのインストールテストを実行
const isInstalled = volta.testVoltaInstallation();
if (isInstalled) {
console.log('✅ Volta is properly installed');
} else {
console.log('❌ Volta is not installed or has issues');
}
```

## チェック項目

- **Husky設定**: v8とv9の両方のバージョンの設定ファイルを確認
- **Node.js**: 現在のバージョンを表示
- **npm**: 現在のバージョンを表示
- **yarn**: インストールされている場合のバージョンを表示
- **Volta**: インストール状況、バージョン、実行ファイルの場所を確認

## Testing

### ローカルテスト

```bash
# 依存関係をインストール
yarn install

# ビルド
yarn build

# ユニットテストを実行
yarn test

# Voltaインストールテストを実行
yarn test:volta
```

### GitHub Actions

このパッケージは[volta-cli/action](https://github.com/volta-cli/action)を使用してGitHub Actionsでテストされます。

テストは以下の環境で実行されます:

- **OS**: Ubuntu、macOS、Windows
- **Volta**: 1.1.1、latest

## License

MIT
39 changes: 39 additions & 0 deletions packages/@d-zero/check-frontend-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@d-zero/check-frontend-env",
"version": "5.0.0-alpha.46",
"description": "Check Frontend Environment for D-ZERO",
"repository": "https://github.com/d-zero-dev/frontend-env.git",
"author": "D-ZERO Co., Ltd.",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"check-frontend-env": "./dist/index.js"
},
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"dev": "tsc --watch --project tsconfig.build.json",
"test": "vitest",
"test:run": "vitest run"
},
"files": [
"dist"
],
"dependencies": {},
"devDependencies": {
"@types/node": "^20.11.24",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
}
}
169 changes: 169 additions & 0 deletions packages/@d-zero/check-frontend-env/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/usr/bin/env node
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

interface EnvironmentInfo {
huskyConfig: {
v8Present: boolean;
v9Present: boolean;
paths: string[];
};
versions: {
node: string;
npm: string;
yarn?: string;
};
volta: {
present: boolean;
version?: string;
path?: string;
homeDir?: string;
};
}

/**
* Husky設定をチェックする
*/
function checkHuskyConfig(): EnvironmentInfo['huskyConfig'] {
const homeDir = os.homedir();
const v8Path = path.join(homeDir, '.config', 'husky', 'init.sh');
const v9Path = path.join(homeDir, '.husky');

return {
v8Present: fs.existsSync(v8Path),
v9Present: fs.existsSync(v9Path),
paths: [v8Path, v9Path].filter((p) => fs.existsSync(p)),
};
}

/**
* 各ソフトウェアのバージョンを取得する
*/
function getVersions(): EnvironmentInfo['versions'] {
const versions: EnvironmentInfo['versions'] = {
node: process.version,
npm: execSync('npm --version').toString().trim(),
};

try {
versions.yarn = execSync('yarn --version').toString().trim();
} catch {
// yarn is not installed
}

return versions;
}

/**
* Voltaのインストール状況をチェックする
*/
function checkVolta(): EnvironmentInfo['volta'] {
const homeDir = os.homedir();
const possiblePaths = [
'/usr/local/bin/volta', // Homebrewなどでグローバルインストール
path.join(homeDir, '.volta', 'bin', 'volta'), // 標準的なインストール場所
];

// PATHからvoltaを探す
try {
const whichOutput = execSync('which volta 2>/dev/null').toString().trim();
if (whichOutput) {
possiblePaths.push(whichOutput);
}
} catch {
// which commandが失敗した場合は無視
}

// Voltaのホームディレクトリ
const voltaHome = process.env.VOLTA_HOME || path.join(homeDir, '.volta');

for (const voltaPath of possiblePaths) {
if (fs.existsSync(voltaPath)) {
try {
const version = execSync(`${voltaPath} --version`).toString().trim();
return {
present: true,
version,
path: voltaPath,
homeDir: voltaHome,
};
} catch {
// 実行権限がない場合など
continue;
}
}
}

return {
present: false,
homeDir: voltaHome,
};
}

/**
* メイン処理
*/
function main() {
const info: EnvironmentInfo = {
huskyConfig: checkHuskyConfig(),
versions: getVersions(),
volta: checkVolta(),
};

console.log('環境チェック結果:');
console.log('-------------------------');
console.log('Husky設定:');
console.log(` v8 (.config/husky): ${info.huskyConfig.v8Present ? '✅' : '❌'}`);
console.log(` v9 (.husky): ${info.huskyConfig.v9Present ? '✅' : '❌'}`);
if (info.huskyConfig.paths.length > 0) {
console.log(' 発見場所:');
for (const p of info.huskyConfig.paths) console.log(` - ${p}`);
}

console.log('\n各バージョン:');
console.log(` Node.js: ${info.versions.node}`);
console.log(` npm: ${info.versions.npm}`);
if (info.versions.yarn) {
console.log(` yarn: ${info.versions.yarn}`);
}

console.log('\nVolta:');
console.log(` インストール: ${info.volta.present ? '✅' : '❌'}`);
if (info.volta.version) {
console.log(` バージョン: ${info.volta.version}`);
}
if (info.volta.path) {
console.log(` 実行ファイル: ${info.volta.path}`);
}
console.log(` ホームディレクトリ: ${info.volta.homeDir}`);
}

// テスト用にエクスポート
export const volta = {
checkVolta,
};

export const husky = {
checkHuskyConfig,
};

export const versions = {
getVersions,
};

export const utils = {
main,
};

// CLIとして直接実行された場合のみmainを実行
const isCli =
process.argv[1] &&
(process.argv[1].endsWith('check-frontend-env') ||
process.argv[1].endsWith('index.js') ||
import.meta.url === `file://${process.argv[1]}`);

if (isCli) {
main();
}
11 changes: 11 additions & 0 deletions packages/@d-zero/check-frontend-env/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": ["./tsconfig.json"],
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationMap": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
}
4 changes: 4 additions & 0 deletions packages/@d-zero/check-frontend-env/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../../tsconfig.json"],
"exclude": ["node_modules", "dist"]
}
Loading