@goqoo/trunks 0.1.0 → 0.3.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/README.ja.md +214 -0
- package/README.md +214 -0
- package/dist/cli.js +8 -1
- package/dist/generate.js +45 -6
- package/dist/types.d.ts +4 -1
- package/package.json +13 -1
- package/.claude/settings.local.json +0 -7
- package/.prettierignore +0 -1
- package/.prettierrc.js +0 -5
- package/CLAUDE.md +0 -71
- package/dts/activity-fields.d.ts +0 -25
- package/dts/customer-fields.d.ts +0 -28
- package/dts/project-fields.d.ts +0 -30
- package/jest.config.js +0 -19
- package/src/cli.ts +0 -28
- package/src/config.ts +0 -23
- package/src/generate.ts +0 -238
- package/src/index.ts +0 -14
- package/src/oauth.ts +0 -14
- package/src/types.ts +0 -63
- package/test/config.test.ts +0 -15
- package/test/generate.test.ts +0 -32
- package/test/types.test.ts +0 -116
- package/trunks.config.ts +0 -18
- package/tsconfig.json +0 -16
package/README.ja.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# trunks
|
|
2
|
+
|
|
3
|
+
[](https://nodejs.org/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
[English](/README.md) | 日本語
|
|
7
|
+
|
|
8
|
+
[@kintone/dts-gen](https://github.com/kintone/js-sdk/tree/main/packages/dts-gen) のラッパー CLI ツール。設定ファイル1つで複数の kintone アプリの TypeScript 型定義を一括生成します。
|
|
9
|
+
|
|
10
|
+
## 特徴
|
|
11
|
+
|
|
12
|
+
- 1コマンドで複数アプリの型定義を生成
|
|
13
|
+
- TypeScript 設定ファイルで型安全な設定(`trunks.config.ts`)
|
|
14
|
+
- 複数の認証方式に対応(パスワード、API トークン、OAuth)
|
|
15
|
+
- Prettier による自動フォーマット(オプション)
|
|
16
|
+
- プレビュー環境・ゲストスペースに対応
|
|
17
|
+
|
|
18
|
+
## クイックスタート
|
|
19
|
+
|
|
20
|
+
1. プロジェクトルートに設定ファイル `trunks.config.ts` を作成:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { defineConfig } from '@goqoo/trunks';
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
host: 'your-subdomain.cybozu.com',
|
|
27
|
+
apps: {
|
|
28
|
+
customer: 123,
|
|
29
|
+
order: 456,
|
|
30
|
+
product: 789,
|
|
31
|
+
},
|
|
32
|
+
auth: { type: 'oauth' },
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. コマンドを実行:
|
|
37
|
+
|
|
38
|
+
グローバルインストールあり:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g @goqoo/trunks
|
|
42
|
+
trunks
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
グローバルインストールなし:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx @goqoo/trunks
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. `dts/` ディレクトリに型定義ファイルが生成されます:
|
|
52
|
+
- `dts/customer-fields.d.ts`
|
|
53
|
+
- `dts/order-fields.d.ts`
|
|
54
|
+
- `dts/product-fields.d.ts`
|
|
55
|
+
|
|
56
|
+
## 設定
|
|
57
|
+
|
|
58
|
+
### 基本設定
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { defineConfig } from '@goqoo/trunks';
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
// 必須
|
|
65
|
+
host: 'your-subdomain.cybozu.com',
|
|
66
|
+
apps: {
|
|
67
|
+
customer: 123, // { アプリ名: アプリID }
|
|
68
|
+
order: 456,
|
|
69
|
+
},
|
|
70
|
+
auth: { type: 'oauth' },
|
|
71
|
+
|
|
72
|
+
// オプション
|
|
73
|
+
outDir: 'dts', // 出力ディレクトリ(デフォルト: "dts")
|
|
74
|
+
preview: false, // プレビュー環境を使用(デフォルト: false)
|
|
75
|
+
guestSpaceId: 5, // ゲストスペース ID(該当する場合)
|
|
76
|
+
namespace: 'kintone.types', // TypeScript の namespace(デフォルト: "kintone.types")
|
|
77
|
+
format: true, // Prettier でフォーマット(デフォルト: false)
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 認証方式
|
|
82
|
+
|
|
83
|
+
環境変数はプロジェクトルートの `.env` ファイルに設定できます:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# .env
|
|
87
|
+
KINTONE_USERNAME=your-username
|
|
88
|
+
KINTONE_PASSWORD=your-password
|
|
89
|
+
KINTONE_API_TOKEN=your-api-token
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> **注意**: 設定ファイルに認証情報を直書きする場合は、設定ファイルを `.gitignore` に追加して、バージョン管理に機密情報がコミットされないようにしてください。環境変数(`.env` ファイル)または標準入力の使用を推奨します。
|
|
93
|
+
|
|
94
|
+
#### パスワード
|
|
95
|
+
|
|
96
|
+
認証情報は設定ファイル、環境変数 `KINTONE_USERNAME` と `KINTONE_PASSWORD`、または標準入力から取得します(この優先順位)。
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
auth: { type: 'password' },
|
|
100
|
+
// または直書き(非推奨)
|
|
101
|
+
auth: { type: 'password', username: 'user', password: 'pass' },
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### API トークン
|
|
105
|
+
|
|
106
|
+
トークンは設定ファイル、環境変数 `KINTONE_API_TOKEN`、または標準入力から取得します(この優先順位)。
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
auth: { type: 'api-token' },
|
|
110
|
+
// または直書き(非推奨)
|
|
111
|
+
auth: { type: 'api-token', token: 'your-token' },
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
複数アプリの場合は `.env` でカンマ区切りで指定:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
KINTONE_API_TOKEN=token1,token2,token3
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### OAuth
|
|
121
|
+
|
|
122
|
+
[Gyuma](https://github.com/nicecai/gyuma) を使用した OAuth 認証。ブラウザが開いて認証を行います。
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
auth: {
|
|
126
|
+
type: 'oauth',
|
|
127
|
+
scope: 'k:app_settings:read', // オプション: カスタムスコープ
|
|
128
|
+
},
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### その他のオプション
|
|
132
|
+
|
|
133
|
+
#### Basic 認証
|
|
134
|
+
|
|
135
|
+
Basic 認証が必要な環境の場合:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
basicAuth: {
|
|
139
|
+
username: 'basic-user',
|
|
140
|
+
password: 'basic-password',
|
|
141
|
+
},
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### プロキシ
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
proxy: {
|
|
148
|
+
host: 'proxy.example.com',
|
|
149
|
+
port: 8080,
|
|
150
|
+
},
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### クライアント証明書(OAuth 用)
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
pfx: {
|
|
157
|
+
filepath: '/path/to/cert.pfx',
|
|
158
|
+
password: 'certificate-password',
|
|
159
|
+
},
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## CLI オプション
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
trunks [options]
|
|
166
|
+
|
|
167
|
+
Options:
|
|
168
|
+
-c, --config <path> 設定ファイルのパス(デフォルト: 自動検出)
|
|
169
|
+
-h, --help ヘルプを表示
|
|
170
|
+
-V, --version バージョンを表示
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 生成される出力
|
|
174
|
+
|
|
175
|
+
アプリ名 `customer`(ID: 123)の場合、以下のファイルが生成されます:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// dts/customer-fields.d.ts
|
|
179
|
+
declare namespace kintone.types {
|
|
180
|
+
interface CustomerFields {
|
|
181
|
+
companyName: kintone.fieldTypes.SingleLineText;
|
|
182
|
+
email: kintone.fieldTypes.Link;
|
|
183
|
+
// ...
|
|
184
|
+
}
|
|
185
|
+
interface SavedCustomerFields extends CustomerFields {
|
|
186
|
+
$id: kintone.fieldTypes.Id;
|
|
187
|
+
$revision: kintone.fieldTypes.Revision;
|
|
188
|
+
// ...
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 開発
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# ビルド
|
|
197
|
+
yarn build
|
|
198
|
+
|
|
199
|
+
# テスト
|
|
200
|
+
yarn test
|
|
201
|
+
|
|
202
|
+
# ウォッチモード
|
|
203
|
+
yarn dev
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 関連プロジェクト
|
|
207
|
+
|
|
208
|
+
- [@kintone/dts-gen](https://github.com/kintone/js-sdk/tree/main/packages/dts-gen) - 型定義生成の本体
|
|
209
|
+
- [Gyuma](https://github.com/nicecai/gyuma) - kintone の OAuth 認証
|
|
210
|
+
- [gotenks](https://github.com/goqoo-on-kintone/gotenks) - kintone TypeScript 型を Go 型に変換
|
|
211
|
+
|
|
212
|
+
## ライセンス
|
|
213
|
+
|
|
214
|
+
MIT License - 詳細は [LICENSE](LICENSE) を参照してください。
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# trunks
|
|
2
|
+
|
|
3
|
+
[](https://nodejs.org/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
English | [日本語](/README.ja.md)
|
|
7
|
+
|
|
8
|
+
A CLI wrapper for [@kintone/dts-gen](https://github.com/kintone/js-sdk/tree/main/packages/dts-gen) that generates TypeScript type definitions for multiple Kintone apps with a single configuration file.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Generate type definitions for multiple apps in one command
|
|
13
|
+
- TypeScript configuration file with type safety (`trunks.config.ts`)
|
|
14
|
+
- Multiple authentication methods (Password, API Token, OAuth)
|
|
15
|
+
- Optional Prettier formatting for generated files
|
|
16
|
+
- Support for preview environments and guest spaces
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
1. Create a configuration file `trunks.config.ts` in your project root:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { defineConfig } from '@goqoo/trunks';
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
host: 'your-subdomain.cybozu.com',
|
|
27
|
+
apps: {
|
|
28
|
+
customer: 123,
|
|
29
|
+
order: 456,
|
|
30
|
+
product: 789,
|
|
31
|
+
},
|
|
32
|
+
auth: { type: 'oauth' },
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. Run the command:
|
|
37
|
+
|
|
38
|
+
With global installation:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g @goqoo/trunks
|
|
42
|
+
trunks
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Without global installation:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx @goqoo/trunks
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. Type definition files will be generated in the `dts/` directory:
|
|
52
|
+
- `dts/customer-fields.d.ts`
|
|
53
|
+
- `dts/order-fields.d.ts`
|
|
54
|
+
- `dts/product-fields.d.ts`
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
### Basic Configuration
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { defineConfig } from '@goqoo/trunks';
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
// Required
|
|
65
|
+
host: 'your-subdomain.cybozu.com',
|
|
66
|
+
apps: {
|
|
67
|
+
customer: 123, // { appName: appId }
|
|
68
|
+
order: 456,
|
|
69
|
+
},
|
|
70
|
+
auth: { type: 'oauth' },
|
|
71
|
+
|
|
72
|
+
// Optional
|
|
73
|
+
outDir: 'dts', // Output directory (default: "dts")
|
|
74
|
+
preview: false, // Use preview environment (default: false)
|
|
75
|
+
guestSpaceId: 5, // Guest space ID (if applicable)
|
|
76
|
+
namespace: 'kintone.types', // TypeScript namespace (default: "kintone.types")
|
|
77
|
+
format: true, // Format with Prettier (default: false)
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Authentication Methods
|
|
82
|
+
|
|
83
|
+
Environment variables can be set in a `.env` file in your project root:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# .env
|
|
87
|
+
KINTONE_USERNAME=your-username
|
|
88
|
+
KINTONE_PASSWORD=your-password
|
|
89
|
+
KINTONE_API_TOKEN=your-api-token
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> **Warning**: If you write credentials directly in the config file, make sure to add the config file to `.gitignore` to avoid committing sensitive information to version control. Using environment variables (`.env` file) or stdin prompts is recommended.
|
|
93
|
+
|
|
94
|
+
#### Password
|
|
95
|
+
|
|
96
|
+
Credentials are read from the config file, environment variables `KINTONE_USERNAME` and `KINTONE_PASSWORD`, or prompted via stdin (in that order of priority).
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
auth: { type: 'password' },
|
|
100
|
+
// Or with direct credentials (not recommended)
|
|
101
|
+
auth: { type: 'password', username: 'user', password: 'pass' },
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### API Token
|
|
105
|
+
|
|
106
|
+
Token is read from the config file, environment variable `KINTONE_API_TOKEN`, or prompted via stdin (in that order of priority).
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
auth: { type: 'api-token' },
|
|
110
|
+
// Or with direct token (not recommended)
|
|
111
|
+
auth: { type: 'api-token', token: 'your-token' },
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For multiple apps, use comma-separated tokens in `.env`:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
KINTONE_API_TOKEN=token1,token2,token3
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### OAuth
|
|
121
|
+
|
|
122
|
+
Uses [Gyuma](https://github.com/nicecai/gyuma) for OAuth authentication. A browser window will open for authentication.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
auth: {
|
|
126
|
+
type: 'oauth',
|
|
127
|
+
scope: 'k:app_settings:read', // Optional: custom scope
|
|
128
|
+
},
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Additional Options
|
|
132
|
+
|
|
133
|
+
#### Basic Authentication
|
|
134
|
+
|
|
135
|
+
For environments that require basic authentication:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
basicAuth: {
|
|
139
|
+
username: 'basic-user',
|
|
140
|
+
password: 'basic-password',
|
|
141
|
+
},
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Proxy
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
proxy: {
|
|
148
|
+
host: 'proxy.example.com',
|
|
149
|
+
port: 8080,
|
|
150
|
+
},
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Client Certificate (for OAuth)
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
pfx: {
|
|
157
|
+
filepath: '/path/to/cert.pfx',
|
|
158
|
+
password: 'certificate-password',
|
|
159
|
+
},
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## CLI Options
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
trunks [options]
|
|
166
|
+
|
|
167
|
+
Options:
|
|
168
|
+
-c, --config <path> Path to config file (default: auto-detect)
|
|
169
|
+
-h, --help Display help
|
|
170
|
+
-V, --version Display version
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Generated Output
|
|
174
|
+
|
|
175
|
+
For an app named `customer` (ID: 123), the following file is generated:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// dts/customer-fields.d.ts
|
|
179
|
+
declare namespace kintone.types {
|
|
180
|
+
interface CustomerFields {
|
|
181
|
+
companyName: kintone.fieldTypes.SingleLineText;
|
|
182
|
+
email: kintone.fieldTypes.Link;
|
|
183
|
+
// ...
|
|
184
|
+
}
|
|
185
|
+
interface SavedCustomerFields extends CustomerFields {
|
|
186
|
+
$id: kintone.fieldTypes.Id;
|
|
187
|
+
$revision: kintone.fieldTypes.Revision;
|
|
188
|
+
// ...
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Build
|
|
197
|
+
yarn build
|
|
198
|
+
|
|
199
|
+
# Test
|
|
200
|
+
yarn test
|
|
201
|
+
|
|
202
|
+
# Watch mode
|
|
203
|
+
yarn dev
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Related Projects
|
|
207
|
+
|
|
208
|
+
- [@kintone/dts-gen](https://github.com/kintone/js-sdk/tree/main/packages/dts-gen) - The underlying type definition generator
|
|
209
|
+
- [Gyuma](https://github.com/nicecai/gyuma) - OAuth authentication for Kintone
|
|
210
|
+
- [gotenks](https://github.com/goqoo-on-kintone/gotenks) - Convert kintone TypeScript types to Go types
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { config as loadEnv } from 'dotenv';
|
|
2
4
|
import { Command } from 'commander';
|
|
3
5
|
import chalk from 'chalk';
|
|
4
6
|
import { loadConfig } from './config.js';
|
|
5
7
|
import { generate } from './generate.js';
|
|
8
|
+
// package.jsonからバージョンを取得
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const { version } = require('../package.json');
|
|
11
|
+
// .envファイルがあれば環境変数として読み込む
|
|
12
|
+
loadEnv({ quiet: true });
|
|
6
13
|
const program = new Command();
|
|
7
14
|
program
|
|
8
15
|
.name('trunks')
|
|
9
16
|
.description('Generate TypeScript type definitions for multiple Kintone apps')
|
|
10
|
-
.version(
|
|
17
|
+
.version(version);
|
|
11
18
|
program
|
|
12
19
|
.command('generate', { isDefault: true })
|
|
13
20
|
.description('Generate type definitions for all configured apps')
|
package/dist/generate.js
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
1
|
+
import { spawn, spawnSync } from 'child_process';
|
|
2
2
|
import { mkdirSync } from 'fs';
|
|
3
3
|
import * as readline from 'readline';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { kebabCase, pascalCase } from 'change-case';
|
|
6
6
|
import { getOauthToken } from './oauth.js';
|
|
7
|
+
// npx prettierが実行可能かチェック
|
|
8
|
+
function isPrettierAvailable() {
|
|
9
|
+
const result = spawnSync('npx', ['prettier', '--version'], {
|
|
10
|
+
stdio: 'pipe',
|
|
11
|
+
encoding: 'utf-8',
|
|
12
|
+
});
|
|
13
|
+
return result.status === 0;
|
|
14
|
+
}
|
|
15
|
+
// Prettierでファイルをフォーマット
|
|
16
|
+
function formatWithPrettier(filePath) {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const proc = spawn('npx', ['prettier', '--write', filePath], {
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
stdio: 'pipe',
|
|
21
|
+
});
|
|
22
|
+
proc.on('close', (code) => {
|
|
23
|
+
resolve(code === 0);
|
|
24
|
+
});
|
|
25
|
+
proc.on('error', () => {
|
|
26
|
+
resolve(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
7
30
|
// 標準入力からテキストを取得
|
|
8
31
|
function prompt(question) {
|
|
9
32
|
const rl = readline.createInterface({
|
|
@@ -67,9 +90,10 @@ async function buildAuthArgs(config) {
|
|
|
67
90
|
const args = {};
|
|
68
91
|
switch (config.auth.type) {
|
|
69
92
|
case 'password': {
|
|
70
|
-
|
|
71
|
-
let
|
|
72
|
-
|
|
93
|
+
// 設定ファイル → 環境変数 → 標準入力の優先順位
|
|
94
|
+
let username = config.auth.username ?? process.env.KINTONE_USERNAME;
|
|
95
|
+
let password = config.auth.password ?? process.env.KINTONE_PASSWORD;
|
|
96
|
+
// 未設定の場合は標準入力で取得
|
|
73
97
|
if (!username) {
|
|
74
98
|
username = await prompt('Kintone Username: ');
|
|
75
99
|
}
|
|
@@ -93,9 +117,18 @@ async function buildAuthArgs(config) {
|
|
|
93
117
|
args['oauth-token'] = oauthToken;
|
|
94
118
|
break;
|
|
95
119
|
}
|
|
96
|
-
case 'api-token':
|
|
97
|
-
|
|
120
|
+
case 'api-token': {
|
|
121
|
+
// 設定ファイル → 環境変数 → 標準入力の優先順位
|
|
122
|
+
let token = config.auth.token ?? process.env.KINTONE_API_TOKEN;
|
|
123
|
+
if (!token) {
|
|
124
|
+
token = await promptPassword('Kintone API Token: ');
|
|
125
|
+
}
|
|
126
|
+
if (!token) {
|
|
127
|
+
throw new Error('API token is required for api-token auth');
|
|
128
|
+
}
|
|
129
|
+
args['api-token'] = token;
|
|
98
130
|
break;
|
|
131
|
+
}
|
|
99
132
|
}
|
|
100
133
|
// Basic認証
|
|
101
134
|
if (config.basicAuth) {
|
|
@@ -186,12 +219,18 @@ export async function generate(config) {
|
|
|
186
219
|
mkdirSync(outDir, { recursive: true });
|
|
187
220
|
const authArgs = await buildAuthArgs(config);
|
|
188
221
|
const apps = Object.entries(config.apps);
|
|
222
|
+
// format: trueの場合のみPrettierを使用
|
|
223
|
+
const usePrettier = config.format === true && isPrettierAvailable();
|
|
189
224
|
console.info(chalk.cyan(`Generating type definitions for ${apps.length} app(s)...`));
|
|
190
225
|
// 順次実行(並列だとコンソール出力が混在する)
|
|
191
226
|
const results = [];
|
|
192
227
|
for (const [appName, appId] of apps) {
|
|
193
228
|
const result = await generateForApp(appName, appId, config, authArgs, outDir);
|
|
194
229
|
results.push(result);
|
|
230
|
+
// 成功したファイルをPrettierでフォーマット
|
|
231
|
+
if (result.success && usePrettier) {
|
|
232
|
+
await formatWithPrettier(result.output);
|
|
233
|
+
}
|
|
195
234
|
}
|
|
196
235
|
const successCount = results.filter((r) => r.success).length;
|
|
197
236
|
const failCount = results.length - successCount;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type PasswordAuth = {
|
|
2
2
|
type: 'password';
|
|
3
|
+
username?: string;
|
|
4
|
+
password?: string;
|
|
3
5
|
};
|
|
4
6
|
export type OAuthAuth = {
|
|
5
7
|
type: 'oauth';
|
|
@@ -7,7 +9,7 @@ export type OAuthAuth = {
|
|
|
7
9
|
};
|
|
8
10
|
export type ApiTokenAuth = {
|
|
9
11
|
type: 'api-token';
|
|
10
|
-
token
|
|
12
|
+
token?: string;
|
|
11
13
|
};
|
|
12
14
|
export type Auth = PasswordAuth | OAuthAuth | ApiTokenAuth;
|
|
13
15
|
export type ProxyConfig = {
|
|
@@ -37,5 +39,6 @@ export type Config = {
|
|
|
37
39
|
preview?: boolean;
|
|
38
40
|
guestSpaceId?: number;
|
|
39
41
|
namespace?: string;
|
|
42
|
+
format?: boolean;
|
|
40
43
|
};
|
|
41
44
|
export declare const defineConfig: (config: Config) => Config;
|
package/package.json
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goqoo/trunks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A CLI wrapper for @kintone/dts-gen that generates type definitions for multiple Kintone apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"package.json"
|
|
17
|
+
],
|
|
7
18
|
"bin": {
|
|
8
19
|
"trunks": "dist/cli.js"
|
|
9
20
|
},
|
|
@@ -37,6 +48,7 @@
|
|
|
37
48
|
"chalk": "^5.4.0",
|
|
38
49
|
"change-case": "^5.4.0",
|
|
39
50
|
"commander": "^13.0.0",
|
|
51
|
+
"dotenv": "^17.3.1",
|
|
40
52
|
"gyuma": "^0.6.1",
|
|
41
53
|
"jiti": "^2.4.0"
|
|
42
54
|
}
|
package/.prettierignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*.md
|
package/.prettierrc.js
DELETED
package/CLAUDE.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## プロジェクト概要
|
|
6
|
-
|
|
7
|
-
@goqoo/trunks - `@kintone/dts-gen`のラッパーCLIツール。
|
|
8
|
-
|
|
9
|
-
### 背景・目的
|
|
10
|
-
|
|
11
|
-
`@kintone/dts-gen`は優れた型定義ファイルを生成するが、CLIとしての使い勝手に課題がある(特に複数アプリの一括生成ができない)。このツールは設定ファイルベースで複数アプリの型定義を一括生成する。
|
|
12
|
-
|
|
13
|
-
### 参考実装
|
|
14
|
-
|
|
15
|
-
[goqoo/src/generator/dts/index.ts](https://github.com/goqoo-on-kintone/goqoo/blob/main/src/generator/dts/index.ts) の機能を単独抽出したもの。
|
|
16
|
-
|
|
17
|
-
goqooでの処理フロー:
|
|
18
|
-
1. 設定ファイルから対象環境を特定
|
|
19
|
-
2. OAuth or ユーザー名/パスワード認証を設定
|
|
20
|
-
3. `appId`オブジェクトをループして各アプリに対し`npx kintone-dts-gen`を実行
|
|
21
|
-
4. 出力ファイル名はkebab-case、型名はPascalCaseで自動生成
|
|
22
|
-
|
|
23
|
-
### 設定ファイル構造
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
type Config = {
|
|
27
|
-
host: string // Kintone環境のホスト(例: "example.cybozu.com")
|
|
28
|
-
apps: Record<string, number> // { appName: appId }
|
|
29
|
-
auth:
|
|
30
|
-
| { type: 'password' } // 環境変数 KINTONE_USERNAME, KINTONE_PASSWORD
|
|
31
|
-
| { type: 'oauth'; scope?: string } // OAuth認証
|
|
32
|
-
| { type: 'api-token'; token: string } // APIトークン
|
|
33
|
-
proxy?: { host: string; port: number } // プロキシ設定(任意)
|
|
34
|
-
basicAuth?: { username: string; password: string } // Basic認証(任意)
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## 開発コマンド
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
yarn install # パッケージインストール
|
|
42
|
-
yarn build # TypeScriptビルド
|
|
43
|
-
yarn dev # ウォッチモードでビルド
|
|
44
|
-
yarn test # テスト実行(Jest + ESM)
|
|
45
|
-
yarn test:watch # ウォッチモードでテスト
|
|
46
|
-
yarn prettier --write . # コードフォーマット
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## ソース構造
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
src/
|
|
53
|
-
├── cli.ts # CLIエントリーポイント(Commander.js)
|
|
54
|
-
├── config.ts # 設定ファイル読み込み(jiti使用)
|
|
55
|
-
├── generate.ts # dts-gen実行処理
|
|
56
|
-
├── index.ts # エクスポート
|
|
57
|
-
└── types.ts # 型定義・defineConfig
|
|
58
|
-
|
|
59
|
-
test/
|
|
60
|
-
├── config.test.ts # configのテスト
|
|
61
|
-
├── generate.test.ts # generateのテスト
|
|
62
|
-
└── types.test.ts # typesのテスト
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 技術スタック
|
|
66
|
-
|
|
67
|
-
- **ランタイム:** Node.js >= 20
|
|
68
|
-
- **パッケージマネージャー:** Yarn
|
|
69
|
-
- **主要依存:** @kintone/dts-gen, Commander.js, jiti, change-case, chalk
|
|
70
|
-
- **テスト:** Jest + ts-jest(ESMモード)
|
|
71
|
-
- **フォーマッタ:** Prettier(シングルクォート、120文字/行)
|