@goqoo/trunks 0.2.0 → 1.0.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 -0
- package/README.ja.md +214 -0
- package/README.md +214 -0
- package/dist/cli.js +8 -1
- package/dist/generate.js +15 -5
- package/dist/types.d.ts +3 -1
- package/package.json +18 -1
- package/.claude/settings.local.json +0 -7
- package/.prettierignore +0 -1
- package/.prettierrc.cjs +0 -6
- package/CLAUDE.md +0 -71
- package/dts/activity-fields.d.ts +0 -25
- package/dts/customer-fields.d.ts +0 -28
- package/jest.config.js +0 -19
- package/src/cli.ts +0 -28
- package/src/config.ts +0 -23
- package/src/generate.ts +0 -273
- package/src/index.ts +0 -14
- package/src/oauth.ts +0 -14
- package/src/types.ts +0 -65
- 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 -19
- package/tsconfig.json +0 -16
package/dts/customer-fields.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
declare namespace kintone.types {
|
|
2
|
-
interface CustomerFields {
|
|
3
|
-
顧客情報メモ欄: kintone.fieldTypes.MultiLineText;
|
|
4
|
-
文字列__1行_: kintone.fieldTypes.SingleLineText;
|
|
5
|
-
Webサイト: kintone.fieldTypes.Link;
|
|
6
|
-
建物名: kintone.fieldTypes.SingleLineText;
|
|
7
|
-
顧客ランク: kintone.fieldTypes.RadioButton;
|
|
8
|
-
支払日: kintone.fieldTypes.DropDown;
|
|
9
|
-
住所: kintone.fieldTypes.SingleLineText;
|
|
10
|
-
電話番号: kintone.fieldTypes.Link;
|
|
11
|
-
会社名: kintone.fieldTypes.SingleLineText;
|
|
12
|
-
郵便番号: kintone.fieldTypes.SingleLineText;
|
|
13
|
-
業種: kintone.fieldTypes.DropDown;
|
|
14
|
-
文字列__1行__0: kintone.fieldTypes.SingleLineText;
|
|
15
|
-
都道府県: kintone.fieldTypes.DropDown;
|
|
16
|
-
締め日: kintone.fieldTypes.DropDown;
|
|
17
|
-
FAX: kintone.fieldTypes.Link;
|
|
18
|
-
}
|
|
19
|
-
interface SavedCustomerFields extends CustomerFields {
|
|
20
|
-
$id: kintone.fieldTypes.Id;
|
|
21
|
-
$revision: kintone.fieldTypes.Revision;
|
|
22
|
-
更新者: kintone.fieldTypes.Modifier;
|
|
23
|
-
作成者: kintone.fieldTypes.Creator;
|
|
24
|
-
顧客No: kintone.fieldTypes.RecordNumber;
|
|
25
|
-
更新日時: kintone.fieldTypes.UpdatedTime;
|
|
26
|
-
作成日時: kintone.fieldTypes.CreatedTime;
|
|
27
|
-
}
|
|
28
|
-
}
|
package/jest.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
export default {
|
|
3
|
-
preset: 'ts-jest/presets/default-esm',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
extensionsToTreatAsEsm: ['.ts'],
|
|
6
|
-
moduleNameMapper: {
|
|
7
|
-
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
8
|
-
},
|
|
9
|
-
transform: {
|
|
10
|
-
'^.+\\.ts$': [
|
|
11
|
-
'ts-jest',
|
|
12
|
-
{
|
|
13
|
-
useESM: true,
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
testMatch: ['<rootDir>/test/**/*.test.ts'],
|
|
18
|
-
collectCoverageFrom: ['src/**/*.ts', '!src/cli.ts'],
|
|
19
|
-
};
|
package/src/cli.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { loadConfig } from './config.js';
|
|
5
|
-
import { generate } from './generate.js';
|
|
6
|
-
|
|
7
|
-
const program = new Command();
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.name('trunks')
|
|
11
|
-
.description('Generate TypeScript type definitions for multiple Kintone apps')
|
|
12
|
-
.version('0.1.0');
|
|
13
|
-
|
|
14
|
-
program
|
|
15
|
-
.command('generate', { isDefault: true })
|
|
16
|
-
.description('Generate type definitions for all configured apps')
|
|
17
|
-
.option('-c, --config <path>', 'Path to config file')
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
try {
|
|
20
|
-
const config = await loadConfig(options.config ? undefined : process.cwd());
|
|
21
|
-
await generate(config);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : error);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
program.parse();
|
package/src/config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'fs';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { createJiti } from 'jiti';
|
|
4
|
-
import type { Config } from './types.js';
|
|
5
|
-
|
|
6
|
-
const CONFIG_FILES = ['trunks.config.ts', 'trunks.config.js', 'trunks.config.mjs'];
|
|
7
|
-
|
|
8
|
-
// 設定ファイルを検索して読み込む
|
|
9
|
-
export async function loadConfig(cwd: string = process.cwd()): Promise<Config> {
|
|
10
|
-
const jiti = createJiti(cwd, { interopDefault: true });
|
|
11
|
-
|
|
12
|
-
for (const filename of CONFIG_FILES) {
|
|
13
|
-
const configPath = resolve(cwd, filename);
|
|
14
|
-
if (existsSync(configPath)) {
|
|
15
|
-
const config = await jiti.import(configPath);
|
|
16
|
-
return config as Config;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Config file not found. Create one of: ${CONFIG_FILES.join(', ')}`
|
|
22
|
-
);
|
|
23
|
-
}
|
package/src/generate.ts
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from 'child_process';
|
|
2
|
-
import { mkdirSync } from 'fs';
|
|
3
|
-
import * as readline from 'readline';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { kebabCase, pascalCase } from 'change-case';
|
|
6
|
-
import type { AgentOptions, Config } from './types.js';
|
|
7
|
-
import { getOauthToken } from './oauth.js';
|
|
8
|
-
|
|
9
|
-
// npx prettierが実行可能かチェック
|
|
10
|
-
function isPrettierAvailable(): boolean {
|
|
11
|
-
const result = spawnSync('npx', ['prettier', '--version'], {
|
|
12
|
-
stdio: 'pipe',
|
|
13
|
-
encoding: 'utf-8',
|
|
14
|
-
});
|
|
15
|
-
return result.status === 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Prettierでファイルをフォーマット
|
|
19
|
-
function formatWithPrettier(filePath: string): Promise<boolean> {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
const proc = spawn('npx', ['prettier', '--write', filePath], {
|
|
22
|
-
cwd: process.cwd(),
|
|
23
|
-
stdio: 'pipe',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
proc.on('close', (code) => {
|
|
27
|
-
resolve(code === 0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
proc.on('error', () => {
|
|
31
|
-
resolve(false);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type DtsGenArgs = Record<string, string | undefined>;
|
|
37
|
-
|
|
38
|
-
// 標準入力からテキストを取得
|
|
39
|
-
function prompt(question: string): Promise<string> {
|
|
40
|
-
const rl = readline.createInterface({
|
|
41
|
-
input: process.stdin,
|
|
42
|
-
output: process.stdout,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return new Promise((resolve) => {
|
|
46
|
-
rl.question(question, (answer) => {
|
|
47
|
-
rl.close();
|
|
48
|
-
resolve(answer);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 標準入力からパスワードを取得(入力を隠す)
|
|
54
|
-
function promptPassword(question: string): Promise<string> {
|
|
55
|
-
return new Promise((resolve) => {
|
|
56
|
-
process.stdout.write(question);
|
|
57
|
-
|
|
58
|
-
const stdin = process.stdin;
|
|
59
|
-
if (!stdin.isTTY) {
|
|
60
|
-
// TTYでない場合は通常の入力
|
|
61
|
-
const rl = readline.createInterface({ input: stdin, output: process.stdout });
|
|
62
|
-
rl.question('', (answer) => {
|
|
63
|
-
rl.close();
|
|
64
|
-
resolve(answer);
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// TTYの場合はraw modeで入力を隠す
|
|
70
|
-
stdin.setRawMode(true);
|
|
71
|
-
stdin.resume();
|
|
72
|
-
stdin.setEncoding('utf8');
|
|
73
|
-
|
|
74
|
-
let password = '';
|
|
75
|
-
const onData = (char: string) => {
|
|
76
|
-
if (char === '\n' || char === '\r' || char === '\u0004') {
|
|
77
|
-
// Enter or Ctrl+D
|
|
78
|
-
stdin.setRawMode(false);
|
|
79
|
-
stdin.removeListener('data', onData);
|
|
80
|
-
stdin.pause();
|
|
81
|
-
process.stdout.write('\n');
|
|
82
|
-
resolve(password);
|
|
83
|
-
} else if (char === '\u0003') {
|
|
84
|
-
// Ctrl+C
|
|
85
|
-
stdin.setRawMode(false);
|
|
86
|
-
process.stdout.write('\n');
|
|
87
|
-
process.exit(1);
|
|
88
|
-
} else if (char === '\u007F' || char === '\b') {
|
|
89
|
-
// Backspace
|
|
90
|
-
password = password.slice(0, -1);
|
|
91
|
-
} else {
|
|
92
|
-
password += char;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
stdin.on('data', onData);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 認証引数を構築
|
|
101
|
-
async function buildAuthArgs(config: Config): Promise<DtsGenArgs> {
|
|
102
|
-
const args: DtsGenArgs = {};
|
|
103
|
-
|
|
104
|
-
switch (config.auth.type) {
|
|
105
|
-
case 'password': {
|
|
106
|
-
let username = process.env.KINTONE_USERNAME;
|
|
107
|
-
let password = process.env.KINTONE_PASSWORD;
|
|
108
|
-
|
|
109
|
-
// 環境変数が未設定の場合は標準入力で取得
|
|
110
|
-
if (!username) {
|
|
111
|
-
username = await prompt('Kintone Username: ');
|
|
112
|
-
}
|
|
113
|
-
if (!password) {
|
|
114
|
-
password = await promptPassword('Kintone Password: ');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!username || !password) {
|
|
118
|
-
throw new Error('Username and password are required for password auth');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
args['username'] = username;
|
|
122
|
-
args['password'] = password;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
case 'oauth': {
|
|
126
|
-
// Gyumaを使ってOAuthトークンを取得
|
|
127
|
-
const agentOptions: AgentOptions = {
|
|
128
|
-
proxy: config.proxy ? `http://${config.proxy.host}:${config.proxy.port}` : undefined,
|
|
129
|
-
pfx: config.pfx,
|
|
130
|
-
};
|
|
131
|
-
const oauthToken = await getOauthToken(config.host, config.auth.scope, agentOptions);
|
|
132
|
-
args['oauth-token'] = oauthToken;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
case 'api-token':
|
|
136
|
-
args['api-token'] = config.auth.token;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Basic認証
|
|
141
|
-
if (config.basicAuth) {
|
|
142
|
-
args['basic-auth-username'] = config.basicAuth.username;
|
|
143
|
-
args['basic-auth-password'] = config.basicAuth.password;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// プロキシ
|
|
147
|
-
if (config.proxy) {
|
|
148
|
-
args['proxy'] = `http://${config.proxy.host}:${config.proxy.port}`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return args;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// kintoneのエラーレスポンスを抽出
|
|
155
|
-
function extractKintoneError(output: string): { code: string; id: string; message: string } | null {
|
|
156
|
-
// 形式: code: 'GAIA_AP15' または "code": "GAIA_AP15"
|
|
157
|
-
const codeMatch = output.match(/code:\s*'([^']+)'/) ?? output.match(/"code":\s*"([^"]+)"/);
|
|
158
|
-
const idMatch = output.match(/id:\s*'([^']+)'/) ?? output.match(/"id":\s*"([^"]+)"/);
|
|
159
|
-
const messageMatch = output.match(/message:\s*'([^']+)'/) ?? output.match(/"message":\s*"([^"]+)"/);
|
|
160
|
-
|
|
161
|
-
const code = codeMatch?.[1];
|
|
162
|
-
const id = idMatch?.[1];
|
|
163
|
-
const message = messageMatch?.[1];
|
|
164
|
-
|
|
165
|
-
if (code && message) {
|
|
166
|
-
return { code, id: id ?? '', message };
|
|
167
|
-
}
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// 単一アプリの型定義を生成
|
|
172
|
-
function generateForApp(
|
|
173
|
-
appName: string,
|
|
174
|
-
appId: number,
|
|
175
|
-
config: Config,
|
|
176
|
-
authArgs: DtsGenArgs,
|
|
177
|
-
outDir: string
|
|
178
|
-
): Promise<{ success: boolean; output: string }> {
|
|
179
|
-
return new Promise((resolve) => {
|
|
180
|
-
const outputPath = `${outDir}/${kebabCase(appName)}-fields.d.ts`;
|
|
181
|
-
const args: DtsGenArgs = {
|
|
182
|
-
'base-url': `https://${config.host}`,
|
|
183
|
-
...authArgs,
|
|
184
|
-
'type-name': `${pascalCase(appName)}Fields`,
|
|
185
|
-
'app-id': String(appId),
|
|
186
|
-
'output': outputPath,
|
|
187
|
-
'guest-space-id': config.guestSpaceId !== undefined ? String(config.guestSpaceId) : undefined,
|
|
188
|
-
'namespace': config.namespace,
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// undefined値をフィルタリングして引数配列を作成
|
|
192
|
-
const cliArgs = Object.entries(args)
|
|
193
|
-
.filter(([, value]) => value !== undefined)
|
|
194
|
-
.map(([key, value]) => `--${key}=${value}`);
|
|
195
|
-
|
|
196
|
-
// プレビュー環境の場合は--previewフラグを追加
|
|
197
|
-
if (config.preview) {
|
|
198
|
-
cliArgs.push('--preview');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const proc = spawn('npx', ['kintone-dts-gen', ...cliArgs], {
|
|
202
|
-
cwd: process.cwd(),
|
|
203
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
let stdout = '';
|
|
207
|
-
let stderr = '';
|
|
208
|
-
proc.stdout?.on('data', (data) => {
|
|
209
|
-
stdout += data.toString();
|
|
210
|
-
});
|
|
211
|
-
proc.stderr?.on('data', (data) => {
|
|
212
|
-
stderr += data.toString();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
proc.on('close', (code) => {
|
|
216
|
-
if (code !== 0) {
|
|
217
|
-
// stdoutとstderr両方からエラー情報を探す
|
|
218
|
-
const output = stdout + stderr;
|
|
219
|
-
const kintoneError = extractKintoneError(output);
|
|
220
|
-
if (kintoneError) {
|
|
221
|
-
console.error(chalk.red(`Error [${appName}]:`), kintoneError.message);
|
|
222
|
-
console.error(chalk.gray(` code: ${kintoneError.code}, id: ${kintoneError.id}`));
|
|
223
|
-
} else {
|
|
224
|
-
console.error(chalk.red(`Error [${appName}]:`), `kintone-dts-gen exited with code ${code}`);
|
|
225
|
-
}
|
|
226
|
-
resolve({ success: false, output: outputPath });
|
|
227
|
-
} else {
|
|
228
|
-
console.info(`${chalk.cyan('info')} ${chalk.magenta('Created')} ${chalk.green(outputPath)}`);
|
|
229
|
-
resolve({ success: true, output: outputPath });
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
proc.on('error', (err) => {
|
|
234
|
-
console.error(chalk.red(`Error [${appName}]:`), err.message);
|
|
235
|
-
resolve({ success: false, output: outputPath });
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// 全アプリの型定義を生成
|
|
241
|
-
export async function generate(config: Config): Promise<void> {
|
|
242
|
-
const outDir = config.outDir ?? 'dts';
|
|
243
|
-
mkdirSync(outDir, { recursive: true });
|
|
244
|
-
|
|
245
|
-
const authArgs = await buildAuthArgs(config);
|
|
246
|
-
const apps = Object.entries(config.apps);
|
|
247
|
-
|
|
248
|
-
// format: trueの場合のみPrettierを使用
|
|
249
|
-
const usePrettier = config.format === true && isPrettierAvailable();
|
|
250
|
-
|
|
251
|
-
console.info(chalk.cyan(`Generating type definitions for ${apps.length} app(s)...`));
|
|
252
|
-
|
|
253
|
-
// 順次実行(並列だとコンソール出力が混在する)
|
|
254
|
-
const results: { success: boolean; output: string }[] = [];
|
|
255
|
-
for (const [appName, appId] of apps) {
|
|
256
|
-
const result = await generateForApp(appName, appId, config, authArgs, outDir);
|
|
257
|
-
results.push(result);
|
|
258
|
-
|
|
259
|
-
// 成功したファイルをPrettierでフォーマット
|
|
260
|
-
if (result.success && usePrettier) {
|
|
261
|
-
await formatWithPrettier(result.output);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const successCount = results.filter((r) => r.success).length;
|
|
266
|
-
const failCount = results.length - successCount;
|
|
267
|
-
|
|
268
|
-
if (failCount > 0) {
|
|
269
|
-
console.info(chalk.yellow(`\nCompleted with ${failCount} error(s). (${successCount}/${results.length} succeeded)`));
|
|
270
|
-
} else {
|
|
271
|
-
console.info(chalk.green('Done!'));
|
|
272
|
-
}
|
|
273
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { defineConfig } from './types.js';
|
|
2
|
-
export type {
|
|
3
|
-
Config,
|
|
4
|
-
Auth,
|
|
5
|
-
PasswordAuth,
|
|
6
|
-
OAuthAuth,
|
|
7
|
-
ApiTokenAuth,
|
|
8
|
-
ProxyConfig,
|
|
9
|
-
BasicAuthConfig,
|
|
10
|
-
PfxConfig,
|
|
11
|
-
AgentOptions,
|
|
12
|
-
} from './types.js';
|
|
13
|
-
export { loadConfig } from './config.js';
|
|
14
|
-
export { generate } from './generate.js';
|
package/src/oauth.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { gyuma } from 'gyuma';
|
|
2
|
-
import type { AgentOptions } from './types.js';
|
|
3
|
-
|
|
4
|
-
// dts-genはフィールド情報を読み取るので k:app_settings:read が必要
|
|
5
|
-
const DEFAULT_SCOPE = 'k:app_settings:read';
|
|
6
|
-
|
|
7
|
-
export const getOauthToken = async (
|
|
8
|
-
domain: string,
|
|
9
|
-
scope: string | undefined,
|
|
10
|
-
agentOptions: AgentOptions
|
|
11
|
-
): Promise<string> => {
|
|
12
|
-
const token = await gyuma({ domain, scope: scope ?? DEFAULT_SCOPE, ...agentOptions }, true);
|
|
13
|
-
return token;
|
|
14
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// 認証設定
|
|
2
|
-
export type PasswordAuth = {
|
|
3
|
-
type: 'password';
|
|
4
|
-
// 環境変数 KINTONE_USERNAME, KINTONE_PASSWORD から取得
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type OAuthAuth = {
|
|
8
|
-
type: 'oauth';
|
|
9
|
-
scope?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type ApiTokenAuth = {
|
|
13
|
-
type: 'api-token';
|
|
14
|
-
token: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type Auth = PasswordAuth | OAuthAuth | ApiTokenAuth;
|
|
18
|
-
|
|
19
|
-
// プロキシ設定
|
|
20
|
-
export type ProxyConfig = {
|
|
21
|
-
host: string;
|
|
22
|
-
port: number;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Basic認証設定
|
|
26
|
-
export type BasicAuthConfig = {
|
|
27
|
-
username: string;
|
|
28
|
-
password: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// クライアント証明書設定(PFX/PKCS#12形式)
|
|
32
|
-
export type PfxConfig = {
|
|
33
|
-
filepath: string;
|
|
34
|
-
password: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Gyuma用のエージェントオプション
|
|
38
|
-
export type AgentOptions = {
|
|
39
|
-
proxy?: string;
|
|
40
|
-
pfx?: PfxConfig;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// メイン設定
|
|
44
|
-
export type Config = {
|
|
45
|
-
host: string; // Kintone環境のホスト(例: "example.cybozu.com")
|
|
46
|
-
apps: Record<string, number>; // { appName: appId }
|
|
47
|
-
auth: Auth;
|
|
48
|
-
proxy?: ProxyConfig;
|
|
49
|
-
basicAuth?: BasicAuthConfig;
|
|
50
|
-
// クライアント証明書(OAuth使用時にGyumaへ渡す)
|
|
51
|
-
pfx?: PfxConfig;
|
|
52
|
-
// 出力ディレクトリ(デフォルト: "dts")
|
|
53
|
-
outDir?: string;
|
|
54
|
-
// プレビュー環境を参照する場合はtrue(デフォルト: false)
|
|
55
|
-
preview?: boolean;
|
|
56
|
-
// ゲストスペースID(ゲストスペース内のアプリの場合に指定)
|
|
57
|
-
guestSpaceId?: number;
|
|
58
|
-
// 生成する型のnamespace(デフォルト: "kintone.types")
|
|
59
|
-
namespace?: string;
|
|
60
|
-
// 生成後にPrettierでフォーマットするか(デフォルト: false)
|
|
61
|
-
format?: boolean;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// 設定ファイルの型(defineConfigのため)
|
|
65
|
-
export const defineConfig = (config: Config): Config => config;
|
package/test/config.test.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from '@jest/globals';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
|
-
import { loadConfig } from '../src/config';
|
|
5
|
-
|
|
6
|
-
describe('loadConfig', () => {
|
|
7
|
-
it('設定ファイルが見つからない場合はエラーをスローする', async () => {
|
|
8
|
-
// 存在しないディレクトリを指定
|
|
9
|
-
await expect(loadConfig('/non-existent-dir-12345')).rejects.toThrow('Config file not found');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('エラーメッセージに設定ファイル名の候補を含む', async () => {
|
|
13
|
-
await expect(loadConfig('/non-existent-dir-12345')).rejects.toThrow('trunks.config.ts');
|
|
14
|
-
});
|
|
15
|
-
});
|
package/test/generate.test.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
2
|
-
import { generate } from '../src/generate';
|
|
3
|
-
import type { Config } from '../src/types';
|
|
4
|
-
|
|
5
|
-
describe('generate', () => {
|
|
6
|
-
const originalEnv = process.env;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
process.env = { ...originalEnv };
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
process.env = originalEnv;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// NOTE: パスワード認証で環境変数が未設定の場合は標準入力を求めるため、
|
|
17
|
-
// 自動テストでは検証が困難。手動テストで確認する。
|
|
18
|
-
|
|
19
|
-
// NOTE: OAuth認証はGyumaがブラウザを開いて認証フローを実行するため、
|
|
20
|
-
// 自動テストでは検証が困難。手動テストで確認する。
|
|
21
|
-
|
|
22
|
-
it('appsが空の場合でもエラーにならない', async () => {
|
|
23
|
-
const config: Config = {
|
|
24
|
-
host: 'example.cybozu.com',
|
|
25
|
-
apps: {},
|
|
26
|
-
auth: { type: 'api-token', token: 'test' },
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// appsが空なのでspawnは呼ばれず、正常終了するはず
|
|
30
|
-
await expect(generate(config)).resolves.toBeUndefined();
|
|
31
|
-
});
|
|
32
|
-
});
|
package/test/types.test.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from '@jest/globals';
|
|
2
|
-
import { defineConfig } from '../src/types';
|
|
3
|
-
import type { Config } from '../src/types';
|
|
4
|
-
|
|
5
|
-
describe('defineConfig', () => {
|
|
6
|
-
it('パスワード認証の設定を返す', () => {
|
|
7
|
-
const config = defineConfig({
|
|
8
|
-
host: 'example.cybozu.com',
|
|
9
|
-
apps: { customer: 1, order: 2 },
|
|
10
|
-
auth: { type: 'password' },
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
expect(config.host).toBe('example.cybozu.com');
|
|
14
|
-
expect(config.apps).toEqual({ customer: 1, order: 2 });
|
|
15
|
-
expect(config.auth.type).toBe('password');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('APIトークン認証の設定を返す', () => {
|
|
19
|
-
const config = defineConfig({
|
|
20
|
-
host: 'example.cybozu.com',
|
|
21
|
-
apps: { customer: 1 },
|
|
22
|
-
auth: { type: 'api-token', token: 'test-token' },
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
expect(config.auth.type).toBe('api-token');
|
|
26
|
-
if (config.auth.type === 'api-token') {
|
|
27
|
-
expect(config.auth.token).toBe('test-token');
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('OAuth認証の設定を返す', () => {
|
|
32
|
-
const config = defineConfig({
|
|
33
|
-
host: 'example.cybozu.com',
|
|
34
|
-
apps: { customer: 1 },
|
|
35
|
-
auth: { type: 'oauth', scope: 'k:app_record:read' },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(config.auth.type).toBe('oauth');
|
|
39
|
-
if (config.auth.type === 'oauth') {
|
|
40
|
-
expect(config.auth.scope).toBe('k:app_record:read');
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('オプション設定を含む設定を返す', () => {
|
|
45
|
-
const config = defineConfig({
|
|
46
|
-
host: 'example.cybozu.com',
|
|
47
|
-
apps: { customer: 1 },
|
|
48
|
-
auth: { type: 'password' },
|
|
49
|
-
proxy: { host: 'proxy.example.com', port: 8080 },
|
|
50
|
-
basicAuth: { username: 'user', password: 'pass' },
|
|
51
|
-
outDir: 'types',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(config.proxy).toEqual({ host: 'proxy.example.com', port: 8080 });
|
|
55
|
-
expect(config.basicAuth).toEqual({ username: 'user', password: 'pass' });
|
|
56
|
-
expect(config.outDir).toBe('types');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('プレビュー環境の設定を返す', () => {
|
|
60
|
-
const config = defineConfig({
|
|
61
|
-
host: 'example.cybozu.com',
|
|
62
|
-
apps: { customer: 1 },
|
|
63
|
-
auth: { type: 'api-token', token: 'test-token' },
|
|
64
|
-
preview: true,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
expect(config.preview).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('ゲストスペースの設定を返す', () => {
|
|
71
|
-
const config = defineConfig({
|
|
72
|
-
host: 'example.cybozu.com',
|
|
73
|
-
apps: { customer: 1 },
|
|
74
|
-
auth: { type: 'api-token', token: 'test-token' },
|
|
75
|
-
guestSpaceId: 5,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(config.guestSpaceId).toBe(5);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('namespaceの設定を返す', () => {
|
|
82
|
-
const config = defineConfig({
|
|
83
|
-
host: 'example.cybozu.com',
|
|
84
|
-
apps: { customer: 1 },
|
|
85
|
-
auth: { type: 'api-token', token: 'test-token' },
|
|
86
|
-
namespace: 'myapp.types',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(config.namespace).toBe('myapp.types');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('型チェックが正しく機能する', () => {
|
|
93
|
-
// 型レベルでのテスト(コンパイルが通ればOK)
|
|
94
|
-
const passwordConfig: Config = {
|
|
95
|
-
host: 'example.cybozu.com',
|
|
96
|
-
apps: { app1: 1 },
|
|
97
|
-
auth: { type: 'password' },
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const apiTokenConfig: Config = {
|
|
101
|
-
host: 'example.cybozu.com',
|
|
102
|
-
apps: { app1: 1 },
|
|
103
|
-
auth: { type: 'api-token', token: 'xxx' },
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const oauthConfig: Config = {
|
|
107
|
-
host: 'example.cybozu.com',
|
|
108
|
-
apps: { app1: 1 },
|
|
109
|
-
auth: { type: 'oauth' },
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
expect(passwordConfig).toBeDefined();
|
|
113
|
-
expect(apiTokenConfig).toBeDefined();
|
|
114
|
-
expect(oauthConfig).toBeDefined();
|
|
115
|
-
});
|
|
116
|
-
});
|
package/trunks.config.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from './src/types'
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
host: 'the-red.cybozu.com',
|
|
5
|
-
format: true,
|
|
6
|
-
preview: false,
|
|
7
|
-
apps: {
|
|
8
|
-
activity: 265,
|
|
9
|
-
customer: 266,
|
|
10
|
-
// project: 267,
|
|
11
|
-
},
|
|
12
|
-
// 以下のいずれかの認証方式を選択
|
|
13
|
-
auth: { type: 'oauth' },
|
|
14
|
-
// または
|
|
15
|
-
// auth: {
|
|
16
|
-
// type: 'api-token',
|
|
17
|
-
// token: '6mrxShdoQdFdN943q9Wg50nr7LxdwMsy1TTFkttF,K6t3rpw8PGoKQm7UPtiG0lyZawUyK0SPyjy4x7wJ',
|
|
18
|
-
// }, // 環境変数 KINTONE_USERNAME, KINTONE_PASSWORD を使用
|
|
19
|
-
})
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"isolatedModules": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"declaration": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"],
|
|
15
|
-
"exclude": ["node_modules", "dist"]
|
|
16
|
-
}
|