@k2works/claude-code-booster 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +42 -42
- package/bin/claude-code-booster +79 -79
- package/lib/assets/.claude/README.md +162 -162
- package/lib/assets/.claude/SKILLS_TEMPLATE.md +100 -100
- package/lib/assets/.claude/scripts/generate-inception-deck.mjs +911 -1024
- package/lib/assets/.claude/settings.json +11 -11
- package/lib/assets/.claude/skills/ai-agent-guidelines/SKILL.md +119 -119
- package/lib/assets/.claude/skills/analyzing-architecture/SKILL.md +87 -87
- package/lib/assets/.claude/skills/analyzing-business/SKILL.md +117 -117
- package/lib/assets/.claude/skills/analyzing-data-model/SKILL.md +80 -80
- package/lib/assets/.claude/skills/analyzing-domain-model/SKILL.md +88 -88
- package/lib/assets/.claude/skills/analyzing-inception-deck/SKILL.md +137 -137
- package/lib/assets/.claude/skills/analyzing-non-functional/SKILL.md +91 -91
- package/lib/assets/.claude/skills/analyzing-operation/SKILL.md +91 -91
- package/lib/assets/.claude/skills/analyzing-requirements/SKILL.md +87 -87
- package/lib/assets/.claude/skills/analyzing-tech-stack/SKILL.md +102 -102
- package/lib/assets/.claude/skills/analyzing-test-strategy/SKILL.md +87 -87
- package/lib/assets/.claude/skills/analyzing-ui-design/SKILL.md +86 -86
- package/lib/assets/.claude/skills/analyzing-usecases/SKILL.md +87 -87
- package/lib/assets/.claude/skills/creating-adr/SKILL.md +115 -115
- package/lib/assets/.claude/skills/developing-backend/SKILL.md +106 -106
- package/lib/assets/.claude/skills/developing-frontend/SKILL.md +96 -96
- package/lib/assets/.claude/skills/developing-release/SKILL.md +154 -154
- package/lib/assets/.claude/skills/generating-slides/SKILL.md +136 -106
- package/lib/assets/.claude/skills/git-commit/SKILL.md +106 -106
- package/lib/assets/.claude/skills/killing-processes/SKILL.md +98 -98
- package/lib/assets/.claude/skills/managing-docs/SKILL.md +200 -200
- package/lib/assets/.claude/skills/managing-operations/DEPLOY.md +77 -77
- package/lib/assets/.claude/skills/managing-operations/SETUP_CSHARP.md +80 -80
- package/lib/assets/.claude/skills/managing-operations/SETUP_FRONTEND.md +84 -84
- package/lib/assets/.claude/skills/managing-operations/SETUP_JAVA.md +75 -75
- package/lib/assets/.claude/skills/managing-operations/SKILL.md +156 -156
- package/lib/assets/.claude/skills/orchestrating-analysis/SKILL.md +134 -134
- package/lib/assets/.claude/skills/orchestrating-development/SKILL.md +243 -243
- package/lib/assets/.claude/skills/orchestrating-project/SKILL.md +193 -193
- package/lib/assets/.claude/skills/planning-releases/SKILL.md +222 -222
- package/lib/assets/.claude/skills/syncing-github-project/SKILL.md +181 -69
- package/lib/assets/.claude/skills/tracking-progress/SKILL.md +164 -164
- package/lib/assets/.devcontainer/devcontainer.json +34 -34
- package/lib/assets/.env.example +17 -17
- package/lib/assets/.gitattributes +4 -4
- package/lib/assets/.github/workflows/docker-publish.yml +77 -77
- package/lib/assets/.github/workflows/mkdocs.yml +39 -39
- package/lib/assets/AGENTS.md +94 -94
- package/lib/assets/CLAUDE.md +162 -162
- package/lib/assets/README.md +269 -269
- package/lib/assets/docker-compose.yml +33 -33
- package/lib/assets/docs/assets/css/extra.css +29 -29
- package/lib/assets/docs/assets/js/extra.js +44 -44
- package/lib/assets/docs/index.md +14 -14
- package/lib/assets/docs/reference/CodexCLIMCP/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/351/226/213/347/231/272/343/203/225/343/203/255/343/203/274.md +532 -532
- package/lib/assets/docs/reference/CodexCLIMCP/343/202/265/343/203/274/343/203/220/343/203/274/350/250/255/345/256/232/346/211/213/351/240/206.md +341 -341
- package/lib/assets/docs/reference/Java/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/347/222/260/345/242/203/346/247/213/347/257/211/343/202/254/343/202/244/343/203/211.md +578 -578
- package/lib/assets/docs/reference/TypeScript/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/347/222/260/345/242/203/346/247/213/347/257/211/343/202/254/343/202/244/343/203/211.md +465 -465
- package/lib/assets/docs/reference/UI/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +448 -448
- package/lib/assets/docs/reference//343/202/210/343/201/204/343/202/275/343/203/225/343/203/210/343/202/246/343/202/247/343/202/242/343/201/250/343/201/257.md +242 -242
- package/lib/assets/docs/reference//343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +2216 -2216
- package/lib/assets/docs/reference//343/202/244/343/203/263/343/203/225/343/203/251/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +1878 -1878
- package/lib/assets/docs/reference//343/202/250/343/202/257/343/202/271/343/203/210/343/203/252/343/203/274/343/203/240/343/203/227/343/203/255/343/202/260/343/203/251/343/203/237/343/203/263/343/202/260.md +554 -554
- package/lib/assets/docs/reference//343/202/263/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/343/201/250/343/203/206/343/202/271/343/203/210/343/202/254/343/202/244/343/203/211.md +705 -705
- package/lib/assets/docs/reference//343/203/206/343/202/271/343/203/210/346/210/246/347/225/245/343/202/254/343/202/244/343/203/211.md +1313 -1313
- package/lib/assets/docs/reference//343/203/207/343/203/274/343/202/277/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +311 -311
- package/lib/assets/docs/reference//343/203/211/343/203/241/343/202/244/343/203/263/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +599 -599
- package/lib/assets/docs/reference//343/203/223/343/202/270/343/203/215/343/202/271/343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243/345/210/206/346/236/220/343/202/254/343/202/244/343/203/211.md +528 -528
- package/lib/assets/docs/reference//343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271/344/275/234/346/210/220/343/202/254/343/202/244/343/203/211.md +682 -682
- package/lib/assets/docs/reference//343/203/252/343/203/252/343/203/274/343/202/271/343/202/254/343/202/244/343/203/211.md +442 -442
- package/lib/assets/docs/reference//343/203/252/343/203/252/343/203/274/343/202/271/343/203/273/343/202/244/343/203/206/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263/350/250/210/347/224/273/343/202/254/343/202/244/343/203/211.md +558 -558
- package/lib/assets/docs/reference//347/222/260/345/242/203/345/244/211/346/225/260/347/256/241/347/220/206/343/202/254/343/202/244/343/203/211.md +663 -663
- package/lib/assets/docs/reference//350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +1248 -1248
- package/lib/assets/docs/reference//351/201/213/347/224/250/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +392 -392
- package/lib/assets/docs/reference//351/226/213/347/231/272/343/202/254/343/202/244/343/203/211.md +235 -235
- package/lib/assets/docs/reference//351/235/236/346/251/237/350/203/275/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +1236 -1236
- package/lib/assets/docs/template/ADR.md +30 -30
- package/lib/assets/docs/template/README.md +50 -50
- package/lib/assets/docs/template//343/201/276/343/201/232/343/201/223/343/202/214/343/202/222/350/252/255/343/202/202/343/201/206/343/203/252/343/202/271/343/203/210.md +12 -12
- package/lib/assets/docs/template//343/202/244/343/203/206/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263/345/256/214/344/272/206/345/240/261/345/221/212/346/233/270.md +58 -58
- package/lib/assets/docs/template//343/202/244/343/203/263/343/202/273/343/203/227/343/202/267/343/203/247/343/203/263/343/203/207/343/203/203/343/202/255.md +13 -13
- package/lib/assets/docs/template//343/203/223/343/202/270/343/203/215/343/202/271/343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243.md +379 -379
- package/lib/assets/docs/template//345/256/214/345/205/250/345/275/242/345/274/217/343/201/256/343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271.md +68 -68
- package/lib/assets/docs/template//350/246/201/344/273/266/345/256/232/347/276/251.md +669 -669
- package/lib/assets/docs/template//350/250/255/350/250/210.md +163 -163
- package/lib/assets/gulpfile.js +23 -23
- package/lib/assets/mkdocs.yml +65 -65
- package/lib/assets/ops/docker/mkdoc/Dockerfile +19 -19
- package/lib/assets/ops/scripts/journal.js +180 -180
- package/lib/assets/ops/scripts/mkdocs.js +82 -82
- package/lib/assets/ops/scripts/release.js +431 -431
- package/lib/assets/ops/scripts/ssh.js +190 -190
- package/lib/assets/ops/scripts/vault.js +299 -299
- package/lib/assets/package-lock.json +1653 -1653
- package/lib/assets/package.json +40 -40
- package/lib/gulpfile.js +37 -37
- package/package.json +41 -41
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { execSync, execFileSync } from 'child_process';
|
|
4
|
-
|
|
5
|
-
// ============================================
|
|
6
|
-
// SSH ヘルパー関数(外部からも利用可能)
|
|
7
|
-
// ============================================
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* SSH 接続パラメータを取得
|
|
11
|
-
* @param {string} [prefix='PRD'] 環境変数プレフィックス('PRD' or 'STG' or 'DEV')
|
|
12
|
-
* @returns {{ host: string, user: string, port: string, keyFile: string | undefined }}
|
|
13
|
-
*/
|
|
14
|
-
export function getSSHConfig(prefix = 'PRD') {
|
|
15
|
-
const host = process.env[`${prefix}_SSH_HOST`];
|
|
16
|
-
const user = process.env[`${prefix}_SSH_USER`];
|
|
17
|
-
const port = process.env[`${prefix}_SSH_PORT`] || '22';
|
|
18
|
-
const keyFile = process.env[`${prefix}_SSH_KEY`];
|
|
19
|
-
|
|
20
|
-
if (!host || !user) {
|
|
21
|
-
throw new Error(`${prefix}_SSH_HOST と ${prefix}_SSH_USER を .env に設定してください`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return { host, user, port, keyFile };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* SSH でリモートコマンドを実行
|
|
29
|
-
* @param {string} command 実行するコマンド
|
|
30
|
-
* @param {object} [options] オプション
|
|
31
|
-
* @param {boolean} [options.ignoreError] エラーを無視するか
|
|
32
|
-
* @param {boolean} [options.capture] 出力を文字列で返すか(true: pipe, false: inherit)
|
|
33
|
-
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
34
|
-
* @returns {string} 標準出力
|
|
35
|
-
*/
|
|
36
|
-
export function sshExec(command, options = {}) {
|
|
37
|
-
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
38
|
-
|
|
39
|
-
const sshCliArgs = ['-o', 'StrictHostKeyChecking=accept-new', '-p', port];
|
|
40
|
-
if (keyFile) {
|
|
41
|
-
sshCliArgs.push('-i', keyFile);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const wrappedCommand = `export PATH=/usr/local/bin:$PATH && ${command}`;
|
|
45
|
-
sshCliArgs.push(`${user}@${host}`, wrappedCommand);
|
|
46
|
-
|
|
47
|
-
console.log(`SSH: ${command}`);
|
|
48
|
-
try {
|
|
49
|
-
const stdio = options.capture ? 'pipe' : options.ignoreError ? 'pipe' : 'inherit';
|
|
50
|
-
return execFileSync('ssh', sshCliArgs, { stdio, encoding: 'utf-8' }) || '';
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (options.ignoreError) {
|
|
53
|
-
return '';
|
|
54
|
-
}
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* SCP でローカルファイル/ディレクトリをリモートに転送
|
|
61
|
-
* @param {string} localPath ローカルパス
|
|
62
|
-
* @param {string} remotePath リモートパス
|
|
63
|
-
* @param {object} [options] オプション
|
|
64
|
-
* @param {boolean} [options.recursive] ディレクトリを再帰的に転送
|
|
65
|
-
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
66
|
-
*/
|
|
67
|
-
export function scpUpload(localPath, remotePath, options = {}) {
|
|
68
|
-
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
69
|
-
|
|
70
|
-
const scpCliArgs = ['-O', '-o', 'StrictHostKeyChecking=accept-new', '-P', port];
|
|
71
|
-
if (keyFile) {
|
|
72
|
-
scpCliArgs.push('-i', keyFile);
|
|
73
|
-
}
|
|
74
|
-
if (options.recursive) {
|
|
75
|
-
scpCliArgs.push('-r');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const normalizedPath = localPath.replace(/\\/g, '/');
|
|
79
|
-
scpCliArgs.push(normalizedPath, `${user}@${host}:${remotePath}`);
|
|
80
|
-
console.log(`SCP: ${localPath} → ${remotePath}`);
|
|
81
|
-
execFileSync('scp', scpCliArgs, { stdio: 'inherit' });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* SCP でリモートファイル/ディレクトリをローカルにダウンロード
|
|
86
|
-
* @param {string} remotePath リモートパス
|
|
87
|
-
* @param {string} localPath ローカルパス
|
|
88
|
-
* @param {object} [options] オプション
|
|
89
|
-
* @param {boolean} [options.recursive] ディレクトリを再帰的に転送
|
|
90
|
-
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
91
|
-
*/
|
|
92
|
-
export function scpDownload(remotePath, localPath, options = {}) {
|
|
93
|
-
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
94
|
-
|
|
95
|
-
const scpCliArgs = ['-O', '-o', 'StrictHostKeyChecking=accept-new', '-P', port];
|
|
96
|
-
if (keyFile) {
|
|
97
|
-
scpCliArgs.push('-i', keyFile);
|
|
98
|
-
}
|
|
99
|
-
if (options.recursive) {
|
|
100
|
-
scpCliArgs.push('-r');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
scpCliArgs.push(`${user}@${host}:${remotePath}`, localPath);
|
|
104
|
-
console.log(`SCP: ${host}:${remotePath} → ${localPath}`);
|
|
105
|
-
execFileSync('scp', scpCliArgs, { stdio: 'inherit' });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ============================================
|
|
109
|
-
// Gulp タスク登録(最小限)
|
|
110
|
-
// ============================================
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* SSH 運用タスクを gulp に登録する
|
|
114
|
-
* @param {import('gulp').Gulp} gulp - Gulp インスタンス
|
|
115
|
-
* @param {{ prefix?: string }} [options] - オプション
|
|
116
|
-
* @param {string} [options.prefix='PRD'] - 環境変数プレフィックス
|
|
117
|
-
*/
|
|
118
|
-
export default function (gulp, options = {}) {
|
|
119
|
-
const prefix = options.prefix || 'PRD';
|
|
120
|
-
|
|
121
|
-
gulp.task('ssh:ping', (done) => {
|
|
122
|
-
try {
|
|
123
|
-
const { host } = getSSHConfig(prefix);
|
|
124
|
-
console.log(`=== ${host} への SSH 接続テスト ===`);
|
|
125
|
-
sshExec('echo "SSH 接続成功: $(hostname) / $(date)"', { prefix });
|
|
126
|
-
done();
|
|
127
|
-
} catch (error) {
|
|
128
|
-
done(error);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
gulp.task('ssh:login', (done) => {
|
|
133
|
-
try {
|
|
134
|
-
const { host, user, port, keyFile } = getSSHConfig(prefix);
|
|
135
|
-
console.log(`=== ${host} にログイン ===`);
|
|
136
|
-
|
|
137
|
-
const sshArgs = ['-o StrictHostKeyChecking=accept-new', `-p ${port}`];
|
|
138
|
-
if (keyFile) {
|
|
139
|
-
sshArgs.push(`-i "${keyFile}"`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
execSync(`ssh ${sshArgs.join(' ')} ${user}@${host}`, { stdio: 'inherit' });
|
|
143
|
-
done();
|
|
144
|
-
} catch (error) {
|
|
145
|
-
done(error);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
gulp.task('ssh:info', (done) => {
|
|
150
|
-
try {
|
|
151
|
-
const { host } = getSSHConfig(prefix);
|
|
152
|
-
console.log(`=== ${host} サーバー情報 ===`);
|
|
153
|
-
sshExec([
|
|
154
|
-
'echo "--- ホスト名 ---" && hostname',
|
|
155
|
-
'echo "--- OS ---" && uname -a',
|
|
156
|
-
'echo "--- ディスク使用量 ---" && df -h / 2>/dev/null',
|
|
157
|
-
'echo "--- メモリ ---" && free -h 2>/dev/null || echo "free コマンドなし"',
|
|
158
|
-
].join(' && '), { prefix });
|
|
159
|
-
done();
|
|
160
|
-
} catch (error) {
|
|
161
|
-
done(error);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
gulp.task('ssh:help', (done) => {
|
|
166
|
-
console.log(`
|
|
167
|
-
SSH 運用タスク一覧
|
|
168
|
-
==================
|
|
169
|
-
|
|
170
|
-
ssh:ping SSH 接続テスト
|
|
171
|
-
ssh:login SSH ログイン(対話シェル)
|
|
172
|
-
ssh:info サーバー情報表示
|
|
173
|
-
|
|
174
|
-
環境変数(.env に設定):
|
|
175
|
-
<PREFIX>_SSH_HOST SSH ホスト(必須)
|
|
176
|
-
<PREFIX>_SSH_USER SSH ユーザー名(必須)
|
|
177
|
-
<PREFIX>_SSH_PORT SSH ポート(デフォルト: 22)
|
|
178
|
-
<PREFIX>_SSH_KEY SSH 鍵ファイルパス
|
|
179
|
-
|
|
180
|
-
※ PREFIX のデフォルトは PRD(例: PRD_SSH_HOST)
|
|
181
|
-
|
|
182
|
-
ヘルパー関数(import して利用):
|
|
183
|
-
getSSHConfig(prefix) 接続パラメータ取得
|
|
184
|
-
sshExec(command, options) リモートコマンド実行
|
|
185
|
-
scpUpload(localPath, remotePath, options) ファイルアップロード
|
|
186
|
-
scpDownload(remotePath, localPath, options) ファイルダウンロード
|
|
187
|
-
`);
|
|
188
|
-
done();
|
|
189
|
-
});
|
|
190
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { execSync, execFileSync } from 'child_process';
|
|
4
|
+
|
|
5
|
+
// ============================================
|
|
6
|
+
// SSH ヘルパー関数(外部からも利用可能)
|
|
7
|
+
// ============================================
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SSH 接続パラメータを取得
|
|
11
|
+
* @param {string} [prefix='PRD'] 環境変数プレフィックス('PRD' or 'STG' or 'DEV')
|
|
12
|
+
* @returns {{ host: string, user: string, port: string, keyFile: string | undefined }}
|
|
13
|
+
*/
|
|
14
|
+
export function getSSHConfig(prefix = 'PRD') {
|
|
15
|
+
const host = process.env[`${prefix}_SSH_HOST`];
|
|
16
|
+
const user = process.env[`${prefix}_SSH_USER`];
|
|
17
|
+
const port = process.env[`${prefix}_SSH_PORT`] || '22';
|
|
18
|
+
const keyFile = process.env[`${prefix}_SSH_KEY`];
|
|
19
|
+
|
|
20
|
+
if (!host || !user) {
|
|
21
|
+
throw new Error(`${prefix}_SSH_HOST と ${prefix}_SSH_USER を .env に設定してください`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { host, user, port, keyFile };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* SSH でリモートコマンドを実行
|
|
29
|
+
* @param {string} command 実行するコマンド
|
|
30
|
+
* @param {object} [options] オプション
|
|
31
|
+
* @param {boolean} [options.ignoreError] エラーを無視するか
|
|
32
|
+
* @param {boolean} [options.capture] 出力を文字列で返すか(true: pipe, false: inherit)
|
|
33
|
+
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
34
|
+
* @returns {string} 標準出力
|
|
35
|
+
*/
|
|
36
|
+
export function sshExec(command, options = {}) {
|
|
37
|
+
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
38
|
+
|
|
39
|
+
const sshCliArgs = ['-o', 'StrictHostKeyChecking=accept-new', '-p', port];
|
|
40
|
+
if (keyFile) {
|
|
41
|
+
sshCliArgs.push('-i', keyFile);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const wrappedCommand = `export PATH=/usr/local/bin:$PATH && ${command}`;
|
|
45
|
+
sshCliArgs.push(`${user}@${host}`, wrappedCommand);
|
|
46
|
+
|
|
47
|
+
console.log(`SSH: ${command}`);
|
|
48
|
+
try {
|
|
49
|
+
const stdio = options.capture ? 'pipe' : options.ignoreError ? 'pipe' : 'inherit';
|
|
50
|
+
return execFileSync('ssh', sshCliArgs, { stdio, encoding: 'utf-8' }) || '';
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (options.ignoreError) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* SCP でローカルファイル/ディレクトリをリモートに転送
|
|
61
|
+
* @param {string} localPath ローカルパス
|
|
62
|
+
* @param {string} remotePath リモートパス
|
|
63
|
+
* @param {object} [options] オプション
|
|
64
|
+
* @param {boolean} [options.recursive] ディレクトリを再帰的に転送
|
|
65
|
+
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
66
|
+
*/
|
|
67
|
+
export function scpUpload(localPath, remotePath, options = {}) {
|
|
68
|
+
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
69
|
+
|
|
70
|
+
const scpCliArgs = ['-O', '-o', 'StrictHostKeyChecking=accept-new', '-P', port];
|
|
71
|
+
if (keyFile) {
|
|
72
|
+
scpCliArgs.push('-i', keyFile);
|
|
73
|
+
}
|
|
74
|
+
if (options.recursive) {
|
|
75
|
+
scpCliArgs.push('-r');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const normalizedPath = localPath.replace(/\\/g, '/');
|
|
79
|
+
scpCliArgs.push(normalizedPath, `${user}@${host}:${remotePath}`);
|
|
80
|
+
console.log(`SCP: ${localPath} → ${remotePath}`);
|
|
81
|
+
execFileSync('scp', scpCliArgs, { stdio: 'inherit' });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* SCP でリモートファイル/ディレクトリをローカルにダウンロード
|
|
86
|
+
* @param {string} remotePath リモートパス
|
|
87
|
+
* @param {string} localPath ローカルパス
|
|
88
|
+
* @param {object} [options] オプション
|
|
89
|
+
* @param {boolean} [options.recursive] ディレクトリを再帰的に転送
|
|
90
|
+
* @param {string} [options.prefix] 環境変数プレフィックス(デフォルト: 'PRD')
|
|
91
|
+
*/
|
|
92
|
+
export function scpDownload(remotePath, localPath, options = {}) {
|
|
93
|
+
const { host, user, port, keyFile } = getSSHConfig(options.prefix || 'PRD');
|
|
94
|
+
|
|
95
|
+
const scpCliArgs = ['-O', '-o', 'StrictHostKeyChecking=accept-new', '-P', port];
|
|
96
|
+
if (keyFile) {
|
|
97
|
+
scpCliArgs.push('-i', keyFile);
|
|
98
|
+
}
|
|
99
|
+
if (options.recursive) {
|
|
100
|
+
scpCliArgs.push('-r');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
scpCliArgs.push(`${user}@${host}:${remotePath}`, localPath);
|
|
104
|
+
console.log(`SCP: ${host}:${remotePath} → ${localPath}`);
|
|
105
|
+
execFileSync('scp', scpCliArgs, { stdio: 'inherit' });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ============================================
|
|
109
|
+
// Gulp タスク登録(最小限)
|
|
110
|
+
// ============================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* SSH 運用タスクを gulp に登録する
|
|
114
|
+
* @param {import('gulp').Gulp} gulp - Gulp インスタンス
|
|
115
|
+
* @param {{ prefix?: string }} [options] - オプション
|
|
116
|
+
* @param {string} [options.prefix='PRD'] - 環境変数プレフィックス
|
|
117
|
+
*/
|
|
118
|
+
export default function (gulp, options = {}) {
|
|
119
|
+
const prefix = options.prefix || 'PRD';
|
|
120
|
+
|
|
121
|
+
gulp.task('ssh:ping', (done) => {
|
|
122
|
+
try {
|
|
123
|
+
const { host } = getSSHConfig(prefix);
|
|
124
|
+
console.log(`=== ${host} への SSH 接続テスト ===`);
|
|
125
|
+
sshExec('echo "SSH 接続成功: $(hostname) / $(date)"', { prefix });
|
|
126
|
+
done();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
done(error);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
gulp.task('ssh:login', (done) => {
|
|
133
|
+
try {
|
|
134
|
+
const { host, user, port, keyFile } = getSSHConfig(prefix);
|
|
135
|
+
console.log(`=== ${host} にログイン ===`);
|
|
136
|
+
|
|
137
|
+
const sshArgs = ['-o StrictHostKeyChecking=accept-new', `-p ${port}`];
|
|
138
|
+
if (keyFile) {
|
|
139
|
+
sshArgs.push(`-i "${keyFile}"`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
execSync(`ssh ${sshArgs.join(' ')} ${user}@${host}`, { stdio: 'inherit' });
|
|
143
|
+
done();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
done(error);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
gulp.task('ssh:info', (done) => {
|
|
150
|
+
try {
|
|
151
|
+
const { host } = getSSHConfig(prefix);
|
|
152
|
+
console.log(`=== ${host} サーバー情報 ===`);
|
|
153
|
+
sshExec([
|
|
154
|
+
'echo "--- ホスト名 ---" && hostname',
|
|
155
|
+
'echo "--- OS ---" && uname -a',
|
|
156
|
+
'echo "--- ディスク使用量 ---" && df -h / 2>/dev/null',
|
|
157
|
+
'echo "--- メモリ ---" && free -h 2>/dev/null || echo "free コマンドなし"',
|
|
158
|
+
].join(' && '), { prefix });
|
|
159
|
+
done();
|
|
160
|
+
} catch (error) {
|
|
161
|
+
done(error);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
gulp.task('ssh:help', (done) => {
|
|
166
|
+
console.log(`
|
|
167
|
+
SSH 運用タスク一覧
|
|
168
|
+
==================
|
|
169
|
+
|
|
170
|
+
ssh:ping SSH 接続テスト
|
|
171
|
+
ssh:login SSH ログイン(対話シェル)
|
|
172
|
+
ssh:info サーバー情報表示
|
|
173
|
+
|
|
174
|
+
環境変数(.env に設定):
|
|
175
|
+
<PREFIX>_SSH_HOST SSH ホスト(必須)
|
|
176
|
+
<PREFIX>_SSH_USER SSH ユーザー名(必須)
|
|
177
|
+
<PREFIX>_SSH_PORT SSH ポート(デフォルト: 22)
|
|
178
|
+
<PREFIX>_SSH_KEY SSH 鍵ファイルパス
|
|
179
|
+
|
|
180
|
+
※ PREFIX のデフォルトは PRD(例: PRD_SSH_HOST)
|
|
181
|
+
|
|
182
|
+
ヘルパー関数(import して利用):
|
|
183
|
+
getSSHConfig(prefix) 接続パラメータ取得
|
|
184
|
+
sshExec(command, options) リモートコマンド実行
|
|
185
|
+
scpUpload(localPath, remotePath, options) ファイルアップロード
|
|
186
|
+
scpDownload(remotePath, localPath, options) ファイルダウンロード
|
|
187
|
+
`);
|
|
188
|
+
done();
|
|
189
|
+
});
|
|
190
|
+
}
|