@goqoo/trunks 0.1.0 → 0.2.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/.prettierrc.cjs +6 -0
- package/dist/generate.js +30 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/generate.ts +36 -1
- package/src/types.ts +2 -0
- package/trunks.config.ts +1 -0
- package/.prettierrc.js +0 -5
- package/dts/project-fields.d.ts +0 -30
package/.prettierrc.cjs
ADDED
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({
|
|
@@ -186,12 +209,18 @@ export async function generate(config) {
|
|
|
186
209
|
mkdirSync(outDir, { recursive: true });
|
|
187
210
|
const authArgs = await buildAuthArgs(config);
|
|
188
211
|
const apps = Object.entries(config.apps);
|
|
212
|
+
// format: trueの場合のみPrettierを使用
|
|
213
|
+
const usePrettier = config.format === true && isPrettierAvailable();
|
|
189
214
|
console.info(chalk.cyan(`Generating type definitions for ${apps.length} app(s)...`));
|
|
190
215
|
// 順次実行(並列だとコンソール出力が混在する)
|
|
191
216
|
const results = [];
|
|
192
217
|
for (const [appName, appId] of apps) {
|
|
193
218
|
const result = await generateForApp(appName, appId, config, authArgs, outDir);
|
|
194
219
|
results.push(result);
|
|
220
|
+
// 成功したファイルをPrettierでフォーマット
|
|
221
|
+
if (result.success && usePrettier) {
|
|
222
|
+
await formatWithPrettier(result.output);
|
|
223
|
+
}
|
|
195
224
|
}
|
|
196
225
|
const successCount = results.filter((r) => r.success).length;
|
|
197
226
|
const failCount = results.length - successCount;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/generate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
@@ -6,6 +6,33 @@ import { kebabCase, pascalCase } from 'change-case';
|
|
|
6
6
|
import type { AgentOptions, Config } from './types.js';
|
|
7
7
|
import { getOauthToken } from './oauth.js';
|
|
8
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
|
+
|
|
9
36
|
type DtsGenArgs = Record<string, string | undefined>;
|
|
10
37
|
|
|
11
38
|
// 標準入力からテキストを取得
|
|
@@ -218,6 +245,9 @@ export async function generate(config: Config): Promise<void> {
|
|
|
218
245
|
const authArgs = await buildAuthArgs(config);
|
|
219
246
|
const apps = Object.entries(config.apps);
|
|
220
247
|
|
|
248
|
+
// format: trueの場合のみPrettierを使用
|
|
249
|
+
const usePrettier = config.format === true && isPrettierAvailable();
|
|
250
|
+
|
|
221
251
|
console.info(chalk.cyan(`Generating type definitions for ${apps.length} app(s)...`));
|
|
222
252
|
|
|
223
253
|
// 順次実行(並列だとコンソール出力が混在する)
|
|
@@ -225,6 +255,11 @@ export async function generate(config: Config): Promise<void> {
|
|
|
225
255
|
for (const [appName, appId] of apps) {
|
|
226
256
|
const result = await generateForApp(appName, appId, config, authArgs, outDir);
|
|
227
257
|
results.push(result);
|
|
258
|
+
|
|
259
|
+
// 成功したファイルをPrettierでフォーマット
|
|
260
|
+
if (result.success && usePrettier) {
|
|
261
|
+
await formatWithPrettier(result.output);
|
|
262
|
+
}
|
|
228
263
|
}
|
|
229
264
|
|
|
230
265
|
const successCount = results.filter((r) => r.success).length;
|
package/src/types.ts
CHANGED
package/trunks.config.ts
CHANGED
package/.prettierrc.js
DELETED
package/dts/project-fields.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
declare namespace kintone.types {
|
|
2
|
-
interface ProjectFields {
|
|
3
|
-
提案商品: kintone.fieldTypes.DropDown;
|
|
4
|
-
アクション内容: kintone.fieldTypes.SingleLineText;
|
|
5
|
-
詳細: kintone.fieldTypes.MultiLineText;
|
|
6
|
-
案件名: kintone.fieldTypes.SingleLineText;
|
|
7
|
-
売上: kintone.fieldTypes.Number;
|
|
8
|
-
会社名: kintone.fieldTypes.SingleLineText;
|
|
9
|
-
商談フェーズ: kintone.fieldTypes.DropDown;
|
|
10
|
-
次回アクション日: kintone.fieldTypes.Date;
|
|
11
|
-
確度: kintone.fieldTypes.DropDown;
|
|
12
|
-
受注予定日: kintone.fieldTypes.Date;
|
|
13
|
-
顧客No_: kintone.fieldTypes.Number;
|
|
14
|
-
初回商談日: kintone.fieldTypes.Date;
|
|
15
|
-
|
|
16
|
-
アクション担当者: kintone.fieldTypes.UserSelect;
|
|
17
|
-
主担当: kintone.fieldTypes.UserSelect;
|
|
18
|
-
主担当組織: kintone.fieldTypes.OrganizationSelect;
|
|
19
|
-
契約書_申込書: kintone.fieldTypes.File;
|
|
20
|
-
}
|
|
21
|
-
interface SavedProjectFields extends ProjectFields {
|
|
22
|
-
$id: kintone.fieldTypes.Id;
|
|
23
|
-
$revision: kintone.fieldTypes.Revision;
|
|
24
|
-
更新者: kintone.fieldTypes.Modifier;
|
|
25
|
-
作成者: kintone.fieldTypes.Creator;
|
|
26
|
-
案件No_: kintone.fieldTypes.RecordNumber;
|
|
27
|
-
更新日時: kintone.fieldTypes.UpdatedTime;
|
|
28
|
-
作成日時: kintone.fieldTypes.CreatedTime;
|
|
29
|
-
}
|
|
30
|
-
}
|