-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.mjs
More file actions
72 lines (59 loc) · 2.18 KB
/
cli.mjs
File metadata and controls
72 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
/**
* WG4 翻訳作業支援ツール統合CLI
*
* 使い方:
* wg4 lint <dir> [--fix] - textlintを実行
* wg4 check-transitions [base] - 翻訳揺れをチェック
* wg4 --help - ヘルプを表示
* wg4 <dir> [--fix] - レガシー互換(lint と同じ)
*/
import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const args = process.argv.slice(2)
const command = args[0]
function showHelp() {
console.log(`
WG4 翻訳作業支援ツール
使い方:
wg4 lint <dir> [--fix] textlintを実行
wg4 check-transitions [base] 翻訳揺れをチェック(デフォルト: waic-main)
wg4 --help このヘルプを表示
wg4 <dir> [--fix] レガシー互換(lint と同じ)
サブコマンド:
lint HTMLファイルに対してtextlintを実行します
--fix オプションで自動修正を行います
check-transitions 現在のブランチとベースブランチの差分から
翻訳揺れを検出します
例:
wg4 lint ./docs
wg4 lint ./docs --fix
wg4 check-transitions
wg4 check-transitions waic-main
`)
}
function runTextlint(args) {
const textlintCli = path.join(__dirname, 'tools', 'textlint', 'cli.mjs')
const child = spawn('node', [textlintCli, ...args], { stdio: 'inherit' })
child.on('close', (code) => process.exit(code))
}
function runCheckTransitions(args) {
const checkTransitionsCli = path.join(__dirname, 'tools', 'check-transitions', 'cli.mjs')
const child = spawn('node', [checkTransitionsCli, ...args], { stdio: 'inherit' })
child.on('close', (code) => process.exit(code))
}
// メイン処理
if (!command || command === '--help' || command === '-h') {
showHelp()
process.exit(0)
}
if (command === 'lint') {
runTextlint(args.slice(1))
} else if (command === 'check-transitions') {
runCheckTransitions(args.slice(1))
} else {
// レガシー互換: サブコマンドなしでディレクトリが指定された場合は lint として扱う
runTextlint(args)
}